Skip to content

Commit

Permalink
fix #1082: missing space before "Promise" when minifying
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 29, 2021
1 parent 18ee69d commit e402940
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 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 a missing space before internal `import()` when minifying ([#1082](https://github.com/evanw/esbuild/issues/1082))

Internal `import()` of a CommonJS module inside the bundle turns into a call to `Promise.resolve().then(() => require())`. However, a space was not inserted before the `Promise` token when minifying, which could lead to a syntax error. This bug has been fixed.

## 0.11.0

**This release contains backwards-incompatible changes.** Since esbuild is before version 1.0.0, these changes have been released as a new minor version to reflect this (as [recommended by npm](https://docs.npmjs.com/cli/v6/using-npm/semver/)). You should either be pinning the exact version of `esbuild` in your `package.json` file or be using a version range syntax that only accepts patch upgrades such as `~0.10.0`. See the documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information.
Expand Down
1 change: 1 addition & 0 deletions internal/js_printer/js_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ func (p *printer) printRequireOrImportExpr(importRecordIndex uint32, leadingInte

// Internal "require()" or "import()"
if record.Kind == ast.ImportDynamic {
p.printSpaceBeforeIdentifier()
p.print("Promise.resolve()")
level = p.printDotThenPrefix()
defer p.printDotThenSuffix()
Expand Down
10 changes: 10 additions & 0 deletions scripts/end-to-end-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,16 @@
}),
)

// This shouldn't cause a syntax error
// https://github.com/evanw/esbuild/issues/1082
tests.push(
test(['in.js', '--outfile=node.js', '--minify', '--bundle'], {
'in.js': `
return import('./in.js')
`,
})
)

// Tests for "arguments" scope issues
tests.push(
test(['in.js', '--outfile=node.js', '--minify'], {
Expand Down

0 comments on commit e402940

Please sign in to comment.