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 ? "global" : arguments[1];
  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 _each = require("lodash/each");
  48.  
  49. var _each2 = _interopRequireDefault(_each);
  50.  
  51. var _babelTypes = require("babel-types");
  52.  
  53. var t = _interopRequireWildcard(_babelTypes);
  54.  
  55. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  56.  
  57. 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; } }
  58.  
  59. /* eslint max-len: 0 */
  60.  
  61. 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");
  62.  
  63. function buildGlobal(namespace, builder) {
  64.   var body = [];
  65.   var container = t.functionExpression(null, [t.identifier("global")], t.blockStatement(body));
  66.   var tree = t.program([t.expressionStatement(t.callExpression(container, [helpers.get("selfGlobal")]))]);
  67.  
  68.   body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.assignmentExpression("=", t.memberExpression(t.identifier("global"), namespace), t.objectExpression([])))]));
  69.  
  70.   builder(body);
  71.  
  72.   return tree;
  73. }
  74.  
  75. function buildUmd(namespace, builder) {
  76.   var body = [];
  77.   body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.identifier("global"))]));
  78.  
  79.   builder(body);
  80.  
  81.   return t.program([buildUmdWrapper({
  82.     FACTORY_PARAMETERS: t.identifier("global"),
  83.     BROWSER_ARGUMENTS: t.assignmentExpression("=", t.memberExpression(t.identifier("root"), namespace), t.objectExpression([])),
  84.     COMMON_ARGUMENTS: t.identifier("exports"),
  85.     AMD_ARGUMENTS: t.arrayExpression([t.stringLiteral("exports")]),
  86.     FACTORY_BODY: body,
  87.     UMD_ROOT: t.identifier("this")
  88.   })]);
  89. }
  90.  
  91. function buildVar(namespace, builder) {
  92.   var body = [];
  93.   body.push(t.variableDeclaration("var", [t.variableDeclarator(namespace, t.objectExpression([]))]));
  94.   builder(body);
  95.   body.push(t.expressionStatement(namespace));
  96.   return t.program(body);
  97. }
  98.  
  99. function buildHelpers(body, namespace, whitelist) {
  100.   (0, _each2.default)(helpers.list, function (name) {
  101.     if (whitelist && whitelist.indexOf(name) < 0) return;
  102.  
  103.     var key = t.identifier(name);
  104.     body.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(namespace, key), helpers.get(name))));
  105.   });
  106. }
  107. 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