loose.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. exports.__esModule = true;
  3. var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");
  4. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  5. var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");
  6. var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
  7. var _inherits2 = require("babel-runtime/helpers/inherits");
  8. var _inherits3 = _interopRequireDefault(_inherits2);
  9. var _babelHelperFunctionName = require("babel-helper-function-name");
  10. var _babelHelperFunctionName2 = _interopRequireDefault(_babelHelperFunctionName);
  11. var _vanilla = require("./vanilla");
  12. var _vanilla2 = _interopRequireDefault(_vanilla);
  13. var _babelTypes = require("babel-types");
  14. var t = _interopRequireWildcard(_babelTypes);
  15. 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; } }
  16. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  17. var LooseClassTransformer = function (_VanillaTransformer) {
  18. (0, _inherits3.default)(LooseClassTransformer, _VanillaTransformer);
  19. function LooseClassTransformer() {
  20. (0, _classCallCheck3.default)(this, LooseClassTransformer);
  21. var _this = (0, _possibleConstructorReturn3.default)(this, _VanillaTransformer.apply(this, arguments));
  22. _this.isLoose = true;
  23. return _this;
  24. }
  25. LooseClassTransformer.prototype._processMethod = function _processMethod(node, scope) {
  26. if (!node.decorators) {
  27. var classRef = this.classRef;
  28. if (!node.static) classRef = t.memberExpression(classRef, t.identifier("prototype"));
  29. var methodName = t.memberExpression(classRef, node.key, node.computed || t.isLiteral(node.key));
  30. var func = t.functionExpression(null, node.params, node.body, node.generator, node.async);
  31. func.returnType = node.returnType;
  32. var key = t.toComputedKey(node, node.key);
  33. if (t.isStringLiteral(key)) {
  34. func = (0, _babelHelperFunctionName2.default)({
  35. node: func,
  36. id: key,
  37. scope: scope
  38. });
  39. }
  40. var expr = t.expressionStatement(t.assignmentExpression("=", methodName, func));
  41. t.inheritsComments(expr, node);
  42. this.body.push(expr);
  43. return true;
  44. }
  45. };
  46. return LooseClassTransformer;
  47. }(_vanilla2.default);
  48. exports.default = LooseClassTransformer;
  49. module.exports = exports["default"];