1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! `Loc` implementation for Mozjs.
#![allow(
clippy::enum_glob_use,
clippy::match_same_arms,
clippy::struct_field_names,
clippy::wildcard_imports
)]
#![allow(
clippy::cast_precision_loss,
clippy::cast_possible_truncation,
clippy::cast_sign_loss
)]
use super::*;
impl Loc for MozjsCode {
fn compute(node: &Node, stats: &mut Stats, is_func_space: bool, is_unit: bool) {
use Mozjs::*;
let (start, end) = init(node, stats, is_func_space, is_unit);
match node.kind_id().into() {
String | DQUOTE | Program => {}
// `HtmlComment` is the Annex-B `<!-- -->` comment kind; count
// its rows as CLOC rather than letting them fall to the `_`
// arm and over-count PLOC (#697).
Comment | HtmlComment => {
add_cloc_lines(stats, start, end);
}
// A `template_string` (`` `…` ``) can span multiple rows; credit
// every spanned row to PLOC to match Python's #415 decision (#778).
TemplateString => {
add_multiline_string_ploc(node, stats, start, end);
}
// `StatementBlock` is a syntactic `{ … }` brace grouping, not a
// logical statement, so it is deliberately absent here (#777). It
// falls through to the `_` PLOC catch-all, matching every other
// language: Rust's `Block`, C/C++'s `CompoundStatement`, and
// Java/Groovy/C#'s `Block` all contribute 0 lloc. Counting it
// inflated JS/TS lloc by one per brace block.
ExpressionStatement | ExportStatement | ImportStatement | IfStatement
| SwitchStatement | ForStatement | ForInStatement | WhileStatement | DoStatement
| TryStatement | WithStatement | BreakStatement | ContinueStatement
| DebuggerStatement | ReturnStatement | ThrowStatement | EmptyStatement
| StatementIdentifier => {
stats.lloc.logical_lines += 1;
}
_ => {
check_comment_ends_on_code_line(stats, start);
stats.ploc.lines.insert(start);
}
}
}
}