Skip to content

Commit

Permalink
fix #272: dynamic import doubling as entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 19, 2020
1 parent 46559d8 commit 45e33dd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

Re-exporting a symbol in an entry point didn't correctly track the cross-chunk dependency, which caused the output file to be missing a required import. This bug has been fixed.

* Fix code splitting if a dynamic entry point is doubled as a normal entry point ([#272](https://github.com/evanw/esbuild/issues/272))

Using a dynamic `import()` expression automatically adds the imported path as an entry point. However, manually adding the imported path to the bundler entry point list resulted in a build failure. This case is now handled.

## 0.6.3

* Fix `/* @__PURE__ */` IIFEs at start of statement ([#258](https://github.com/evanw/esbuild/issues/258))
Expand Down
31 changes: 31 additions & 0 deletions internal/bundler/bundler_splitting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,34 @@ export {
},
})
}

func TestSplittingDynamicImportIssue272(t *testing.T) {
expectBundled(t, bundled{
files: map[string]string{
"/a.js": `
import('./b')
`,
"/b.js": `
export default 1
`,
},
entryPaths: []string{"/a.js", "/b.js"},
options: config.Options{
IsBundling: true,
CodeSplitting: true,
OutputFormat: config.FormatESModule,
AbsOutputDir: "/out",
},
expected: map[string]string{
"/out/a.js": `// /a.js
import("./b.js");
`,
"/out/b.js": `// /b.js
var b_default = 1;
export {
b_default as default
};
`,
},
})
}
2 changes: 1 addition & 1 deletion internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,8 @@ func (c *linkerContext) scanImportsAndExports() {
otherFileMeta := &c.fileMeta[*record.SourceIndex]
if otherFileMeta.entryPointStatus == entryPointNone {
c.entryPoints = append(c.entryPoints, *record.SourceIndex)
otherFileMeta.entryPointStatus = entryPointDynamicImport
}
otherFileMeta.entryPointStatus = entryPointDynamicImport
}
} else {
// If we're not splitting, then import() is just a require() that
Expand Down

0 comments on commit 45e33dd

Please sign in to comment.