@@ -46,23 +46,20 @@ class AMDRequireDependenciesBlockParserPlugin {
46
46
}
47
47
48
48
apply ( parser ) {
49
- parser . hooks . call . for ( "require" ) . tap (
50
- "AMDRequireDependenciesBlockParserPlugin" ,
51
- this . processCallRequire . bind (
52
- Object . create ( this , {
53
- parser : { value : parser }
54
- } )
55
- )
56
- ) ;
49
+ parser . hooks . call
50
+ . for ( "require" )
51
+ . tap (
52
+ "AMDRequireDependenciesBlockParserPlugin" ,
53
+ this . processCallRequire . bind ( this , parser )
54
+ ) ;
57
55
}
58
56
59
- processArray ( expr , param ) {
60
- const parser = this . parser ;
57
+ processArray ( parser , expr , param ) {
61
58
if ( param . isArray ( ) ) {
62
59
for ( const p of param . items ) {
63
- const result = this . processItem ( expr , p ) ;
60
+ const result = this . processItem ( parser , expr , p ) ;
64
61
if ( result === undefined ) {
65
- this . processContext ( expr , p ) ;
62
+ this . processContext ( parser , expr , p ) ;
66
63
}
67
64
}
68
65
return true ;
@@ -99,13 +96,12 @@ class AMDRequireDependenciesBlockParserPlugin {
99
96
return true ;
100
97
}
101
98
}
102
- processItem ( expr , param ) {
103
- const parser = this . parser ;
99
+ processItem ( parser , expr , param ) {
104
100
if ( param . isConditional ( ) ) {
105
101
for ( const p of param . options ) {
106
- const result = this . processItem ( expr , p ) ;
102
+ const result = this . processItem ( parser , expr , p ) ;
107
103
if ( result === undefined ) {
108
- this . processContext ( expr , p ) ;
104
+ this . processContext ( parser , expr , p ) ;
109
105
}
110
106
}
111
107
return true ;
@@ -140,7 +136,7 @@ class AMDRequireDependenciesBlockParserPlugin {
140
136
return true ;
141
137
}
142
138
}
143
- processContext ( expr , param ) {
139
+ processContext ( parser , expr , param ) {
144
140
const dep = ContextDependencyHelpers . create (
145
141
AMDRequireContextDependency ,
146
142
param . range ,
@@ -150,39 +146,38 @@ class AMDRequireDependenciesBlockParserPlugin {
150
146
) ;
151
147
if ( ! dep ) return ;
152
148
dep . loc = expr . loc ;
153
- dep . optional = ! ! this . parser . scope . inTry ;
154
- this . parser . state . current . addDependency ( dep ) ;
149
+ dep . optional = ! ! parser . scope . inTry ;
150
+ parser . state . current . addDependency ( dep ) ;
155
151
return true ;
156
152
}
157
153
158
- processCallRequire ( expr ) {
159
- const processArrayForRequestString = param => {
160
- if ( param . isArray ( ) ) {
161
- const result = param . items . map ( item =>
162
- processItemForRequestString ( item )
163
- ) ;
164
- if ( result . every ( Boolean ) ) return result . join ( " " ) ;
165
- } else if ( param . isConstArray ( ) ) {
166
- return param . array . join ( " " ) ;
167
- }
168
- } ;
154
+ processArrayForRequestString ( param ) {
155
+ if ( param . isArray ( ) ) {
156
+ const result = param . items . map ( item =>
157
+ this . processItemForRequestString ( item )
158
+ ) ;
159
+ if ( result . every ( Boolean ) ) return result . join ( " " ) ;
160
+ } else if ( param . isConstArray ( ) ) {
161
+ return param . array . join ( " " ) ;
162
+ }
163
+ }
169
164
170
- const processItemForRequestString = param => {
171
- if ( param . isConditional ( ) ) {
172
- const result = param . options . map ( item =>
173
- processItemForRequestString ( item )
174
- ) ;
175
- if ( result . every ( Boolean ) ) return result . join ( "|" ) ;
176
- } else if ( param . isString ( ) ) {
177
- return param . string ;
178
- }
179
- } ;
165
+ processItemForRequestString ( param ) {
166
+ if ( param . isConditional ( ) ) {
167
+ const result = param . options . map ( item =>
168
+ this . processItemForRequestString ( item )
169
+ ) ;
170
+ if ( result . every ( Boolean ) ) return result . join ( "|" ) ;
171
+ } else if ( param . isString ( ) ) {
172
+ return param . string ;
173
+ }
174
+ }
180
175
176
+ processCallRequire ( parser , expr ) {
181
177
let param ;
182
178
let dep ;
183
179
let result ;
184
180
185
- const parser = this . parser ;
186
181
const old = parser . state . current ;
187
182
188
183
if ( expr . arguments . length >= 1 ) {
@@ -194,14 +189,14 @@ class AMDRequireDependenciesBlockParserPlugin {
194
189
expr . arguments . length > 2 ? expr . arguments [ 2 ] . range : null ,
195
190
parser . state . module ,
196
191
expr . loc ,
197
- processArrayForRequestString ( param )
192
+ this . processArrayForRequestString ( param )
198
193
) ;
199
194
parser . state . current = dep ;
200
195
}
201
196
202
197
if ( expr . arguments . length === 1 ) {
203
198
parser . inScope ( [ ] , ( ) => {
204
- result = this . processArray ( expr , param ) ;
199
+ result = this . processArray ( parser , expr , param ) ;
205
200
} ) ;
206
201
parser . state . current = old ;
207
202
if ( ! result ) return ;
@@ -212,7 +207,7 @@ class AMDRequireDependenciesBlockParserPlugin {
212
207
if ( expr . arguments . length === 2 || expr . arguments . length === 3 ) {
213
208
try {
214
209
parser . inScope ( [ ] , ( ) => {
215
- result = this . processArray ( expr , param ) ;
210
+ result = this . processArray ( parser , expr , param ) ;
216
211
} ) ;
217
212
if ( ! result ) {
218
213
dep = new UnsupportedDependency ( "unsupported" , expr . range ) ;
@@ -246,14 +241,30 @@ class AMDRequireDependenciesBlockParserPlugin {
246
241
}
247
242
}
248
243
249
- newRequireDependenciesBlock ( ...args ) {
250
- return new AMDRequireDependenciesBlock ( ...args ) ;
244
+ newRequireDependenciesBlock (
245
+ expr ,
246
+ arrayRange ,
247
+ functionRange ,
248
+ errorCallbackRange ,
249
+ module ,
250
+ loc ,
251
+ request
252
+ ) {
253
+ return new AMDRequireDependenciesBlock (
254
+ expr ,
255
+ arrayRange ,
256
+ functionRange ,
257
+ errorCallbackRange ,
258
+ module ,
259
+ loc ,
260
+ request
261
+ ) ;
251
262
}
252
- newRequireItemDependency ( ... args ) {
253
- return new AMDRequireItemDependency ( ... args ) ;
263
+ newRequireItemDependency ( request , range ) {
264
+ return new AMDRequireItemDependency ( request , range ) ;
254
265
}
255
- newRequireArrayDependency ( ... args ) {
256
- return new AMDRequireArrayDependency ( ... args ) ;
266
+ newRequireArrayDependency ( depsArray , range ) {
267
+ return new AMDRequireArrayDependency ( depsArray , range ) ;
257
268
}
258
269
}
259
270
module . exports = AMDRequireDependenciesBlockParserPlugin ;
0 commit comments