Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix string literal span on import/export specifiers to only include string literal #540

Merged
merged 11 commits into from
Dec 29, 2019
6 changes: 4 additions & 2 deletions ecmascript/parser/src/parser/stmt/module_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ impl<'a, I: Tokens> Parser<'a, I> {
if let Ok(&Token::Str { .. }) = cur!(false) {
match bump!() {
Token::Str { value, has_escape } => {
let str_end = self.input.prev_span().hi();
expect!(';');
return Ok(ModuleDecl::Import(ImportDecl {
span: span!(start),
src: Str {
span: span!(str_start),
span: Span::new(str_start, str_end, Default::default()),
value,
has_escape,
},
Expand Down Expand Up @@ -450,12 +451,13 @@ impl<'a, I: Tokens> Parser<'a, I> {
match *cur!(true)? {
Token::Str { .. } => match bump!() {
Token::Str { value, has_escape } => {
let end = self.input.prev_span().hi();
expect!(';');

Ok(Str {
value,
has_escape,
span: Span::new(start, self.input.prev_span().hi(), Default::default()),
span: Span::new(start, end, Default::default()),
})
}
_ => unreachable!(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"type": "StringLiteral",
"span": {
"start": 18,
"end": 26,
"end": 25,
"ctxt": 0
},
"value": "react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"type": "StringLiteral",
"span": {
"start": 18,
"end": 26,
"end": 25,
"ctxt": 0
},
"value": "react",
Expand Down
4 changes: 3 additions & 1 deletion ecmascript/parser/tests/typescript/custom/issue-535/input.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from "test";
export * from "test" ;
import "test" ;
import Test from "test" ;
64 changes: 61 additions & 3 deletions ecmascript/parser/tests/typescript/custom/issue-535/input.ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,80 @@
"type": "Module",
"span": {
"start": 0,
"end": 21,
"end": 66,
"ctxt": 0
},
"body": [
{
"type": "ExportAllDeclaration",
"span": {
"start": 0,
"end": 21,
"end": 22,
"ctxt": 0
},
"source": {
"type": "StringLiteral",
"span": {
"start": 14,
"end": 21,
"end": 20,
"ctxt": 0
},
"value": "test",
"hasEscape": false
}
},
{
"type": "ImportDeclaration",
"span": {
"start": 24,
"end": 39,
"ctxt": 0
},
"specifiers": [],
"source": {
"type": "StringLiteral",
"span": {
"start": 31,
"end": 37,
"ctxt": 0
},
"value": "test",
"hasEscape": false
}
},
{
"type": "ImportDeclaration",
"span": {
"start": 41,
"end": 66,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 7,
"end": 12,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 48,
"end": 52,
"ctxt": 0
},
"value": "Test",
"typeAnnotation": null,
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 58,
"end": 64,
"ctxt": 0
},
"value": "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"type": "StringLiteral",
"span": {
"start": 18,
"end": 26,
"end": 25,
"ctxt": 0
},
"value": "react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"type": "StringLiteral",
"span": {
"start": 45,
"end": 49,
"end": 48,
"ctxt": 0
},
"value": "a",
Expand Down