fix incorrect member expression properties

This commit is contained in:
Sebastian McKenzie
2015-01-02 16:39:35 +11:00
parent b34fcb0cd9
commit 6e8c73f65f
5 changed files with 14 additions and 12 deletions

View File

@@ -98,6 +98,10 @@ exports.MemberExpression = function (node, print) {
var obj = node.object;
print(obj);
if (!node.computed && t.isMemberExpression(node.property)) {
throw new TypeError("Got a MemberExpression for MemberExpression property");
}
if (node.computed) {
this.push("[");
print(node.property);

View File

@@ -276,7 +276,9 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
if (callee.object.name !== "super") return;
// super.test(); -> ClassName.prototype.MethodName.call(this);
callee.property = t.memberExpression(callee.property, t.identifier("call"));
callee.object = t.memberExpression(callee.object, callee.property, callee.computed);
callee.computed = false;
callee.property = t.identifier("call");
node.arguments.unshift(t.thisExpression());
}
}

View File

@@ -87,13 +87,9 @@ exports.CallExpression = function (node, parent, file, scope) {
callee.object = t.assignmentExpression("=", temp, callee.object);
}
if (callee.computed) {
callee.object = t.memberExpression(callee.object, callee.property, true);
callee.property = t.identifier("apply");
callee.computed = false;
} else {
callee.property = t.memberExpression(callee.property, t.identifier("apply"));
}
callee.object = t.memberExpression(callee.object, callee.property, callee.computed);
callee.computed = false;
callee.property = t.identifier("apply");
} else {
node.callee = t.memberExpression(node.callee, t.identifier("apply"));
}

View File

@@ -28,9 +28,9 @@ exports.ast = {
if (!t.isReferenced(obj, node)) return;
if (coreHas(obj) && _.has(core[obj.name], prop.name)) {
if (!node.computed && coreHas(obj) && _.has(core[obj.name], prop.name)) {
this.stop();
return t.memberExpression(file._coreId, node);
return t.memberExpression(t.memberExpression(file._coreId, node.object), node.property, node.computed);
}
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && coreHas(node)) {
// new Promise -> new _core.Promise

View File

@@ -24,8 +24,8 @@ var Test = (function () {
_Foo.call.apply(_Foo, [this].concat(_slice.call(arguments)));
_Foo.call.apply(_Foo, [this, "test"].concat(_slice.call(arguments)));
_Foo.prototype.test.call.apply(_Foo.prototype, [this].concat(_slice.call(arguments)));
_Foo.prototype.test.call.apply(_Foo.prototype, [this, "test"].concat(_slice.call(arguments)));
_Foo.prototype.test.call.apply(_Foo.prototype.test, [this].concat(_slice.call(arguments)));
_Foo.prototype.test.call.apply(_Foo.prototype.test, [this, "test"].concat(_slice.call(arguments)));
};
_inherits(Test, _Foo);