Repository navigation
Compile the packages an import()-loaded module requires; compile TypeScript enums in packages - #1517
Merged
Merged
Conversation
A compiled package spells each enum as a bare `var` filled by an
immediately invoked function (`(function (Kind) { Kind["A"] = "A"; })(Kind
|| (exports.Kind = Kind = {}))`). Inference types the variable from the
empty object the argument creates, so every member read landed on `{}` and
failed at run time. When every member value is a literal, the declaration
now becomes the object literal the function builds, keys in Node's
own-property order, and the call becomes the export assignment it
performs. The TypeScript 5 spelling, the earlier `Kind = exports.Kind ||
(exports.Kind = {})` spelling and unexported enums are recognized; merged,
computed or otherwise written enums keep their text.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A workspace package loaded on demand had its npm dependency selected, but the selection never scanned that dependency's own JavaScript: it is outside the startup module order, so a compiled CommonJS dist requiring a sibling package was refused with "the module is not supported yet". The scan of the import() graph now follows opted-in package JavaScript through its literal require() and import edges. The lowering appended those modules by their import declarations only, so a CommonJS file's requires never joined the compiled graph and their bindings stayed fenced. Preflight's resolved module edges, require edges included, now reach the walks that append import(), fork() and Worker modules, with lazy requires ordered after their module and inline require cycles answered as at startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`deadDeclarators.add(d).add(memoDecl)` stopped the self-hosting build with "chained Set method calls ... has no scriptc lowering yet". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
…/npm-dynamic-import-deps
TypeScript's ES module emit for an exported enum is `export var Kind;`
followed by the IIFE. The rewrite replaced the declaration with a plain
`var Kind = { ... };`, so importers of the module lost the export. The
replacement now keeps the modifiers before `var`.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1458. Review the stack below it first.
Summary
Packages required by a module loaded through
import(). #1487 made npm selection follow the program modules a literalimport()reaches, so a workspace package loaded on demand gets its npm dependencies compiled. That stopped one level too early. When the dependency was compiled CommonJS that requires a sibling package (a package shipping.d.tsplus JS, the way@typescript-eslint/*and many tsc-built packages ship), the build was refused with "SC1010: the '' module is not supported yet". The same program with a static import compiled. Two pieces were missing:import()graph skipped package files, so the dependency's own requires were never read. It now follows opted-in package JavaScript through its literalrequire()and import edges, the same files the program can load.import()-only modules by their import declarations alone, so a CommonJS file's requires never joined the compiled graph and its require bindings stayed fenced. Preflight already resolves every file's module edges, require edges included. Those edges now reach the walks that appendimport(),fork()andWorkermodules. Lazy requires are ordered after their module, and an inline require that closes a cycle there is answered as at startup.TypeScript enums in npm packages. tsc compiles an enum to a bare
varfilled by an immediately invoked function:Inference types
Kindfrom the empty object the argument creates, so every member read landed on{}, and reading one failed at run time ("undefined is not representable in a '{}' slot"). When every member value is a literal, a new rewrite stage (npm-static-enum-iife.ts) turns the declaration into the object literal the function builds and the call into the export assignment it performs. Keys follow Node's own-property order: integer keys ascending, then the rest in insertion order, with a later write replacing an earlier value in place. Numeric enums keep their reverse mapping. The stage recognizes three spellings:Kind = exports.Kind || (exports.Kind = {});Merged declarations, computed members, members referencing other members, and any other write to the variable keep their original text.
Self-hosting. #1422's
deadDeclarators.add(d).add(memoDecl)(innpm-static-bundled-esm.ts) stopped the self-hosted compiler with "chained Set method calls … has no scriptc lowering yet". The split into two calls now lives in #1422 (1092f69) and is merged up through #1458 into this branch. This branch's earlier copy of the same change merges cleanly with it.Evidence
workspace-dynamic-import-deps. The program loads a workspace package throughimport(). That package imports a compiled CommonJS scoped package, which re-exports from a nested file that requires a sibling scoped package exporting a tsc-emitted string enum. Output is byte-identical to Node's. On Compile polyfill packages that are Node builtins as the builtins #1458's tip the build fails with SC2013/SC1010.npm-static-enum-iife.test.tsruns original and rewritten modules under Node for exported string enums, numeric enums (reverse mapping, negative values, key order, a duplicate value), and an unexported enum. It also checks that line positions are preserved, and that merged, computed, side-effecting and reassigned enums are left alone.workspace-dynamic-import,dynamic-import,dynamic-import-local,workspace-*andhoisted-workspacenpm cases pass.self-hosting-native-driver.test.tspasses on the final candidate (1673 s).pnpm lint,pnpm format:checkandtest:ts7 --baselines-onlypass. Re-recording all order baselines adds only the new case's entry.package-shimssuites and the frontend unit tests pass: 1103 of 1104. The one failure,node24-url-authority, comes from the sandbox's Node 24.15 versus the pinned 24.22.🤖 Generated with Claude Code