Last active
August 29, 2015 14:22
-
-
Save jakepusateri/3be3f85f7dfa12a8e97a to your computer and use it in GitHub Desktop.
yui remover plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
} | |
}); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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