@@ -5,6 +5,22 @@ const generator = require('@babel/generator').default;
5
5
const babel = require ( '@babel/core' ) ;
6
6
const Module = require ( './module' ) ;
7
7
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
+
8
24
const resolve = ( path , t , requirements ) => {
9
25
const binding = path . scope . getBinding ( path . node . name ) ;
10
26
@@ -58,7 +74,8 @@ const resolve = (path, t, requirements) => {
58
74
module . exports = function evaluate (
59
75
path /* : any */ ,
60
76
t /* : any */ ,
61
- filename /* : string */
77
+ filename /* : string */ ,
78
+ transformModule /* : (text: string) => { code: string } */ = defaultTransformModule
62
79
) {
63
80
const requirements = [ ] ;
64
81
@@ -147,21 +164,7 @@ module.exports = function evaluate(
147
164
148
165
const m = new Module ( filename ) ;
149
166
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 ;
165
168
166
169
m . evaluate (
167
170
dedent `
0 commit comments