test: add invalid-lone-import test (#10950)
* test: add lone import test * polish: raise recoverable error
This commit is contained in:
parent
a28353703f
commit
455d782ef0
@ -919,7 +919,10 @@ export default class ExpressionParser extends LValParser {
|
||||
this.expectPlugin("dynamicImport", node.start);
|
||||
|
||||
if (!this.match(tt.parenL)) {
|
||||
this.unexpected(null, tt.parenL);
|
||||
this.raise(
|
||||
this.state.lastTokStart,
|
||||
"import can only be used in import() or import.meta",
|
||||
);
|
||||
}
|
||||
return this.finishNode(node, "Import");
|
||||
case tt._this:
|
||||
|
||||
1
packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-lone-import/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-lone-import/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
(import)
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["dynamicImport"]
|
||||
}
|
||||
72
packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-lone-import/output.json
vendored
Normal file
72
packages/babel-parser/test/fixtures/experimental/dynamic-import/invalid-lone-import/output.json
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 8,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"errors": [
|
||||
"SyntaxError: import can only be used in import() or import.meta (1:1)"
|
||||
],
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 8,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 0,
|
||||
"end": 8,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "Import",
|
||||
"start": 1,
|
||||
"end": 7,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"parenthesized": true,
|
||||
"parenStart": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user