Skip to content

Commit

Permalink
fix(es/parser): Fix span of BindingIdent (#8859)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8856
  • Loading branch information
kdy1 authored Apr 15, 2024
1 parent 739a92b commit fbd32fb
Show file tree
Hide file tree
Showing 1,176 changed files with 12,531 additions and 12,346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
//! 7 | var f4 = <T>(x: T, x: T) => { }
//! 8 |
//! 9 | function foo2(x: string, x: number) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 10 | var f5 = function foo(x: string, x: number) { }
//! 11 | var f6 = function (x: string, x: number) { }
//! 12 | var f7 = (x: string, x: number) => { }
Expand All @@ -88,9 +88,9 @@
//! 8 |
//! 9 | function foo2(x: string, x: number) { }
//! 10 | var f5 = function foo(x: string, x: number) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 11 | var f6 = function (x: string, x: number) { }
//! 12 | var f7 = (x: string, x: number) => { }
//! 13 | var f8 = <T>(x: T, y: T) => { }
Expand All @@ -102,9 +102,9 @@
//! 9 | function foo2(x: string, x: number) { }
//! 10 | var f5 = function foo(x: string, x: number) { }
//! 11 | var f6 = function (x: string, x: number) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 12 | var f7 = (x: string, x: number) => { }
//! 13 | var f8 = <T>(x: T, y: T) => { }
//! `----
Expand Down Expand Up @@ -143,9 +143,9 @@
//! 15 | class C {
//! 16 | foo(x, x) { }
//! 17 | foo2(x: number, x: string) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 18 | foo3<T>(x: T, x: T) { }
//! 19 | }
//! `----
Expand All @@ -156,9 +156,9 @@
//! 16 | foo(x, x) { }
//! 17 | foo2(x: number, x: string) { }
//! 18 | foo3<T>(x: T, x: T) { }
//! : ^^|^ ^^|^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 19 | }
//! 20 |
//! 21 | interface I {
Expand All @@ -184,9 +184,9 @@
//! 34 | var b = {
//! 35 | foo(x, x) { },
//! 36 | a: function foo(x: number, x: string) { },
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 37 | b: <T>(x: T, x: T) => { }
//! 38 | }
//! `----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
//! 7 | var f4 = <T>(x: T, x: T) => { }
//! 8 |
//! 9 | function foo2(x: string, x: number) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 10 | var f5 = function foo(x: string, x: number) { }
//! 11 | var f6 = function (x: string, x: number) { }
//! 12 | var f7 = (x: string, x: number) => { }
Expand All @@ -88,9 +88,9 @@
//! 8 |
//! 9 | function foo2(x: string, x: number) { }
//! 10 | var f5 = function foo(x: string, x: number) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 11 | var f6 = function (x: string, x: number) { }
//! 12 | var f7 = (x: string, x: number) => { }
//! 13 | var f8 = <T>(x: T, y: T) => { }
Expand All @@ -102,9 +102,9 @@
//! 9 | function foo2(x: string, x: number) { }
//! 10 | var f5 = function foo(x: string, x: number) { }
//! 11 | var f6 = function (x: string, x: number) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 12 | var f7 = (x: string, x: number) => { }
//! 13 | var f8 = <T>(x: T, y: T) => { }
//! `----
Expand Down Expand Up @@ -143,9 +143,9 @@
//! 15 | class C {
//! 16 | foo(x, x) { }
//! 17 | foo2(x: number, x: string) { }
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 18 | foo3<T>(x: T, x: T) { }
//! 19 | }
//! `----
Expand All @@ -156,9 +156,9 @@
//! 16 | foo(x, x) { }
//! 17 | foo2(x: number, x: string) { }
//! 18 | foo3<T>(x: T, x: T) { }
//! : ^^|^ ^^|^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 19 | }
//! 20 |
//! 21 | interface I {
Expand All @@ -184,9 +184,9 @@
//! 34 | var b = {
//! 35 | foo(x, x) { },
//! 36 | a: function foo(x: number, x: string) { },
//! : ^^^^|^^^^ ^^^^|^^^^
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! : | |
//! : | `-- used as parameter more than once
//! : `-- previous definition here
//! 37 | b: <T>(x: T, x: T) => { }
//! 38 | }
//! `----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
export var Foo = function Foo(/** @internal */ isInternal1, /** @internal */ isInternal2, /** @internal */ isInternal3, // @internal
isInternal4, // nothing
/** @internal */ isInternal5, /* @internal */ isInternal6 /* trailing */ , /* @internal */ isInternal7, /** @internal */ // not work
/** @internal */ isInternal5, /* @internal */ isInternal6/* trailing */ , /* @internal */ isInternal7, /** @internal */ // not work
notInternal1, // @internal
/* not work */ notInternal2, /* not work */ // @internal
/* not work */ notInternal3) {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/tsc-references/parserindenter.1.normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ var Formatting;
}
return null;
};
_proto.GetIndentationDelta = function GetIndentationDelta(tokenStartPosition, childTokenStartPosition /*?*/ ) {
_proto.GetIndentationDelta = function GetIndentationDelta(tokenStartPosition, childTokenStartPosition/*?*/ ) {
Debug.Assert(childTokenStartPosition !== undefined, "Error: caller must pass 'null' for undefined position");
var indentationDeltaSize = this.offsetIndentationDeltas.GetValue(tokenStartPosition);
if (indentationDeltaSize === null) {
Expand Down
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) { }
Loading

0 comments on commit fbd32fb

Please sign in to comment.