Skip to content

Commit

Permalink
fix #437: crash in minify and splitting edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Oct 6, 2020
1 parent 925421f commit 048dea3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

* Fix regression in 0.7.9 when minifying with code splitting ([#437](https://github.com/evanw/esbuild/issues/437))

In certain specific cases, bundling and minifying with code splitting active can cause a crash. This is a regression that was introduced in version 0.7.9 due to the fix for issue [#421](https://github.com/evanw/esbuild/issues/421). The crash has been fixed and this case now has test coverage.

## 0.7.10

* Recover from bad `main` field in `package.json` ([#423](https://github.com/evanw/esbuild/issues/423))
Expand Down
29 changes: 29 additions & 0 deletions internal/bundler/bundler_splitting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,32 @@ func TestSplittingDuplicateChunkCollision(t *testing.T) {
},
})
}

func TestSplittingMinifyIdentifiersCrashIssue437(t *testing.T) {
splitting_suite.expectBundled(t, bundled{
files: map[string]string{
"/a.js": `
import {foo} from "./shared"
console.log(foo)
`,
"/b.js": `
import {foo} from "./shared"
console.log(foo)
`,
"/c.js": `
import "./shared"
`,
"/shared.js": `
export function foo(bar) {}
`,
},
entryPaths: []string{"/a.js", "/b.js", "/c.js"},
options: config.Options{
Mode: config.ModeBundle,
CodeSplitting: true,
MinifyIdentifiers: true,
OutputFormat: config.FormatESModule,
AbsOutputDir: "/out",
},
})
}
5 changes: 2 additions & 3 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2537,9 +2537,8 @@ func (c *linkerContext) chunkFileOrder(chunk *chunkInfo) (js []uint32, jsParts [
for partIndex, part := range repr.ast.Parts {
isPartInThisChunk := chunk.entryBits.equals(repr.meta.partMeta[partIndex].entryBits)
if isPartInThisChunk {
if !canFileBeSplit {
isFileInThisChunk = true
} else if uint32(partIndex) != repr.meta.nsExportPartIndex && c.shouldIncludePart(repr, part) {
isFileInThisChunk = true
if canFileBeSplit && uint32(partIndex) != repr.meta.nsExportPartIndex && c.shouldIncludePart(repr, part) {
if sourceIndex == runtime.SourceIndex {
jsPartsPrefix = appendOrExtendPartRange(jsPartsPrefix, sourceIndex, uint32(partIndex))
} else {
Expand Down
29 changes: 29 additions & 0 deletions internal/bundler/snapshots/snapshots_splitting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,35 @@ import("../node_modules/package/index.js");
// /Users/user/project/node_modules/package/index.js
console.log("imported");

================================================================================
TestSplittingMinifyIdentifiersCrashIssue437
---------- /out/a.js ----------
import {
a as o
} from "./chunk.Q6GOQWO2.js";

// /a.js
console.log(o);

---------- /out/b.js ----------
import {
a as o
} from "./chunk.Q6GOQWO2.js";

// /b.js
console.log(o);

---------- /out/chunk.Q6GOQWO2.js ----------
// /shared.js
function n(o) {
}

export {
n as a
};

---------- /out/c.js ----------

================================================================================
TestSplittingMissingLazyExport
---------- /out/a.js ----------
Expand Down

0 comments on commit 048dea3

Please sign in to comment.