-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: separately export
__proto__
for compatibility with CJS Transpi…
…ler Re-exports (#5380) * test: add a basic test * feat: Export __proto__ outside the forEach * test: update test snapshots * Enhance the reliability of the test * 4.10.0 * Introduce output.reexportProtoFromExternal option * Update documentation * Adapt tests * Tweak documentation * Update Command line flags --------- Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
- Loading branch information
1 parent
7624208
commit f74d0a9
Showing
33 changed files
with
279 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { execSync } = require('node:child_process'); | ||
|
||
module.exports = defineTest({ | ||
description: | ||
'Disable reexporting the __proto__ from the external module if both output.externalLiveBindings and output.reExportProtoFromExternal are false', | ||
formats: ['cjs'], | ||
options: { | ||
output: { | ||
externalLiveBindings: false, | ||
reexportProtoFromExternal: false | ||
}, | ||
plugins: [ | ||
{ | ||
resolveId(id) { | ||
if (id.endsWith('main.js')) { | ||
return { id }; | ||
} | ||
return { | ||
id, | ||
external: true | ||
}; | ||
}, | ||
buildEnd() { | ||
this.emitFile({ | ||
type: 'prebuilt-chunk', | ||
fileName: 'foo.js', | ||
code: | ||
'exports.foo = 1;\n' + | ||
'Object.defineProperty(exports, "__proto__", {\n' + | ||
' enumerable: true,\n' + | ||
' value: 2\n' + | ||
'});' | ||
}); | ||
this.emitFile({ | ||
type: 'prebuilt-chunk', | ||
fileName: 'execute.mjs', | ||
code: | ||
'import assert from "node:assert";\n' + | ||
'import { foo, __proto__ } from "./cjs.js";\n' + | ||
'assert.strictEqual(foo, 1);\n' + | ||
'assert.strictEqual(__proto__, undefined);' | ||
}); | ||
} | ||
} | ||
] | ||
}, | ||
after() { | ||
execSync('node _actual/execute.mjs', { cwd: __dirname }); | ||
} | ||
}); |
9 changes: 9 additions & 0 deletions
9
test/form/samples/cjs-transpiler-re-exports-1/_expected/cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var foo_js = require('./foo.js'); | ||
|
||
|
||
|
||
Object.keys(foo_js).forEach(function (k) { | ||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = foo_js[k]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './foo.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { execSync } = require('node:child_process'); | ||
|
||
module.exports = defineTest({ | ||
description: | ||
'Compatibility with CJS Transpiler Re-exports if output.externalLiveBindings is false', | ||
formats: ['cjs'], | ||
options: { | ||
output: { | ||
externalLiveBindings: false | ||
}, | ||
plugins: [ | ||
{ | ||
resolveId(id) { | ||
if (id.endsWith('main.js')) { | ||
return { id }; | ||
} | ||
return { | ||
id, | ||
external: true | ||
}; | ||
}, | ||
buildEnd() { | ||
this.emitFile({ | ||
type: 'prebuilt-chunk', | ||
fileName: 'foo.js', | ||
code: | ||
'exports.foo = 1;\n' + | ||
'Object.defineProperty(exports, "__proto__", {\n' + | ||
' enumerable: true,\n' + | ||
' value: 2\n' + | ||
'});' | ||
}); | ||
this.emitFile({ | ||
type: 'prebuilt-chunk', | ||
fileName: 'execute.mjs', | ||
code: | ||
'import assert from "node:assert";\n' + | ||
'import { foo, __proto__ } from "./cjs.js";\n' + | ||
'assert.strictEqual(foo, 1);\n' + | ||
'assert.strictEqual(__proto__, 2);' | ||
}); | ||
} | ||
} | ||
] | ||
}, | ||
after() { | ||
execSync('node _actual/execute.mjs', { cwd: __dirname }); | ||
} | ||
}); |
16 changes: 16 additions & 0 deletions
16
test/form/samples/cjs-transpiler-re-exports/_expected/cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
var foo_js = require('./foo.js'); | ||
|
||
|
||
|
||
Object.prototype.hasOwnProperty.call(foo_js, '__proto__') && | ||
!Object.prototype.hasOwnProperty.call(exports, '__proto__') && | ||
Object.defineProperty(exports, '__proto__', { | ||
enumerable: true, | ||
value: foo_js['__proto__'] | ||
}); | ||
|
||
Object.keys(foo_js).forEach(function (k) { | ||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = foo_js[k]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './foo.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.