index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*istanbul ignore next*/"use strict";
  2. exports.__esModule = true;
  3. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  4. var _getIterator3 = _interopRequireDefault(_getIterator2);
  5. var _symbol = require("babel-runtime/core-js/symbol");
  6. var _symbol2 = _interopRequireDefault(_symbol);
  7. exports.default = function ( /*istanbul ignore next*/_ref) {
  8. /*istanbul ignore next*/var t = _ref.types;
  9. function Property(path, node, scope, getObjectRef, file) {
  10. var replaceSupers = new /*istanbul ignore next*/_babelHelperReplaceSupers2.default({
  11. getObjectRef: getObjectRef,
  12. methodNode: node,
  13. methodPath: path,
  14. isStatic: true,
  15. scope: scope,
  16. file: file
  17. });
  18. replaceSupers.replace();
  19. }
  20. var CONTAINS_SUPER = /*istanbul ignore next*/(0, _symbol2.default)();
  21. return {
  22. visitor: { /*istanbul ignore next*/
  23. Super: function Super(path) {
  24. var parentObj = path.findParent(function (path) /*istanbul ignore next*/{
  25. return path.isObjectExpression();
  26. });
  27. if (parentObj) parentObj.node[CONTAINS_SUPER] = true;
  28. },
  29. ObjectExpression: { /*istanbul ignore next*/
  30. exit: function exit(path, file) {
  31. if (!path.node[CONTAINS_SUPER]) return;
  32. var objectRef = /*istanbul ignore next*/void 0;
  33. var getObjectRef = function getObjectRef() /*istanbul ignore next*/{
  34. return objectRef = objectRef || path.scope.generateUidIdentifier("obj");
  35. };
  36. var propPaths = path.get("properties");
  37. for ( /*istanbul ignore next*/var _iterator = propPaths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  38. /*istanbul ignore next*/
  39. var _ref2;
  40. if (_isArray) {
  41. if (_i >= _iterator.length) break;
  42. _ref2 = _iterator[_i++];
  43. } else {
  44. _i = _iterator.next();
  45. if (_i.done) break;
  46. _ref2 = _i.value;
  47. }
  48. var propPath = _ref2;
  49. if (propPath.isObjectProperty()) propPath = propPath.get("value");
  50. Property(propPath, propPath.node, path.scope, getObjectRef, file);
  51. }
  52. if (objectRef) {
  53. path.scope.push({ id: objectRef });
  54. path.replaceWith(t.assignmentExpression("=", objectRef, path.node));
  55. }
  56. }
  57. }
  58. }
  59. };
  60. };
  61. var /*istanbul ignore next*/_babelHelperReplaceSupers = require("babel-helper-replace-supers");
  62. /*istanbul ignore next*/
  63. var _babelHelperReplaceSupers2 = _interopRequireDefault(_babelHelperReplaceSupers);
  64. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  65. module.exports = exports["default"];