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()
&& 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,
}))

View File

@ -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": {

View File

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

View File

@ -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": {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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