@@ -15,7 +15,6 @@ const {
15
15
ObjectDefineProperty,
16
16
ObjectSetPrototypeOf,
17
17
PromiseAll,
18
- ReflectApply,
19
18
RegExpPrototypeExec,
20
19
SafeArrayIterator,
21
20
SafeWeakMap,
@@ -148,29 +147,22 @@ function nextHookFactory(chain, meta, { validateArgs, validateOutput }) {
148
147
}
149
148
150
149
return ObjectDefineProperty (
151
- async ( ... args ) => {
150
+ async ( arg0 = undefined , context ) => {
152
151
// Update only when hook is invoked to avoid fingering the wrong filePath
153
152
meta . hookErrIdentifier = `${ hookFilePath } '${ hookName } '` ;
154
153
155
- validateArgs ( `${ meta . hookErrIdentifier } hook's ${ nextHookName } ()` , args ) ;
154
+ validateArgs ( `${ meta . hookErrIdentifier } hook's ${ nextHookName } ()` , arg0 , context ) ;
156
155
157
156
const outputErrIdentifier = `${ chain [ generatedHookIndex ] . url } '${ hookName } ' hook's ${ nextHookName } ()` ;
158
157
159
158
// Set when next<HookName> is actually called, not just generated.
160
159
if ( generatedHookIndex === 0 ) { meta . chainFinished = true ; }
161
160
162
- // `context` is an optional argument that only needs to be passed when changed
163
- switch ( args . length ) {
164
- case 1 : // It was omitted, so supply the cached value
165
- ArrayPrototypePush ( args , meta . context ) ;
166
- break ;
167
- case 2 : // Overrides were supplied, so update cached value
168
- ObjectAssign ( meta . context , args [ 1 ] ) ;
169
- break ;
161
+ if ( context ) { // `context` has already been validated, so no fancy check needed.
162
+ ObjectAssign ( meta . context , context ) ;
170
163
}
171
164
172
- ArrayPrototypePush ( args , nextNextHook ) ;
173
- const output = await ReflectApply ( hook , undefined , args ) ;
165
+ const output = await hook ( arg0 , meta . context , nextNextHook ) ;
174
166
175
167
validateOutput ( outputErrIdentifier , output ) ;
176
168
@@ -575,7 +567,7 @@ class ESMLoader {
575
567
shortCircuited : false ,
576
568
} ;
577
569
578
- const validateArgs = ( hookErrIdentifier , { 0 : nextUrl , 1 : ctx } ) => {
570
+ const validateArgs = ( hookErrIdentifier , nextUrl , ctx ) => {
579
571
if ( typeof nextUrl !== 'string' ) {
580
572
// non-strings can be coerced to a url string
581
573
// validateString() throws a less-specific error
@@ -829,7 +821,7 @@ class ESMLoader {
829
821
shortCircuited : false ,
830
822
} ;
831
823
832
- const validateArgs = ( hookErrIdentifier , { 0 : suppliedSpecifier , 1 : ctx } ) => {
824
+ const validateArgs = ( hookErrIdentifier , suppliedSpecifier , ctx ) => {
833
825
validateString (
834
826
suppliedSpecifier ,
835
827
`${ hookErrIdentifier } specifier` ,
0 commit comments