From a55fced20bd62c50098c4da0384a54b3af11260b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 17 Jan 2020 22:33:01 -0500 Subject: [PATCH] Fix spans for "as" and const assertions (#593) - Fix spans for "as" and const assertions --- ecmascript/parser/src/parser/expr/ops.rs | 9 ++++++--- .../parser/tests/typescript/cast/as/input.ts.json | 12 ++++++------ .../typescript/cast/assert-and-assign/input.ts.json | 2 +- .../cast/multiple-assert-and-assign/input.ts.json | 4 ++-- .../typescript/cast/need-parentheses/input.ts.json | 2 +- .../custom/import-type/typeof/as/input.ts.json | 2 +- .../tests/typescript/custom/issue-338/input.ts.json | 2 +- .../issue-401-const-assertion-array/input.ts.json | 2 +- .../issue-401-const-assertion-literal/input.ts.json | 2 +- .../issue-401-const-assertion-object/input.ts.json | 2 +- 10 files changed, 21 insertions(+), 18 deletions(-) diff --git a/ecmascript/parser/src/parser/expr/ops.rs b/ecmascript/parser/src/parser/expr/ops.rs index d79986c3163..446582ea1b6 100644 --- a/ecmascript/parser/src/parser/expr/ops.rs +++ b/ecmascript/parser/src/parser/expr/ops.rs @@ -73,17 +73,20 @@ impl<'a, I: Tokens> Parser<'a, I> { && !self.input.had_line_break_before_cur() && is!("as") { - let span = span!(left.span().lo()); + let start = left.span().lo(); let expr = left; let node = if peeked_is!("const") { bump!(); // as let _ = cur!(false); bump!(); // const - Box::new(Expr::TsConstAssertion(TsConstAssertion { span, expr })) + Box::new(Expr::TsConstAssertion(TsConstAssertion { + span: span!(start), + expr, + })) } else { let type_ann = self.next_then_parse_ts_type()?; Box::new(Expr::TsAs(TsAsExpr { - span, + span: span!(start), expr, type_ann, })) diff --git a/ecmascript/parser/tests/typescript/cast/as/input.ts.json b/ecmascript/parser/tests/typescript/cast/as/input.ts.json index f486257281d..3b0944e1ee6 100644 --- a/ecmascript/parser/tests/typescript/cast/as/input.ts.json +++ b/ecmascript/parser/tests/typescript/cast/as/input.ts.json @@ -17,7 +17,7 @@ "type": "TsAsExpression", "span": { "start": 0, - "end": 1, + "end": 6, "ctxt": 0 }, "expression": { @@ -64,7 +64,7 @@ "type": "TsAsExpression", "span": { "start": 8, - "end": 13, + "end": 24, "ctxt": 0 }, "expression": { @@ -120,7 +120,7 @@ "type": "BinaryExpression", "span": { "start": 49, - "end": 56, + "end": 66, "ctxt": 0 }, "operator": "===", @@ -139,7 +139,7 @@ "type": "TsAsExpression", "span": { "start": 55, - "end": 56, + "end": 66, "ctxt": 0 }, "expression": { @@ -174,14 +174,14 @@ "type": "TsAsExpression", "span": { "start": 92, - "end": 100, + "end": 105, "ctxt": 0 }, "expression": { "type": "TsAsExpression", "span": { "start": 92, - "end": 93, + "end": 100, "ctxt": 0 }, "expression": { diff --git a/ecmascript/parser/tests/typescript/cast/assert-and-assign/input.ts.json b/ecmascript/parser/tests/typescript/cast/assert-and-assign/input.ts.json index de38b4f5a4f..4110e10a581 100644 --- a/ecmascript/parser/tests/typescript/cast/assert-and-assign/input.ts.json +++ b/ecmascript/parser/tests/typescript/cast/assert-and-assign/input.ts.json @@ -25,7 +25,7 @@ "type": "TsAsExpression", "span": { "start": 1, - "end": 2, + "end": 12, "ctxt": 0 }, "expression": { diff --git a/ecmascript/parser/tests/typescript/cast/multiple-assert-and-assign/input.ts.json b/ecmascript/parser/tests/typescript/cast/multiple-assert-and-assign/input.ts.json index 6b931a9b572..c4cf57a12b7 100644 --- a/ecmascript/parser/tests/typescript/cast/multiple-assert-and-assign/input.ts.json +++ b/ecmascript/parser/tests/typescript/cast/multiple-assert-and-assign/input.ts.json @@ -25,14 +25,14 @@ "type": "TsAsExpression", "span": { "start": 1, - "end": 12, + "end": 19, "ctxt": 0 }, "expression": { "type": "TsAsExpression", "span": { "start": 1, - "end": 2, + "end": 12, "ctxt": 0 }, "expression": { diff --git a/ecmascript/parser/tests/typescript/cast/need-parentheses/input.ts.json b/ecmascript/parser/tests/typescript/cast/need-parentheses/input.ts.json index a0f8d46570c..b0ca8c49a7e 100644 --- a/ecmascript/parser/tests/typescript/cast/need-parentheses/input.ts.json +++ b/ecmascript/parser/tests/typescript/cast/need-parentheses/input.ts.json @@ -106,7 +106,7 @@ "type": "TsAsExpression", "span": { "start": 12, - "end": 13, + "end": 18, "ctxt": 0 }, "expression": { diff --git a/ecmascript/parser/tests/typescript/custom/import-type/typeof/as/input.ts.json b/ecmascript/parser/tests/typescript/custom/import-type/typeof/as/input.ts.json index 9de967f4b31..e5d91f146d9 100644 --- a/ecmascript/parser/tests/typescript/custom/import-type/typeof/as/input.ts.json +++ b/ecmascript/parser/tests/typescript/custom/import-type/typeof/as/input.ts.json @@ -38,7 +38,7 @@ "type": "TsAsExpression", "span": { "start": 12, - "end": 26, + "end": 50, "ctxt": 0 }, "expression": { diff --git a/ecmascript/parser/tests/typescript/custom/issue-338/input.ts.json b/ecmascript/parser/tests/typescript/custom/issue-338/input.ts.json index b113c54aff6..e7838b09093 100644 --- a/ecmascript/parser/tests/typescript/custom/issue-338/input.ts.json +++ b/ecmascript/parser/tests/typescript/custom/issue-338/input.ts.json @@ -38,7 +38,7 @@ "type": "TsAsExpression", "span": { "start": 12, - "end": 15, + "end": 37, "ctxt": 0 }, "expression": { diff --git a/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-array/input.ts.json b/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-array/input.ts.json index 4c19517d967..f449ed1fdbb 100644 --- a/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-array/input.ts.json +++ b/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-array/input.ts.json @@ -38,7 +38,7 @@ "type": "TsConstAssertion", "span": { "start": 8, - "end": 16, + "end": 25, "ctxt": 0 }, "expr": { diff --git a/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-literal/input.ts.json b/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-literal/input.ts.json index c00a297962c..f81ddd27fc2 100644 --- a/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-literal/input.ts.json +++ b/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-literal/input.ts.json @@ -38,7 +38,7 @@ "type": "TsConstAssertion", "span": { "start": 8, - "end": 15, + "end": 24, "ctxt": 0 }, "expr": { diff --git a/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-object/input.ts.json b/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-object/input.ts.json index 37f9b1c68e8..682ff90a002 100644 --- a/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-object/input.ts.json +++ b/ecmascript/parser/tests/typescript/custom/issue-401-const-assertion-object/input.ts.json @@ -38,7 +38,7 @@ "type": "TsConstAssertion", "span": { "start": 8, - "end": 25, + "end": 34, "ctxt": 0 }, "expr": {