Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This should throw
const inst = new webpack.optimize.OccurrenceOrderPlugin()
export default (config) => {
config.plugins = [
inst
]
return config
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');