Skip to content

Instantly share code, notes, and snippets.

@jakepusateri
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakepusateri/3be3f85f7dfa12a8e97a to your computer and use it in GitHub Desktop.
Save jakepusateri/3be3f85f7dfa12a8e97a to your computer and use it in GitHub Desktop.
yui remover plugin
module.exports = function (babel) {
var t = babel.types;
var requires;
return new babel.Transformer('plugin-example', {
CallExpression: function (node, parent, scope, file) {
var isYUIMethod = node.callee.object &&
t.isIdentifier(node.callee.object, { name: 'YUI' });
var isAddCall = node.callee.property &&
t.isIdentifier(node.callee.property, { name: 'add' });
var isYUIAdd = isYUIMethod && isAddCall;
/** Import yui as _Y **/
file.addImport('yui', 'Y', true);
/** Add requires as imports **/
var requires = node.arguments[3].properties[0];
requires.value.elements.forEach(function (element, idx) {
file.addImport(element.value);
});
/** Return function body **/
if (isYUIAdd) {
return node.arguments[1].body;
}
},
AssignmentExpression: function (node, parent, scope, file) {
var isYAssignment = node.left.object.name === 'Y';
if (isYAssignment) {
console.log('Assign to Y namespace detected');
}
}
});
};
YUI.add('module-name', function (Y) {
Y.ModuleNameSpace = {
mutableY: true
};
}, 'versionString', {
requires: ['dependency1', 'dep2']
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment