Skip to content

LHS nodes are defined incorrectly in Babel 8 #17384

@RReverser

Description

@RReverser

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

(not applicable)

Configuration file name

No response

Configuration

No response

Current and expected behavior

I noticed that in Babel 8 the node definitions for LHS positions are defined incorrectly, e.g.:

left: {
validate:
!process.env.BABEL_8_BREAKING && !process.env.BABEL_TYPES_8_BREAKING
? assertNodeType("LVal", "OptionalMemberExpression")
: assertNodeType(
"Identifier",
"MemberExpression",
"OptionalMemberExpression",
"ArrayPattern",
"ObjectPattern",
"TSAsExpression",
"TSSatisfiesExpression",
"TSTypeAssertion",
"TSNonNullExpression",
),

and

const declaration = assertNodeType("VariableDeclaration");
const lval = assertNodeType(
"Identifier",
"MemberExpression",
"ArrayPattern",
"ObjectPattern",
"TSAsExpression",
"TSSatisfiesExpression",
"TSTypeAssertion",
"TSNonNullExpression",
);

and

: assertNodeType(
"Identifier",
"MemberExpression",
"OptionalMemberExpression",
"ArrayPattern",
"ObjectPattern",
"TSAsExpression",
"TSSatisfiesExpression",
"TSTypeAssertion",
"TSNonNullExpression",
),

and some more places, worth combing through all definitions.

For example, OptionalMemberExpression is not valid assignment target - you can't do foo?.bar = 42;. Same for TSAsExpression - foo as number = 42; is not legal either. Some other TS node types I'm not sure about, worth checking.

It's also not clear why those places use manual lists instead of the old LVal alias, although that alias currently also includes problematic node types like:

These nodes can't be LVal by themselves, they are just pattern-like nodes that can appear inside other patterns but not by themselves.

Environment

(not applicable)

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions