Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parse error when using named import "as" with flow parser (#13659)
- Loading branch information
Showing
5 changed files
with
194 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/babel-parser/test/fixtures/flow/imports/imports-with-as-identifiers/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// @flow | ||
import { foo as as } from "foo"; | ||
import { as as as } from "foo"; | ||
import { as as foo } from "foo"; |
123 changes: 123 additions & 0 deletions
123
packages/babel-parser/test/fixtures/flow/imports/imports-with-as-identifiers/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":106,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":32}}, | ||
"errors": [ | ||
"SyntaxError: Identifier 'as' has already been declared. (3:15)" | ||
], | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":106,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":32}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":9,"end":41,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":32}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":18,"end":27,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":18}}, | ||
"imported": { | ||
"type": "Identifier", | ||
"start":18,"end":21,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":12},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"importKind": null, | ||
"local": { | ||
"type": "Identifier", | ||
"start":25,"end":27,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":18},"identifierName":"as"}, | ||
"name": "as" | ||
} | ||
} | ||
], | ||
"importKind": "value", | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":35,"end":40,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":31}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
}, | ||
"leadingComments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " @flow", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}} | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":42,"end":73,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":31}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":51,"end":59,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":17}}, | ||
"imported": { | ||
"type": "Identifier", | ||
"start":51,"end":53,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":11},"identifierName":"as"}, | ||
"name": "as" | ||
}, | ||
"importKind": null, | ||
"local": { | ||
"type": "Identifier", | ||
"start":57,"end":59,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":17},"identifierName":"as"}, | ||
"name": "as" | ||
} | ||
} | ||
], | ||
"importKind": "value", | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":67,"end":72,"loc":{"start":{"line":3,"column":25},"end":{"line":3,"column":30}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
} | ||
}, | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":74,"end":106,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":32}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":83,"end":92,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":18}}, | ||
"imported": { | ||
"type": "Identifier", | ||
"start":83,"end":85,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":11},"identifierName":"as"}, | ||
"name": "as" | ||
}, | ||
"importKind": null, | ||
"local": { | ||
"type": "Identifier", | ||
"start":89,"end":92,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":18},"identifierName":"foo"}, | ||
"name": "foo" | ||
} | ||
} | ||
], | ||
"importKind": "value", | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":100,"end":105,"loc":{"start":{"line":4,"column":26},"end":{"line":4,"column":31}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
} | ||
} | ||
], | ||
"directives": [] | ||
}, | ||
"comments": [ | ||
{ | ||
"type": "CommentLine", | ||
"value": " @flow", | ||
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}} | ||
} | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand-2/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import {type foo as as} from "foo"; |
44 changes: 44 additions & 0 deletions
44
packages/babel-parser/test/fixtures/flow/type-imports/import-type-shorthand-2/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ImportDeclaration", | ||
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}}, | ||
"specifiers": [ | ||
{ | ||
"type": "ImportSpecifier", | ||
"start":8,"end":22,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":22}}, | ||
"imported": { | ||
"type": "Identifier", | ||
"start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"importKind": "type", | ||
"local": { | ||
"type": "Identifier", | ||
"start":20,"end":22,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":22},"identifierName":"as"}, | ||
"name": "as" | ||
} | ||
} | ||
], | ||
"importKind": "value", | ||
"source": { | ||
"type": "StringLiteral", | ||
"start":29,"end":34,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":34}}, | ||
"extra": { | ||
"rawValue": "foo", | ||
"raw": "\"foo\"" | ||
}, | ||
"value": "foo" | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |