Fix spans for "as" and const assertions (#593)

- Fix spans for "as" and const assertions
This commit is contained in:
David Sherret 2020-01-17 22:33:01 -05:00 committed by 강동윤
parent 2880250309
commit a55fced20b
10 changed files with 21 additions and 18 deletions

View File

@ -73,17 +73,20 @@ impl<'a, I: Tokens> Parser<'a, I> {
&& !self.input.had_line_break_before_cur() && !self.input.had_line_break_before_cur()
&& is!("as") && is!("as")
{ {
let span = span!(left.span().lo()); let start = left.span().lo();
let expr = left; let expr = left;
let node = if peeked_is!("const") { let node = if peeked_is!("const") {
bump!(); // as bump!(); // as
let _ = cur!(false); let _ = cur!(false);
bump!(); // const bump!(); // const
Box::new(Expr::TsConstAssertion(TsConstAssertion { span, expr })) Box::new(Expr::TsConstAssertion(TsConstAssertion {
span: span!(start),
expr,
}))
} else { } else {
let type_ann = self.next_then_parse_ts_type()?; let type_ann = self.next_then_parse_ts_type()?;
Box::new(Expr::TsAs(TsAsExpr { Box::new(Expr::TsAs(TsAsExpr {
span, span: span!(start),
expr, expr,
type_ann, type_ann,
})) }))

View File

@ -17,7 +17,7 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 0, "start": 0,
"end": 1, "end": 6,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {
@ -64,7 +64,7 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 8, "start": 8,
"end": 13, "end": 24,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {
@ -120,7 +120,7 @@
"type": "BinaryExpression", "type": "BinaryExpression",
"span": { "span": {
"start": 49, "start": 49,
"end": 56, "end": 66,
"ctxt": 0 "ctxt": 0
}, },
"operator": "===", "operator": "===",
@ -139,7 +139,7 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 55, "start": 55,
"end": 56, "end": 66,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {
@ -174,14 +174,14 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 92, "start": 92,
"end": 100, "end": 105,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 92, "start": 92,
"end": 93, "end": 100,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {

View File

@ -25,7 +25,7 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 1, "start": 1,
"end": 2, "end": 12,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {

View File

@ -25,14 +25,14 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 1, "start": 1,
"end": 12, "end": 19,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 1, "start": 1,
"end": 2, "end": 12,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {

View File

@ -106,7 +106,7 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 12, "start": 12,
"end": 13, "end": 18,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {

View File

@ -38,7 +38,7 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 12, "start": 12,
"end": 26, "end": 50,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {

View File

@ -38,7 +38,7 @@
"type": "TsAsExpression", "type": "TsAsExpression",
"span": { "span": {
"start": 12, "start": 12,
"end": 15, "end": 37,
"ctxt": 0 "ctxt": 0
}, },
"expression": { "expression": {

View File

@ -38,7 +38,7 @@
"type": "TsConstAssertion", "type": "TsConstAssertion",
"span": { "span": {
"start": 8, "start": 8,
"end": 16, "end": 25,
"ctxt": 0 "ctxt": 0
}, },
"expr": { "expr": {

View File

@ -38,7 +38,7 @@
"type": "TsConstAssertion", "type": "TsConstAssertion",
"span": { "span": {
"start": 8, "start": 8,
"end": 15, "end": 24,
"ctxt": 0 "ctxt": 0
}, },
"expr": { "expr": {

View File

@ -38,7 +38,7 @@
"type": "TsConstAssertion", "type": "TsConstAssertion",
"span": { "span": {
"start": 8, "start": 8,
"end": 25, "end": 34,
"ctxt": 0 "ctxt": 0
}, },
"expr": { "expr": {