UNPKG

babel-plugin-yui

Version:
101 lines (84 loc) 3.25 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function () { var requires = []; var inProgess = false; function clean() { inProgess = false; requires = []; }; return { // This plugin add easy access to the class properties inherits: require("babel-plugin-syntax-class-properties"), visitor: { FunctionDeclaration: function FunctionDeclaration(path) { if (inProgess) { return; } inProgess = true; var node = path.node; // This is a controller. if (node.id.name === 'render') { path.parentPath.replaceWith((0, _engine.use)(node.body.body, requires)); } inProgess = false; }, Program: { enter: function enter(path) { var addY = true; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = path.get('body')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var _path = _step.value; // Finds all the imports if (_path.isImportDeclaration()) { var module = _path.node.source.value; if (_path.node.specifiers.length == 0 || module.indexOf('/') >= 0) { requires.push(types.stringLiteral(_path3.default.basename(module, '.js'))); } // modules.push(t.stringLiteral(path.node.specifiers[0].local.name)); if (_path.node.specifiers.length <= 0) { _path.remove(); } } else if (_path.isExportDefaultDeclaration() || _path.isExportDeclaration()) { if (_path.node.declaration.type === 'FunctionDeclaration' && _path.node.declaration.id.name === 'render') { addY = false; } } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } if (addY) { path.unshiftContainer("body", (0, _engine.add)(this.file.opts.basename, requires)); } }, exit: function exit(path) { clean(); } } } }; }; var _babelTypes = require('babel-types'); var types = _interopRequireWildcard(_babelTypes); var _engine = require('./templates/engine'); var _path2 = require('path'); var _path3 = _interopRequireDefault(_path2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }