@@ -9,12 +9,22 @@ var ConstDependency = require("./ConstDependency");
9
9
var AMDDefineDependency = require ( "./AMDDefineDependency" ) ;
10
10
var ContextDependencyHelpers = require ( "./ContextDependencyHelpers" ) ;
11
11
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
+
12
22
module . exports = AbstractPlugin . create ( {
13
23
"call define" : function ( expr ) {
14
24
var array , fn , obj ;
15
25
switch ( expr . arguments . length ) {
16
26
case 1 :
17
- if ( expr . arguments [ 0 ] . type == "FunctionExpression" ) {
27
+ if ( expr . arguments [ 0 ] . type == "FunctionExpression" || isBoundFunctionExpression ( expr . arguments [ 0 ] ) ) {
18
28
// define(f() {...})
19
29
fn = expr . arguments [ 0 ] ;
20
30
} else if ( expr . arguments [ 0 ] . type === "ObjectExpression" ) {
@@ -29,7 +39,7 @@ module.exports = AbstractPlugin.create({
29
39
case 2 :
30
40
if ( expr . arguments [ 0 ] . type === "Literal" ) {
31
41
// define("...", ...)
32
- if ( expr . arguments [ 1 ] . type === "FunctionExpression" ) {
42
+ if ( expr . arguments [ 1 ] . type === "FunctionExpression" || isBoundFunctionExpression ( expr . arguments [ 0 ] ) ) {
33
43
// define("...", f() {...})
34
44
fn = expr . arguments [ 1 ] ;
35
45
} else if ( expr . arguments [ 1 ] . type === "ObjectExpression" ) {
@@ -69,6 +79,19 @@ module.exports = AbstractPlugin.create({
69
79
else
70
80
this . walkExpression ( fn . body ) ;
71
81
} . 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 ) ;
72
95
} else if ( fn || obj ) {
73
96
this . walkExpression ( fn || obj ) ;
74
97
}
0 commit comments