ReviewOS

also looking at this

stacks/dtsx

fix(bundle): leave template literal text alone when renaming identifiers

#3131
Open mkantautas wants to merge fix/bundle-template-literal-rename into main
3 files +108 -3
9 days ago

Summary

When a bundle renames a name, the same word inside a template literal type is renamed too. With src/flag.ts:

export default 1

and src/index.ts:

import enabled from './flag'
export type Status = `enabled` | `disabled`
export function isEnabled(): number { return Number(enabled) }

generate({ bundle: true }) emits type Status = `__dtsx_default_export__` | `disabled`;, and a consumer assigning 'enabled' fails with TS2322. A declaration renamed for a collision (Options to Options_1) does the same to `Options-${Options}`.

Changes

renameIdentifiers skipped quoted strings and comments, but not template literals. It now copies template literal text as written and still renames inside ${} placeholders, including nested templates. A // inside template text is no longer read as a comment either.

Testing

A renameIdentifiers case in test/bundle-linker.test.ts and an end-to-end generate({ bundle: true }) case in test/module-graph.test.ts, which type-checks a consumer with the existing runTsc helper. Both fail on main.

bun test (Zig library built with the pinned Zig, so its tests run too), typecheck, lint and zig build test pass. Bundles of pinia, vue-router, vue-core's runtime-core, reactivity and shared, knip and tailwindcss are byte-identical before and after.

3 changed files on the files tab, with 0 review threads.

Sign in to comment on this pull request.