Repository navigation
Conversation
imports in JS compiler toolsimports in JS compiler tools
There was a problem hiding this comment.
Code Review
This pull request refactors the initialization logic of several compiler modules (modules.mjs, parseTools.mjs, and parseTools_legacy.mjs) by wrapping top-level side effects into explicit initialization functions (initModules, initParseTools, and initLegacyParseTools). This allows the tools (compiler.mjs and preprocessor.mjs) to use static imports instead of dynamic imports, which were previously used to delay execution until global settings were configured. Regarding the feedback, it is recommended to initialize POINTER_SIZE and POINTER_TYPE to sensible default values (such as wasm32 defaults) in parseTools.mjs to prevent potential undefined errors or test failures in scripts that import the module without explicitly calling initParseTools().
…ssor.mjs` Move top-level setting evaluations in `src/modules.mjs`, `src/parseTools.mjs`, and `src/parseTools_legacy.mjs` into explicit `initModules()`, `initParseTools()`, and `initLegacyParseTools()` functions called after `applySettings()`. This allows `tools/compiler.mjs` and `tools/preprocessor.mjs` to use normal top-level `import` statements instead of dynamic `await import()` calls. Avoids a second round of dynamic module resolution at runtime (reducing `compiler.mjs`'s `startup` phase from ~19 ms to ~5 ms under `EMPROFILE=2`) and makes the module graph completely static so the tools can be cleanly bundled into single-file outputs without code-splitting boundaries or top-level evaluation order issues.
d26baa8 to
4a8eb7c
Compare
Move top-level setting evaluations in
src/modules.mjs,src/parseTools.mjs, andsrc/parseTools_legacy.mjsinto explicitinitModules(),initParseTools(), andinitLegacyParseTools()functions called afterapplySettings().This allows
tools/compiler.mjsandtools/preprocessor.mjsto use normal top-levelimportstatements instead of dynamicawait import()calls.Avoids a second round of dynamic module resolution at runtime (reducing
compiler.mjs'sstartupphase from ~19 ms to ~5 ms underEMPROFILE=2) and makes the module graph completely static so the tools can be cleanly bundled into single-file outputs without code-splitting boundaries or top-level evaluation order issues.