Skip to content

Commit

Permalink
All transformations return AST to allow chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
okonet committed Feb 15, 2017
1 parent 36c745b commit 2e4e011
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 20 deletions.
3 changes: 1 addition & 2 deletions lib/transformations/bannerPlugin/bannerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ module.exports = function(j, ast) {
return utils.findPluginsRootNodes(j, ast)
.forEach(path => {
utils.createOrUpdatePluginByName(j, path, 'webpack.BannerPlugin', loaderOptions);
})
.toSource({ quote: 'single' });
});
};
2 changes: 1 addition & 1 deletion lib/transformations/defineTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function runTest(dirName, transformName, options, testFilePrefix) {
jscodeshift = jscodeshift.withParser(module.parser);
}
const ast = jscodeshift(source);
const output = transform(jscodeshift, ast);
const output = transform(jscodeshift, ast).toSource({ quote: 'single' });
expect(output).toMatchSnapshot();
}

Expand Down
13 changes: 6 additions & 7 deletions lib/transformations/extractTextPlugin/extractTextPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const safeTraverse = require('../utils').safeTraverse;
const findPluginsByName = require('../utils').findPluginsByName;

module.exports = function(j, ast) {
const changeArguments = function(p) {
const changeArguments = function(p) {
const args = p.value.arguments;
// if(args.length === 1) {
// return p;
// } else
// } else
const literalArgs = args.filter(p => p.type === 'Literal');
if (literalArgs && literalArgs.length > 1) {
const newArgs = j.objectExpression(literalArgs.map((p, index) =>
const newArgs = j.objectExpression(literalArgs.map((p, index) =>
j.property('init',
j.identifier(index === 0 ? 'fallback': 'use'),
j.literal(p.value)
Expand All @@ -18,16 +18,15 @@ module.exports = function(j, ast) {
p.value.arguments = [newArgs];
}
console.log(p.value.arguments);
return p;
return p;
};
const name = getName(j, ast, 'extract-text-webpack-plugin');
return ast.find(j.CallExpression)
.filter(p => p.value.callee.object)
.filter(p => p.value.callee.object.name === name)
.forEach(changeArguments)
.toSource({ quote: 'single' })
.forEach(changeArguments);
//.forEach(p => console.log(p.toSource()));

//return ast.toSource({ quote: 'single' });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ module.exports = function(j, ast) {
.filter(path => path.parent.value.key.name === 'plugins')
.forEach(path => {
createOrUpdatePluginByName(j, path, 'webpack.optimize.LoaderOptionsPlugin', loaderOptions);
})
.toSource({ quote: 'single' });
});
};
2 changes: 1 addition & 1 deletion lib/transformations/loaders/loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,5 @@ module.exports = function(j, ast) {
];
transforms.forEach(t => t());

return ast.toSource({ quote: 'single' });
return ast;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ module.exports = function(j, ast) {
} else {
j(path).remove();
}
})
.toSource({ quote: 'single' });
});
};
2 changes: 1 addition & 1 deletion lib/transformations/removeJsonLoader/removeJsonLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ module.exports = function(j, ast) {

transforms.forEach(t => t(ast));

return ast.toSource({ quote: 'single' });
return ast;
};
3 changes: 1 addition & 2 deletions lib/transformations/resolve/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ module.exports = function transformer(j, ast) {
.filter(prop => prop.key.name === 'root')
.length === 1;
})
.forEach(createModuleArray)
.toSource();
.forEach(createModuleArray);
};
3 changes: 1 addition & 2 deletions lib/transformations/uglifyJsPlugin/uglifyJsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ module.exports = function(j, ast) {
// Plugin is called without arguments
args.push(j.objectExpression([createSourceMapsProperty()]));
}
})
.toSource({ quote: 'single' });
});
};

0 comments on commit 2e4e011

Please sign in to comment.