Revert "remove es7.abstractReferences, playground.methodBinding and playground.objectGetterMemoisation"
This reverts commit f4ce216d1c.
This commit is contained in:
111
src/babel/transformation/transformers/es7/abstract-references.js
Normal file
111
src/babel/transformation/transformers/es7/abstract-references.js
Normal file
@@ -0,0 +1,111 @@
|
||||
// https://github.com/zenparsing/es-abstract-refs
|
||||
|
||||
import * as util from "../../../util";
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var experimental = true;
|
||||
|
||||
var container = function (parent, call, ret, file) {
|
||||
if (t.isExpressionStatement(parent) && !file.isConsequenceExpressionStatement(parent)) {
|
||||
// we don't need to worry about return values
|
||||
return call;
|
||||
} else {
|
||||
var exprs = [];
|
||||
if (t.isSequenceExpression(call)) {
|
||||
exprs = call.expressions;
|
||||
} else {
|
||||
exprs.push(call);
|
||||
}
|
||||
exprs.push(ret);
|
||||
return t.sequenceExpression(exprs);
|
||||
}
|
||||
};
|
||||
|
||||
export function AssignmentExpression(node, parent, scope, file) {
|
||||
var left = node.left;
|
||||
if (!t.isVirtualPropertyExpression(left)) return;
|
||||
|
||||
var value = node.right;
|
||||
var temp;
|
||||
|
||||
// we need to return `node.right`
|
||||
if (!t.isExpressionStatement(parent)) {
|
||||
temp = scope.generateTempBasedOnNode(node.right);
|
||||
if (temp) value = temp;
|
||||
}
|
||||
|
||||
if (node.operator !== "=") {
|
||||
value = t.binaryExpression(
|
||||
node.operator[0],
|
||||
util.template("abstract-expression-get", {
|
||||
PROPERTY: node.property,
|
||||
OBJECT: node.object
|
||||
}),
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
var call = util.template("abstract-expression-set", {
|
||||
PROPERTY: left.property,
|
||||
OBJECT: left.object,
|
||||
VALUE: value
|
||||
});
|
||||
|
||||
if (temp) {
|
||||
call = t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, node.right),
|
||||
call
|
||||
]);
|
||||
}
|
||||
|
||||
return container(parent, call, value, file);
|
||||
}
|
||||
|
||||
export function UnaryExpression(node, parent, scope, file) {
|
||||
var arg = node.argument;
|
||||
if (!t.isVirtualPropertyExpression(arg)) return;
|
||||
if (node.operator !== "delete") return;
|
||||
|
||||
var call = util.template("abstract-expression-delete", {
|
||||
PROPERTY: arg.property,
|
||||
OBJECT: arg.object
|
||||
});
|
||||
|
||||
return container(parent, call, t.literal(true), file);
|
||||
}
|
||||
|
||||
export function CallExpression(node, parent, scope) {
|
||||
var callee = node.callee;
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
var temp = scope.generateTempBasedOnNode(callee.object);
|
||||
|
||||
var call = util.template("abstract-expression-call", {
|
||||
PROPERTY: callee.property,
|
||||
OBJECT: temp || callee.object
|
||||
});
|
||||
|
||||
call.arguments = call.arguments.concat(node.arguments);
|
||||
|
||||
if (temp) {
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, callee.object),
|
||||
call
|
||||
]);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
}
|
||||
|
||||
export function VirtualPropertyExpression(node) {
|
||||
return util.template("abstract-expression-get", {
|
||||
PROPERTY: node.property,
|
||||
OBJECT: node.object
|
||||
});
|
||||
}
|
||||
|
||||
export function PrivateDeclaration(node) {
|
||||
return t.variableDeclaration("const", node.declarations.map(function (id) {
|
||||
return t.variableDeclarator(id, t.newExpression(t.identifier("WeakMap"), []));
|
||||
}));
|
||||
}
|
||||
@@ -15,7 +15,9 @@ export default {
|
||||
"es6.arrowFunctions": require("./es6/arrow-functions"),
|
||||
|
||||
"playground.malletOperator": require("./playground/mallet-operator"),
|
||||
"playground.methodBinding": require("./playground/method-binding"),
|
||||
"playground.memoizationOperator": require("./playground/memoization-operator"),
|
||||
"playground.objectGetterMemoization": require("./playground/object-getter-memoization"),
|
||||
|
||||
reactCompat: require("./other/react-compat"),
|
||||
react: require("./other/react"),
|
||||
@@ -47,6 +49,7 @@ export default {
|
||||
|
||||
"es6.regex.sticky": require("./es6/regex.sticky"),
|
||||
"es6.regex.unicode": require("./es6/regex.unicode"),
|
||||
"es7.abstractReferences": require("./es7/abstract-references"),
|
||||
|
||||
"es6.constants": require("./es6/constants"),
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var playground = true;
|
||||
|
||||
export function BindMemberExpression(node, parent, scope) {
|
||||
var object = node.object;
|
||||
var prop = node.property;
|
||||
|
||||
var temp = scope.generateTempBasedOnNode(node.object);
|
||||
if (temp) object = temp;
|
||||
|
||||
var call = t.callExpression(
|
||||
t.memberExpression(t.memberExpression(object, prop), t.identifier("bind")),
|
||||
[object, ...node.arguments]
|
||||
);
|
||||
|
||||
if (temp) {
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, node.object),
|
||||
call
|
||||
]);
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
}
|
||||
|
||||
export function BindFunctionExpression(node, parent, scope) {
|
||||
var buildCall = function (args) {
|
||||
var param = scope.generateUidIdentifier("val");
|
||||
return t.functionExpression(null, [param], t.blockStatement([
|
||||
t.returnStatement(t.callExpression(t.memberExpression(param, node.callee), args))
|
||||
]));
|
||||
};
|
||||
|
||||
var temp = scope.generateTemp("args");
|
||||
|
||||
return t.sequenceExpression([
|
||||
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
|
||||
buildCall(node.arguments.map(function (node, i) {
|
||||
return t.memberExpression(temp, t.literal(i), true);
|
||||
}))
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var playground = true;
|
||||
|
||||
var visitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isFunction()) return this.skip();
|
||||
|
||||
if (this.isReturnStatement() && node.argument) {
|
||||
node.argument = t.memberExpression(t.callExpression(state.file.addHelper("define-property"), [
|
||||
t.thisExpression(),
|
||||
state.key,
|
||||
node.argument
|
||||
]), state.key, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export function MethodDefinition(node, parent, scope, file) {
|
||||
if (node.kind !== "memo") return;
|
||||
node.kind = "get";
|
||||
|
||||
console.error("Object getter memoization is deprecated and will be removed in 5.0.0");
|
||||
|
||||
t.ensureBlock(node.value);
|
||||
|
||||
var key = node.key;
|
||||
|
||||
if (t.isIdentifier(key) && !node.computed) {
|
||||
key = t.literal(key.name);
|
||||
}
|
||||
|
||||
var state = {
|
||||
key: key,
|
||||
file: file
|
||||
};
|
||||
|
||||
this.get("value").traverse(visitor, state);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
export { MethodDefinition as Property };
|
||||
Reference in New Issue
Block a user