conversion.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.toComputedKey = toComputedKey;
  4. exports.ensureBlock = ensureBlock;
  5. exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
  6. var _babelTypes = require("babel-types");
  7. var t = _interopRequireWildcard(_babelTypes);
  8. 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; } }
  9. function toComputedKey() {
  10. var node = this.node;
  11. var key = void 0;
  12. if (this.isMemberExpression()) {
  13. key = node.property;
  14. } else if (this.isProperty() || this.isMethod()) {
  15. key = node.key;
  16. } else {
  17. throw new ReferenceError("todo");
  18. }
  19. if (!node.computed) {
  20. if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
  21. }
  22. return key;
  23. }
  24. function ensureBlock() {
  25. return t.ensureBlock(this.node);
  26. }
  27. function arrowFunctionToShadowed() {
  28. if (!this.isArrowFunctionExpression()) return;
  29. this.ensureBlock();
  30. var node = this.node;
  31. node.expression = false;
  32. node.type = "FunctionExpression";
  33. node.shadow = node.shadow || true;
  34. }