@@ -150,7 +150,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
150
150
visitForOf (n , parent );
151
151
break ;
152
152
case Token .SUPER :
153
- visitSuper (n );
153
+ visitSuper (n , parent );
154
154
break ;
155
155
case Token .STRING_KEY :
156
156
visitStringKey (n );
@@ -238,14 +238,14 @@ private void checkClassReassignment(Node clazz) {
238
238
NodeTraversal .traverse (compiler , enclosingFunction , checkAssigns );
239
239
}
240
240
241
- private void visitSuper (Node node ) {
242
- Node enclosing = node . getParent () ;
241
+ private void visitSuper (Node node , Node parent ) {
242
+ Node enclosing = parent ;
243
243
Node potentialCallee = node ;
244
- if (!enclosing .isCall ()) {
245
- enclosing = enclosing .getParent ();
246
- potentialCallee = potentialCallee . getParent () ;
244
+ if (!parent .isCall ()) {
245
+ enclosing = parent .getParent ();
246
+ potentialCallee = parent ;
247
247
}
248
- if (!( enclosing .isCall () && enclosing .getFirstChild () == potentialCallee ) ) {
248
+ if (!enclosing .isCall () || enclosing .getFirstChild () != potentialCallee ) {
249
249
cannotConvertYet (node , "Only calls to super or to a method of super are supported." );
250
250
return ;
251
251
}
@@ -265,11 +265,22 @@ private void visitSuper(Node node) {
265
265
266
266
Node enclosingMemberDef = NodeUtil .getEnclosingClassMember (node );
267
267
if (enclosingMemberDef .isStaticMember ()) {
268
- node .getParent ().replaceChild (node , clazz .getFirstChild ().getNext ().cloneTree ());
269
- Node callTarget = IR .getprop (potentialCallee .detachFromParent (), IR .string ("call" ));
270
- callTarget .useSourceInfoIfMissingFromForTree (enclosing );
268
+ Node superName = clazz .getFirstChild ().getNext ();
269
+ Node callTarget ;
270
+ potentialCallee .detachFromParent ();
271
+ if (potentialCallee == node ) {
272
+ // of the form super()
273
+ potentialCallee =
274
+ IR .getprop (superName .cloneTree (), IR .string (enclosingMemberDef .getString ()));
275
+ enclosing .putBooleanProp (Node .FREE_CALL , false );
276
+ } else {
277
+ // of the form super.method()
278
+ potentialCallee .replaceChild (node , superName .cloneTree ());
279
+ }
280
+ callTarget = IR .getprop (potentialCallee , IR .string ("call" ));
271
281
enclosing .addChildToFront (callTarget );
272
282
enclosing .addChildAfter (IR .thisNode (), callTarget );
283
+ enclosing .useSourceInfoIfMissingFromForTree (enclosing );
273
284
compiler .reportCodeChange ();
274
285
return ;
275
286
}
0 commit comments