motion
Version:
motion - moving development forward
34 lines (30 loc) • 1.2 kB
JavaScript
exports.__esModule = true;
exports['default'] = MotionApp;
// wraps your app in closure / export
function MotionApp(_ref) {
var name = _ref.name;
return function MotionAppPlugin(_ref2) {
var Plugin = _ref2.Plugin;
var t = _ref2.types;
return new Plugin("motion-transform-app", {
visitor: {
Program: {
exit: function exit(node) {
// wrap program in commonjs + iife
node.body = [t.expressionStatement(
// exports["name"] = function(){}
t.assignmentExpression('=', t.identifier('exports["' + name + '"]'),
//wrapFnName
t.functionExpression(null, [t.identifier('Motion'), t.identifier('opts')], t.blockStatement([
// closure (function(Motion) {})(Motion)
t.callExpression(t.functionExpression(null, [t.identifier('Motion')], t.blockStatement([].concat(node.body, t.expressionStatement(t.callExpression(t.identifier('Motion.start'), [])))) // end blockStatement
), // end functionExpression
[t.identifier('Motion')]) // end callExpression
]))))];
}
}
}
});
};
}
module.exports = exports['default'];