BVB Source Codes

reactide Show build-external-helpers.js Source code

Return Download reactide: download build-external-helpers.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4.  
  5. exports.default = function (whitelist) {
  6.   var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "global";
  7.  
  8.   var namespace = t.identifier("babelHelpers");
  9.  
  10.   var builder = function builder(body) {
  11.     return buildHelpers(body, namespace, whitelist);
  12.   };
  13.  
  14.   var tree = void 0;
  15.  
  16.   var build = {
  17.     global: buildGlobal,
  18.     umd: buildUmd,
  19.     var: buildVar
  20.   }[outputType];
  21.  
  22.   if (build) {
  23.     tree = build(namespace, builder);
  24.   } else {
  25.     throw new Error(messages.get("unsupportedOutputType", outputType));
  26.   }
  27.  
  28.   return (0, _babelGenerator2.default)(tree).code;
  29. };
  30.  
  31. var _babelHelpers = require("babel-helpers");
  32.  
  33. var helpers = _interopRequireWildcard(_babelHelpers);
  34.  
  35. var _babelGenerator = require("babel-generator");
  36.  
  37. var _babelGenerator2 = _interopRequireDefault(_babelGenerator);
  38.  
  39. var _babelMessages = require("babel-messages");
  40.  
  41. var messages = _interopRequireWildcard(_babelMessages);
  42.  
  43. var _babelTemplate = require("babel-template");
  44.  
  45. var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
  46.  
  47. var _babelTypes = require("babel-types");
  48.  
  49. var t = _interopRequireWildcard(_babelTypes);
  50.  
  51. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  52.  
  53. 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; } }
  54.  
  55. var buildUmdWrapper = (0, _babelTemplate2.default)("\n  (function (root, factory) {\n    if (typeof define === \"function\" && define.amd) {\n      define(AMD_ARGUMENTS, factory);\n    } else if (typeof exports === \"object\") {\n      factory(COMMON_ARGUMENTS);\n    } else {\n      factory(BROWSER_ARGUMENTS);\n    }\n  })(UMD_ROOT, function (FACTORY_PARAMETERS) {\n    FACTORY_BODY\n  });\n");
  56.  
  57. function buildGlobal(namespace, builder) {
  58.   var body = [];
  59.   var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
  60.   var tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
  61.  
  62.   body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([])))]));
  63.  
  64.   builder(body);
  65.  
  66.   return tree;
  67. }
  68.  
  69. function buildUmd(namespace, builder) {
  70.   var body = [];
  71.   body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.identifier("global"))]));
  72.  
  73.   builder(body);
  74.  
  75.   return t.program([buildUmdWrapper({
  76.     FACTORY_PARAMETERS: t.identifier("global"),
  77.     BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression([])),
  78.     COMMON_ARGUMENTS: t.identifier("exports"),
  79.     AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]),
  80.     FACTORY_BODY: body,
  81.     UMD_ROOT: t.identifier("this")
  82.   })]);
  83. }
  84.  
  85. function buildVar(namespace, builder) {
  86.   var body = [];
  87.   body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.objectExpression([]))]));
  88.   builder(body);
  89.   body.push(t.expressionStatement(namespace));
  90.   return t.program(body);
  91. }
  92.  
  93. function buildHelpers(body, namespace, whitelist) {
  94.   helpers.list.forEach(function (name) {
  95.     if (whitelist && whitelist.indexOf(name) < 0) return;
  96.  
  97.     var key = t.identifier(name);
  98.     body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))));
  99.   });
  100. }
  101. module.exports = exports["default"];
downloadbuild-external-helpers.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