-
-
Notifications
You must be signed in to change notification settings - Fork 775
fix(ast/estree): fix BindingIdentifier
#9822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #9822 will not alter performanceComparing Summary
|
fb88238 to
4628d1e
Compare
c402430 to
9da220e
Compare
f50cef0 to
223e16f
Compare
4628d1e to
ce97302
Compare
223e16f to
cd18358
Compare
ce97302 to
b91d6c8
Compare
b91d6c8 to
d252425
Compare
|
Personally I would like to rewrite Something like: enum BindingPattern {
BindingIdentifier(Box<'a, BindingIdentifierWithType<'a>>),
ObjectPattern(Box<'a, ObjectPatternWithType<'a>>),
ArrayPattern(Box<'a, ArrayPatternWithType<'a>>),
AssignmentPattern(Box<'a, AssignmentPatternWithType<'a>>),
}
struct BindingIdentifierWithType<'a> {
pub span: Span,
pub ident: BindingIdentifier<'a>,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub optional: bool,
}
struct ObjectPatternWithType<'a> {
pub span: Span,
// `ObjectPattern` is a separate type because it also has a `Span`
pub pattern: ObjectPattern<'a>,
pub type_annotation: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub optional: bool,
}
// Same for `ArrayPatternWithType` and `AssignmentPatternWithType`This has the downside of requiring more AST types. But the advantage is that we could make illegal syntax impossible to represent in the AST. e.g. the type annotation is not legal here: [x: Foo] = array;But... problem is that Anyway... TLDR... if |
d252425 to
c79728f
Compare
c79728f to
7940c54
Compare
Binding side is tricky #9822, so I went with chipping away these two first.
7940c54 to
d1802c8
Compare
Class.idBindingIdentifier
|
It looks like Here is an example: let x: string = "foo"$ node napi/parser/example.mjs test.ts
"id": {
"type": "Identifier",
"start": 45,
"end": 54,
"name": "x",
"decorators": [],
"optional": false, // 👈
"typeAnnotation": null, // 👈
"typeAnnotation": { // 👈
"type": "TSTypeAnnotation",
"start": 46,
"end": 54,
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 48,
"end": 54
}
},
"optional": false // 👈
},I'm not sure if we should concern with this right now or proceed with this until we see issues with this approach. |
8a2e977 to
00642cd
Compare
overlookmotel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplicate fields in JSON are not ideal, and we'll need to fix at some point. But let's go with it for now, and fix it later once we have achieved alignment of the whole AST.
If it turns out we have to change the shape of BindingPattern anyway, then that'll make it easier to fix.
Merge activity
|
spec: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/ast-spec/src/expression/Identifier/spec.ts I'm not sure whether this can be fixed on struct side `BindingIdentifier` instead of field side `Class.id`. `BindingIdentifier` is used inside flatten `BindingPatternKind` enum, so changing it might be complicated. There are probably many instances like this, so I'm just trying to see the pattern first.
00642cd to
d69cc34
Compare
| export interface BindingIdentifier extends Span { | ||
| type: 'Identifier'; | ||
| name: string; | ||
| decorators?: []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this types be generated as non optional?

spec: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/ast-spec/src/expression/Identifier/spec.ts
I'm not sure whether this can be fixed on struct side
BindingIdentifierinstead of field sideClass.id.BindingIdentifieris used inside flattenBindingPatternKindenum, so changing it might be complicated.There are probably many instances like this, so I'm just trying to see the pattern first.