@@ -9,12 +9,22 @@ var ConstDependency = require("./ConstDependency");
99var AMDDefineDependency = require ( "./AMDDefineDependency" ) ;
1010var ContextDependencyHelpers = require ( "./ContextDependencyHelpers" ) ;
1111
12+ function isBoundFunctionExpression ( expr ) {
13+ if ( expr . type !== "CallExpression" ) return false ;
14+ if ( expr . callee . type !== "MemberExpression" ) return false ;
15+ if ( expr . callee . computed ) return false ;
16+ if ( expr . callee . object . type !== "FunctionExpression" ) return false ;
17+ if ( expr . callee . property . type !== "Identifier" ) return false ;
18+ if ( expr . callee . property . name !== "bind" ) return false ;
19+ return true ;
20+ }
21+
1222module . exports = AbstractPlugin . create ( {
1323 "call define" : function ( expr ) {
1424 var array , fn , obj ;
1525 switch ( expr . arguments . length ) {
1626 case 1 :
17- if ( expr . arguments [ 0 ] . type == "FunctionExpression" ) {
27+ if ( expr . arguments [ 0 ] . type == "FunctionExpression" || isBoundFunctionExpression ( expr . arguments [ 0 ] ) ) {
1828 // define(f() {...})
1929 fn = expr . arguments [ 0 ] ;
2030 } else if ( expr . arguments [ 0 ] . type === "ObjectExpression" ) {
@@ -29,7 +39,7 @@ module.exports = AbstractPlugin.create({
2939 case 2 :
3040 if ( expr . arguments [ 0 ] . type === "Literal" ) {
3141 // define("...", ...)
32- if ( expr . arguments [ 1 ] . type === "FunctionExpression" ) {
42+ if ( expr . arguments [ 1 ] . type === "FunctionExpression" || isBoundFunctionExpression ( expr . arguments [ 0 ] ) ) {
3343 // define("...", f() {...})
3444 fn = expr . arguments [ 1 ] ;
3545 } else if ( expr . arguments [ 1 ] . type === "ObjectExpression" ) {
@@ -69,6 +79,19 @@ module.exports = AbstractPlugin.create({
6979 else
7080 this . walkExpression ( fn . body ) ;
7181 } . bind ( this ) ) ;
82+ } else if ( fn && isBoundFunctionExpression ( fn ) ) {
83+ var inTry = this . scope . inTry ;
84+ this . inScope ( fn . callee . object . params . filter ( function ( i ) {
85+ return [ "require" , "module" , "exports" ] . indexOf ( i . name ) < 0 ;
86+ } ) , function ( ) {
87+ this . scope . inTry = inTry ;
88+ if ( fn . callee . object . body . type === "BlockStatement" )
89+ this . walkStatement ( fn . callee . object . body ) ;
90+ else
91+ this . walkExpression ( fn . callee . object . body ) ;
92+ } . bind ( this ) ) ;
93+ if ( fn . arguments )
94+ this . walkExpressions ( fn . arguments ) ;
7295 } else if ( fn || obj ) {
7396 this . walkExpression ( fn || obj ) ;
7497 }
0 commit comments