mirror of
https://github.com/hanzoai/esbuild.git
synced 2026-09-24 16:58:50 +00:00
follow up: cjs evaluation fixes
This commit is contained in:
+2
-2
@@ -2,9 +2,9 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
* Fix ES module evaluation when an error is thrown ([#4461](https://github.com/evanw/esbuild/issues/4461), [#4467](https://github.com/evanw/esbuild/pull/4467))
|
||||
* Fix module evaluation when an error is thrown ([#4461](https://github.com/evanw/esbuild/issues/4461), [#4467](https://github.com/evanw/esbuild/pull/4467))
|
||||
|
||||
If an error is thrown during ES module evaluation, esbuild previously didn't preserve the state of the module for subsequent module references. This was observable if `import()` is used to import the module multiple times. The thrown error is supposed to be thrown by every call to `import()`, not just the first. With this release, esbuild will now throw the same error every time you call `import()` on a module that throws during its evaluation.
|
||||
If an error is thrown during module evaluation, esbuild previously didn't preserve the state of the module for subsequent module references. This was observable if `import()` or `require()` is used to import a module multiple times. The thrown error is supposed to be thrown by every call to `import()` or `require()`, not just the first. With this release, esbuild will now throw the same error every time you call `import()` or `require()` on a module that throws during its evaluation.
|
||||
|
||||
* Fix some edge cases around the `new` operator ([#4477](https://github.com/evanw/esbuild/issues/4477))
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source {
|
||||
try {
|
||||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res
|
||||
} catch (e) {
|
||||
throw (err = [e]), e
|
||||
throw err = [e], e
|
||||
}
|
||||
}
|
||||
export var __esmMin = (fn, res, err) => () => {
|
||||
@@ -183,7 +183,7 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source {
|
||||
try {
|
||||
return fn && (res = fn(fn = 0)), res
|
||||
} catch (e) {
|
||||
throw (err = [e]), e
|
||||
throw err = [e], e
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,9 +191,19 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source {
|
||||
// implementations, a compact one for minified code and a verbose one that
|
||||
// generates friendly names in V8's profiler and in stack traces.
|
||||
export var __commonJS = (cb, mod) => function __require() {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {exports: {}}).exports, mod), mod.exports
|
||||
try {
|
||||
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports
|
||||
} catch (e) {
|
||||
throw mod = 0, e
|
||||
}
|
||||
}
|
||||
export var __commonJSMin = (cb, mod) => () => {
|
||||
try {
|
||||
return mod || cb((mod = { exports: {} }).exports, mod), mod.exports
|
||||
} catch (e) {
|
||||
throw mod = 0, e
|
||||
}
|
||||
}
|
||||
export var __commonJSMin = (cb, mod) => () => (mod || cb((mod = {exports: {}}).exports, mod), mod.exports)
|
||||
|
||||
// Used to implement ESM exports both for "require()" and "import * as"
|
||||
export var __export = (target, all) => {
|
||||
|
||||
@@ -2141,6 +2141,40 @@ for (const minify of [[], ['--minify']]) {
|
||||
throw null
|
||||
`,
|
||||
}, { async: true }),
|
||||
test(['--bundle', 'in.js', '--outfile=node.js'].concat(minify), {
|
||||
'in.js': `
|
||||
let errors = []
|
||||
for (let i = 0; i < 3; i++) {
|
||||
try {
|
||||
require('./foo')
|
||||
throw new Error('Expected an error')
|
||||
} catch (e) {
|
||||
if (e.message !== 'stop1') throw 'fail ' + i + ': ' + e
|
||||
if (errors.includes(e)) throw 'fail ' + i + ': wrong object'
|
||||
errors.push(e)
|
||||
}
|
||||
}
|
||||
`,
|
||||
'foo.js': `
|
||||
exports.counter = (exports.counter | 0) + 1
|
||||
throw new Error('stop' + exports.counter)
|
||||
`,
|
||||
}),
|
||||
test(['--bundle', 'in.js', '--outfile=node.js'].concat(minify), {
|
||||
'in.js': `
|
||||
for (let i = 0; i < 3; i++) {
|
||||
try {
|
||||
require('./foo')
|
||||
throw new Error('Expected an error')
|
||||
} catch (e) {
|
||||
if (e !== null) throw 'fail ' + i + ': ' + e
|
||||
}
|
||||
}
|
||||
`,
|
||||
'foo.js': `
|
||||
throw null
|
||||
`,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user