From 418de75e773e4f1fe38b9393edf3823f6c95777a Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Thu, 22 Jan 2015 07:54:01 +1100 Subject: [PATCH] fix bare super call being illegal in non-constructors --- .../transformation/helpers/replace-supers.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/6to5/transformation/helpers/replace-supers.js b/lib/6to5/transformation/helpers/replace-supers.js index 56c3c9fdf7..591f58e403 100644 --- a/lib/6to5/transformation/helpers/replace-supers.js +++ b/lib/6to5/transformation/helpers/replace-supers.js @@ -202,20 +202,21 @@ ReplaceSupers.prototype.specHandle = function (getThisReference, node, parent) { throw this.file.errorWithNode(node, "illegal use of bare super"); } } else if (t.isCallExpression(node)) { - // super(); is illegal inside non-constructors - // https://esdiscuss.org/topic/super-call-in-methods - // https://twitter.com/wycats/status/544553184396836864 - if (methodNode.key.name !== "constructor") { - var methodName = methodNode.key.name || "METHOD_NAME"; - throw this.file.errorWithNode(node, "Direct super call is illegal in non-constructor, use super." + methodName + "() instead"); - } - var callee = node.callee; if (t.isIdentifier(callee, { name: "super" })) { // super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this); property = methodNode.key; computed = methodNode.computed; args = node.arguments; + + // bare `super` call is illegal inside non-constructors + // - https://esdiscuss.org/topic/super-call-in-methods + // - https://twitter.com/wycats/status/544553184396836864 + if (methodNode.key.name !== "constructor") { + var methodName = methodNode.key.name || "METHOD_NAME"; + console.log(node); + throw this.file.errorWithNode(node, "Direct super call is illegal in non-constructor, use super." + methodName + "() instead"); + } } else { if (!t.isMemberExpression(callee)) return; if (callee.object.name !== "super") return;