@parcel/packager-js 2.6.0 → 2.7.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 +70 -62
- package/package.json +7 -7
- package/src/ScopeHoistingPackager.js +82 -62
|
@@ -396,7 +396,15 @@ class ScopeHoistingPackager {
|
|
|
396
396
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
397
397
|
let skipped = this.bundleGraph.isDependencySkipped(dep);
|
|
398
398
|
|
|
399
|
-
if (
|
|
399
|
+
if (skipped) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (!resolved) {
|
|
404
|
+
if (!dep.isOptional) {
|
|
405
|
+
this.addExternal(dep);
|
|
406
|
+
}
|
|
407
|
+
|
|
400
408
|
continue;
|
|
401
409
|
}
|
|
402
410
|
|
|
@@ -567,69 +575,15 @@ ${code}
|
|
|
567
575
|
let replacements = new Map();
|
|
568
576
|
|
|
569
577
|
for (let dep of deps) {
|
|
570
|
-
|
|
578
|
+
let specifierType = dep.specifierType === 'esm' ? `:${dep.specifierType}` : '';
|
|
579
|
+
depMap.set(`${assetId}:${(0, _utils2.getSpecifier)(dep)}${!dep.meta.placeholder ? specifierType : ''}`, dep);
|
|
571
580
|
let asyncResolution = this.bundleGraph.resolveAsyncDependency(dep, this.bundle);
|
|
572
581
|
let resolved = (asyncResolution === null || asyncResolution === void 0 ? void 0 : asyncResolution.type) === 'asset' ? // Prefer the underlying asset over a runtime to load it. It will
|
|
573
582
|
// be wrapped in Promise.resolve() later.
|
|
574
583
|
asyncResolution.value : this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
575
584
|
|
|
576
585
|
if (!resolved && !dep.isOptional && !this.bundleGraph.isDependencySkipped(dep)) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
for (let [imported, {
|
|
580
|
-
local
|
|
581
|
-
}] of dep.symbols) {
|
|
582
|
-
// If already imported, just add the already renamed variable to the mapping.
|
|
583
|
-
let renamed = external.get(imported);
|
|
584
|
-
|
|
585
|
-
if (renamed && local !== '*') {
|
|
586
|
-
replacements.set(local, renamed);
|
|
587
|
-
continue;
|
|
588
|
-
} // For CJS output, always use a property lookup so that exports remain live.
|
|
589
|
-
// For ESM output, use named imports which are always live.
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (this.bundle.env.outputFormat === 'commonjs') {
|
|
593
|
-
renamed = external.get('*');
|
|
594
|
-
|
|
595
|
-
if (!renamed) {
|
|
596
|
-
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${dep.specifier}`);
|
|
597
|
-
external.set('*', renamed);
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
if (local !== '*') {
|
|
601
|
-
let replacement;
|
|
602
|
-
|
|
603
|
-
if (imported === '*') {
|
|
604
|
-
replacement = renamed;
|
|
605
|
-
} else if (imported === 'default') {
|
|
606
|
-
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
607
|
-
this.usedHelpers.add('$parcel$interopDefault');
|
|
608
|
-
} else {
|
|
609
|
-
replacement = this.getPropertyAccess(renamed, imported);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
replacements.set(local, replacement);
|
|
613
|
-
}
|
|
614
|
-
} else {
|
|
615
|
-
// Rename the specifier so that multiple local imports of the same imported specifier
|
|
616
|
-
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
617
|
-
// local variables do not shadow it.
|
|
618
|
-
if (this.exportedSymbols.has(local)) {
|
|
619
|
-
renamed = local;
|
|
620
|
-
} else if (imported === 'default' || imported === '*') {
|
|
621
|
-
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${dep.specifier}`);
|
|
622
|
-
} else {
|
|
623
|
-
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${imported}`);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
external.set(imported, renamed);
|
|
627
|
-
|
|
628
|
-
if (local !== '*') {
|
|
629
|
-
replacements.set(local, renamed);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
586
|
+
this.addExternal(dep, replacements);
|
|
633
587
|
}
|
|
634
588
|
|
|
635
589
|
if (!resolved) {
|
|
@@ -671,7 +625,7 @@ ${code}
|
|
|
671
625
|
return [depMap, replacements];
|
|
672
626
|
}
|
|
673
627
|
|
|
674
|
-
addExternal(dep) {
|
|
628
|
+
addExternal(dep, replacements) {
|
|
675
629
|
if (this.bundle.env.outputFormat === 'global') {
|
|
676
630
|
throw new (_diagnostic().default)({
|
|
677
631
|
diagnostic: {
|
|
@@ -695,7 +649,60 @@ ${code}
|
|
|
695
649
|
this.externals.set(dep.specifier, external);
|
|
696
650
|
}
|
|
697
651
|
|
|
698
|
-
|
|
652
|
+
for (let [imported, {
|
|
653
|
+
local
|
|
654
|
+
}] of dep.symbols) {
|
|
655
|
+
// If already imported, just add the already renamed variable to the mapping.
|
|
656
|
+
let renamed = external.get(imported);
|
|
657
|
+
|
|
658
|
+
if (renamed && local !== '*' && replacements) {
|
|
659
|
+
replacements.set(local, renamed);
|
|
660
|
+
continue;
|
|
661
|
+
} // For CJS output, always use a property lookup so that exports remain live.
|
|
662
|
+
// For ESM output, use named imports which are always live.
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
if (this.bundle.env.outputFormat === 'commonjs') {
|
|
666
|
+
renamed = external.get('*');
|
|
667
|
+
|
|
668
|
+
if (!renamed) {
|
|
669
|
+
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${dep.specifier}`);
|
|
670
|
+
external.set('*', renamed);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
if (local !== '*' && replacements) {
|
|
674
|
+
let replacement;
|
|
675
|
+
|
|
676
|
+
if (imported === '*') {
|
|
677
|
+
replacement = renamed;
|
|
678
|
+
} else if (imported === 'default') {
|
|
679
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
680
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
681
|
+
} else {
|
|
682
|
+
replacement = this.getPropertyAccess(renamed, imported);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
replacements.set(local, replacement);
|
|
686
|
+
}
|
|
687
|
+
} else {
|
|
688
|
+
// Rename the specifier so that multiple local imports of the same imported specifier
|
|
689
|
+
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
690
|
+
// local variables do not shadow it.
|
|
691
|
+
if (this.exportedSymbols.has(local)) {
|
|
692
|
+
renamed = local;
|
|
693
|
+
} else if (imported === 'default' || imported === '*') {
|
|
694
|
+
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${dep.specifier}`);
|
|
695
|
+
} else {
|
|
696
|
+
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${imported}`);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
external.set(imported, renamed);
|
|
700
|
+
|
|
701
|
+
if (local !== '*' && replacements) {
|
|
702
|
+
replacements.set(local, renamed);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
699
706
|
}
|
|
700
707
|
|
|
701
708
|
getSymbolResolution(parentAsset, resolved, imported, dep) {
|
|
@@ -707,8 +714,9 @@ ${code}
|
|
|
707
714
|
symbol
|
|
708
715
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
709
716
|
|
|
710
|
-
if (resolvedAsset.type !== 'js') {
|
|
711
|
-
// Graceful fallback for non-js imports
|
|
717
|
+
if (resolvedAsset.type !== 'js' || dep && this.bundleGraph.isDependencySkipped(dep)) {
|
|
718
|
+
// Graceful fallback for non-js imports or when trying to resolve a symbol
|
|
719
|
+
// that is actually unused but we still need a placeholder value.
|
|
712
720
|
return '{}';
|
|
713
721
|
}
|
|
714
722
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.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.
|
|
20
|
+
"parcel": "^2.7.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.
|
|
24
|
-
"@parcel/hash": "2.
|
|
25
|
-
"@parcel/plugin": "2.
|
|
23
|
+
"@parcel/diagnostic": "2.7.0",
|
|
24
|
+
"@parcel/hash": "2.7.0",
|
|
25
|
+
"@parcel/plugin": "2.7.0",
|
|
26
26
|
"@parcel/source-map": "^2.0.0",
|
|
27
|
-
"@parcel/utils": "2.
|
|
27
|
+
"@parcel/utils": "2.7.0",
|
|
28
28
|
"globals": "^13.2.0",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "9e5d05586577e89991ccf90400f2c741dca11aa3"
|
|
32
32
|
}
|
|
@@ -400,7 +400,15 @@ export class ScopeHoistingPackager {
|
|
|
400
400
|
for (let dep of deps) {
|
|
401
401
|
let resolved = this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
402
402
|
let skipped = this.bundleGraph.isDependencySkipped(dep);
|
|
403
|
-
if (
|
|
403
|
+
if (skipped) {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (!resolved) {
|
|
408
|
+
if (!dep.isOptional) {
|
|
409
|
+
this.addExternal(dep);
|
|
410
|
+
}
|
|
411
|
+
|
|
404
412
|
continue;
|
|
405
413
|
}
|
|
406
414
|
|
|
@@ -581,7 +589,14 @@ ${code}
|
|
|
581
589
|
let depMap = new Map();
|
|
582
590
|
let replacements = new Map();
|
|
583
591
|
for (let dep of deps) {
|
|
584
|
-
|
|
592
|
+
let specifierType =
|
|
593
|
+
dep.specifierType === 'esm' ? `:${dep.specifierType}` : '';
|
|
594
|
+
depMap.set(
|
|
595
|
+
`${assetId}:${getSpecifier(dep)}${
|
|
596
|
+
!dep.meta.placeholder ? specifierType : ''
|
|
597
|
+
}`,
|
|
598
|
+
dep,
|
|
599
|
+
);
|
|
585
600
|
|
|
586
601
|
let asyncResolution = this.bundleGraph.resolveAsyncDependency(
|
|
587
602
|
dep,
|
|
@@ -598,62 +613,7 @@ ${code}
|
|
|
598
613
|
!dep.isOptional &&
|
|
599
614
|
!this.bundleGraph.isDependencySkipped(dep)
|
|
600
615
|
) {
|
|
601
|
-
|
|
602
|
-
for (let [imported, {local}] of dep.symbols) {
|
|
603
|
-
// If already imported, just add the already renamed variable to the mapping.
|
|
604
|
-
let renamed = external.get(imported);
|
|
605
|
-
if (renamed && local !== '*') {
|
|
606
|
-
replacements.set(local, renamed);
|
|
607
|
-
continue;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
// For CJS output, always use a property lookup so that exports remain live.
|
|
611
|
-
// For ESM output, use named imports which are always live.
|
|
612
|
-
if (this.bundle.env.outputFormat === 'commonjs') {
|
|
613
|
-
renamed = external.get('*');
|
|
614
|
-
if (!renamed) {
|
|
615
|
-
renamed = this.getTopLevelName(
|
|
616
|
-
`$${this.bundle.publicId}$${dep.specifier}`,
|
|
617
|
-
);
|
|
618
|
-
|
|
619
|
-
external.set('*', renamed);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (local !== '*') {
|
|
623
|
-
let replacement;
|
|
624
|
-
if (imported === '*') {
|
|
625
|
-
replacement = renamed;
|
|
626
|
-
} else if (imported === 'default') {
|
|
627
|
-
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
628
|
-
this.usedHelpers.add('$parcel$interopDefault');
|
|
629
|
-
} else {
|
|
630
|
-
replacement = this.getPropertyAccess(renamed, imported);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
replacements.set(local, replacement);
|
|
634
|
-
}
|
|
635
|
-
} else {
|
|
636
|
-
// Rename the specifier so that multiple local imports of the same imported specifier
|
|
637
|
-
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
638
|
-
// local variables do not shadow it.
|
|
639
|
-
if (this.exportedSymbols.has(local)) {
|
|
640
|
-
renamed = local;
|
|
641
|
-
} else if (imported === 'default' || imported === '*') {
|
|
642
|
-
renamed = this.getTopLevelName(
|
|
643
|
-
`$${this.bundle.publicId}$${dep.specifier}`,
|
|
644
|
-
);
|
|
645
|
-
} else {
|
|
646
|
-
renamed = this.getTopLevelName(
|
|
647
|
-
`$${this.bundle.publicId}$${imported}`,
|
|
648
|
-
);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
external.set(imported, renamed);
|
|
652
|
-
if (local !== '*') {
|
|
653
|
-
replacements.set(local, renamed);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
616
|
+
this.addExternal(dep, replacements);
|
|
657
617
|
}
|
|
658
618
|
|
|
659
619
|
if (!resolved) {
|
|
@@ -705,7 +665,7 @@ ${code}
|
|
|
705
665
|
return [depMap, replacements];
|
|
706
666
|
}
|
|
707
667
|
|
|
708
|
-
addExternal(dep: Dependency
|
|
668
|
+
addExternal(dep: Dependency, replacements?: Map<string, string>) {
|
|
709
669
|
if (this.bundle.env.outputFormat === 'global') {
|
|
710
670
|
throw new ThrowableDiagnostic({
|
|
711
671
|
diagnostic: {
|
|
@@ -735,7 +695,61 @@ ${code}
|
|
|
735
695
|
this.externals.set(dep.specifier, external);
|
|
736
696
|
}
|
|
737
697
|
|
|
738
|
-
|
|
698
|
+
for (let [imported, {local}] of dep.symbols) {
|
|
699
|
+
// If already imported, just add the already renamed variable to the mapping.
|
|
700
|
+
let renamed = external.get(imported);
|
|
701
|
+
if (renamed && local !== '*' && replacements) {
|
|
702
|
+
replacements.set(local, renamed);
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// For CJS output, always use a property lookup so that exports remain live.
|
|
707
|
+
// For ESM output, use named imports which are always live.
|
|
708
|
+
if (this.bundle.env.outputFormat === 'commonjs') {
|
|
709
|
+
renamed = external.get('*');
|
|
710
|
+
if (!renamed) {
|
|
711
|
+
renamed = this.getTopLevelName(
|
|
712
|
+
`$${this.bundle.publicId}$${dep.specifier}`,
|
|
713
|
+
);
|
|
714
|
+
|
|
715
|
+
external.set('*', renamed);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
if (local !== '*' && replacements) {
|
|
719
|
+
let replacement;
|
|
720
|
+
if (imported === '*') {
|
|
721
|
+
replacement = renamed;
|
|
722
|
+
} else if (imported === 'default') {
|
|
723
|
+
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
724
|
+
this.usedHelpers.add('$parcel$interopDefault');
|
|
725
|
+
} else {
|
|
726
|
+
replacement = this.getPropertyAccess(renamed, imported);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
replacements.set(local, replacement);
|
|
730
|
+
}
|
|
731
|
+
} else {
|
|
732
|
+
// Rename the specifier so that multiple local imports of the same imported specifier
|
|
733
|
+
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
734
|
+
// local variables do not shadow it.
|
|
735
|
+
if (this.exportedSymbols.has(local)) {
|
|
736
|
+
renamed = local;
|
|
737
|
+
} else if (imported === 'default' || imported === '*') {
|
|
738
|
+
renamed = this.getTopLevelName(
|
|
739
|
+
`$${this.bundle.publicId}$${dep.specifier}`,
|
|
740
|
+
);
|
|
741
|
+
} else {
|
|
742
|
+
renamed = this.getTopLevelName(
|
|
743
|
+
`$${this.bundle.publicId}$${imported}`,
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
external.set(imported, renamed);
|
|
748
|
+
if (local !== '*' && replacements) {
|
|
749
|
+
replacements.set(local, renamed);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
739
753
|
}
|
|
740
754
|
|
|
741
755
|
getSymbolResolution(
|
|
@@ -749,10 +763,16 @@ ${code}
|
|
|
749
763
|
exportSymbol,
|
|
750
764
|
symbol,
|
|
751
765
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
752
|
-
|
|
753
|
-
|
|
766
|
+
|
|
767
|
+
if (
|
|
768
|
+
resolvedAsset.type !== 'js' ||
|
|
769
|
+
(dep && this.bundleGraph.isDependencySkipped(dep))
|
|
770
|
+
) {
|
|
771
|
+
// Graceful fallback for non-js imports or when trying to resolve a symbol
|
|
772
|
+
// that is actually unused but we still need a placeholder value.
|
|
754
773
|
return '{}';
|
|
755
774
|
}
|
|
775
|
+
|
|
756
776
|
let isWrapped =
|
|
757
777
|
!this.bundle.hasAsset(resolvedAsset) ||
|
|
758
778
|
(this.wrappedAssets.has(resolvedAsset.id) &&
|