add support for call expression abstract references and more versatile tests
This commit is contained in:
1
lib/6to5/templates/abstract-expression-call.js
Normal file
1
lib/6to5/templates/abstract-expression-call.js
Normal file
@@ -0,0 +1 @@
|
||||
PROPERTY[Symbol.referenceGet](OBJECT).call(OBJECT)
|
||||
@@ -3,30 +3,53 @@
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
var container = function (parent, call, ret) {
|
||||
if (t.isExpressionStatement(parent)) {
|
||||
// we don't need to worry about return values
|
||||
return call;
|
||||
} else {
|
||||
return t.sequenceExpression([call, ret]);
|
||||
}
|
||||
};
|
||||
|
||||
exports.AssignmentExpression = function (node, parent) {
|
||||
var left = node.left;
|
||||
if (!t.isVirtualPropertyExpression(left)) return;
|
||||
|
||||
return util.template("abstract-expression-set", {
|
||||
var right = node.right;
|
||||
|
||||
var call = util.template("abstract-expression-set", {
|
||||
PROPERTY: left.property,
|
||||
OBJECT: left.object,
|
||||
VALUE: node.right
|
||||
VALUE: right
|
||||
});
|
||||
|
||||
return container(parent, call, right);
|
||||
};
|
||||
|
||||
exports.UnaryExpression = function (node, parent) {
|
||||
if (!t.isVirtualPropertyExpression(node.argument)) return;
|
||||
var arg = node.argument;
|
||||
if (!t.isVirtualPropertyExpression(arg)) return;
|
||||
if (node.operator !== "delete") return;
|
||||
|
||||
return util.template("abstract-expression-delete", {
|
||||
PROPERTY: node.property,
|
||||
OBJECT: node.object
|
||||
var call = util.template("abstract-expression-delete", {
|
||||
PROPERTY: arg.property,
|
||||
OBJECT: arg.object
|
||||
});
|
||||
|
||||
return container(parent, call, t.literal(true));
|
||||
};
|
||||
|
||||
exports.CallExpression = function (node, parent) {
|
||||
var callee = node.callee;
|
||||
if (!t.isVirtualPropertyExpression(callee)) return;
|
||||
|
||||
var call = util.template("abstract-expression-call", {
|
||||
PROPERTY: callee.property,
|
||||
OBJECT: callee.object
|
||||
});
|
||||
call.arguments = call.arguments.concat(node.arguments);
|
||||
return call;
|
||||
};
|
||||
|
||||
exports.VirtualPropertyExpression = function (node) {
|
||||
|
||||
2
test/fixtures/transformation/es7-abstract-references/call/actual.js
vendored
Normal file
2
test/fixtures/transformation/es7-abstract-references/call/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
foo::bar();
|
||||
foo::bar("arg");
|
||||
4
test/fixtures/transformation/es7-abstract-references/call/expected.js
vendored
Normal file
4
test/fixtures/transformation/es7-abstract-references/call/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
bar[Symbol.referenceGet](foo).call(foo);
|
||||
bar[Symbol.referenceGet](foo).call(foo, "arg");
|
||||
@@ -1 +1,3 @@
|
||||
delete foo::bar;
|
||||
|
||||
if (delete foo::bar);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
bar[Symbol.referenceDelete](foo);
|
||||
|
||||
if ((bar[Symbol.referenceDelete](foo), true)) ;
|
||||
|
||||
3
test/fixtures/transformation/es7-abstract-references/options.json
vendored
Normal file
3
test/fixtures/transformation/es7-abstract-references/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"experimental": true
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
foo::bar = baz;
|
||||
if (foo::bar = baz);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
bar[Symbol.referenceSet](foo, baz);
|
||||
if ((bar[Symbol.referenceSet](foo, baz), baz)) ;
|
||||
|
||||
Reference in New Issue
Block a user