Repository navigation
fix(cli): rewrite import extensions in transpile output - #36403
rathodkunj2005 wants to merge 6 commits into
Conversation
bartlomieju
left a comment
There was a problem hiding this comment.
Fixes #36399 and matches what the docs promise. The parse_module_with_post_process + VisitMut approach is the right hook, and clearing raw so the new value is what gets emitted is the easy thing to get wrong.
I pushed one fix: rewrite was matching on the extension alone, so it also rewrote specifiers that don't point at anything deno transpile emits — https://deno.land/x/foo/mod.ts became .../mod.js, and likewise for npm:/jsr:/bare/absolute specifiers. That turns a working import into a 404. It now only rewrites ./ and ../ specifiers, which is both what the docs describe ("./foo.ts → ./foo.js") and what tsc's rewriteRelativeImportExtensions does. Added unit coverage for the non-relative cases.
Two non-blocking nits:
check_import_extensions.tsprints a singletrue/false, so a failure gives no clue which specifier didn't get rewritten.assertEqualson the emitted text, or a fewasserts, would make CI failures diagnosable.- The stray
export {};in the middle of that file isn't doing anything — the top-levelawaitalready makes it a module.
The test node_compat failure looks unrelated to this change. LGTM.
|
Thanks — addressed both review comments in 182fbcf. What changed:
Verification run locally:
|
|
Follow-up: fixed the formatter failure from the new
|
Closes #36399.
Summary
deno transpile(.ts/.tsx→.js,.mts→.mjs,.cts→.cjs).Verification
cargo check -p deno./tools/format.js --check cli/tools/transpile.rs cli/tools/transpile/import_extensions.rs tests/specs/transpile/__test__.jsonc tests/specs/transpile/import_extensions.ts tests/specs/transpile/check_import_extensions.ts tests/specs/transpile/rewrite_import_extensions_emit.outrustc --edition=2024 --test cli/tools/transpile/import_extensions.rs -o /tmp/import_extensions_test && /tmp/import_extensions_test(2 passed)AI assistance was used to investigate the issue and implement this change; I reviewed the resulting code and tests.