@parcel/packager-js 2.0.0-rc.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ScopeHoistingPackager.js +18 -9
- package/lib/helpers.js +1 -1
- package/package.json +8 -8
- package/src/ScopeHoistingPackager.js +24 -9
- package/src/helpers.js +1 -1
|
@@ -244,7 +244,7 @@ class ScopeHoistingPackager {
|
|
|
244
244
|
}];
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
-
if (shouldWrap || asset.meta.shouldWrap || this.isAsyncBundle || this.bundle.env.sourceType === 'script' || this.bundleGraph.isAssetReferenced(this.bundle, asset) || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.meta.shouldWrap)) {
|
|
247
|
+
if (shouldWrap || asset.meta.shouldWrap || this.isAsyncBundle || this.bundle.env.sourceType === 'script' || this.bundleGraph.isAssetReferenced(this.bundle, asset) || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')) {
|
|
248
248
|
this.wrappedAssets.add(asset.id);
|
|
249
249
|
return true;
|
|
250
250
|
}
|
|
@@ -686,7 +686,7 @@ ${code}
|
|
|
686
686
|
// and no __esModule flag, we need to resolve to the namespace instead.
|
|
687
687
|
|
|
688
688
|
|
|
689
|
-
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' && resolvedAsset.symbols.hasExportSymbol('*') && resolvedAsset.symbols.hasExportSymbol('default') && !resolvedAsset.symbols.hasExportSymbol('__esModule'); // Find the namespace object for the resolved module. If wrapped and this
|
|
689
|
+
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') && resolvedAsset.symbols.hasExportSymbol('*') && resolvedAsset.symbols.hasExportSymbol('default') && !resolvedAsset.symbols.hasExportSymbol('__esModule'); // Find the namespace object for the resolved module. If wrapped and this
|
|
690
690
|
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
691
691
|
// the hoisted variable declared above. Otherwise, if not wrapped, use the
|
|
692
692
|
// namespace export symbol.
|
|
@@ -704,7 +704,9 @@ ${code}
|
|
|
704
704
|
// we need to use a member access off the namespace object rather
|
|
705
705
|
// than a direct reference. If importing default from a CJS module,
|
|
706
706
|
// use a helper to check the __esModule flag at runtime.
|
|
707
|
-
|
|
707
|
+
let kind = dep === null || dep === void 0 ? void 0 : dep.meta.kind;
|
|
708
|
+
|
|
709
|
+
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' && resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
708
710
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
709
711
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
710
712
|
} else {
|
|
@@ -749,7 +751,7 @@ ${code}
|
|
|
749
751
|
let prependLineCount = 0;
|
|
750
752
|
let append = '';
|
|
751
753
|
let shouldWrap = this.wrappedAssets.has(asset.id);
|
|
752
|
-
let usedSymbols = this.bundleGraph.getUsedSymbols(asset);
|
|
754
|
+
let usedSymbols = (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(asset));
|
|
753
755
|
let assetId = asset.meta.id;
|
|
754
756
|
(0, _assert().default)(typeof assetId === 'string'); // If the asset has a namespace export symbol, it is CommonJS.
|
|
755
757
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
@@ -760,7 +762,7 @@ ${code}
|
|
|
760
762
|
// The one case where this isn't true is in ESM library entries, where the only
|
|
761
763
|
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
762
764
|
// instead of the namespace object.
|
|
763
|
-
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && this.bundleGraph.getUsedSymbols(dep).has('*'))) || // If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
765
|
+
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'))) || // If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
764
766
|
// we fallback on the namespace object.
|
|
765
767
|
asset.symbols.hasExportSymbol('*') && [...usedSymbols].some(s => !asset.symbols.hasExportSymbol(s)) || // If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
766
768
|
// include the namespace object for the default export.
|
|
@@ -803,7 +805,7 @@ ${code}
|
|
|
803
805
|
}
|
|
804
806
|
|
|
805
807
|
let unused = incomingDeps.every(d => {
|
|
806
|
-
let symbols = this.bundleGraph.getUsedSymbols(d);
|
|
808
|
+
let symbols = (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(d));
|
|
807
809
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
808
810
|
});
|
|
809
811
|
return !unused;
|
|
@@ -849,16 +851,23 @@ ${code}
|
|
|
849
851
|
// $parcel$export calls for each used symbol of the dependency.
|
|
850
852
|
|
|
851
853
|
|
|
852
|
-
if (isWrapped || resolved.meta.staticExports === false || this.bundleGraph.getUsedSymbols(resolved).has('*')
|
|
854
|
+
if (isWrapped || resolved.meta.staticExports === false || (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') || // an empty asset
|
|
855
|
+
!resolved.meta.hasCJSExports && resolved.symbols.hasExportSymbol('*')) {
|
|
853
856
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep);
|
|
854
857
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
855
858
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
856
859
|
} else {
|
|
857
|
-
for (let symbol of this.bundleGraph.getUsedSymbols(dep)) {
|
|
860
|
+
for (let symbol of (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep))) {
|
|
861
|
+
if (symbol === 'default' || // `export * as ...` does not include the default export
|
|
862
|
+
symbol === '__esModule') {
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
|
|
858
866
|
let resolvedSymbol = this.getSymbolResolution(asset, resolved, symbol);
|
|
859
867
|
let get = this.buildFunctionExpression([], resolvedSymbol);
|
|
860
868
|
let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`) : '';
|
|
861
869
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(symbol)}, ${get}${set});\n`;
|
|
870
|
+
this.usedHelpers.add('$parcel$export');
|
|
862
871
|
prependLineCount++;
|
|
863
872
|
}
|
|
864
873
|
}
|
|
@@ -960,7 +969,7 @@ ${code}
|
|
|
960
969
|
return true;
|
|
961
970
|
}
|
|
962
971
|
|
|
963
|
-
return asset.sideEffects === false && this.bundleGraph.getUsedSymbols(asset).size == 0 && !this.bundleGraph.isAssetReferenced(this.bundle, asset);
|
|
972
|
+
return asset.sideEffects === false && (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(asset)).size == 0 && !this.bundleGraph.isAssetReferenced(this.bundle, asset);
|
|
964
973
|
}
|
|
965
974
|
|
|
966
975
|
isScriptEntry(asset) {
|
package/lib/helpers.js
CHANGED
|
@@ -43,7 +43,7 @@ const helpers = {
|
|
|
43
43
|
`,
|
|
44
44
|
$parcel$exportWildcard: `function $parcel$exportWildcard(dest, source) {
|
|
45
45
|
Object.keys(source).forEach(function(key) {
|
|
46
|
-
if (key === 'default' || key === '__esModule') {
|
|
46
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/index.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.0.0
|
|
20
|
+
"parcel": "^2.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.0.0
|
|
24
|
-
"@parcel/hash": "2.0.0
|
|
25
|
-
"@parcel/plugin": "2.0.0
|
|
26
|
-
"@parcel/source-map": "2.0.0
|
|
27
|
-
"@parcel/utils": "2.0.0
|
|
23
|
+
"@parcel/diagnostic": "^2.0.0",
|
|
24
|
+
"@parcel/hash": "^2.0.0",
|
|
25
|
+
"@parcel/plugin": "^2.0.0",
|
|
26
|
+
"@parcel/source-map": "^2.0.0",
|
|
27
|
+
"@parcel/utils": "^2.0.0",
|
|
28
28
|
"globals": "^13.2.0",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "84da50ae6943bff9741e2fc76d2f4968074cbbd6"
|
|
32
32
|
}
|
|
@@ -244,7 +244,7 @@ export class ScopeHoistingPackager {
|
|
|
244
244
|
this.bundleGraph.isAssetReferenced(this.bundle, asset) ||
|
|
245
245
|
this.bundleGraph
|
|
246
246
|
.getIncomingDependencies(asset)
|
|
247
|
-
.some(dep => dep.meta.shouldWrap)
|
|
247
|
+
.some(dep => dep.meta.shouldWrap && dep.specifierType !== 'url')
|
|
248
248
|
) {
|
|
249
249
|
this.wrappedAssets.add(asset.id);
|
|
250
250
|
return true;
|
|
@@ -741,7 +741,7 @@ ${code}
|
|
|
741
741
|
exportSymbol === 'default' &&
|
|
742
742
|
staticExports &&
|
|
743
743
|
!isWrapped &&
|
|
744
|
-
dep?.meta.kind === 'Import' &&
|
|
744
|
+
(dep?.meta.kind === 'Import' || dep?.meta.kind === 'Export') &&
|
|
745
745
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
746
746
|
resolvedAsset.symbols.hasExportSymbol('default') &&
|
|
747
747
|
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
@@ -771,8 +771,9 @@ ${code}
|
|
|
771
771
|
// we need to use a member access off the namespace object rather
|
|
772
772
|
// than a direct reference. If importing default from a CJS module,
|
|
773
773
|
// use a helper to check the __esModule flag at runtime.
|
|
774
|
+
let kind = dep?.meta.kind;
|
|
774
775
|
if (
|
|
775
|
-
dep
|
|
776
|
+
(!dep || kind === 'Import' || kind === 'Export') &&
|
|
776
777
|
exportSymbol === 'default' &&
|
|
777
778
|
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
778
779
|
this.needsDefaultInterop(resolvedAsset)
|
|
@@ -840,7 +841,7 @@ ${code}
|
|
|
840
841
|
let append = '';
|
|
841
842
|
|
|
842
843
|
let shouldWrap = this.wrappedAssets.has(asset.id);
|
|
843
|
-
let usedSymbols = this.bundleGraph.getUsedSymbols(asset);
|
|
844
|
+
let usedSymbols = nullthrows(this.bundleGraph.getUsedSymbols(asset));
|
|
844
845
|
let assetId = asset.meta.id;
|
|
845
846
|
invariant(typeof assetId === 'string');
|
|
846
847
|
|
|
@@ -865,7 +866,8 @@ ${code}
|
|
|
865
866
|
.getIncomingDependencies(asset)
|
|
866
867
|
.some(
|
|
867
868
|
dep =>
|
|
868
|
-
!dep.isEntry &&
|
|
869
|
+
!dep.isEntry &&
|
|
870
|
+
nullthrows(this.bundleGraph.getUsedSymbols(dep)).has('*'),
|
|
869
871
|
))) ||
|
|
870
872
|
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
871
873
|
// we fallback on the namespace object.
|
|
@@ -922,7 +924,7 @@ ${code}
|
|
|
922
924
|
}
|
|
923
925
|
|
|
924
926
|
let unused = incomingDeps.every(d => {
|
|
925
|
-
let symbols = this.bundleGraph.getUsedSymbols(d);
|
|
927
|
+
let symbols = nullthrows(this.bundleGraph.getUsedSymbols(d));
|
|
926
928
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
927
929
|
});
|
|
928
930
|
return !unused;
|
|
@@ -976,13 +978,25 @@ ${code}
|
|
|
976
978
|
if (
|
|
977
979
|
isWrapped ||
|
|
978
980
|
resolved.meta.staticExports === false ||
|
|
979
|
-
this.bundleGraph.getUsedSymbols(resolved).has('*')
|
|
981
|
+
nullthrows(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
982
|
+
// an empty asset
|
|
983
|
+
(!resolved.meta.hasCJSExports &&
|
|
984
|
+
resolved.symbols.hasExportSymbol('*'))
|
|
980
985
|
) {
|
|
981
986
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep);
|
|
982
987
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
983
988
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
984
989
|
} else {
|
|
985
|
-
for (let symbol of
|
|
990
|
+
for (let symbol of nullthrows(
|
|
991
|
+
this.bundleGraph.getUsedSymbols(dep),
|
|
992
|
+
)) {
|
|
993
|
+
if (
|
|
994
|
+
symbol === 'default' || // `export * as ...` does not include the default export
|
|
995
|
+
symbol === '__esModule'
|
|
996
|
+
) {
|
|
997
|
+
continue;
|
|
998
|
+
}
|
|
999
|
+
|
|
986
1000
|
let resolvedSymbol = this.getSymbolResolution(
|
|
987
1001
|
asset,
|
|
988
1002
|
resolved,
|
|
@@ -996,6 +1010,7 @@ ${code}
|
|
|
996
1010
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(
|
|
997
1011
|
symbol,
|
|
998
1012
|
)}, ${get}${set});\n`;
|
|
1013
|
+
this.usedHelpers.add('$parcel$export');
|
|
999
1014
|
prependLineCount++;
|
|
1000
1015
|
}
|
|
1001
1016
|
}
|
|
@@ -1122,7 +1137,7 @@ ${code}
|
|
|
1122
1137
|
|
|
1123
1138
|
return (
|
|
1124
1139
|
asset.sideEffects === false &&
|
|
1125
|
-
this.bundleGraph.getUsedSymbols(asset).size == 0 &&
|
|
1140
|
+
nullthrows(this.bundleGraph.getUsedSymbols(asset)).size == 0 &&
|
|
1126
1141
|
!this.bundleGraph.isAssetReferenced(this.bundle, asset)
|
|
1127
1142
|
);
|
|
1128
1143
|
}
|
package/src/helpers.js
CHANGED
|
@@ -38,7 +38,7 @@ export const helpers = {
|
|
|
38
38
|
`,
|
|
39
39
|
$parcel$exportWildcard: `function $parcel$exportWildcard(dest, source) {
|
|
40
40
|
Object.keys(source).forEach(function(key) {
|
|
41
|
-
if (key === 'default' || key === '__esModule') {
|
|
41
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|