@@ -653,8 +653,11 @@ function packageExportsResolve(
653
653
const resolveResult = resolvePackageTarget (
654
654
packageJSONUrl , target , '' , packageSubpath , base , false , false , conditions
655
655
) ;
656
- if ( resolveResult === null || resolveResult === undefined )
656
+
657
+ if ( resolveResult == null ) {
657
658
throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
659
+ }
660
+
658
661
return resolveResult ;
659
662
}
660
663
@@ -691,12 +694,19 @@ function packageExportsResolve(
691
694
692
695
if ( bestMatch ) {
693
696
const target = exports [ bestMatch ] ;
694
- const resolveResult = resolvePackageTarget ( packageJSONUrl , target ,
695
- bestMatchSubpath , bestMatch ,
696
- base , true , false ,
697
- conditions ) ;
698
- if ( resolveResult === null || resolveResult === undefined )
697
+ const resolveResult = resolvePackageTarget (
698
+ packageJSONUrl ,
699
+ target ,
700
+ bestMatchSubpath ,
701
+ bestMatch ,
702
+ base ,
703
+ true ,
704
+ false ,
705
+ conditions ) ;
706
+
707
+ if ( resolveResult == null ) {
699
708
throwExportsNotFound ( packageSubpath , packageJSONUrl , base ) ;
709
+ }
700
710
return resolveResult ;
701
711
}
702
712
@@ -740,8 +750,9 @@ function packageImportsResolve(name, base, conditions) {
740
750
const resolveResult = resolvePackageTarget (
741
751
packageJSONUrl , imports [ name ] , '' , name , base , false , true , conditions
742
752
) ;
743
- if ( resolveResult !== null && resolveResult !== undefined )
753
+ if ( resolveResult != null ) {
744
754
return resolveResult . resolved ;
755
+ }
745
756
} else {
746
757
let bestMatch = '' ;
747
758
let bestMatchSubpath ;
@@ -771,8 +782,9 @@ function packageImportsResolve(name, base, conditions) {
771
782
bestMatchSubpath ,
772
783
bestMatch , base , true ,
773
784
true , conditions ) ;
774
- if ( resolveResult !== null && resolveResult !== undefined )
785
+ if ( resolveResult != null ) {
775
786
return resolveResult . resolved ;
787
+ }
776
788
}
777
789
}
778
790
}
@@ -875,12 +887,14 @@ function packageResolve(specifier, base, conditions) {
875
887
}
876
888
if ( packageSubpath === '.' ) {
877
889
return {
878
- resolved : legacyMainResolve ( packageJSONUrl ,
879
- packageConfig ,
880
- base ) ,
890
+ resolved : legacyMainResolve (
891
+ packageJSONUrl ,
892
+ packageConfig ,
893
+ base ) ,
881
894
...( packageConfig . type !== 'none' ) && { format : packageConfig . type }
882
895
} ;
883
896
}
897
+
884
898
return {
885
899
resolved : new URL ( packageSubpath , packageJSONUrl ) ,
886
900
...( packageConfig . type !== 'none' ) && { format : packageConfig . type }
@@ -927,7 +941,8 @@ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
927
941
function moduleResolve ( specifier , base , conditions , preserveSymlinks ) {
928
942
// Order swapped from spec for minor perf gain.
929
943
// Ok since relative URLs cannot parse as URLs.
930
- let resolved , format ;
944
+ let resolved ;
945
+ let format ;
931
946
if ( shouldBeTreatedAsRelativeOrAbsolutePath ( specifier ) ) {
932
947
resolved = new URL ( specifier , base ) ;
933
948
} else if ( specifier [ 0 ] === '#' ) {
@@ -939,11 +954,15 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
939
954
( { resolved, format } = packageResolve ( specifier , base , conditions ) ) ;
940
955
}
941
956
}
942
- if ( resolved . protocol !== 'file:' )
943
- return { url : resolved } ;
957
+ if ( resolved . protocol !== 'file:' ) {
958
+ return {
959
+ url : resolved
960
+ } ;
961
+ }
962
+
944
963
return {
945
964
url : finalizeResolution ( resolved , base , preserveSymlinks ) ,
946
- ...( format !== undefined && format !== null ) && { format : format }
965
+ ...( format != null ) && { format }
947
966
} ;
948
967
}
949
968
@@ -1032,11 +1051,16 @@ function defaultResolve(specifier, context = {}, defaultResolveUnused) {
1032
1051
}
1033
1052
1034
1053
conditions = getConditionsSet ( conditions ) ;
1035
- let url , format ;
1054
+ let url ;
1055
+ let format ;
1036
1056
try {
1037
1057
( { url, format } =
1038
- moduleResolve ( specifier , parentURL , conditions ,
1039
- isMain ? preserveSymlinksMain : preserveSymlinks ) ) ;
1058
+ moduleResolve (
1059
+ specifier ,
1060
+ parentURL ,
1061
+ conditions ,
1062
+ isMain ? preserveSymlinksMain : preserveSymlinks
1063
+ ) ) ;
1040
1064
} catch ( error ) {
1041
1065
// Try to give the user a hint of what would have been the
1042
1066
// resolved CommonJS module
@@ -1066,7 +1090,7 @@ function defaultResolve(specifier, context = {}, defaultResolveUnused) {
1066
1090
1067
1091
return {
1068
1092
url : `${ url } ` ,
1069
- ...( format !== undefined && format !== null ) && { format : format }
1093
+ ...( format != null ) && { format }
1070
1094
} ;
1071
1095
}
1072
1096
0 commit comments