File tree Expand file tree Collapse file tree 5 files changed +32
-0
lines changed
test/configCases/scope-hoisting/export-global Expand file tree Collapse file tree 5 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,9 @@ const getFinalName = (
136
136
} else if ( ! info . module . isUsed ( exportName ) ) {
137
137
return "/* unused export */ undefined" ;
138
138
}
139
+ if ( info . globalExports . has ( directExport ) ) {
140
+ return directExport ;
141
+ }
139
142
const name = info . internalNames . get ( directExport ) ;
140
143
if ( ! name ) {
141
144
throw new Error (
@@ -562,6 +565,7 @@ class ConcatenatedModule extends Module {
562
565
globalScope : undefined ,
563
566
moduleScope : undefined ,
564
567
internalNames : new Map ( ) ,
568
+ globalExports : new Set ( ) ,
565
569
exportMap : exportMap ,
566
570
reexportMap : reexportMap ,
567
571
hasNamespaceObject : false ,
@@ -941,6 +945,19 @@ class ConcatenatedModule extends Module {
941
945
}
942
946
}
943
947
}
948
+
949
+ // add exported globals
950
+ if ( info . type === "concatenated" ) {
951
+ const variables = new Set ( ) ;
952
+ for ( const variable of info . moduleScope . variables ) {
953
+ variables . add ( variable . name ) ;
954
+ }
955
+ for ( const [ , variable ] of info . exportMap ) {
956
+ if ( ! variables . has ( variable ) ) {
957
+ info . globalExports . add ( variable ) ;
958
+ }
959
+ }
960
+ }
944
961
}
945
962
946
963
// generate names for symbols
Original file line number Diff line number Diff line change
1
+ import { process as p } from "./module" ;
2
+ import { process as p2 } from "./module2" ;
3
+
4
+ it ( "should export globals correctly" , ( ) => {
5
+ expect ( p ) . toBe ( 42 ) ;
6
+ expect ( p2 ) . toBe ( process ) ;
7
+ } ) ;
Original file line number Diff line number Diff line change
1
+ const process = 42 ;
2
+ export { process } ;
Original file line number Diff line number Diff line change
1
+ export { process } ;
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ optimization : {
3
+ concatenateModules : true
4
+ }
5
+ } ;
You can’t perform that action at this time.
0 commit comments