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: parse import module, ... #15198

Merged
merged 1 commit into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/babel-parser/src/parser/statement.ts
Expand Up @@ -2747,8 +2747,9 @@ export default abstract class StatementParser extends ExpressionParser {
let isImportReflection = false;
if (this.isContextual(tt._module)) {
const lookahead = this.lookahead();
if (tokenIsIdentifier(lookahead.type)) {
if (lookahead.type !== tt._from) {
const nextType = lookahead.type;
if (tokenIsIdentifier(nextType)) {
if (nextType !== tt._from) {
// import module x
isImportReflection = true;
} else {
Expand All @@ -2760,9 +2761,10 @@ export default abstract class StatementParser extends ExpressionParser {
isImportReflection = true;
}
}
} else {
} else if (nextType !== tt.comma) {
// import module { x } ...
// This is invalid, we will continue parsing and throw
// import module "foo"
// They are invalid, we will continue parsing and throw
// a recoverable error later
isImportReflection = true;
}
Expand Down
@@ -0,0 +1 @@
import module, { createRequire } from "module";
@@ -0,0 +1,52 @@
{
"type": "File",
"start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":47,"index":47}},
"program": {
"type": "Program",
"start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":47,"index":47}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":47,"index":47}},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start":7,"end":13,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":13,"index":13}},
"local": {
"type": "Identifier",
"start":7,"end":13,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":13,"index":13},"identifierName":"module"},
"name": "module"
}
},
{
"type": "ImportSpecifier",
"start":17,"end":30,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":30,"index":30}},
"imported": {
"type": "Identifier",
"start":17,"end":30,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":30,"index":30},"identifierName":"createRequire"},
"name": "createRequire"
},
"local": {
"type": "Identifier",
"start":17,"end":30,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":30,"index":30},"identifierName":"createRequire"},
"name": "createRequire"
}
}
],
"module": false,
"source": {
"type": "StringLiteral",
"start":38,"end":46,"loc":{"start":{"line":1,"column":38,"index":38},"end":{"line":1,"column":46,"index":46}},
"extra": {
"rawValue": "module",
"raw": "\"module\""
},
"value": "module"
}
}
],
"directives": []
}
}