Skip to content

bug(semantic): incorrect parents for ArrayAssignmentTarget #4435

@DonIsaac

Description

@DonIsaac

Consider the following JS snippet:

let _a, b;
foo.forEach(item => {
	[_a, b] = item;
	doSomething(b);
});

When the AST is viewed on the playground, _a is in the (seemingly) expected node:

https://oxc-project.github.io/oxc/playground/?code=3YCAAIDGgICAgICAgIC2mcpqpbutXC+Uf72ne1SDCJK4Tn++NlLltohMrXmjZqTqJg1QwG6pQhU2rkclTIa8/2PwyR/FKLiP+NUxD23V6F5UHPN/ezQkgA%3D%3D

However, when I get a reference to _a and iterate through its parents like so:

// here, `reference` is the restructured write on _a (the only reference _a has)
for parent in self.nodes().iter_parents(reference.node_id()) {
    println!("{:#?}", parent.kind().debug_name());
}

I get this output:

"IdentifierReference(_a)"
"SimpleAssignmentTarget"
"AssignmentTarget"
"AssignmentTarget"
"AssignmentExpression"
"ExpressionStatement"
"FunctionBody"
"ArrowFunctionExpression"
"Argument"
"CallExpression"
"ExpressionStatement"
"Program"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions