@parcel/packager-js 2.8.0 → 2.8.1

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.
@@ -855,44 +855,9 @@ ${code}
855
855
  prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
856
856
  prependLineCount += 2;
857
857
  this.usedHelpers.add('$parcel$defineInteropFlag');
858
- } // Find the used exports of this module. This is based on the used symbols of
859
- // incoming dependencies rather than the asset's own used exports so that we include
860
- // re-exported symbols rather than only symbols declared in this asset.
861
-
862
-
863
- let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
864
- let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
865
- if (symbol === '*') {
866
- return false;
867
- } // If we need default interop, then all symbols are needed because the `default`
868
- // symbol really maps to the whole namespace.
869
-
870
-
871
- if (defaultInterop) {
872
- return true;
873
- }
874
-
875
- let unused = incomingDeps.every(d => {
876
- let symbols = (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(d));
877
- return !symbols.has(symbol) && !symbols.has('*');
878
- });
879
- return !unused;
880
- });
881
-
882
- if (usedExports.length > 0) {
883
- // Insert $parcel$export calls for each of the used exports. This creates a getter/setter
884
- // for the symbol so that when the value changes the object property also changes. This is
885
- // required to simulate ESM live bindings. It's easier to do it this way rather than inserting
886
- // additional assignments after each mutation of the original binding.
887
- prepend += `\n${usedExports.map(exp => {
888
- let resolved = this.getSymbolResolution(asset, asset, exp);
889
- let get = this.buildFunctionExpression([], resolved);
890
- let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`) : '';
891
- return `$parcel$export($${assetId}$exports, ${JSON.stringify(exp)}, ${get}${set});`;
892
- }).join('\n')}\n`;
893
- this.usedHelpers.add('$parcel$export');
894
- prependLineCount += 1 + usedExports.length;
895
- } // Find wildcard re-export dependencies, and make sure their exports are also included in ours.
858
+ } // Find wildcard re-export dependencies, and make sure their exports are also included in
859
+ // ours. Importantly, add them before the asset's own exports so that wildcard exports get
860
+ // correctly overwritten by own exports of the same name.
896
861
 
897
862
 
898
863
  for (let dep of deps) {
@@ -941,6 +906,43 @@ ${code}
941
906
  }
942
907
  }
943
908
  }
909
+ } // Find the used exports of this module. This is based on the used symbols of
910
+ // incoming dependencies rather than the asset's own used exports so that we include
911
+ // re-exported symbols rather than only symbols declared in this asset.
912
+
913
+
914
+ let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
915
+ let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
916
+ if (symbol === '*') {
917
+ return false;
918
+ } // If we need default interop, then all symbols are needed because the `default`
919
+ // symbol really maps to the whole namespace.
920
+
921
+
922
+ if (defaultInterop) {
923
+ return true;
924
+ }
925
+
926
+ let unused = incomingDeps.every(d => {
927
+ let symbols = (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(d));
928
+ return !symbols.has(symbol) && !symbols.has('*');
929
+ });
930
+ return !unused;
931
+ });
932
+
933
+ if (usedExports.length > 0) {
934
+ // Insert $parcel$export calls for each of the used exports. This creates a getter/setter
935
+ // for the symbol so that when the value changes the object property also changes. This is
936
+ // required to simulate ESM live bindings. It's easier to do it this way rather than inserting
937
+ // additional assignments after each mutation of the original binding.
938
+ prepend += `\n${usedExports.map(exp => {
939
+ let resolved = this.getSymbolResolution(asset, asset, exp);
940
+ let get = this.buildFunctionExpression([], resolved);
941
+ let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`) : '';
942
+ return `$parcel$export($${assetId}$exports, ${JSON.stringify(exp)}, ${get}${set});`;
943
+ }).join('\n')}\n`;
944
+ this.usedHelpers.add('$parcel$export');
945
+ prependLineCount += 1 + usedExports.length;
944
946
  }
945
947
  }
946
948
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/packager-js",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
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.8.0"
20
+ "parcel": "^2.8.1"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.8.0",
24
- "@parcel/hash": "2.8.0",
25
- "@parcel/plugin": "2.8.0",
23
+ "@parcel/diagnostic": "2.8.1",
24
+ "@parcel/hash": "2.8.1",
25
+ "@parcel/plugin": "2.8.1",
26
26
  "@parcel/source-map": "^2.1.1",
27
- "@parcel/utils": "2.8.0",
27
+ "@parcel/utils": "2.8.1",
28
28
  "globals": "^13.2.0",
29
29
  "nullthrows": "^1.1.1"
30
30
  },
31
- "gitHead": "c3bbe0a6160186f496ca2f9e9bead9376c0522f1"
31
+ "gitHead": "f8d3fc30ca5b33d8f8674525f2a741d662c5986a"
32
32
  }
@@ -996,50 +996,9 @@ ${code}
996
996
  this.usedHelpers.add('$parcel$defineInteropFlag');
997
997
  }
998
998
 
999
- // Find the used exports of this module. This is based on the used symbols of
1000
- // incoming dependencies rather than the asset's own used exports so that we include
1001
- // re-exported symbols rather than only symbols declared in this asset.
1002
- let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
1003
- let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
1004
- if (symbol === '*') {
1005
- return false;
1006
- }
1007
-
1008
- // If we need default interop, then all symbols are needed because the `default`
1009
- // symbol really maps to the whole namespace.
1010
- if (defaultInterop) {
1011
- return true;
1012
- }
1013
-
1014
- let unused = incomingDeps.every(d => {
1015
- let symbols = nullthrows(this.bundleGraph.getUsedSymbols(d));
1016
- return !symbols.has(symbol) && !symbols.has('*');
1017
- });
1018
- return !unused;
1019
- });
1020
-
1021
- if (usedExports.length > 0) {
1022
- // Insert $parcel$export calls for each of the used exports. This creates a getter/setter
1023
- // for the symbol so that when the value changes the object property also changes. This is
1024
- // required to simulate ESM live bindings. It's easier to do it this way rather than inserting
1025
- // additional assignments after each mutation of the original binding.
1026
- prepend += `\n${usedExports
1027
- .map(exp => {
1028
- let resolved = this.getSymbolResolution(asset, asset, exp);
1029
- let get = this.buildFunctionExpression([], resolved);
1030
- let set = asset.meta.hasCJSExports
1031
- ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`)
1032
- : '';
1033
- return `$parcel$export($${assetId}$exports, ${JSON.stringify(
1034
- exp,
1035
- )}, ${get}${set});`;
1036
- })
1037
- .join('\n')}\n`;
1038
- this.usedHelpers.add('$parcel$export');
1039
- prependLineCount += 1 + usedExports.length;
1040
- }
1041
-
1042
- // Find wildcard re-export dependencies, and make sure their exports are also included in ours.
999
+ // Find wildcard re-export dependencies, and make sure their exports are also included in
1000
+ // ours. Importantly, add them before the asset's own exports so that wildcard exports get
1001
+ // correctly overwritten by own exports of the same name.
1043
1002
  for (let dep of deps) {
1044
1003
  let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
1045
1004
  if (dep.isOptional || this.bundleGraph.isDependencySkipped(dep)) {
@@ -1105,6 +1064,49 @@ ${code}
1105
1064
  }
1106
1065
  }
1107
1066
  }
1067
+
1068
+ // Find the used exports of this module. This is based on the used symbols of
1069
+ // incoming dependencies rather than the asset's own used exports so that we include
1070
+ // re-exported symbols rather than only symbols declared in this asset.
1071
+ let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
1072
+ let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
1073
+ if (symbol === '*') {
1074
+ return false;
1075
+ }
1076
+
1077
+ // If we need default interop, then all symbols are needed because the `default`
1078
+ // symbol really maps to the whole namespace.
1079
+ if (defaultInterop) {
1080
+ return true;
1081
+ }
1082
+
1083
+ let unused = incomingDeps.every(d => {
1084
+ let symbols = nullthrows(this.bundleGraph.getUsedSymbols(d));
1085
+ return !symbols.has(symbol) && !symbols.has('*');
1086
+ });
1087
+ return !unused;
1088
+ });
1089
+
1090
+ if (usedExports.length > 0) {
1091
+ // Insert $parcel$export calls for each of the used exports. This creates a getter/setter
1092
+ // for the symbol so that when the value changes the object property also changes. This is
1093
+ // required to simulate ESM live bindings. It's easier to do it this way rather than inserting
1094
+ // additional assignments after each mutation of the original binding.
1095
+ prepend += `\n${usedExports
1096
+ .map(exp => {
1097
+ let resolved = this.getSymbolResolution(asset, asset, exp);
1098
+ let get = this.buildFunctionExpression([], resolved);
1099
+ let set = asset.meta.hasCJSExports
1100
+ ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`)
1101
+ : '';
1102
+ return `$parcel$export($${assetId}$exports, ${JSON.stringify(
1103
+ exp,
1104
+ )}, ${get}${set});`;
1105
+ })
1106
+ .join('\n')}\n`;
1107
+ this.usedHelpers.add('$parcel$export');
1108
+ prependLineCount += 1 + usedExports.length;
1109
+ }
1108
1110
  }
1109
1111
 
1110
1112
  return [prepend, prependLineCount, append];