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. exports.default = function (_ref) {
  6.   var t = _ref.types;
  7.  
  8.   function isValidDefine(path) {
  9.     if (!path.isExpressionStatement()) return;
  10.  
  11.     var expr = path.get("expression");
  12.     if (!expr.isCallExpression()) return false;
  13.     if (!expr.get("callee").isIdentifier({ name: "define" })) return false;
  14.  
  15.     var args = expr.get("arguments");
  16.     if (args.length === 3 && !args.shift().isStringLiteral()) return false;
  17.     if (args.length !== 2) return false;
  18.     if (!args.shift().isArrayExpression()) return false;
  19.     if (!args.shift().isFunctionExpression()) return false;
  20.  
  21.     return true;
  22.   }
  23.  
  24.   return {
  25.     inherits: require("babel-plugin-transform-es2015-modules-amd"),
  26.  
  27.     visitor: {
  28.       Program: {
  29.         exit: function exit(path, state) {
  30.           var last = path.get("body").pop();
  31.           if (!isValidDefine(last)) return;
  32.  
  33.           var call = last.node.expression;
  34.           var args = call.arguments;
  35.  
  36.           var moduleName = args.length === 3 ? args.shift() : null;
  37.           var amdArgs = call.arguments[0];
  38.           var func = call.arguments[1];
  39.           var browserGlobals = state.opts.globals || {};
  40.  
  41.           var commonArgs = amdArgs.elements.map(function (arg) {
  42.             if (arg.value === "module" || arg.value === "exports") {
  43.               return t.identifier(arg.value);
  44.             } else {
  45.               return t.callExpression(t.identifier("require"), [arg]);
  46.             }
  47.           });
  48.  
  49.           var browserArgs = amdArgs.elements.map(function (arg) {
  50.             if (arg.value === "module") {
  51.               return t.identifier("mod");
  52.             } else if (arg.value === "exports") {
  53.               return t.memberExpression(t.identifier("mod"), t.identifier("exports"));
  54.             } else {
  55.               var memberExpression = void 0;
  56.  
  57.               if (state.opts.exactGlobals) {
  58.                 var globalRef = browserGlobals[arg.value];
  59.                 if (globalRef) {
  60.                   memberExpression = globalRef.split(".").reduce(function (accum, curr) {
  61.                     return t.memberExpression(accum, t.identifier(curr));
  62.                   }, t.identifier("global"));
  63.                 } else {
  64.                   memberExpression = t.memberExpression(t.identifier("global"), t.identifier(t.toIdentifier(arg.value)));
  65.                 }
  66.               } else {
  67.                 var requireName = (0, _path.basename)(arg.value, (0, _path.extname)(arg.value));
  68.                 var globalName = browserGlobals[requireName] || requireName;
  69.                 memberExpression = t.memberExpression(t.identifier("global"), t.identifier(t.toIdentifier(globalName)));
  70.               }
  71.  
  72.               return memberExpression;
  73.             }
  74.           });
  75.  
  76.           var moduleNameOrBasename = moduleName ? moduleName.value : this.file.opts.basename;
  77.           var globalToAssign = t.memberExpression(t.identifier("global"), t.identifier(t.toIdentifier(moduleNameOrBasename)));
  78.           var prerequisiteAssignments = null;
  79.  
  80.           if (state.opts.exactGlobals) {
  81.             var globalName = browserGlobals[moduleNameOrBasename];
  82.  
  83.             if (globalName) {
  84.               prerequisiteAssignments = [];
  85.  
  86.               var members = globalName.split(".");
  87.               globalToAssign = members.slice(1).reduce(function (accum, curr) {
  88.                 prerequisiteAssignments.push(buildPrerequisiteAssignment({ GLOBAL_REFERENCE: accum }));
  89.                 return t.memberExpression(accum, t.identifier(curr));
  90.               }, t.memberExpression(t.identifier("global"), t.identifier(members[0])));
  91.             }
  92.           }
  93.  
  94.           var globalExport = buildGlobalExport({
  95.             BROWSER_ARGUMENTS: browserArgs,
  96.             PREREQUISITE_ASSIGNMENTS: prerequisiteAssignments,
  97.             GLOBAL_TO_ASSIGN: globalToAssign
  98.           });
  99.  
  100.           last.replaceWith(buildWrapper({
  101.             MODULE_NAME: moduleName,
  102.             AMD_ARGUMENTS: amdArgs,
  103.             COMMON_ARGUMENTS: commonArgs,
  104.             GLOBAL_EXPORT: globalExport,
  105.             FUNC: func
  106.           }));
  107.         }
  108.       }
  109.     }
  110.   };
  111. };
  112.  
  113. var _path = require("path");
  114.  
  115. var _babelTemplate = require("babel-template");
  116.  
  117. var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
  118.  
  119. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  120.  
  121. var buildPrerequisiteAssignment = (0, _babelTemplate2.default)("\n  GLOBAL_REFERENCE = GLOBAL_REFERENCE || {}\n");
  122.  
  123. var buildGlobalExport = (0, _babelTemplate2.default)("\n  var mod = { exports: {} };\n  factory(BROWSER_ARGUMENTS);\n  PREREQUISITE_ASSIGNMENTS\n  GLOBAL_TO_ASSIGN = mod.exports;\n");
  124.  
  125. var buildWrapper = (0, _babelTemplate2.default)("\n  (function (global, factory) {\n    if (typeof define === \"function\" && define.amd) {\n      define(MODULE_NAME, AMD_ARGUMENTS, factory);\n    } else if (typeof exports !== \"undefined\") {\n      factory(COMMON_ARGUMENTS);\n    } else {\n      GLOBAL_EXPORT\n    }\n  })(this, FUNC);\n");
  126.  
  127. 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