Mario Romano 29df96a085 react app
2016-04-06 17:52:19 +01:00

50 lines
1.1 KiB
JavaScript

// This file contains methods that convert the path node into another node or some other type of data.
"use strict";
var _interopRequireWildcard = require("babel-runtime/helpers/interop-require-wildcard")["default"];
exports.__esModule = true;
exports.toComputedKey = toComputedKey;
exports.ensureBlock = ensureBlock;
exports.arrowFunctionToShadowed = arrowFunctionToShadowed;
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
function toComputedKey() {
var node = this.node;
var key = undefined;
if (this.isMemberExpression()) {
key = node.property;
} else if (this.isProperty() || this.isMethod()) {
key = node.key;
} else {
throw new ReferenceError("todo");
}
if (!node.computed) {
if (t.isIdentifier(key)) key = t.stringLiteral(key.name);
}
return key;
}
function ensureBlock() {
return t.ensureBlock(this.node);
}
function arrowFunctionToShadowed() {
// todo: maybe error
if (!this.isArrowFunctionExpression()) return;
this.ensureBlock();
var node = this.node;
node.expression = false;
node.type = "FunctionExpression";
node.shadow = node.shadow || true;
}