Skip to content

Commit fb2ad1e

Browse files
matetokodiksh8281
authored andcommitted
Fix exporting async functions in ESM modules
Add mjs file matching to regression test script
1 parent 32e9a72 commit fb2ad1e

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/parser/esprima_cpp/esprima.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6811,7 +6811,7 @@ class Parser {
68116811
this->throwUnexpectedToken(this->lookahead);
68126812
}
68136813
this->consumeSemicolon();
6814-
} else if (this->lookahead.type == Token::KeywordToken) {
6814+
} else if (this->lookahead.type == Token::KeywordToken || this->matchAsyncFunction()) {
68156815
// export var f = 1;
68166816
auto oldNameCallback = this->nameDeclaredCallback;
68176817
AtomicStringVector declaredNames;
@@ -6827,19 +6827,24 @@ class Parser {
68276827
}
68286828
AtomicStringVector declaredName;
68296829
ASTNode declaration = nullptr;
6830-
switch (this->lookahead.valueKeywordKind) {
6831-
case KeywordKind::LetKeyword:
6832-
case KeywordKind::ConstKeyword:
6833-
declaration = this->parseLexicalDeclaration(builder, false);
6834-
break;
6835-
case KeywordKind::VarKeyword:
6836-
case KeywordKind::ClassKeyword:
6837-
case KeywordKind::FunctionKeyword:
6838-
declaration = this->parseStatementListItem(builder);
6839-
break;
6840-
default:
6841-
this->throwUnexpectedToken(this->lookahead);
6842-
break;
6830+
6831+
if (this->lookahead.type == Token::KeywordToken) {
6832+
switch (this->lookahead.valueKeywordKind) {
6833+
case KeywordKind::LetKeyword:
6834+
case KeywordKind::ConstKeyword:
6835+
declaration = this->parseLexicalDeclaration(builder, false);
6836+
break;
6837+
case KeywordKind::VarKeyword:
6838+
case KeywordKind::ClassKeyword:
6839+
case KeywordKind::FunctionKeyword:
6840+
declaration = this->parseStatementListItem(builder);
6841+
break;
6842+
default:
6843+
this->throwUnexpectedToken(this->lookahead);
6844+
break;
6845+
}
6846+
} else {
6847+
declaration = this->parseFunctionDeclaration(builder);
68436848
}
68446849

68456850
for (size_t i = 0; i < declaredNames.size(); i++) {
@@ -6852,9 +6857,6 @@ class Parser {
68526857
}
68536858
exportDeclaration = this->finalize(node, builder.createExportNamedDeclarationNode(declaration, ASTNodeList(), nullptr));
68546859
this->nameDeclaredCallback = oldNameCallback;
6855-
} else if (this->matchAsyncFunction()) {
6856-
ASTNode declaration = this->parseFunctionDeclaration(builder);
6857-
exportDeclaration = this->finalize(node, builder.createExportNamedDeclarationNode(declaration, ASTNodeList(), nullptr));
68586860
} else {
68596861
ASTNodeList specifiers;
68606862
ASTNode source = nullptr;

tools/run-tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,11 @@ def run_regression_tests(engine, arch, extra_arg):
447447
REGRESSION_ASSERT_JS = join(REGRESSION_DIR, 'assert.js')
448448

449449
print('Running regression tests:')
450-
xpass = glob(join(REGRESSION_DIR, 'issue-*.js'))
450+
xpass = glob(join(REGRESSION_DIR, 'issue-*.js')) + glob(join(REGRESSION_DIR, 'issue-*.mjs'))
451451
xpass_result = _run_regression_tests(engine, REGRESSION_ASSERT_JS, xpass, False)
452452

453453
print('Running regression tests expected to fail:')
454-
xfail = glob(join(REGRESSION_XFAIL_DIR, 'issue-*.js'))
454+
xfail = glob(join(REGRESSION_XFAIL_DIR, 'issue-*.js')) + glob(join(REGRESSION_XFAIL_DIR, 'issue-*.mjs'))
455455
xfail_result = _run_regression_tests(engine, REGRESSION_ASSERT_JS, xfail, True)
456456

457457
tests_total = len(xpass) + len(xfail)

0 commit comments

Comments
 (0)