fix corner cases with export default (#4673)
This commit is contained in:
37
lib/parse.js
37
lib/parse.js
@@ -1351,13 +1351,46 @@ function parse($TEXT, options) {
|
||||
}
|
||||
if (is("keyword", "default")) {
|
||||
next();
|
||||
var body = expression();
|
||||
semicolon();
|
||||
var start = S.token;
|
||||
var body = export_default_decl();
|
||||
if (body) {
|
||||
body.start = start;
|
||||
body.end = prev();
|
||||
} else {
|
||||
body = expression();
|
||||
semicolon();
|
||||
}
|
||||
return new AST_ExportDefault({ body: body });
|
||||
}
|
||||
return new AST_ExportDeclaration({ body: export_decl() });
|
||||
}
|
||||
|
||||
function maybe_named(def, exp) {
|
||||
var node = function_(exp);
|
||||
if (node.name) {
|
||||
node = new def(node);
|
||||
node.name = new AST_SymbolDefun(node.name);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function export_default_decl() {
|
||||
switch (S.token.value) {
|
||||
case "async":
|
||||
if (!is_token(peek(), "keyword", "function")) return;
|
||||
next();
|
||||
next();
|
||||
if (!is("operator", "*")) return maybe_named(AST_AsyncDefun, AST_AsyncFunction);
|
||||
next();
|
||||
return maybe_named(AST_AsyncGeneratorDefun, AST_AsyncGeneratorFunction);
|
||||
case "function":
|
||||
next();
|
||||
if (!is("operator", "*")) return maybe_named(AST_Defun, AST_Function);
|
||||
next();
|
||||
return maybe_named(AST_GeneratorDefun, AST_GeneratorFunction);
|
||||
}
|
||||
}
|
||||
|
||||
var export_decl = embed_tokens(function() {
|
||||
switch (S.token.value) {
|
||||
case "async":
|
||||
|
||||
Reference in New Issue
Block a user