Skip to content

fix(engine): name an anonymous default export before its static elements - #5544

Open
IamYipi wants to merge 1 commit into
boa-dev:mainfrom
IamYipi:fix/default-export-class-name
Open

IamYipi wants to merge 1 commit into
boa-dev:mainfrom
IamYipi:fix/default-export-class-name

Conversation

@IamYipi

@IamYipi IamYipi commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

This Pull Request fixes the name of an anonymous class exported with export default AssignmentExpression when the class has a static name method.

export default (class { static name() { return 'name method'; } });
// C.name was the string "default" instead of the method

export default AssignmentExpression ; evaluates an anonymous function definition with NamedEvaluation and the argument "default". For a class, ClassDefinitionEvaluation calls SetFunctionName(F, "default") before it defines the static elements, so a static name method replaces the name. Boa compiled the expression first and then emitted SetFunctionName on the finished class, which overwrote the method.

It changes the following:

  • The parser names the expression default with set_anonymous_function_definition_name, as it already does for every other NamedEvaluation site (variable declarations, assignments, property definitions, class fields). The name is then in place when the class is compiled.
  • The bytecompiler no longer emits the late SetFunctionName for DefaultAssignmentExpression. The step comments now follow the spec.
  • Adds test_default_export_named_evaluation to core/engine/tests/module.rs. It checks that anonymous functions, arrow functions and classes are still named default, and that a static name method replaces the name.

Test262 results for the full suite, compared with main using boa_tester compare: 2 tests fixed, no regressions.

test/language/module-code/eval-export-dflt-expr-cls-name-meth.js
test/language/expressions/dynamic-import/eval-export-dflt-expr-cls-name-meth.js

cargo fmt --all --check is clean. So is cargo clippy -p boa_parser -p boa_engine --all-features --all-targets with -D warnings.

@IamYipi
IamYipi requested a review from a team as a code owner September 30, 2026 03:55
@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Sep 30, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Sep 30, 2026
@github-actions github-actions Bot added C-Parser Issues surrounding the parser C-Tests Issues and PRs related to the tests. C-VM Issues and PRs related to the Boa Virtual Machine. labels Sep 30, 2026
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,447 51,449 +2
Ignored 1,648 1,648 0
Failed 483 481 -2
Panics 0 0 0
Conformance 96.02% 96.03% +0.00%
Fixed tests (2):
test/language/module-code/eval-export-dflt-expr-cls-name-meth.js (previously Failed)
test/language/expressions/dynamic-import/eval-export-dflt-expr-cls-name-meth.js (previously Failed)

Tested main commit: ef40c63283e1bb73f371d93372e9e95217a36945
Tested PR commit: eff4a463ec41dc1037a88968103c4538948bc409
Compare commits: ef40c63...eff4a46

`export default AssignmentExpression` names an anonymous function
definition through NamedEvaluation, so a class gets the name "default"
inside ClassDefinitionEvaluation, before its static elements are
defined, and a static `name` method replaces it. The bytecompiler
instead called SetFunctionName on the finished value, which overwrote
such a method. Name the expression in the parser, as every other
NamedEvaluation site does, and drop the late SetFunctionName.
@IamYipi
IamYipi force-pushed the fix/default-export-class-name branch from 8382ab6 to eff4a46 Compare October 7, 2026 08:23
@IamYipi

IamYipi commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main: the Lint failure came from the Rust 1.99 clippy lints that #5552 fixed. cargo fmt --check and cargo clippy -D warnings on boa_engine, boa_parser and boa_ast pass on the rebased branch.

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.02%. Comparing base (6ddc2b4) to head (eff4a46).
⚠️ Report is 1064 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5544       +/-   ##
===========================================
+ Coverage   47.24%   63.02%   +15.77%     
===========================================
  Files         476      536       +60     
  Lines       46892    60309    +13417     
===========================================
+ Hits        22154    38007    +15853     
+ Misses      24738    22302     -2436     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Parser Issues surrounding the parser C-Tests Issues and PRs related to the tests. C-VM Issues and PRs related to the Boa Virtual Machine. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant