@@ -5,6 +5,22 @@ const generator = require('@babel/generator').default;
55const babel = require ( '@babel/core' ) ;
66const Module = require ( './module' ) ;
77
8+ function defaultTransformModule ( text ) {
9+ return babel . transformSync ( text , {
10+ filename : this . filename ,
11+ plugins : [
12+ // Include this plugin to avoid extra config when using { module: false } for webpack
13+ '@babel/plugin-transform-modules-commonjs' ,
14+ '@babel/plugin-proposal-export-namespace-from' ,
15+ // We don't support dynamic imports when evaluating, but don't wanna syntax error
16+ // This will replace dynamic imports with an object that does nothing
17+ require . resolve ( './dynamic-import-noop' ) ,
18+ [ require . resolve ( './extract' ) , { evaluate : true } ] ,
19+ ] ,
20+ exclude : / n o d e _ m o d u l e s / ,
21+ } ) ;
22+ }
23+
824const resolve = ( path , t , requirements ) => {
925 const binding = path . scope . getBinding ( path . node . name ) ;
1026
@@ -58,7 +74,8 @@ const resolve = (path, t, requirements) => {
5874module . exports = function evaluate (
5975 path /* : any */ ,
6076 t /* : any */ ,
61- filename /* : string */
77+ filename /* : string */ ,
78+ transformModule /* : (text: string) => { code: string } */ = defaultTransformModule
6279) {
6380 const requirements = [ ] ;
6481
@@ -147,21 +164,7 @@ module.exports = function evaluate(
147164
148165 const m = new Module ( filename ) ;
149166
150- m . transform = function transform ( text ) {
151- return babel . transformSync ( text , {
152- filename : this . filename ,
153- plugins : [
154- // Include this plugin to avoid extra config when using { module: false } for webpack
155- '@babel/plugin-transform-modules-commonjs' ,
156- '@babel/plugin-proposal-export-namespace-from' ,
157- // We don't support dynamic imports when evaluating, but don't wanna syntax error
158- // This will replace dynamic imports with an object that does nothing
159- require . resolve ( './dynamic-import-noop' ) ,
160- [ require . resolve ( './extract' ) , { evaluate : true } ] ,
161- ] ,
162- exclude : / n o d e _ m o d u l e s / ,
163- } ) ;
164- } ;
167+ m . transform = transformModule ;
165168
166169 m . evaluate (
167170 dedent `
0 commit comments