Files
ladybird/Tests/LibJS/AST/expected/parameter-forms.txt
Andreas Kling 30394ece8d LibJS: Use natural source positions for parser-synthesized identifiers
The Rust parser used to copy several "rule_start"-derived positions
from the C++ implementation: every identifier inside a binding pattern
inherited the pattern's `[`/`{` position, every property identifier
after `.` inherited the period's position, every spread element
inherited the surrounding `[`/`{` position, and identifier-name
property keys inherited the object/class start position. This was
useful while comparing bytecode against the C++ port; with the C++
side gone, those quirks just hide the actual source positions in
source maps and devtools.

Drop the dedicated `binding_pattern_start` parser field and the
`ident_pos_override` parameter on `parse_property_key`, and capture
each identifier's own start position at the consume site.

Add an AST snapshot test that pins the new per-identifier positions
for object, array, nested, and parameter binding patterns.
2026-04-27 08:04:11 +02:00

76 lines
3.0 KiB
Plaintext

Program (script) @1:1
├─ FunctionDeclaration "rest_params" @1:1
│ ├─ parameters
│ │ ├─ Identifier "a" [argument:0] @1:22
│ │ └─ rest
│ │ └─ Identifier "rest" [argument:1] @1:22
│ └─ body
│ └─ FunctionBody @2:5
│ └─ ReturnStatement @2:5
│ └─ BinaryExpression (+) @2:14
│ ├─ Identifier "a" [argument:0] @2:12
│ └─ MemberExpression @2:20
│ ├─ Identifier "rest" [argument:1] @2:16
│ └─ Identifier "length" @2:21
├─ FunctionDeclaration "default_params" @5:1
│ ├─ parameters
│ │ ├─ Identifier "a" [argument:0] @5:25
│ │ └─ Identifier "b" [argument:1] @5:25
│ │ └─ default
│ │ └─ NumericLiteral 10 @5:32
│ └─ body
│ └─ FunctionBody @6:5
│ └─ ReturnStatement @6:5
│ └─ BinaryExpression (+) @6:14
│ ├─ Identifier "a" [argument:0] @6:12
│ └─ Identifier "b" [argument:1] @6:16
├─ FunctionDeclaration "destructured_array" @9:1
│ ├─ parameters
│ │ └─ BindingPattern (array)
│ │ ├─ entry
│ │ │ └─ alias
│ │ │ └─ Identifier "x" [variable:0] @9:30
│ │ └─ entry
│ │ └─ alias
│ │ └─ Identifier "y" [variable:1] @9:33
│ └─ body
│ └─ FunctionBody @10:5
│ └─ ReturnStatement @10:5
│ └─ BinaryExpression (+) @10:14
│ ├─ Identifier "x" [variable:0] @10:12
│ └─ Identifier "y" [variable:1] @10:16
├─ FunctionDeclaration "destructured_object" @13:1
│ ├─ parameters
│ │ └─ BindingPattern (object)
│ │ ├─ entry
│ │ │ └─ name
│ │ │ └─ Identifier "a" [variable:0] @13:32
│ │ └─ entry
│ │ └─ name
│ │ └─ Identifier "b" [variable:1] @13:35
│ └─ body
│ └─ FunctionBody @14:5
│ └─ ReturnStatement @14:5
│ └─ BinaryExpression (+) @14:14
│ ├─ Identifier "a" [variable:0] @14:12
│ └─ Identifier "b" [variable:1] @14:16
└─ FunctionDeclaration "mixed" @17:1
├─ parameters
│ ├─ Identifier "first" [argument:0] @17:16
│ ├─ BindingPattern (object)
│ │ └─ entry
│ │ └─ name
│ │ └─ Identifier "x" [variable:0] @17:25
│ └─ rest
│ └─ Identifier "rest" [argument:2] @17:16
└─ body
└─ FunctionBody @18:5
└─ ReturnStatement @18:5
└─ BinaryExpression (+) @18:22
├─ BinaryExpression (+) @18:18
│ ├─ Identifier "first" [argument:0] @18:12
│ └─ Identifier "x" [variable:0] @18:20
└─ MemberExpression @18:28
├─ Identifier "rest" [argument:2] @18:24
└─ Identifier "length" @18:29