fix(codegen): when async is on the left-hand side of a for-of, wrap it in parentheses (#2407)

Refer to
55e1127a49/internal/js_printer/js_printer.go (L3097-L3104)
This commit is contained in:
Dunqing 2024-02-13 22:42:23 +08:00 committed by GitHub
parent 83cb78fbb0
commit b5deb9a708
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View file

@ -315,7 +315,15 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ForStatementLeft<'a> {
match &self {
ForStatementLeft::UsingDeclaration(var) => var.gen(p, ctx),
ForStatementLeft::VariableDeclaration(var) => var.gen(p, ctx),
ForStatementLeft::AssignmentTarget(target) => target.gen(p, ctx),
ForStatementLeft::AssignmentTarget(target) => {
let wrap = matches!(
target,
AssignmentTarget::SimpleAssignmentTarget(
SimpleAssignmentTarget::AssignmentTargetIdentifier(identifier)
) if identifier.name == "async"
);
p.wrap(wrap, |p| target.gen(p, ctx));
}
}
}
}

View file

@ -1,6 +1,6 @@
codegen_runtime_test262 Summary:
AST Parsed : 19407/19407 (100.00%)
Positive Passed: 19260/19407 (99.24%)
Positive Passed: 19262/19407 (99.25%)
Expect to run correctly: "annexB/built-ins/String/prototype/substr/surrogate-pairs.js"
But got a runtime error: Test262Error: start: 1 Expected SameValue(«<>», «\udf06») to be true
@ -433,12 +433,6 @@ But got a runtime error: ReferenceError: Must call super constructor in derived
Expect to run correctly: "language/statements/class/subclass/derived-class-return-override-for-of-arrow.js"
But got a runtime error: ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
Expect to run correctly: "language/statements/for-of/head-lhs-async-escaped.js"
But got a runtime error: SyntaxError: The left-hand side of a for-of loop may not be 'async'.
Expect to run correctly: "language/statements/for-of/head-lhs-async-parens.js"
But got a runtime error: SyntaxError: The left-hand side of a for-of loop may not be 'async'.
Expect to run correctly: "language/statements/for-of/string-astral-truncated.js"
But got a runtime error: Test262Error: Expected SameValue(«\», «\ud801») to be true