@@ -6406,19 +6406,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64066406 write ( "});" ) ;
64076407 }
64086408
6409- function emitAMDDependencies ( node : SourceFile , includeNonAmdDependencies : boolean ) {
6410- // An AMD define function has the following shape:
6411- // define(id?, dependencies?, factory);
6412- //
6413- // This has the shape of
6414- // define(name, ["module1", "module2"], function (module1Alias) {
6415- // The location of the alias in the parameter list in the factory function needs to
6416- // match the position of the module name in the dependency list.
6417- //
6418- // To ensure this is true in cases of modules with no aliases, e.g.:
6419- // `import "module"` or `<amd-dependency path= "a.css" />`
6420- // we need to add modules without alias names to the end of the dependencies list
6409+ interface AMDDependencyNames {
6410+ aliasedModuleNames : string [ ] ;
6411+ unaliasedModuleNames : string [ ] ;
6412+ importAliasNames : string [ ] ;
6413+ }
64216414
6415+ function getAMDDependencyNames ( node : SourceFile , includeNonAmdDependencies : boolean ) : AMDDependencyNames {
64226416 // names of modules with corresponding parameter in the factory function
64236417 let aliasedModuleNames : string [ ] = [ ] ;
64246418 // names of modules with no corresponding parameters in factory function
@@ -6453,6 +6447,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64536447 }
64546448 }
64556449
6450+ return { aliasedModuleNames, unaliasedModuleNames, importAliasNames } ;
6451+ }
6452+
6453+ function emitAMDDependencies ( node : SourceFile , includeNonAmdDependencies : boolean ) {
6454+ // An AMD define function has the following shape:
6455+ // define(id?, dependencies?, factory);
6456+ //
6457+ // This has the shape of
6458+ // define(name, ["module1", "module2"], function (module1Alias) {
6459+ // The location of the alias in the parameter list in the factory function needs to
6460+ // match the position of the module name in the dependency list.
6461+ //
6462+ // To ensure this is true in cases of modules with no aliases, e.g.:
6463+ // `import "module"` or `<amd-dependency path= "a.css" />`
6464+ // we need to add modules without alias names to the end of the dependencies list
6465+
6466+ let dependencyNames = getAMDDependencyNames ( node , includeNonAmdDependencies ) ;
6467+ emitAMDDependencyList ( dependencyNames ) ;
6468+ write ( ", " ) ;
6469+ emitAMDFactoryHeader ( dependencyNames ) ;
6470+ }
6471+
6472+ function emitAMDDependencyList ( { aliasedModuleNames, unaliasedModuleNames } : AMDDependencyNames ) {
64566473 write ( "[\"require\", \"exports\"" ) ;
64576474 if ( aliasedModuleNames . length ) {
64586475 write ( ", " ) ;
@@ -6462,11 +6479,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64626479 write ( ", " ) ;
64636480 write ( unaliasedModuleNames . join ( ", " ) ) ;
64646481 }
6465- write ( "], function (require, exports" ) ;
6482+ write ( "]" ) ;
6483+ }
6484+
6485+ function emitAMDFactoryHeader ( { importAliasNames } : AMDDependencyNames ) {
6486+ write ( "function (require, exports" ) ;
64666487 if ( importAliasNames . length ) {
64676488 write ( ", " ) ;
64686489 write ( importAliasNames . join ( ", " ) ) ;
64696490 }
6491+ write ( ") {" ) ;
64706492 }
64716493
64726494 function emitAMDModule ( node : SourceFile , startIndex : number ) {
@@ -6479,7 +6501,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64796501 write ( "\"" + node . moduleName + "\", " ) ;
64806502 }
64816503 emitAMDDependencies ( node , /*includeNonAmdDependencies*/ true ) ;
6482- write ( ") {" ) ;
64836504 increaseIndent ( ) ;
64846505 emitExportStarHelper ( ) ;
64856506 emitCaptureThisForNodeIfNecessary ( node ) ;
@@ -6505,17 +6526,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
65056526 emitEmitHelpers ( node ) ;
65066527 collectExternalModuleInfo ( node ) ;
65076528
6529+ let dependencyNames = getAMDDependencyNames ( node , /*includeNonAmdDependencies*/ false ) ;
6530+
65086531 // Module is detected first to support Browserify users that load into a browser with an AMD loader
6509- writeLines ( `(function (deps, factory) {
6532+ writeLines ( `(function (factory) {
65106533 if (typeof module === 'object' && typeof module.exports === 'object') {
65116534 var v = factory(require, exports); if (v !== undefined) module.exports = v;
65126535 }
65136536 else if (typeof define === 'function' && define.amd) {
6514- define(deps, factory);
6515- }
6537+ define(` ) ;
6538+ emitAMDDependencyList ( dependencyNames ) ;
6539+ write ( ", factory);" ) ;
6540+ writeLines ( ` }
65166541})(` ) ;
6517- emitAMDDependencies ( node , false ) ;
6518- write ( ") {" ) ;
6542+ emitAMDFactoryHeader ( dependencyNames ) ;
65196543 increaseIndent ( ) ;
65206544 emitExportStarHelper ( ) ;
65216545 emitCaptureThisForNodeIfNecessary ( node ) ;
0 commit comments