-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix export namespace of an excluded asset #4220
Conversation
Benchmark Resultspackages/benchmarks/three ✅
Timings
Cold BundlesNo bundle changes detected. Cached Bundles
packages/benchmarks/kitchen-sink ✅
Timings
Cold Bundles
Cached Bundles
packages/benchmarks/react-hn ✅
Timings
Cold BundlesNo bundle changes detected. Cached Bundles
packages/benchmarks/ak-editor 🚨
Timings
Cold BundlesNo bundles found, this is probably a failed build... Cached BundlesNo bundles found, this is probably a failed build... |
ac16275
to
b23482c
Compare
Should it have been excluded though? Seems like if later code is referencing it, then maybe excluding it was wrong? Probably misunderstanding. |
4810963
to
77d7f0d
Compare
77d7f0d
to
0fec5a4
Compare
Well, symbols in // index.js
export * from "./exports";
export const Main = "main";
// exports.js
export { a } from "./version";
export { b } from "./version2";
// version(2) just export a variable The big questions: should we not emit the helper function is possible :? (function(){
function $parcel$exportWildcard(dest, source) {
Object.keys(source).forEach(function (key) {
if (key === 'default' || key === '__esModule') {
return;
}
Object.defineProperty(dest, key, {
enumerable: true,
get: function get() {
return source[key];
}
});
});
return dest;
}
// ASSET: /Users/niklas/Documents/_dev/_git/parcel/parcel/packages/core/integration-tests/test/integration/scope-hoisting/es6/import-namespace-sideEffects/other/index.js
var $e367b6edc7f6de5eef03bc6e42a99$exports = {};
// ASSET: /Users/niklas/Documents/_dev/_git/parcel/parcel/packages/core/integration-tests/test/integration/scope-hoisting/es6/import-namespace-sideEffects/other/exports.js
var $d52a61ca40f5bad1d825ae05f8$exports = {};
var $e7fabb81ca3e1f1a1428a4a075efc$export$a = "foo";
var $c295ce722e44b4d388a0f05140b040$export$b = "bar";
$d52a61ca40f5bad1d825ae05f8$exports.a = $e7fabb81ca3e1f1a1428a4a075efc$export$a;
$d52a61ca40f5bad1d825ae05f8$exports.b = $c295ce722e44b4d388a0f05140b040$export$b;
$parcel$exportWildcard($e367b6edc7f6de5eef03bc6e42a99$exports, $d52a61ca40f5bad1d825ae05f8$exports);
const $e367b6edc7f6de5eef03bc6e42a99$export$Main = "main";
$e367b6edc7f6de5eef03bc6e42a99$exports.Main = $e367b6edc7f6de5eef03bc6e42a99$export$Main;
output = $e367b6edc7f6de5eef03bc6e42a99$exports;
})(); output with this change: (function(){
// ASSET: /Users/niklas/Documents/_dev/_git/parcel/parcel/packages/core/integration-tests/test/integration/scope-hoisting/es6/import-namespace-sideEffects/other/exports.js
// ASSET: /Users/niklas/Documents/_dev/_git/parcel/parcel/packages/core/integration-tests/test/integration/scope-hoisting/es6/import-namespace-sideEffects/other/version.js
var $e7fabb81ca3e1f1a1428a4a075efc$export$a = "foo";
var $c295ce722e44b4d388a0f05140b040$export$b = "bar";
// ASSET: /Users/niklas/Documents/_dev/_git/parcel/parcel/packages/core/integration-tests/test/integration/scope-hoisting/es6/import-namespace-sideEffects/other/index.js
var $e367b6edc7f6de5eef03bc6e42a99$exports = {};
$e367b6edc7f6de5eef03bc6e42a99$exports.a = $e7fabb81ca3e1f1a1428a4a075efc$export$a;
$e367b6edc7f6de5eef03bc6e42a99$exports.b = $c295ce722e44b4d388a0f05140b040$export$b;
const $e367b6edc7f6de5eef03bc6e42a99$export$Main = "main";
$e367b6edc7f6de5eef03bc6e42a99$exports.Main = $e367b6edc7f6de5eef03bc6e42a99$export$Main;
output = $e367b6edc7f6de5eef03bc6e42a99$exports;
})(); |
f999ab9
to
44f0ddb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I fully understand what's going on here. 😉
Could we schedule a time to go through your changes over video so you can explain them to me?
@@ -438,6 +459,86 @@ export function link({ | |||
); | |||
let mod = nullthrows(bundleGraph.getDependencyResolution(dep, bundle)); | |||
path.replaceWith(t.valueToNode(mod.id)); | |||
} else if (callee.name === '$parcel$exportAll') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I totally understand why this is necessary vs the old $parcel$exportWildcard
with a $parcelRequire
inside. Seems like a bunch of logic got duplicated?
This is indeed a giant hack and way too complex, let's do #4387 instead. |
↪️ Pull Request
Closes #4216
An asset with
export * from ...
might be excluded byconcat
, so the exportsSpecifier will be undefined (so$parcel$exportWildcard(something, ReexportingExportsSpecifier)
doesn't work).Solution: don't emit
$parcel$exportWildcard
if the imported asset is a ES6 module, in which casebundleGraph.getExportedSymbols(mod)
are traversed and assignments emitted.cc @wbinnssmith, does this fix your problem?