@@ -6404,19 +6404,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64046404 write ( "});" ) ;
64056405 }
64066406
6407- function emitAMDDependencies ( node : SourceFile , includeNonAmdDependencies : boolean ) {
6408- // An AMD define function has the following shape:
6409- // define(id?, dependencies?, factory);
6410- //
6411- // This has the shape of
6412- // define(name, ["module1", "module2"], function (module1Alias) {
6413- // The location of the alias in the parameter list in the factory function needs to
6414- // match the position of the module name in the dependency list.
6415- //
6416- // To ensure this is true in cases of modules with no aliases, e.g.:
6417- // `import "module"` or `<amd-dependency path= "a.css" />`
6418- // we need to add modules without alias names to the end of the dependencies list
6407+ interface AMDDependencyNames {
6408+ aliasedModuleNames : string [ ] ;
6409+ unaliasedModuleNames : string [ ] ;
6410+ importAliasNames : string [ ] ;
6411+ }
64196412
6413+ function getAMDDependencyNames ( node : SourceFile , includeNonAmdDependencies : boolean ) : AMDDependencyNames {
64206414 // names of modules with corresponding parameter in the factory function
64216415 let aliasedModuleNames : string [ ] = [ ] ;
64226416 // names of modules with no corresponding parameters in factory function
@@ -6451,6 +6445,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64516445 }
64526446 }
64536447
6448+ return { aliasedModuleNames, unaliasedModuleNames, importAliasNames } ;
6449+ }
6450+
6451+ function emitAMDDependencies ( node : SourceFile , includeNonAmdDependencies : boolean ) {
6452+ // An AMD define function has the following shape:
6453+ // define(id?, dependencies?, factory);
6454+ //
6455+ // This has the shape of
6456+ // define(name, ["module1", "module2"], function (module1Alias) {
6457+ // The location of the alias in the parameter list in the factory function needs to
6458+ // match the position of the module name in the dependency list.
6459+ //
6460+ // To ensure this is true in cases of modules with no aliases, e.g.:
6461+ // `import "module"` or `<amd-dependency path= "a.css" />`
6462+ // we need to add modules without alias names to the end of the dependencies list
6463+
6464+ let dependencyNames = getAMDDependencyNames ( node , includeNonAmdDependencies ) ;
6465+ emitAMDDependencyList ( dependencyNames ) ;
6466+ write ( ", " ) ;
6467+ emitAMDFactoryHeader ( dependencyNames ) ;
6468+ }
6469+
6470+ function emitAMDDependencyList ( { aliasedModuleNames, unaliasedModuleNames } : AMDDependencyNames ) {
64546471 write ( "[\"require\", \"exports\"" ) ;
64556472 if ( aliasedModuleNames . length ) {
64566473 write ( ", " ) ;
@@ -6460,11 +6477,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64606477 write ( ", " ) ;
64616478 write ( unaliasedModuleNames . join ( ", " ) ) ;
64626479 }
6463- write ( "], function (require, exports" ) ;
6480+ write ( "]" ) ;
6481+ }
6482+
6483+ function emitAMDFactoryHeader ( { importAliasNames } : AMDDependencyNames ) {
6484+ write ( "function (require, exports" ) ;
64646485 if ( importAliasNames . length ) {
64656486 write ( ", " ) ;
64666487 write ( importAliasNames . join ( ", " ) ) ;
64676488 }
6489+ write ( ") {" ) ;
64686490 }
64696491
64706492 function emitAMDModule ( node : SourceFile , startIndex : number ) {
@@ -6477,7 +6499,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
64776499 write ( "\"" + node . moduleName + "\", " ) ;
64786500 }
64796501 emitAMDDependencies ( node , /*includeNonAmdDependencies*/ true ) ;
6480- write ( ") {" ) ;
64816502 increaseIndent ( ) ;
64826503 emitExportStarHelper ( ) ;
64836504 emitCaptureThisForNodeIfNecessary ( node ) ;
@@ -6503,17 +6524,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
65036524 emitEmitHelpers ( node ) ;
65046525 collectExternalModuleInfo ( node ) ;
65056526
6527+ let dependencyNames = getAMDDependencyNames ( node , /*includeNonAmdDependencies*/ false ) ;
6528+
65066529 // Module is detected first to support Browserify users that load into a browser with an AMD loader
6507- writeLines ( `(function (deps, factory) {
6530+ writeLines ( `(function (factory) {
65086531 if (typeof module === 'object' && typeof module.exports === 'object') {
65096532 var v = factory(require, exports); if (v !== undefined) module.exports = v;
65106533 }
65116534 else if (typeof define === 'function' && define.amd) {
6512- define(deps, factory);
6513- }
6535+ define(` ) ;
6536+ emitAMDDependencyList ( dependencyNames ) ;
6537+ write ( ", factory);" ) ;
6538+ writeLines ( ` }
65146539})(` ) ;
6515- emitAMDDependencies ( node , false ) ;
6516- write ( ") {" ) ;
6540+ emitAMDFactoryHeader ( dependencyNames ) ;
65176541 increaseIndent ( ) ;
65186542 emitExportStarHelper ( ) ;
65196543 emitCaptureThisForNodeIfNecessary ( node ) ;
0 commit comments