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. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  10.  
  11. var _getIterator3 = _interopRequireDefault(_getIterator2);
  12.  
  13. exports.default = function (_ref) {
  14.   var t = _ref.types;
  15.  
  16.   function cleanDecorators(decorators) {
  17.     return decorators.reverse().map(function (dec) {
  18.       return dec.expression;
  19.     });
  20.   }
  21.  
  22.   function transformClass(path, ref, state) {
  23.     var nodes = [];
  24.  
  25.     state;
  26.  
  27.     var classDecorators = path.node.decorators;
  28.     if (classDecorators) {
  29.       path.node.decorators = null;
  30.       classDecorators = cleanDecorators(classDecorators);
  31.  
  32.       for (var _iterator = classDecorators, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  33.         var _ref2;
  34.  
  35.         if (_isArray) {
  36.           if (_i >= _iterator.length) break;
  37.           _ref2 = _iterator[_i++];
  38.         } else {
  39.           _i = _iterator.next();
  40.           if (_i.done) break;
  41.           _ref2 = _i.value;
  42.         }
  43.  
  44.         var decorator = _ref2;
  45.  
  46.         nodes.push(buildClassDecorator({
  47.           CLASS_REF: ref,
  48.           DECORATOR: decorator
  49.         }));
  50.       }
  51.     }
  52.  
  53.     var map = (0, _create2.default)(null);
  54.  
  55.     for (var _iterator2 = path.get("body.body"), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
  56.       var _ref3;
  57.  
  58.       if (_isArray2) {
  59.         if (_i2 >= _iterator2.length) break;
  60.         _ref3 = _iterator2[_i2++];
  61.       } else {
  62.         _i2 = _iterator2.next();
  63.         if (_i2.done) break;
  64.         _ref3 = _i2.value;
  65.       }
  66.  
  67.       var method = _ref3;
  68.  
  69.       var decorators = method.node.decorators;
  70.       if (!decorators) continue;
  71.  
  72.       var _alias = t.toKeyAlias(method.node);
  73.       map[_alias] = map[_alias] || [];
  74.       map[_alias].push(method.node);
  75.  
  76.       method.remove();
  77.     }
  78.  
  79.     for (var alias in map) {
  80.       var items = map[alias];
  81.  
  82.       items;
  83.     }
  84.  
  85.     return nodes;
  86.   }
  87.  
  88.   function hasDecorators(path) {
  89.     if (path.isClass()) {
  90.       if (path.node.decorators) return true;
  91.  
  92.       for (var _iterator3 = path.node.body.body, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
  93.         var _ref4;
  94.  
  95.         if (_isArray3) {
  96.           if (_i3 >= _iterator3.length) break;
  97.           _ref4 = _iterator3[_i3++];
  98.         } else {
  99.           _i3 = _iterator3.next();
  100.           if (_i3.done) break;
  101.           _ref4 = _i3.value;
  102.         }
  103.  
  104.         var method = _ref4;
  105.  
  106.         if (method.decorators) {
  107.           return true;
  108.         }
  109.       }
  110.     } else if (path.isObjectExpression()) {
  111.       for (var _iterator4 = path.node.properties, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
  112.         var _ref5;
  113.  
  114.         if (_isArray4) {
  115.           if (_i4 >= _iterator4.length) break;
  116.           _ref5 = _iterator4[_i4++];
  117.         } else {
  118.           _i4 = _iterator4.next();
  119.           if (_i4.done) break;
  120.           _ref5 = _i4.value;
  121.         }
  122.  
  123.         var prop = _ref5;
  124.  
  125.         if (prop.decorators) {
  126.           return true;
  127.         }
  128.       }
  129.     }
  130.  
  131.     return false;
  132.   }
  133.  
  134.   function doError(path) {
  135.     throw path.buildCodeFrameError("Decorators are not officially supported yet in 6.x pending a proposal update.\nHowever, if you need to use them you can install the legacy decorators transform with:\n\nnpm install babel-plugin-transform-decorators-legacy --save-dev\n\nand add the following line to your .babelrc file:\n\n{\n  \"plugins\": [\"transform-decorators-legacy\"]\n}\n\nThe repo url is: https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy.\n    ");
  136.   }
  137.  
  138.   return {
  139.     inherits: require("babel-plugin-syntax-decorators"),
  140.  
  141.     visitor: {
  142.       ClassExpression: function ClassExpression(path) {
  143.         if (!hasDecorators(path)) return;
  144.         doError(path);
  145.  
  146.         (0, _babelHelperExplodeClass2.default)(path);
  147.  
  148.         var ref = path.scope.generateDeclaredUidIdentifier("ref");
  149.         var nodes = [];
  150.  
  151.         nodes.push(t.assignmentExpression("=", ref, path.node));
  152.  
  153.         nodes = nodes.concat(transformClass(path, ref, this));
  154.  
  155.         nodes.push(ref);
  156.  
  157.         path.replaceWith(t.sequenceExpression(nodes));
  158.       },
  159.       ClassDeclaration: function ClassDeclaration(path) {
  160.         if (!hasDecorators(path)) return;
  161.         doError(path);
  162.         (0, _babelHelperExplodeClass2.default)(path);
  163.  
  164.         var ref = path.node.id;
  165.         var nodes = [];
  166.  
  167.         nodes = nodes.concat(transformClass(path, ref, this).map(function (expr) {
  168.           return t.expressionStatement(expr);
  169.         }));
  170.         nodes.push(t.expressionStatement(ref));
  171.  
  172.         path.insertAfter(nodes);
  173.       },
  174.       ObjectExpression: function ObjectExpression(path) {
  175.         if (!hasDecorators(path)) return;
  176.         doError(path);
  177.       }
  178.     }
  179.   };
  180. };
  181.  
  182. var _babelTemplate = require("babel-template");
  183.  
  184. var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
  185.  
  186. var _babelHelperExplodeClass = require("babel-helper-explode-class");
  187.  
  188. var _babelHelperExplodeClass2 = _interopRequireDefault(_babelHelperExplodeClass);
  189.  
  190. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  191.  
  192. var buildClassDecorator = (0, _babelTemplate2.default)("\n  CLASS_REF = DECORATOR(CLASS_REF) || CLASS_REF;\n");
  193.  
  194. 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