@@ -46,23 +46,20 @@ class AMDRequireDependenciesBlockParserPlugin {
4646 }
4747
4848 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+ ) ;
5755 }
5856
59- processArray ( expr , param ) {
60- const parser = this . parser ;
57+ processArray ( parser , expr , param ) {
6158 if ( param . isArray ( ) ) {
6259 for ( const p of param . items ) {
63- const result = this . processItem ( expr , p ) ;
60+ const result = this . processItem ( parser , expr , p ) ;
6461 if ( result === undefined ) {
65- this . processContext ( expr , p ) ;
62+ this . processContext ( parser , expr , p ) ;
6663 }
6764 }
6865 return true ;
@@ -99,13 +96,12 @@ class AMDRequireDependenciesBlockParserPlugin {
9996 return true ;
10097 }
10198 }
102- processItem ( expr , param ) {
103- const parser = this . parser ;
99+ processItem ( parser , expr , param ) {
104100 if ( param . isConditional ( ) ) {
105101 for ( const p of param . options ) {
106- const result = this . processItem ( expr , p ) ;
102+ const result = this . processItem ( parser , expr , p ) ;
107103 if ( result === undefined ) {
108- this . processContext ( expr , p ) ;
104+ this . processContext ( parser , expr , p ) ;
109105 }
110106 }
111107 return true ;
@@ -140,7 +136,7 @@ class AMDRequireDependenciesBlockParserPlugin {
140136 return true ;
141137 }
142138 }
143- processContext ( expr , param ) {
139+ processContext ( parser , expr , param ) {
144140 const dep = ContextDependencyHelpers . create (
145141 AMDRequireContextDependency ,
146142 param . range ,
@@ -150,39 +146,38 @@ class AMDRequireDependenciesBlockParserPlugin {
150146 ) ;
151147 if ( ! dep ) return ;
152148 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 ) ;
155151 return true ;
156152 }
157153
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+ }
169164
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+ }
180175
176+ processCallRequire ( parser , expr ) {
181177 let param ;
182178 let dep ;
183179 let result ;
184180
185- const parser = this . parser ;
186181 const old = parser . state . current ;
187182
188183 if ( expr . arguments . length >= 1 ) {
@@ -194,14 +189,14 @@ class AMDRequireDependenciesBlockParserPlugin {
194189 expr . arguments . length > 2 ? expr . arguments [ 2 ] . range : null ,
195190 parser . state . module ,
196191 expr . loc ,
197- processArrayForRequestString ( param )
192+ this . processArrayForRequestString ( param )
198193 ) ;
199194 parser . state . current = dep ;
200195 }
201196
202197 if ( expr . arguments . length === 1 ) {
203198 parser . inScope ( [ ] , ( ) => {
204- result = this . processArray ( expr , param ) ;
199+ result = this . processArray ( parser , expr , param ) ;
205200 } ) ;
206201 parser . state . current = old ;
207202 if ( ! result ) return ;
@@ -212,7 +207,7 @@ class AMDRequireDependenciesBlockParserPlugin {
212207 if ( expr . arguments . length === 2 || expr . arguments . length === 3 ) {
213208 try {
214209 parser . inScope ( [ ] , ( ) => {
215- result = this . processArray ( expr , param ) ;
210+ result = this . processArray ( parser , expr , param ) ;
216211 } ) ;
217212 if ( ! result ) {
218213 dep = new UnsupportedDependency ( "unsupported" , expr . range ) ;
@@ -246,14 +241,30 @@ class AMDRequireDependenciesBlockParserPlugin {
246241 }
247242 }
248243
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+ ) ;
251262 }
252- newRequireItemDependency ( ... args ) {
253- return new AMDRequireItemDependency ( ... args ) ;
263+ newRequireItemDependency ( request , range ) {
264+ return new AMDRequireItemDependency ( request , range ) ;
254265 }
255- newRequireArrayDependency ( ... args ) {
256- return new AMDRequireArrayDependency ( ... args ) ;
266+ newRequireArrayDependency ( depsArray , range ) {
267+ return new AMDRequireArrayDependency ( depsArray , range ) ;
257268 }
258269}
259270module . exports = AMDRequireDependenciesBlockParserPlugin ;
0 commit comments