File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
packages/app/src/sandbox/eval/transpilers/babel/worker Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import type FSType from 'fs';
44import evaluateCode from '../../../loaders/eval' ;
55
66let cache = { } ;
7+ let transpileBeforeExec = false ;
78
89export const resetCache = ( ) => {
910 cache = { } ;
@@ -22,6 +23,11 @@ export default function evaluate(
2223 return ( ) => { } ;
2324 }
2425
26+ if ( requirePath === 'babel-register' ) {
27+ transpileBeforeExec = true ;
28+ return ( ) => { } ;
29+ }
30+
2531 if ( requirePath === 'require-from-string' ) {
2632 return ( newCode : string ) =>
2733 evaluate (
@@ -62,7 +68,7 @@ export default function evaluate(
6268 moduleDirectory : [ 'node_modules' ] ,
6369 } ) ;
6470
65- const resolvedCode = fs . readFileSync ( resolvedPath ) . toString ( ) ;
71+ let resolvedCode = fs . readFileSync ( resolvedPath ) . toString ( ) ;
6672 const id = hashsum ( resolvedCode + resolvedPath ) ;
6773
6874 if ( cache [ id ] ) {
@@ -71,6 +77,12 @@ export default function evaluate(
7177
7278 cache [ id ] = { } ;
7379
80+ if ( transpileBeforeExec ) {
81+ const { code : transpiledCode } = Babel . transform ( resolvedCode ) ;
82+
83+ resolvedCode = transpiledCode ;
84+ }
85+
7486 cache [ id ] = evaluate (
7587 fs ,
7688 BFSRequire ,
You can’t perform that action at this time.
0 commit comments