Skip to content

Commit cbd5eb8

Browse files
committed
release notes and tests for #4082
1 parent 31052bd commit cbd5eb8

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
* Fix invalid generated source maps ([#4080](https://github.com/evanw/esbuild/issues/4080), [#4082](https://github.com/evanw/esbuild/issues/4082), [#4107](https://github.com/evanw/esbuild/issues/4107))
6+
7+
This release fixes a regression from version 0.24.1 that could cause esbuild to generate invalid source maps. Specifically under certain conditions, esbuild could generate a mapping with an out-of-bounds source index. It was introduced by code that attempted to improve esbuild's handling of "null" entries in source maps (i.e. mappings with a generated position but no original position). This regression has been fixed.
8+
9+
This fix was contributed by [@jridgewell](https://github.com/jridgewell).
10+
511
* Fix a crash with `switch` optimization ([#4088](https://github.com/evanw/esbuild/issues/4088))
612

713
The new code in the previous release to optimize dead code in switch statements accidentally introduced a crash in the edge case where one or more switch case values include a function expression. This is because esbuild now visits the case values first to determine whether any cases are dead code, and then visits the case values once the dead code status is known. That triggered some internal asserts that guard against traversing the AST in an unexpected order. This crash has been fixed by changing esbuild to expect the new traversal ordering. Here's an example of affected code:

scripts/verify-source-map.js

+62
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,62 @@ const toSearchAbsoluteSourcesURL = {
496496
test: 'input.js',
497497
}
498498

499+
// This case covers a crash when esbuild would generate an invalid source map
500+
// containing a mapping with an index of a source that's out of bounds of the
501+
// "sources" array. This happened when generating the namespace exports chunk
502+
// which in this case is triggered by "export * as it from". For more
503+
// information, see: https://github.com/evanw/esbuild/issues/4080
504+
const testCaseNullMappingIssue4080 = {
505+
'foo.js': `// foo.js
506+
here.is.some.code = "foo!";
507+
//# sourceMappingURL=foo.js.map
508+
`,
509+
'foo.js.map': `{
510+
"version": 3,
511+
"sources": ["./src/foo.js"],
512+
"sourcesContent": ["here\\n .is\\n .some\\n .code\\n = 'foo!'\\n"],
513+
"mappings": ";AAAA,KACG,GACA,KACA,OACC;",
514+
"names": []
515+
}`,
516+
'bar.js': `// bar.js
517+
here.is.some.more.code = "bar!";
518+
//# sourceMappingURL=bar.js.map
519+
`,
520+
'bar.js.map': `{
521+
"version": 3,
522+
"sources": ["./src/bar.js"],
523+
"sourcesContent": ["here\\n .is.some.more\\n .code\\n = 'bar!'\\n"],
524+
"mappings": ";AAAA,KACG,GAAG,KAAK,KACR,OACC;",
525+
"names": []
526+
}`,
527+
'core.js': `// core.js
528+
import "./bar.js";
529+
530+
// lib.js
531+
var value = "lib!";
532+
export {
533+
value
534+
};
535+
//# sourceMappingURL=core.js.map
536+
`,
537+
'core.js.map': `{
538+
"version": 3,
539+
"sources": ["./src/core.js", "./src/lib.js"],
540+
"sourcesContent": ["import './bar.js'\\nexport { value } from './lib.js'\\n", "export const value = 'lib!'\\n"],
541+
"mappings": ";AAAA,OAAO;;;ACAA,IAAM,QAAQ;",
542+
"names": []
543+
}`,
544+
'entry.js': `import './foo.js'
545+
export * as it from './core.js'
546+
`,
547+
}
548+
549+
const toSearchNullMappingIssue4080 = {
550+
'foo!': 'src/foo.js',
551+
'bar!': 'src/bar.js',
552+
'lib!': 'src/lib.js',
553+
}
554+
499555
async function check(kind, testCase, toSearch, { outfile, flags, entryPoints, crlf, followUpFlags = [], checkFirstChunk }) {
500556
let failed = 0
501557

@@ -959,6 +1015,12 @@ async function main() {
9591015
entryPoints: ['entry.js'],
9601016
crlf,
9611017
}),
1018+
check('issue-4048' + suffix, testCaseNullMappingIssue4080, toSearchNullMappingIssue4080, {
1019+
outfile: 'out.js',
1020+
flags: flags.concat('--bundle', '--format=esm'),
1021+
entryPoints: ['entry.js'],
1022+
crlf,
1023+
}),
9621024

9631025
// Checks for the "names" field
9641026
checkNames('names' + suffix, testCaseNames, {

0 commit comments

Comments
 (0)