@@ -60,10 +60,21 @@ class Loader {
60
60
// For backwards compatibility purposes, we will manually compose
61
61
// `format()`, `fetch()` and `transform()` into a `load()` function.
62
62
const hook = id => ( ...args ) => this . handleStack ( id , ...args ) ;
63
- const resolve = hook ( 'resolve' ) ;
63
+ const resolve = shortCircuit ( hook ( 'resolve' ) ) ;
64
64
const getFormat = hook ( 'format' ) ;
65
65
const getSource = hook ( 'fetch' ) ;
66
66
67
+ // See #4. In Node 18 we now need to specify explicitly that we're
68
+ // short-circuiting, which is what this function does.
69
+ function shortCircuit ( fn ) {
70
+ return async function ( ...args ) {
71
+ return {
72
+ shortCircuit : true ,
73
+ ...await fn ( ...args ) ,
74
+ } ;
75
+ }
76
+ }
77
+
67
78
// Handling transformation is fundamentally different as we have to
68
79
// chain results here.
69
80
const transformSource = async ( source , ctx , node ) => {
@@ -109,7 +120,7 @@ class Loader {
109
120
// higher, which uses the new approach. We only have to export a
110
121
// `resolve` and `load` function here, but the difficulty is that the
111
122
// `load()` function has to be composed manually!
112
- const load = async function ( url , ctx , defaultLoad ) {
123
+ const load = shortCircuit ( async function ( url , ctx , defaultLoad ) {
113
124
114
125
// If the format was already specified by the resolve hook, we
115
126
// won't try to fetch it again. Note that this functionality is
@@ -143,7 +154,7 @@ class Loader {
143
154
source : transform . source ,
144
155
} ;
145
156
146
- } ;
157
+ } ) ;
147
158
return { resolve, load } ;
148
159
149
160
}
0 commit comments