test: add invalid-lone-import test (#10950)

* test: add lone import test

* polish: raise recoverable error
This commit is contained in:
Huáng Jùnliàng 2020-01-03 17:08:59 -05:00 committed by Nicolò Ribaudo
parent a28353703f
commit 455d782ef0
4 changed files with 80 additions and 1 deletions

View File

@ -919,7 +919,10 @@ export default class ExpressionParser extends LValParser {
this.expectPlugin("dynamicImport", node.start); this.expectPlugin("dynamicImport", node.start);
if (!this.match(tt.parenL)) { 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"); return this.finishNode(node, "Import");
case tt._this: case tt._this:

View File

@ -0,0 +1,3 @@
{
"plugins": ["dynamicImport"]
}

View 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": []
}
}