-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
💻
- 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.:
babel/packages/babel-types/src/definitions/core.ts
Lines 72 to 86 in f68ac51
| 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
babel/packages/babel-types/src/definitions/core.ts
Lines 1702 to 1712 in f68ac51
| const declaration = assertNodeType("VariableDeclaration"); | |
| const lval = assertNodeType( | |
| "Identifier", | |
| "MemberExpression", | |
| "ArrayPattern", | |
| "ObjectPattern", | |
| "TSAsExpression", | |
| "TSSatisfiesExpression", | |
| "TSTypeAssertion", | |
| "TSNonNullExpression", | |
| ); |
and
babel/packages/babel-types/src/definitions/core.ts
Lines 76 to 86 in f68ac51
| : 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:
- RestElement:
aliases: ["LVal", "PatternLike"], - AssignmentPattern:
aliases: ["Pattern", "PatternLike", "LVal"],
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