File tree Expand file tree Collapse file tree 3 files changed +230
-103
lines changed Expand file tree Collapse file tree 3 files changed +230
-103
lines changed Original file line number Diff line number Diff line change @@ -542,7 +542,14 @@ module.exports = {
542542
543543 let parser = require ( '@babel/helper-compilation-targets' ) . default ;
544544 if ( typeof targets === 'object' && targets !== null ) {
545- return parser ( targets ) ;
545+ // babel version 7.10.0 introduced a change that mutates the input:
546+ // https://github.com/babel/babel/pull/11500
547+ // copy the object to guard against it, otherwise subsequent calls to
548+ // _getTargets() will only have a mutated copy and lose all config from `config/targets.js`
549+ // in the host application.
550+ // PR to fix this upstream in babel: https://github.com/babel/babel/pull/11648
551+ const copy = clone ( targets ) ;
552+ return parser ( copy ) ;
546553 } else {
547554 return targets ;
548555 }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ const terminateWorkerPool = require('./utils/terminate-workers');
1818const path = require ( 'path' ) ;
1919const fs = require ( 'fs' ) ;
2020const rimraf = require ( 'rimraf' ) ;
21+ const clone = require ( 'clone' ) ;
2122
2223function prepareAddon ( addon ) {
2324 addon . pkg . keywords . push ( 'ember-addon' ) ;
@@ -1353,6 +1354,16 @@ describe('ember-cli-babel', function() {
13531354 let pluginRequired = this . addon . isPluginRequired ( 'transform-regenerator' ) ;
13541355 expect ( pluginRequired ) . to . be . false ;
13551356 } ) ;
1357+
1358+ it ( 'defensively copies `targets` to prevent @babel/helper-compilation-functions mutating it' , function ( ) {
1359+ let targets = {
1360+ browsers : [ 'last 2 Chrome versions' ]
1361+ } ;
1362+ this . addon . project . targets = clone ( targets ) ;
1363+
1364+ this . addon . isPluginRequired ( 'transform-regenerator' ) ;
1365+ expect ( this . addon . project . targets ) . to . deep . equal ( targets ) ;
1366+ } ) ;
13561367 } ) ;
13571368} ) ;
13581369
You can’t perform that action at this time.
0 commit comments