parse export & import statements correctly (#5550)

fixes #5548
This commit is contained in:
Alex Lam S.L
2022-07-07 21:04:56 +01:00
committed by GitHub
parent 80787ff7ef
commit b2bc2e1173
5 changed files with 93 additions and 19 deletions

View File

@@ -815,7 +815,7 @@ function parse($TEXT, options) {
}
}
var statement = embed_tokens(function() {
var statement = embed_tokens(function(toplevel) {
handle_regexp();
switch (S.token.type) {
case "string":
@@ -854,9 +854,11 @@ function parse($TEXT, options) {
if (S.in_async) return simple_statement();
break;
case "export":
if (!toplevel && options.module !== "") unexpected();
next();
return export_();
case "import":
if (!toplevel && options.module !== "") unexpected();
var token = peek();
if (!(token.type == "punc" && /^[(.]$/.test(token.value))) {
next();
@@ -2563,7 +2565,7 @@ function parse($TEXT, options) {
}
S.input.push_directives_stack();
while (!is("eof"))
body.push(statement());
body.push(statement(true));
S.input.pop_directives_stack();
var end = prev() || start;
var toplevel = options.toplevel;