Skip to content

Instantly share code, notes, and snippets.

@jakepusateri
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save jakepusateri/3be3f85f7dfa12a8e97a to your computer and use it in GitHub Desktop.

Select an option

Save jakepusateri/3be3f85f7dfa12a8e97a to your computer and use it in GitHub Desktop.

Revisions

  1. jakepusateri revised this gist Jun 4, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion transformer
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,6 @@ module.exports = function (babel) {

    /** Return function body **/
    if (isYUIAdd) {
    console.log(node.arguments[1].body.body[0].expression);
    return node.arguments[1].body;
    }
    },
  2. jakepusateri created this gist Jun 4, 2015.
    37 changes: 37 additions & 0 deletions transformer
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    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) {
    console.log(node.arguments[1].body.body[0].expression);
    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');
    }
    }
    });
    };


    7 changes: 7 additions & 0 deletions yui-input
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    YUI.add('module-name', function (Y) {
    Y.ModuleNameSpace = {
    mutableY: true
    };
    }, 'versionString', {
    requires: ['dependency1', 'dep2']
    });