@@ -68,16 +68,43 @@ module.exports = AbstractPlugin.create({
6868 break ;
6969 default : return ;
7070 }
71+ var fnParams = null ;
72+ var fnParamsOffset = 0 ;
73+ if ( fn ) {
74+ if ( fn . type === "FunctionExpression" ) fnParams = fn . params ;
75+ else if ( isBoundFunctionExpression ( fn ) ) {
76+ fnParams = fn . callee . object . params ;
77+ fnParamsOffset = fn . arguments . length - 1 ;
78+ if ( fnParamsOffset < 0 ) fnParamsOffset = 0 ;
79+ }
80+ }
81+ var fnRenames = Object . create ( this . scope . renames ) ;
7182 if ( array ) {
83+ var identifiers = { } ;
7284 var param = this . evaluateExpression ( array ) ;
73- var result = this . applyPluginsBailResult ( "call define:amd:array" , expr , param ) ;
85+ var result = this . applyPluginsBailResult ( "call define:amd:array" , expr , param , identifiers ) ;
7486 if ( ! result ) return ;
87+ if ( fnParams ) fnParams = fnParams . slice ( fnParamsOffset ) . filter ( function ( param , idx ) {
88+ if ( identifiers [ idx ] ) {
89+ fnRenames [ "$" + param . name ] = identifiers [ idx ] ;
90+ return false ;
91+ }
92+ return true ;
93+ } ) ;
94+ } else {
95+ var identifiers = [ "require" , "exports" , "module" ] ;
96+ if ( fnParams ) fnParams = fnParams . slice ( fnParamsOffset ) . filter ( function ( param , idx ) {
97+ if ( identifiers [ idx ] ) {
98+ fnRenames [ "$" + param . name ] = identifiers [ idx ] ;
99+ return false ;
100+ }
101+ return true ;
102+ } ) ;
75103 }
76104 if ( fn && fn . type === "FunctionExpression" ) {
77105 var inTry = this . scope . inTry ;
78- this . inScope ( fn . params . filter ( function ( i ) {
79- return [ "require" , "module" , "exports" ] . indexOf ( i . name ) < 0 ;
80- } ) , function ( ) {
106+ this . inScope ( fnParams , function ( ) {
107+ this . scope . renames = fnRenames ;
81108 this . scope . inTry = inTry ;
82109 if ( fn . body . type === "BlockStatement" )
83110 this . walkStatement ( fn . body ) ;
@@ -89,6 +116,7 @@ module.exports = AbstractPlugin.create({
89116 this . inScope ( fn . callee . object . params . filter ( function ( i ) {
90117 return [ "require" , "module" , "exports" ] . indexOf ( i . name ) < 0 ;
91118 } ) , function ( ) {
119+ this . scope . renames = fnRenames ;
92120 this . scope . inTry = inTry ;
93121 if ( fn . callee . object . body . type === "BlockStatement" )
94122 this . walkStatement ( fn . callee . object . body ) ;
@@ -108,9 +136,11 @@ module.exports = AbstractPlugin.create({
108136 this . state . current . addDependency ( dep ) ;
109137 return true ;
110138 } ,
111- "call define:amd:array" : function ( expr , param ) {
139+ "call define:amd:array" : function ( expr , param , identifiers ) {
112140 if ( param . isArray ( ) ) {
113- param . items . forEach ( function ( param ) {
141+ param . items . forEach ( function ( param , idx ) {
142+ if ( param . isString ( ) && [ "require" , "module" , "exports" ] . indexOf ( param . string ) >= 0 )
143+ identifiers [ idx ] = param . string ;
114144 var result = this . applyPluginsBailResult ( "call define:amd:item" , expr , param ) ;
115145 if ( result === undefined ) {
116146 this . applyPluginsBailResult ( "call define:amd:context" , expr , param ) ;
@@ -119,9 +149,10 @@ module.exports = AbstractPlugin.create({
119149 return true ;
120150 } else if ( param . isConstArray ( ) ) {
121151 var deps = [ ] ;
122- param . array . forEach ( function ( request ) {
152+ param . array . forEach ( function ( request , idx ) {
123153 var dep , localModule ;
124154 if ( [ "require" , "exports" , "module" ] . indexOf ( request ) >= 0 ) {
155+ identifiers [ idx ] = request ;
125156 dep = request ;
126157 } else if ( localModule = LocalModulesHelpers . getLocalModule ( this . state , request ) ) {
127158 dep = new LocalModuleDependency ( localModule ) ;
0 commit comments