Repository navigation
Emit JS library aliases after non-aliases - #28032
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to handle dependency cycles involving aliases in src/jsifier.mjs by deferring the emission of alias definitions until after their targets are initialized, and adds a test case in test/test_jslib.py to verify this behavior. The feedback suggests moving the newly added emittedLibraryItems and deferredAliases variables from the module scope into the runJSify function scope to avoid shared mutable state and potential correctness issues during multiple executions.
58dbca2 to
fd78e88
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces tracking for library aliases separately from library items in src/jsifier.mjs to ensure they are emitted in the correct order, specifically after their targets. It also updates test/test_jslib.py to add a test case verifying that aliases are correctly emitted even when a dependency cycle exists. There are no review comments to address, and I have no additional feedback to provide.
c3e22dc to
ecfac0e
Compare
When a JS library alias target (e.g. `foo`) is visited first and transitively depends on its own alias (e.g. `foo_alias: 'foo'`), `addedLibraryItems['foo']` is marked as visited before `var _foo = ...` is emitted. Emitting `var _foo_alias = _foo;` inline during dependency traversal causes it to appear before `var _foo = ...`, leaving `_foo_alias` initialized to `undefined` for arrow functions and non-hoisted values. Collect JS library alias assignments in `libraryAliases` and emit them after `libraryItems` (and before `postSets`) so all target symbols are defined before any alias assignment runs.
ecfac0e to
75fe99e
Compare
When a JS library alias target (e.g.
foo) is visited first andtransitively depends on its own alias (e.g.
foo_alias: 'foo'),addedLibraryItems['foo']is marked as visited beforevar _foo = ...is emitted. Emitting
var _foo_alias = _foo;inline during dependencytraversal causes it to appear before
var _foo = ..., leaving_foo_aliasinitialized toundefinedfor arrow functions andnon-hoisted values.
Collect JS library alias assignments in
libraryAliasesand emit themafter
libraryItems(and beforepostSets) so all target symbols aredefined before any alias assignment runs.
Split out from #27995 where this issue was first spotted.