@parcel/packager-js 2.0.0-nightly.1135 → 2.0.0-nightly.1138
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 +65 -59
- package/package.json +7 -7
- package/src/ScopeHoistingPackager.js +66 -59
|
@@ -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
|
|
|
@@ -575,62 +583,7 @@ ${code}
|
|
|
575
583
|
asyncResolution.value : this.bundleGraph.getResolvedAsset(dep, this.bundle);
|
|
576
584
|
|
|
577
585
|
if (!resolved && !dep.isOptional && !this.bundleGraph.isDependencySkipped(dep)) {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
for (let [imported, {
|
|
581
|
-
local
|
|
582
|
-
}] of dep.symbols) {
|
|
583
|
-
// If already imported, just add the already renamed variable to the mapping.
|
|
584
|
-
let renamed = external.get(imported);
|
|
585
|
-
|
|
586
|
-
if (renamed && local !== '*') {
|
|
587
|
-
replacements.set(local, renamed);
|
|
588
|
-
continue;
|
|
589
|
-
} // For CJS output, always use a property lookup so that exports remain live.
|
|
590
|
-
// For ESM output, use named imports which are always live.
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
if (this.bundle.env.outputFormat === 'commonjs') {
|
|
594
|
-
renamed = external.get('*');
|
|
595
|
-
|
|
596
|
-
if (!renamed) {
|
|
597
|
-
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${dep.specifier}`);
|
|
598
|
-
external.set('*', renamed);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
if (local !== '*') {
|
|
602
|
-
let replacement;
|
|
603
|
-
|
|
604
|
-
if (imported === '*') {
|
|
605
|
-
replacement = renamed;
|
|
606
|
-
} else if (imported === 'default') {
|
|
607
|
-
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
608
|
-
this.usedHelpers.add('$parcel$interopDefault');
|
|
609
|
-
} else {
|
|
610
|
-
replacement = this.getPropertyAccess(renamed, imported);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
replacements.set(local, replacement);
|
|
614
|
-
}
|
|
615
|
-
} else {
|
|
616
|
-
// Rename the specifier so that multiple local imports of the same imported specifier
|
|
617
|
-
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
618
|
-
// local variables do not shadow it.
|
|
619
|
-
if (this.exportedSymbols.has(local)) {
|
|
620
|
-
renamed = local;
|
|
621
|
-
} else if (imported === 'default' || imported === '*') {
|
|
622
|
-
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${dep.specifier}`);
|
|
623
|
-
} else {
|
|
624
|
-
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${imported}`);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
external.set(imported, renamed);
|
|
628
|
-
|
|
629
|
-
if (local !== '*') {
|
|
630
|
-
replacements.set(local, renamed);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
586
|
+
this.addExternal(dep, replacements);
|
|
634
587
|
}
|
|
635
588
|
|
|
636
589
|
if (!resolved) {
|
|
@@ -672,7 +625,7 @@ ${code}
|
|
|
672
625
|
return [depMap, replacements];
|
|
673
626
|
}
|
|
674
627
|
|
|
675
|
-
addExternal(dep) {
|
|
628
|
+
addExternal(dep, replacements) {
|
|
676
629
|
if (this.bundle.env.outputFormat === 'global') {
|
|
677
630
|
throw new (_diagnostic().default)({
|
|
678
631
|
diagnostic: {
|
|
@@ -696,7 +649,60 @@ ${code}
|
|
|
696
649
|
this.externals.set(dep.specifier, external);
|
|
697
650
|
}
|
|
698
651
|
|
|
699
|
-
|
|
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
|
+
}
|
|
700
706
|
}
|
|
701
707
|
|
|
702
708
|
getSymbolResolution(parentAsset, resolved, imported, dep) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-js",
|
|
3
|
-
"version": "2.0.0-nightly.
|
|
3
|
+
"version": "2.0.0-nightly.1138+411d4c2e8",
|
|
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-nightly.
|
|
20
|
+
"parcel": "2.0.0-nightly.1136+411d4c2e8"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.0.0-nightly.
|
|
24
|
-
"@parcel/hash": "2.6.3-nightly.
|
|
25
|
-
"@parcel/plugin": "2.0.0-nightly.
|
|
23
|
+
"@parcel/diagnostic": "2.0.0-nightly.1138+411d4c2e8",
|
|
24
|
+
"@parcel/hash": "2.6.3-nightly.2761+411d4c2e8",
|
|
25
|
+
"@parcel/plugin": "2.0.0-nightly.1138+411d4c2e8",
|
|
26
26
|
"@parcel/source-map": "^2.0.0",
|
|
27
|
-
"@parcel/utils": "2.0.0-nightly.
|
|
27
|
+
"@parcel/utils": "2.0.0-nightly.1138+411d4c2e8",
|
|
28
28
|
"globals": "^13.2.0",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "411d4c2e81f2dd9aa25be4fab82623e39f9ca49a"
|
|
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
|
|
|
@@ -605,62 +613,7 @@ ${code}
|
|
|
605
613
|
!dep.isOptional &&
|
|
606
614
|
!this.bundleGraph.isDependencySkipped(dep)
|
|
607
615
|
) {
|
|
608
|
-
|
|
609
|
-
for (let [imported, {local}] of dep.symbols) {
|
|
610
|
-
// If already imported, just add the already renamed variable to the mapping.
|
|
611
|
-
let renamed = external.get(imported);
|
|
612
|
-
if (renamed && local !== '*') {
|
|
613
|
-
replacements.set(local, renamed);
|
|
614
|
-
continue;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
// For CJS output, always use a property lookup so that exports remain live.
|
|
618
|
-
// For ESM output, use named imports which are always live.
|
|
619
|
-
if (this.bundle.env.outputFormat === 'commonjs') {
|
|
620
|
-
renamed = external.get('*');
|
|
621
|
-
if (!renamed) {
|
|
622
|
-
renamed = this.getTopLevelName(
|
|
623
|
-
`$${this.bundle.publicId}$${dep.specifier}`,
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
external.set('*', renamed);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
if (local !== '*') {
|
|
630
|
-
let replacement;
|
|
631
|
-
if (imported === '*') {
|
|
632
|
-
replacement = renamed;
|
|
633
|
-
} else if (imported === 'default') {
|
|
634
|
-
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
635
|
-
this.usedHelpers.add('$parcel$interopDefault');
|
|
636
|
-
} else {
|
|
637
|
-
replacement = this.getPropertyAccess(renamed, imported);
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
replacements.set(local, replacement);
|
|
641
|
-
}
|
|
642
|
-
} else {
|
|
643
|
-
// Rename the specifier so that multiple local imports of the same imported specifier
|
|
644
|
-
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
645
|
-
// local variables do not shadow it.
|
|
646
|
-
if (this.exportedSymbols.has(local)) {
|
|
647
|
-
renamed = local;
|
|
648
|
-
} else if (imported === 'default' || imported === '*') {
|
|
649
|
-
renamed = this.getTopLevelName(
|
|
650
|
-
`$${this.bundle.publicId}$${dep.specifier}`,
|
|
651
|
-
);
|
|
652
|
-
} else {
|
|
653
|
-
renamed = this.getTopLevelName(
|
|
654
|
-
`$${this.bundle.publicId}$${imported}`,
|
|
655
|
-
);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
external.set(imported, renamed);
|
|
659
|
-
if (local !== '*') {
|
|
660
|
-
replacements.set(local, renamed);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
616
|
+
this.addExternal(dep, replacements);
|
|
664
617
|
}
|
|
665
618
|
|
|
666
619
|
if (!resolved) {
|
|
@@ -712,7 +665,7 @@ ${code}
|
|
|
712
665
|
return [depMap, replacements];
|
|
713
666
|
}
|
|
714
667
|
|
|
715
|
-
addExternal(dep: Dependency
|
|
668
|
+
addExternal(dep: Dependency, replacements?: Map<string, string>) {
|
|
716
669
|
if (this.bundle.env.outputFormat === 'global') {
|
|
717
670
|
throw new ThrowableDiagnostic({
|
|
718
671
|
diagnostic: {
|
|
@@ -742,7 +695,61 @@ ${code}
|
|
|
742
695
|
this.externals.set(dep.specifier, external);
|
|
743
696
|
}
|
|
744
697
|
|
|
745
|
-
|
|
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
|
+
}
|
|
746
753
|
}
|
|
747
754
|
|
|
748
755
|
getSymbolResolution(
|