@@ -184,8 +184,8 @@ const presetRegExp = new RegExp('@babel/preset-');
184184function normalizeV7Config ( config ) {
185185 return {
186186 ...config ,
187- plugins : config . plugins . map ( stripParams ( pluginRegExp ) ) ,
188- presets : config . presets . map ( stripParams ( presetRegExp ) ) ,
187+ plugins : ( config . plugins || [ ] ) . map ( stripParams ( pluginRegExp ) ) ,
188+ presets : ( config . presets || [ ] ) . map ( stripParams ( presetRegExp ) ) ,
189189 } ;
190190}
191191
@@ -357,8 +357,73 @@ self.addEventListener('message', async event => {
357357 lastConfig = stringifiedConfig ;
358358 }
359359
360- const flattenedPresets = flatten ( config . presets || [ ] ) ;
361- const flattenedPlugins = flatten ( config . plugins || [ ] ) ;
360+ const plugins = [ ...( config . plugins || [ ] ) ] ;
361+
362+ if ( ! disableCodeSandboxPlugins ) {
363+ plugins . push ( 'dynamic-import-node' ) ;
364+
365+ if ( loaderOptions . dynamicCSSModules ) {
366+ plugins . push ( 'dynamic-css-modules' ) ;
367+ }
368+
369+ if ( ! sandboxOptions || sandboxOptions . infiniteLoopProtection ) {
370+ plugins . push ( 'babel-plugin-transform-prevent-infinite-loops' ) ;
371+ }
372+ }
373+
374+ plugins . push ( [
375+ 'babel-plugin-detective' ,
376+ { source : true , nodes : true , generated : true } ,
377+ ] ) ;
378+
379+ const customConfig =
380+ / ^ \/ n o d e _ m o d u l e s / . test ( path ) && / \. j s $ / . test ( path )
381+ ? {
382+ parserOpts : version === 7 && {
383+ plugins : [ 'dynamicImport' , 'objectRestSpread' ] ,
384+ } ,
385+ presets :
386+ version === 7 ? [ 'env' , 'react' ] : [ 'es2015' , 'react' , 'stage-0' ] ,
387+ plugins : [
388+ version === 7
389+ ? 'transform-modules-commonjs'
390+ : 'transform-es2015-modules-commonjs' ,
391+ version === 7
392+ ? 'proposal-class-properties'
393+ : 'transform-class-properties' ,
394+ ...( version === 7
395+ ? [ '@babel/plugin-transform-runtime' ]
396+ : [
397+ [
398+ 'transform-runtime' ,
399+ {
400+ helpers : false ,
401+ polyfill : false ,
402+ regenerator : true ,
403+ } ,
404+ ] ,
405+ [
406+ 'transform-regenerator' ,
407+ {
408+ // Async functions are converted to generators by babel-preset-env
409+ async : false ,
410+ } ,
411+ ] ,
412+ ] ) ,
413+ 'dynamic-import-node' ,
414+ [
415+ 'babel-plugin-detective' ,
416+ { source : true , nodes : true , generated : true } ,
417+ ] ,
418+ ] . filter ( Boolean ) ,
419+ }
420+ : {
421+ ...config ,
422+ plugins,
423+ } ;
424+
425+ const flattenedPresets = flatten ( customConfig . presets || [ ] ) ;
426+ const flattenedPlugins = flatten ( customConfig . plugins || [ ] ) ;
362427
363428 if ( ! disableCodeSandboxPlugins ) {
364429 if (
@@ -470,71 +535,6 @@ self.addEventListener('message', async event => {
470535 } )
471536 ) ;
472537
473- const plugins = [ ...( config . plugins || [ ] ) ] ;
474-
475- if ( ! disableCodeSandboxPlugins ) {
476- plugins . push ( 'dynamic-import-node' ) ;
477-
478- if ( loaderOptions . dynamicCSSModules ) {
479- plugins . push ( 'dynamic-css-modules' ) ;
480- }
481-
482- if ( ! sandboxOptions || sandboxOptions . infiniteLoopProtection ) {
483- plugins . push ( 'babel-plugin-transform-prevent-infinite-loops' ) ;
484- }
485- }
486-
487- plugins . push ( [
488- 'babel-plugin-detective' ,
489- { source : true , nodes : true , generated : true } ,
490- ] ) ;
491-
492- const customConfig =
493- / ^ \/ n o d e _ m o d u l e s / . test ( path ) && / \. j s $ / . test ( path )
494- ? {
495- parserOpts : version === 7 && {
496- plugins : [ 'dynamicImport' , 'objectRestSpread' ] ,
497- } ,
498- presets :
499- version === 7 ? [ 'env' , 'react' ] : [ 'es2015' , 'react' , 'stage-0' ] ,
500- plugins : [
501- version === 7
502- ? 'transform-modules-commonjs'
503- : 'transform-es2015-modules-commonjs' ,
504- version === 7
505- ? 'proposal-class-properties'
506- : 'transform-class-properties' ,
507- ...( version === 7
508- ? [ ]
509- : [
510- [
511- 'transform-runtime' ,
512- {
513- helpers : false ,
514- polyfill : false ,
515- regenerator : true ,
516- } ,
517- ] ,
518- [
519- 'transform-regenerator' ,
520- {
521- // Async functions are converted to generators by babel-preset-env
522- async : false ,
523- } ,
524- ] ,
525- ] ) ,
526- 'dynamic-import-node' ,
527- [
528- 'babel-plugin-detective' ,
529- { source : true , nodes : true , generated : true } ,
530- ] ,
531- ] . filter ( Boolean ) ,
532- }
533- : {
534- ...config ,
535- plugins,
536- } ;
537-
538538 await compile (
539539 code ,
540540 version === 7 ? normalizeV7Config ( customConfig ) : customConfig ,
0 commit comments