Skip to content

Commit b52b339

Browse files
tbreisacherblickly
tbreisacher
authored andcommitted
When calling super['someProperty']() (as opposed to super.someProperty()) report an error instead of crashing.
Fixes #1184 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=104729872
1 parent 23cbe19 commit b52b339

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/com/google/javascript/jscomp/Es6ConvertSuper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ private void visitSuper(Node node, Node parent) {
108108
enclosingCall = parent.getParent();
109109
potentialCallee = parent;
110110
}
111-
if (!enclosingCall.isCall() || enclosingCall.getFirstChild() != potentialCallee) {
111+
if (!enclosingCall.isCall()
112+
|| enclosingCall.getFirstChild() != potentialCallee
113+
|| enclosingCall.getFirstChild().isGetElem()) {
112114
compiler.report(JSError.make(node, CANNOT_CONVERT_YET,
113115
"Only calls to super or to a method of super are supported."));
114116
return;

test/com/google/javascript/jscomp/Es6ToEs3ConverterTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,21 @@ public void testSuperCall() {
515515
"}"));
516516
}
517517

518+
public void testComputedSuper() {
519+
testError(
520+
LINE_JOINER.join(
521+
"class Foo {",
522+
" ['m']() { return 1; }",
523+
"}",
524+
"",
525+
"class Bar extends Foo {",
526+
" ['m']() {",
527+
" return super['m']() + 1;",
528+
" }",
529+
"}"),
530+
CANNOT_CONVERT_YET);
531+
}
532+
518533
public void testMultiNameClass() {
519534
test("var F = class G {}",
520535
"/** @constructor @struct */ var F = function() {};");

0 commit comments

Comments
 (0)