[nest] Use AST-based CommonJS import rewriting#2080
Conversation
Signed-off-by: yao <zhangyaoruo@outlook.com>
SWC's `module.span.start` keeps the leading shebang line inside the module span but excludes leading line/block comments and a BOM. The previous `getLeadingSyntaxByteOffset` skipped the shebang, which made `module.span.start - leadingOffset - 1` shift every subsequent byte→string mapping. A steps bundle that starts with `#!/usr/bin/env node` would either throw `Unable to map SWC byte position X to a string index` or silently corrupt the rewrite. - Rename `getLeadingSyntaxByteOffset` → `getLeadingCommentByteOffset` and drop the shebang branch. - Document the invariant tying SWC's 1-based global byte counter to source-relative offsets so a future change to SWC's span behavior doesn't silently break the rewriter. - Add test coverage for shebang, shebang+comment, BOM, CRLF, dynamic imports, empty named imports, `default as`, mixed default+namespace, duplicate imports of the same module, and template-literal substrings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 7ae4af5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Benchmark Results
workflow with no steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 1 step💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 10 sequential steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 25 sequential steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 50 sequential steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express Promise.all with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express Promise.all with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express Promise.all with 50 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express Promise.race with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express Promise.race with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express Promise.race with 50 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 10 sequential data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 25 sequential data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 50 sequential data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 10 concurrent data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 25 concurrent data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express workflow with 50 concurrent data payload steps (10KB)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express Stream Benchmarks (includes TTFB metrics)workflow with stream💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express stream pipeline with 5 transform steps (1MB)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express 10 parallel streams (1MB each)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express fan-out fan-in 10 streams (1MB each)💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express SummaryFastest Framework by WorldWinner determined by most benchmark wins
Fastest World by FrameworkWinner determined by most benchmark wins
Column Definitions
Worlds:
❌ Some benchmark jobs failed:
Check the workflow run for details. |
🧪 E2E Test Results✅ All tests passed Summary
Details by Category✅ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
✅ 📋 Other
|
Co-Authored-By: yao <zhangyaoruo@outlook.com>Closes #2001. Picks up @boomyao's AST-based CJS import rewriter from #2001 and addresses review feedback on top:
module.span.startkeeps a leading shebang line inside the module span but excludes leading line/block comments and a BOM. The previousgetLeadingSyntaxByteOffsetskipped the shebang, which mademodule.span.start - leadingOffset - 1shift every byte→string mapping by the shebang's length. A steps bundle starting with#!/usr/bin/env nodewould either throwUnable to map SWC byte position X to a string indexor silently corrupt the rewrite. Renamed togetLeadingCommentByteOffsetand dropped the shebang branch.import("..."), empty named imports,default as, mixed default+namespace, two imports of the same module, and an import-shaped substring inside a template literal.