Skip to content

Commit

Permalink
fix for "module.exports = null" (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Nov 18, 2020
1 parent f7ef235 commit d1725c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

Previously esbuild always joined the `baseUrl` path to the end of the current directory path. However, if the `baseUrl` was an absolute path, that would end up including the current directory path twice. This situation could arise internally in certain cases involving multiple `tsconfig.json` files and `extends` fields even if the `tsconfig.json` files themselves didn't have absolute paths. Absolute paths are now not modified and should work correctly.

* Fix crash for modules that do `module.exports = null` ([#532](https://github.com/evanw/esbuild/issues/532))

The code generated by esbuild would crash at run-time if a module overwrote `module.exports` with null or undefined. This has been fixed and no longer crashes.

## 0.8.9

* Add support for the `mips64le` architecture ([#523](https://github.com/evanw/esbuild/issues/523))
Expand Down
4 changes: 2 additions & 2 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func code(isES6 bool) string {
}
export var __exportStar = (target, module, desc) => {
__markAsModule(target)
if (typeof module === 'object' || typeof module === 'function')
if (module && typeof module === 'object' || typeof module === 'function')
`

// Avoid "let" when not using ES6
Expand Down Expand Up @@ -116,7 +116,7 @@ func code(isES6 bool) string {
if (module && module.__esModule)
return module
return __exportStar(
__defProp(__create(__getProtoOf(module)), 'default', { value: module, enumerable: true }),
__defProp(module != null ? __create(__getProtoOf(module)) : {}, 'default', { value: module, enumerable: true }),
module)
}
Expand Down
8 changes: 8 additions & 0 deletions scripts/end-to-end-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@
'in.js': `import * as out from './foo'; if (out.default !== 123) throw 'fail'`,
'foo.js': `module.exports = 123`,
}),
test(['--bundle', 'in.js', '--outfile=node.js', '--target=' + target].concat(minify), {
'in.js': `import * as out from './foo'; if (out.default !== null) throw 'fail'`,
'foo.js': `module.exports = null`,
}),
test(['--bundle', 'in.js', '--outfile=node.js', '--target=' + target].concat(minify), {
'in.js': `import * as out from './foo'; if (out.default !== void 0) throw 'fail'`,
'foo.js': `module.exports = void 0`,
}),
test(['--bundle', 'in.js', '--outfile=node.js', '--target=' + target].concat(minify), {
'in.js': `import * as out from './foo'; if (out.foo !== 123) throw 'fail'`,
'foo.js': `export var foo = 123`,
Expand Down

0 comments on commit d1725c9

Please sign in to comment.