Skip to content

Commit

Permalink
Fix span of arrow expression with type params (#1365)
Browse files Browse the repository at this point in the history
swc_ecma_parser:
 - Fix span of arrow expression with type params.

Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
  • Loading branch information
dsherret and kdy1 authored Jan 28, 2021
1 parent 767f21e commit 4155822
Show file tree
Hide file tree
Showing 60 changed files with 337 additions and 184 deletions.
2 changes: 1 addition & 1 deletion ecmascript/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_parser"
repository = "https://github.com/swc-project/swc.git"
version = "0.45.4"
version = "0.45.5"

[features]
default = []
Expand Down
2 changes: 2 additions & 0 deletions ecmascript/parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ impl<'a, I: Tokens> Parser<I> {
let mut arrow = p.parse_assignment_expr_base()?;
match *arrow {
Expr::Arrow(ArrowExpr {
ref mut span,
ref mut type_params,
..
}) => {
*span = Span::new(type_parameters.span.lo, span.hi, Default::default());
*type_params = Some(type_parameters);
}
_ => unexpected!(p, "("),
Expand Down
1 change: 1 addition & 0 deletions ecmascript/parser/tests/span/ts/expr/arrow-type-params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const a = <T>(value: T): any => {};
150 changes: 150 additions & 0 deletions ecmascript/parser/tests/span/ts/expr/arrow-type-params.ts.spans
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
warning: Module
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:1
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: ModuleItem
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:1
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: Stmt
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:1
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: Decl
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:1
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: VarDecl
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:1
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: VarDeclarator
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:7
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: Pat
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:7
|
1 | const a = <T>(value: T): any => {};
| ^

warning: Ident
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:7
|
1 | const a = <T>(value: T): any => {};
| ^

warning: Expr
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:11
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^

warning: ArrowExpr
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:11
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^^^^^^^^^^^^^^^^^

warning: Pat
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:15
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^

warning: Ident
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:15
|
1 | const a = <T>(value: T): any => {};
| ^^^^^^^^

warning: TsTypeAnn
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:20
|
1 | const a = <T>(value: T): any => {};
| ^^^

warning: TsType
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:22
|
1 | const a = <T>(value: T): any => {};
| ^

warning: TsTypeRef
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:22
|
1 | const a = <T>(value: T): any => {};
| ^

warning: TsEntityName
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:22
|
1 | const a = <T>(value: T): any => {};
| ^

warning: Ident
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:22
|
1 | const a = <T>(value: T): any => {};
| ^

warning: BlockStmtOrExpr
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:33
|
1 | const a = <T>(value: T): any => {};
| ^^

warning: BlockStmt
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:33
|
1 | const a = <T>(value: T): any => {};
| ^^

warning: TsTypeParamDecl
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:11
|
1 | const a = <T>(value: T): any => {};
| ^^^

warning: TsTypeParam
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:12
|
1 | const a = <T>(value: T): any => {};
| ^

warning: Ident
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:12
|
1 | const a = <T>(value: T): any => {};
| ^

warning: TsTypeAnn
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:24
|
1 | const a = <T>(value: T): any => {};
| ^^^^^

warning: TsType
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:26
|
1 | const a = <T>(value: T): any => {};
| ^^^

warning: TsKeywordType
--> $DIR/tests/span/ts/expr/arrow-type-params.ts:1:26
|
1 | const a = <T>(value: T): any => {};
| ^^^

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"expression": {
"type": "ArrowFunctionExpression",
"span": {
"start": 64,
"start": 61,
"end": 78,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"expression": {
"type": "ArrowFunctionExpression",
"span": {
"start": 3,
"start": 0,
"end": 17,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 38,
"start": 11,
"end": 49,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 23,
"start": 20,
"end": 117,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@
"value": {
"type": "ArrowFunctionExpression",
"span": {
"start": 477,
"start": 474,
"end": 488,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 11,
"start": 8,
"end": 18,
"ctxt": 0
},
Expand Down Expand Up @@ -192,7 +192,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 46,
"start": 43,
"end": 54,
"ctxt": 0
},
Expand Down Expand Up @@ -288,7 +288,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 67,
"start": 64,
"end": 78,
"ctxt": 0
},
Expand Down Expand Up @@ -395,7 +395,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 91,
"start": 88,
"end": 110,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5996,7 +5996,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 3272,
"start": 3236,
"end": 3308,
"ctxt": 0
},
Expand Down Expand Up @@ -6184,7 +6184,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 3371,
"start": 3335,
"end": 3407,
"ctxt": 0
},
Expand Down Expand Up @@ -6372,7 +6372,7 @@
"init": {
"type": "ArrowFunctionExpression",
"span": {
"start": 3470,
"start": 3434,
"end": 3589,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@
"expression": {
"type": "ArrowFunctionExpression",
"span": {
"start": 494,
"start": 491,
"end": 505,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@
"expression": {
"type": "ArrowFunctionExpression",
"span": {
"start": 449,
"start": 446,
"end": 460,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@
"test": {
"type": "ArrowFunctionExpression",
"span": {
"start": 369,
"start": 366,
"end": 386,
"ctxt": 0
},
Expand Down Expand Up @@ -749,7 +749,7 @@
"expression": {
"type": "ArrowFunctionExpression",
"span": {
"start": 401,
"start": 398,
"end": 418,
"ctxt": 0
},
Expand Down Expand Up @@ -1493,7 +1493,7 @@
"discriminant": {
"type": "ArrowFunctionExpression",
"span": {
"start": 919,
"start": 916,
"end": 936,
"ctxt": 0
},
Expand Down Expand Up @@ -1601,7 +1601,7 @@
"expression": {
"type": "ArrowFunctionExpression",
"span": {
"start": 954,
"start": 951,
"end": 966,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"expression": {
"type": "ArrowFunctionExpression",
"span": {
"start": 68,
"start": 65,
"end": 90,
"ctxt": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@
"argument": {
"type": "ArrowFunctionExpression",
"span": {
"start": 1294,
"start": 1291,
"end": 1305,
"ctxt": 0
},
Expand Down
Loading

0 comments on commit 4155822

Please sign in to comment.