@@ -4992,10 +4992,18 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
4992
4992
}
4993
4993
}
4994
4994
4995
+ // storage has the following structure
4996
+ // {
4997
+ // <exported-name-from-current-module> : void 0,
4998
+ // <exported-name-obtained-from star export in module 'm'>: 'm'
4999
+ // }
5000
+ // this allows to:
5001
+ // - prevent star exports to overwrite locally exported names
5002
+ // - bind star exported names to particular module so they won't be overwritten by other star exports
4995
5003
const exportedNamesStorageRef = makeUniqueName ( "exportedNames" ) ;
4996
5004
4997
5005
writeLine ( ) ;
4998
- write ( `var ${ exportedNamesStorageRef } = { ` ) ;
5006
+ write ( `var ${ exportedNamesStorageRef } = {` ) ;
4999
5007
increaseIndent ( ) ;
5000
5008
5001
5009
let started = false ;
@@ -5036,7 +5044,26 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
5036
5044
writeLine ( ) ;
5037
5045
write ( "};" ) ;
5038
5046
5039
- return exportedNamesStorageRef ;
5047
+ writeLine ( ) ;
5048
+
5049
+ const exportStarFunction = makeUniqueName ( "exportStar" ) ;
5050
+
5051
+ // define an export star helper function
5052
+ write ( `function ${ exportStarFunction } (m, name) {` ) ;
5053
+ writeLine ( ) ;
5054
+ write ( ` for(var n in m) {` ) ;
5055
+ writeLine ( ) ;
5056
+ // if name is not yet taken by either local names or names in other modules - reserve it
5057
+ write ( ` if (!${ exportedNamesStorageRef } .hasOwnProperty(n)) ${ exportedNamesStorageRef } [n] = name;` ) ;
5058
+ writeLine ( ) ;
5059
+ // only export value if it was exported from the module with name 'name';
5060
+ write ( ` if (${ exportedNamesStorageRef } [n] === name) ${ exportFunctionForFile } (n, m[n]);` ) ;
5061
+ writeLine ( ) ;
5062
+ write ( " }" ) ;
5063
+ writeLine ( ) ;
5064
+ write ( "}" )
5065
+
5066
+ return exportStarFunction ;
5040
5067
5041
5068
function writeExportedName ( node : Identifier | Declaration ) : void {
5042
5069
if ( started ) {
@@ -5058,7 +5085,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
5058
5085
emitDeclarationName ( < Declaration > node ) ;
5059
5086
}
5060
5087
5061
- write ( "': true " ) ;
5088
+ write ( "': void 0 " ) ;
5062
5089
}
5063
5090
}
5064
5091
@@ -5234,12 +5261,12 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
5234
5261
emitVariableDeclarationsForImports ( ) ;
5235
5262
writeLine ( ) ;
5236
5263
var exportedDeclarations = processTopLevelVariableAndFunctionDeclarations ( node ) ;
5237
- let exportedLocalNames = emitLocalStorageForExportedNamesIfNecessary ( exportedDeclarations )
5264
+ let exportStarFunction = emitLocalStorageForExportedNamesIfNecessary ( exportedDeclarations )
5238
5265
writeLine ( ) ;
5239
5266
write ( "return {" ) ;
5240
5267
increaseIndent ( ) ;
5241
5268
writeLine ( ) ;
5242
- emitSetters ( exportedLocalNames ) ;
5269
+ emitSetters ( exportStarFunction ) ;
5243
5270
writeLine ( ) ;
5244
5271
emitExecute ( node , startIndex ) ;
5245
5272
emitTempDeclarations ( /*newLine*/ true )
@@ -5248,7 +5275,7 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
5248
5275
write ( "}" ) ; // return
5249
5276
}
5250
5277
5251
- function emitSetters ( exportedLocalNamesRef : string ) {
5278
+ function emitSetters ( exportStarFunction : string ) {
5252
5279
write ( "setters:[" ) ;
5253
5280
for ( let i = 0 ; i < externalImports . length ; ++ i ) {
5254
5281
if ( i !== 0 ) {
@@ -5341,16 +5368,8 @@ if (typeof __param !== "function") __param = function (paramIndex, decorator) {
5341
5368
writeLine ( ) ;
5342
5369
// export * from 'foo'
5343
5370
// emit as:
5344
- // for (var n in _foo) exports(n, _foo[n]);
5345
- // NOTE: it is safe to use name 'n' since parameter name always starts with '_'
5346
- write ( `for (var n in ${ parameterName } )` ) ;
5347
- increaseIndent ( ) ;
5348
- writeLine ( ) ;
5349
- if ( exportedLocalNamesRef ) {
5350
- write ( `if (!${ exportedLocalNamesRef } .hasOwnProperty(n))` ) ;
5351
- }
5352
- write ( ` ${ exportFunctionForFile } (n, ${ parameterName } [n]);` )
5353
- decreaseIndent ( ) ;
5371
+ // exportStar(_foo, 'foo');
5372
+ write ( `${ exportStarFunction } (${ parameterName } , ${ getExternalModuleNameText ( importNode ) } );` ) ;
5354
5373
}
5355
5374
5356
5375
writeLine ( ) ;
0 commit comments