diff --git a/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap b/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap index 3eefb81ec37..550faf1fba2 100644 --- a/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap +++ b/lib/transformations/removeDeprecatedPlugins/__snapshots__/removeDeprecatedPlugins.test.js.snap @@ -30,3 +30,15 @@ export default (config) => { } " `; + +exports[`removeDeprecatedPlugins transforms correctly using "removeDeprecatedPlugins-4" data 1`] = ` +"// This should throw +const inst = new webpack.optimize.OccurrenceOrderPlugin() +export default (config) => { + config.plugins = [ + inst + ] + return config +} +" +`; diff --git a/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js new file mode 100644 index 00000000000..fab47caf971 --- /dev/null +++ b/lib/transformations/removeDeprecatedPlugins/__testfixtures__/removeDeprecatedPlugins-4.input.js @@ -0,0 +1,8 @@ +// This should throw +const inst = new webpack.optimize.OccurrenceOrderPlugin() +export default (config) => { + config.plugins = [ + inst + ] + return config +} diff --git a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js index 6a849fb2978..a3d193800f3 100644 --- a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js +++ b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.js @@ -19,13 +19,12 @@ module.exports = function(j, ast, source) { return utils.findPluginsByName(j, ast, deprecatedPlugingsList) .forEach(path => { // For now we only support the case there plugins are defined in an Array - if (path.parent && - path.parent.value && - utils.isType(path.parent.value, 'ArrayExpression') - ) { + const arrayPath = utils.safeTraverse(path, ['parent','value']); + if (arrayPath && utils.isType(arrayPath, 'ArrayExpression')) { // Check how many plugins are defined and // if there is only last plugin left remove `plugins: []` node - if (path.parent.value.elements.length === 1) { + const arrayElementsPath = utils.safeTraverse(arrayPath, ['elements']); + if (arrayElementsPath && arrayElementsPath.length === 1) { j(path.parent.parent).remove(); } else { j(path).remove(); diff --git a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js index a487225a6d0..748a0c35ea1 100644 --- a/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js +++ b/lib/transformations/removeDeprecatedPlugins/removeDeprecatedPlugins.test.js @@ -4,3 +4,4 @@ defineTest(__dirname, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-0'); defineTest(__dirname, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-1'); defineTest(__dirname, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-2'); defineTest(__dirname, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-3'); +defineTest(__dirname, 'removeDeprecatedPlugins', 'removeDeprecatedPlugins-4');