BVB Source Codes

reactide Show index.js Source code

Return Download reactide: download index.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4.  
  5. var _create = require("babel-runtime/core-js/object/create");
  6.  
  7. var _create2 = _interopRequireDefault(_create);
  8.  
  9. exports.default = function (_ref) {
  10.   var t = _ref.types;
  11.  
  12.   function isValidRequireCall(path) {
  13.     if (!path.isCallExpression()) return false;
  14.     if (!path.get("callee").isIdentifier({ name: "require" })) return false;
  15.     if (path.scope.getBinding("require")) return false;
  16.  
  17.     var args = path.get("arguments");
  18.     if (args.length !== 1) return false;
  19.  
  20.     var arg = args[0];
  21.     if (!arg.isStringLiteral()) return false;
  22.  
  23.     return true;
  24.   }
  25.  
  26.   var amdVisitor = {
  27.     ReferencedIdentifier: function ReferencedIdentifier(_ref2) {
  28.       var node = _ref2.node,
  29.           scope = _ref2.scope;
  30.  
  31.       if (node.name === "exports" && !scope.getBinding("exports")) {
  32.         this.hasExports = true;
  33.       }
  34.  
  35.       if (node.name === "module" && !scope.getBinding("module")) {
  36.         this.hasModule = true;
  37.       }
  38.     },
  39.     CallExpression: function CallExpression(path) {
  40.       if (!isValidRequireCall(path)) return;
  41.       this.bareSources.push(path.node.arguments[0]);
  42.       path.remove();
  43.     },
  44.     VariableDeclarator: function VariableDeclarator(path) {
  45.       var id = path.get("id");
  46.       if (!id.isIdentifier()) return;
  47.  
  48.       var init = path.get("init");
  49.       if (!isValidRequireCall(init)) return;
  50.  
  51.       var source = init.node.arguments[0];
  52.       this.sourceNames[source.value] = true;
  53.       this.sources.push([id.node, source]);
  54.  
  55.       path.remove();
  56.     }
  57.   };
  58.  
  59.   return {
  60.     inherits: require("babel-plugin-transform-es2015-modules-commonjs"),
  61.  
  62.     pre: function pre() {
  63.       this.sources = [];
  64.       this.sourceNames = (0, _create2.default)(null);
  65.  
  66.       this.bareSources = [];
  67.  
  68.       this.hasExports = false;
  69.       this.hasModule = false;
  70.     },
  71.  
  72.  
  73.     visitor: {
  74.       Program: {
  75.         exit: function exit(path) {
  76.           var _this = this;
  77.  
  78.           if (this.ran) return;
  79.           this.ran = true;
  80.  
  81.           path.traverse(amdVisitor, this);
  82.  
  83.           var params = this.sources.map(function (source) {
  84.             return source[0];
  85.           });
  86.           var sources = this.sources.map(function (source) {
  87.             return source[1];
  88.           });
  89.  
  90.           sources = sources.concat(this.bareSources.filter(function (str) {
  91.             return !_this.sourceNames[str.value];
  92.           }));
  93.  
  94.           var moduleName = this.getModuleName();
  95.           if (moduleName) moduleName = t.stringLiteral(moduleName);
  96.  
  97.           if (this.hasExports) {
  98.             sources.unshift(t.stringLiteral("exports"));
  99.             params.unshift(t.identifier("exports"));
  100.           }
  101.  
  102.           if (this.hasModule) {
  103.             sources.unshift(t.stringLiteral("module"));
  104.             params.unshift(t.identifier("module"));
  105.           }
  106.  
  107.           var node = path.node;
  108.  
  109.           var factory = buildFactory({
  110.             PARAMS: params,
  111.             BODY: node.body
  112.           });
  113.           factory.expression.body.directives = node.directives;
  114.           node.directives = [];
  115.  
  116.           node.body = [buildDefine({
  117.             MODULE_NAME: moduleName,
  118.             SOURCES: sources,
  119.             FACTORY: factory
  120.           })];
  121.         }
  122.       }
  123.     }
  124.   };
  125. };
  126.  
  127. var _babelTemplate = require("babel-template");
  128.  
  129. var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
  130.  
  131. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  132.  
  133. var buildDefine = (0, _babelTemplate2.default)("\n  define(MODULE_NAME, [SOURCES], FACTORY);\n");
  134.  
  135. var buildFactory = (0, _babelTemplate2.default)("\n  (function (PARAMS) {\n    BODY;\n  })\n");
  136.  
  137. module.exports = exports["default"];
downloadindex.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top