@@ -61,6 +61,10 @@ class Loader {
6161 // an object with the same keys as `exports`, whose values are get/set
6262 // functions for the actual exported values.
6363 this . _dynamicInstantiate = undefined ;
64+ // These hooks are called FILO when resolve(...).format is 'module' and
65+ // has the signature
66+ // (code : string, url : string) -> Promise<code : string>
67+ this . _transformSource = [ ] ;
6468 // The index for assigning unique URLs to anonymous module evaluation
6569 this . evalIndex = 0 ;
6670 }
@@ -133,14 +137,26 @@ class Loader {
133137 return module . getNamespace ( ) ;
134138 }
135139
136- hook ( { resolve, dynamicInstantiate } ) {
140+ async transformSource ( url , code ) {
141+ for ( const transformFn of this . _transformSource ) {
142+ code = await transformFn ( url , code ) ;
143+ }
144+
145+ return code ;
146+ }
147+
148+ hook ( { resolve, dynamicInstantiate, transformSource } ) {
137149 // Use .bind() to avoid giving access to the Loader instance when called.
138150 if ( resolve !== undefined )
139151 this . _resolve = FunctionPrototype . bind ( resolve , null ) ;
140152 if ( dynamicInstantiate !== undefined ) {
141153 this . _dynamicInstantiate =
142154 FunctionPrototype . bind ( dynamicInstantiate , null ) ;
143155 }
156+ if ( transformSource !== undefined ) {
157+ // this.transformSource protects `this`, no need to bind.
158+ this . _transformSource . push ( transformSource ) ;
159+ }
144160 }
145161
146162 async getModuleJob ( specifier , parentURL ) {
0 commit comments