fix: disallow import assertionts in export without from (#12264)

This commit is contained in:
Huáng Jùnliàng 2020-10-28 02:07:20 -04:00 committed by GitHub
parent a8c66f4680
commit b7754d3c82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -1906,6 +1906,10 @@ export default class StatementParser extends ExpressionParser {
if (this.eatContextual("from")) { if (this.eatContextual("from")) {
node.source = this.parseImportSource(); node.source = this.parseImportSource();
this.checkExport(node); this.checkExport(node);
const assertions = this.maybeParseImportAssertions();
if (assertions) {
node.assertions = assertions;
}
} else { } else {
if (expect) { if (expect) {
this.unexpected(); this.unexpected();
@ -1914,11 +1918,6 @@ export default class StatementParser extends ExpressionParser {
} }
} }
const assertions = this.maybeParseImportAssertions();
if (assertions) {
node.assertions = assertions;
}
this.semicolon(); this.semicolon();
} }

View File

@ -0,0 +1,2 @@
const foo = 1;
export { foo } assert { type: "json" };

View File

@ -0,0 +1,9 @@
{
"plugins": [
[
"importAssertions"
]
],
"sourceType": "module",
"throws": "Unexpected token, expected \";\" (2:15)"
}