Skip to content
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

fix(es/parser): Fix span of BindingIdent #8859

Merged
merged 7 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 8 additions & 5 deletions crates/swc_ecma_parser/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,6 @@ impl<I: Tokens> Parser<I> {
ref mut span,
..
})
| Pat::Ident(BindingIdent {
ref mut type_ann,
id: Ident { ref mut span, .. },
..
})
| Pat::Object(ObjectPat {
ref mut type_ann,
ref mut span,
Expand All @@ -235,6 +230,14 @@ impl<I: Tokens> Parser<I> {
}
*type_ann = new_type_ann;
}

Pat::Ident(BindingIdent {
ref mut type_ann, ..
}) => {
let new_type_ann = self.try_parse_ts_type_ann()?;
*type_ann = new_type_ann;
}

Pat::Assign(AssignPat { ref mut span, .. }) => {
if (self.try_parse_ts_type_ann()?).is_some() {
*span = Span::new(pat_start, self.input.prev_span().hi, Default::default());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,14 @@
,-[$DIR/tests/span/ts/decl/decorated-class.ts:4:1]
4 | export class CommentController {
5 | constructor(private commentService: CommentService) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^
`----

x Ident
,-[$DIR/tests/span/ts/decl/decorated-class.ts:4:1]
4 | export class CommentController {
5 | constructor(private commentService: CommentService) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^
`----

x TsTypeAnn
Expand Down Expand Up @@ -617,15 +617,15 @@
,-[$DIR/tests/span/ts/decl/decorated-class.ts:9:1]
9 | public updateComment(
10 | @Param('id') id: string,
: ^^^^^^^^^^
: ^^
11 | @Body() updateCommentDto: UpdateCommentDto,
`----

x Ident
,-[$DIR/tests/span/ts/decl/decorated-class.ts:9:1]
9 | public updateComment(
10 | @Param('id') id: string,
: ^^^^^^^^^^
: ^^
11 | @Body() updateCommentDto: UpdateCommentDto,
`----

Expand Down Expand Up @@ -713,15 +713,15 @@
,-[$DIR/tests/span/ts/decl/decorated-class.ts:10:1]
10 | @Param('id') id: string,
11 | @Body() updateCommentDto: UpdateCommentDto,
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^^^
12 | @User() user: UserType,
`----

x Ident
,-[$DIR/tests/span/ts/decl/decorated-class.ts:10:1]
10 | @Param('id') id: string,
11 | @Body() updateCommentDto: UpdateCommentDto,
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: ^^^^^^^^^^^^^^^^
12 | @User() user: UserType,
`----

Expand Down Expand Up @@ -825,15 +825,15 @@
,-[$DIR/tests/span/ts/decl/decorated-class.ts:11:1]
11 | @Body() updateCommentDto: UpdateCommentDto,
12 | @User() user: UserType,
: ^^^^^^^^^^^^^^
: ^^^^
13 | ) {
`----

x Ident
,-[$DIR/tests/span/ts/decl/decorated-class.ts:11:1]
11 | @Body() updateCommentDto: UpdateCommentDto,
12 | @User() user: UserType,
: ^^^^^^^^^^^^^^
: ^^^^
13 | ) {
`----

Expand Down Expand Up @@ -1370,15 +1370,15 @@
,-[$DIR/tests/span/ts/decl/decorated-class.ts:18:1]
18 | @Delete(COMMENT_DELETE_ENDPOINT)
19 | public deleteComment(@Param('id') id: string, @User() user: UserType) {
: ^^^^^^^^^^
: ^^
20 | return this.commentService.delete(id, user.id);
`----

x Ident
,-[$DIR/tests/span/ts/decl/decorated-class.ts:18:1]
18 | @Delete(COMMENT_DELETE_ENDPOINT)
19 | public deleteComment(@Param('id') id: string, @User() user: UserType) {
: ^^^^^^^^^^
: ^^
20 | return this.commentService.delete(id, user.id);
`----

Expand Down Expand Up @@ -1466,15 +1466,15 @@
,-[$DIR/tests/span/ts/decl/decorated-class.ts:18:1]
18 | @Delete(COMMENT_DELETE_ENDPOINT)
19 | public deleteComment(@Param('id') id: string, @User() user: UserType) {
: ^^^^^^^^^^^^^^
: ^^^^
20 | return this.commentService.delete(id, user.id);
`----

x Ident
,-[$DIR/tests/span/ts/decl/decorated-class.ts:18:1]
18 | @Delete(COMMENT_DELETE_ENDPOINT)
19 | public deleteComment(@Param('id') id: string, @User() user: UserType) {
: ^^^^^^^^^^^^^^
: ^^^^
20 | return this.commentService.delete(id, user.id);
`----

Expand Down
1 change: 1 addition & 0 deletions crates/swc_ecma_parser/tests/span/ts/issue-8856/param.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function b(a: number = 1) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

x Module
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x ModuleItem
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x Stmt
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x Decl
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x FnDecl
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x Ident
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^
`----

x Function
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x Param
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^
`----

x Pat
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^
`----

x AssignPat
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^^^^^^
`----

x Pat
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^
`----

x Ident
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^
`----

x TsTypeAnn
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^^^
`----

x TsType
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^
`----

x TsKeywordType
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^^^^
`----

x Expr
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^
`----

x Lit
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^
`----

x Number
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^
`----

x BlockStmt
,-[$DIR/tests/span/ts/issue-8856/param.ts:1:1]
1 | function b(a: number = 1) { }
: ^^^
`----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a: number
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

x Module
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^^^^^^^^^^
`----

x ModuleItem
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^^^^^^^^^^
`----

x Stmt
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^^^^^^^^^^
`----

x Decl
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^^^^^^^^^^
`----

x VarDecl
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^^^^^^^^^^
`----

x VarDeclarator
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^^^^
`----

x Pat
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^
`----

x Ident
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^
`----

x TsTypeAnn
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^^^
`----

x TsType
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^
`----

x TsKeywordType
,-[$DIR/tests/span/ts/issue-8856/var-decl.ts:1:1]
1 | const a: number
: ^^^^^^
`----
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@
,-[$DIR/tests/span/ts/type/interface.ts:2:1]
2 | new();
3 | (foo: string): void;
: ^^^^^^^^^^^
: ^^^
4 | [foo: string]: void;
`----

x Ident
,-[$DIR/tests/span/ts/type/interface.ts:2:1]
2 | new();
3 | (foo: string): void;
: ^^^^^^^^^^^
: ^^^
4 | [foo: string]: void;
`----

Expand Down
Loading
Loading