You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Empty slots in JS for headers count as logical lines, and the pdf.js snapshots are stale #1265
#1143 attributes the pdf.js snapshot differences to a parse error in tree-sitter-javascript, but that's not what's happening. The upstream issue it references (tree-sitter/tree-sitter-javascript#351) was closed as a misreading of the playground output.
What actually changed is the shape of for statements. Since the grammar update in #1141, the initializer and condition of a for (...) header are bare expressions instead of being wrapped in expression_statement nodes:
for (i = 0; i < 4; ++i) {}
(for_statement
(assignment_expression) ; (binary_expression) ; (update_expression)
(statement_block))
Because the JS-family Loc implementations count expression_statement nodes, each for (a; b; c) used to count 3 logical lines and now counts 1. That's in line with how C++ and Java count a for header. With the exclusion list in tests/pdf_js_test.rs removed, the snapshot differences are almost entirely in lloc, lloc_average, lloc_min and lloc_max.
One inconsistency remains: an empty initializer or condition is still an empty_statement node, and empty_statement is counted. So:
code
lloc
for (i = 0; i < 4; ++i) {}
2
for (; i < 4; ++i) {}
3
for (;;) {}
4
The same applies to JavaScript, Mozjs, TypeScript and TSX.
Proposed fix:
don't count an empty_statement whose parent is a for_statement;
Activity