fix export default of anonymous generators and async functions
This commit is contained in:
parent
f8ff349ba7
commit
d08dc6cf73
12
lib/parse.js
12
lib/parse.js
|
|
@ -982,7 +982,7 @@ function parse($TEXT, options) {
|
|||
}
|
||||
};
|
||||
|
||||
var statement = embed_tokens(function() {
|
||||
var statement = embed_tokens(function(is_export_default) {
|
||||
handle_regexp();
|
||||
switch (S.token.type) {
|
||||
case "string":
|
||||
|
|
@ -1011,7 +1011,7 @@ function parse($TEXT, options) {
|
|||
if (S.token.value == "async" && is_token(peek(), "keyword", "function")) {
|
||||
next();
|
||||
next();
|
||||
return function_(AST_Defun, false, true);
|
||||
return function_(AST_Defun, false, true, is_export_default);
|
||||
}
|
||||
if (S.token.value == "import" && !is_token(peek(), "punc", "(")) {
|
||||
next();
|
||||
|
|
@ -1085,7 +1085,7 @@ function parse($TEXT, options) {
|
|||
|
||||
case "function":
|
||||
next();
|
||||
return function_(AST_Defun);
|
||||
return function_(AST_Defun, false, false, is_export_default);
|
||||
|
||||
case "if":
|
||||
next();
|
||||
|
|
@ -1308,7 +1308,7 @@ function parse($TEXT, options) {
|
|||
});
|
||||
};
|
||||
|
||||
var function_ = function(ctor, is_generator_property, is_async) {
|
||||
var function_ = function(ctor, is_generator_property, is_async, is_export_default) {
|
||||
if (is_generator_property && is_async) croak("generators cannot be async");
|
||||
var start = S.token
|
||||
|
||||
|
|
@ -1319,7 +1319,7 @@ function parse($TEXT, options) {
|
|||
}
|
||||
|
||||
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
|
||||
if (in_statement && !name)
|
||||
if (in_statement && !name && !is_export_default)
|
||||
unexpected();
|
||||
|
||||
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
|
||||
|
|
@ -2528,7 +2528,7 @@ function parse($TEXT, options) {
|
|||
&& is_token(peek(), "punc")) {
|
||||
exported_value = expression(false);
|
||||
semicolon();
|
||||
} else if ((node = statement()) instanceof AST_Definitions && is_default) {
|
||||
} else if ((node = statement(is_default)) instanceof AST_Definitions && is_default) {
|
||||
unexpected(node.start);
|
||||
} else if (node instanceof AST_Definitions || node instanceof AST_Defun || node instanceof AST_DefClass) {
|
||||
exported_definition = node;
|
||||
|
|
|
|||
|
|
@ -262,3 +262,37 @@ trailing_comma: {
|
|||
}
|
||||
expect_exact: "export const a = 1;"
|
||||
}
|
||||
|
||||
export_default_anonymous_function: {
|
||||
input: {
|
||||
export default function () {
|
||||
foo();
|
||||
}
|
||||
}
|
||||
expect_exact: "export default function(){foo()};"
|
||||
}
|
||||
|
||||
export_default_anonymous_generator: {
|
||||
input: {
|
||||
export default function * () {
|
||||
yield foo();
|
||||
}
|
||||
}
|
||||
expect_exact: "export default function*(){yield foo()};"
|
||||
}
|
||||
|
||||
export_default_anonymous_async_function: {
|
||||
input: {
|
||||
export default async function() {
|
||||
return await foo();
|
||||
}
|
||||
}
|
||||
expect_exact: "export default async function(){return await foo()};"
|
||||
}
|
||||
|
||||
export_default_async_arrow_function: {
|
||||
input: {
|
||||
export default async () => await foo();
|
||||
}
|
||||
expect_exact: "export default async()=>await foo();"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user