From 6e8c73f65fa375f097755a6b7300acce584f9266 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 2 Jan 2015 16:39:35 +1100 Subject: [PATCH] fix incorrect member expression properties --- lib/6to5/generation/generators/expressions.js | 4 ++++ lib/6to5/transformation/transformers/es6-classes.js | 4 +++- lib/6to5/transformation/transformers/es6-spread.js | 10 +++------- .../transformers/optional-core-aliasing.js | 4 ++-- .../es6-classes/accessing-super-class/expected.js | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/6to5/generation/generators/expressions.js b/lib/6to5/generation/generators/expressions.js index b5a583d6bb..17f5dbda68 100644 --- a/lib/6to5/generation/generators/expressions.js +++ b/lib/6to5/generation/generators/expressions.js @@ -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); diff --git a/lib/6to5/transformation/transformers/es6-classes.js b/lib/6to5/transformation/transformers/es6-classes.js index 7a63b42f13..d1e48dda5b 100644 --- a/lib/6to5/transformation/transformers/es6-classes.js +++ b/lib/6to5/transformation/transformers/es6-classes.js @@ -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()); } } diff --git a/lib/6to5/transformation/transformers/es6-spread.js b/lib/6to5/transformation/transformers/es6-spread.js index 7c8062bcdf..e1dc5269d0 100644 --- a/lib/6to5/transformation/transformers/es6-spread.js +++ b/lib/6to5/transformation/transformers/es6-spread.js @@ -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")); } diff --git a/lib/6to5/transformation/transformers/optional-core-aliasing.js b/lib/6to5/transformation/transformers/optional-core-aliasing.js index 9d2d7b5756..9c4831a87e 100644 --- a/lib/6to5/transformation/transformers/optional-core-aliasing.js +++ b/lib/6to5/transformation/transformers/optional-core-aliasing.js @@ -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 diff --git a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js index 3de724c2c7..028865cfc7 100644 --- a/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js +++ b/test/fixtures/transformation/es6-classes/accessing-super-class/expected.js @@ -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);