Program: 27176
Project: 27176
Buggy source:
/** 
 * Classes are processed in 3 phases: <ol> <li>The class name is extracted. <li>Class members are processed and rewritten. <li>The constructor is built. </ol>
 */
private void visitClass(final NodeTraversal t,final Node classNode,final Node parent){
  checkClassReassignment(classNode);
  ClassDeclarationMetadata metadata=ClassDeclarationMetadata.create(classNode,parent);
  if (metadata == null || metadata.fullClassName == null) {
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + classNode);
  }
  if (metadata.hasSuperClass() && !metadata.superClassNameNode.isQualifiedName()) {
    compiler.report(JSError.make(metadata.superClassNameNode,DYNAMIC_EXTENDS_TYPE));
    return;
  }
  Preconditions.checkState(NodeUtil.isStatement(metadata.insertionPoint),"String_Node_Str",metadata.insertionPoint);
  Node constructor=null;
  JSDocInfo ctorJSDocInfo=null;
  Node classMembers=classNode.getLastChild();
  for (  Node member : classMembers.children()) {
    if ((member.isComputedProp() && (member.getBooleanProp(Node.COMPUTED_PROP_GETTER) || member.getBooleanProp(Node.COMPUTED_PROP_SETTER))) || (member.isGetterDef() || member.isSetterDef())) {
      visitNonMethodMember(member,metadata);
    }
 else     if (member.isMemberFunctionDef() && member.getString().equals("String_Node_Str")) {
      ctorJSDocInfo=member.getJSDocInfo();
      constructor=member.getFirstChild().detach();
      if (!metadata.anonymous) {
        constructor.replaceChild(constructor.getFirstChild(),metadata.classNameNode.cloneNode());
      }
    }
 else     if (member.isEmpty()) {
    }
 else {
      Preconditions.checkState(member.isMemberFunctionDef() || member.isComputedProp(),"String_Node_Str",member);
      Preconditions.checkState(!member.getBooleanProp(Node.COMPUTED_PROP_VARIABLE),"String_Node_Str",member);
      visitMethod(member,metadata);
    }
  }
  if (metadata.definePropertiesObjForPrototype.hasChildren()) {
    compiler.ensureLibraryInjected("String_Node_Str",false);
    Node definePropsCall=IR.exprResult(IR.call(NodeUtil.newQName(compiler,"String_Node_Str"),NodeUtil.newQName(compiler,metadata.fullClassName + "String_Node_Str"),metadata.definePropertiesObjForPrototype));
    definePropsCall.useSourceInfoIfMissingFromForTree(classNode);
    metadata.insertNodeAndAdvance(definePropsCall);
  }
  if (metadata.definePropertiesObjForClass.hasChildren()) {
    compiler.ensureLibraryInjected("String_Node_Str",false);
    Node definePropsCall=IR.exprResult(IR.call(NodeUtil.newQName(compiler,"String_Node_Str"),NodeUtil.newQName(compiler,metadata.fullClassName),metadata.definePropertiesObjForClass));
    definePropsCall.useSourceInfoIfMissingFromForTree(classNode);
    metadata.insertNodeAndAdvance(definePropsCall);
  }
  checkNotNull(constructor);
  JSDocInfo classJSDoc=NodeUtil.getBestJSDocInfo(classNode);
  JSDocInfoBuilder newInfo=JSDocInfoBuilder.maybeCopyFrom(classJSDoc);
  newInfo.recordConstructor();
  Node enclosingStatement=NodeUtil.getEnclosingStatement(classNode);
  if (metadata.hasSuperClass()) {
    String superClassString=metadata.superClassNameNode.getQualifiedName();
    if (newInfo.isInterfaceRecorded()) {
      newInfo.recordExtendedInterface(new JSTypeExpression(new Node(Token.BANG,IR.string(superClassString)),metadata.superClassNameNode.getSourceFileName()));
    }
 else {
      if (shouldAddInheritsPolyfill && !classNode.isFromExterns()) {
        Node classNameNode=NodeUtil.newQName(compiler,metadata.fullClassName).useSourceInfoIfMissingFrom(metadata.classNameNode);
        Node superClassNameNode=NodeUtil.newQName(compiler,superClassString).useSourceInfoIfMissingFrom(metadata.superClassNameNode);
        Node inherits=IR.call(NodeUtil.newQName(compiler,INHERITS),classNameNode,superClassNameNode);
        Node inheritsCall=IR.exprResult(inherits);
        compiler.ensureLibraryInjected("String_Node_Str",false);
        inheritsCall.useSourceInfoIfMissingFromForTree(metadata.superClassNameNode);
        enclosingStatement.getParent().addChildAfter(inheritsCall,enclosingStatement);
      }
      newInfo.recordBaseType(new JSTypeExpression(new Node(Token.BANG,IR.string(superClassString)),metadata.superClassNameNode.getSourceFileName()));
    }
  }
  addTypeDeclarations(metadata,enclosingStatement);
  updateClassJsDoc(ctorJSDocInfo,newInfo);
  if (NodeUtil.isStatement(classNode)) {
    constructor.getFirstChild().setString("String_Node_Str");
    Node ctorVar=IR.let(metadata.classNameNode.cloneNode(),constructor);
    ctorVar.useSourceInfoIfMissingFromForTree(classNode);
    parent.replaceChild(classNode,ctorVar);
  }
 else {
    parent.replaceChild(classNode,constructor);
  }
  NodeUtil.markFunctionsDeleted(classNode,compiler);
  if (NodeUtil.isStatement(constructor)) {
    constructor.setJSDocInfo(newInfo.build());
  }
 else   if (parent.isName()) {
    Node var=parent.getParent();
    var.setJSDocInfo(newInfo.build());
  }
 else   if (constructor.getParent().isName()) {
    Node var=constructor.getGrandparent();
    var.setJSDocInfo(newInfo.build());
  }
 else   if (parent.isAssign()) {
    parent.setJSDocInfo(newInfo.build());
  }
 else {
    throw new IllegalStateException("String_Node_Str" + parent);
  }
  constructor.putBooleanProp(Node.IS_ES6_CLASS,true);
  t.reportCodeChange();
}

Fixed version (ground truth):
/** 
 * Classes are processed in 3 phases: <ol> <li>The class name is extracted. <li>Class members are processed and rewritten. <li>The constructor is built. </ol>
 */
private void visitClass(final NodeTraversal t,final Node classNode,final Node parent){
  checkClassReassignment(classNode);
  ClassDeclarationMetadata metadata=ClassDeclarationMetadata.create(classNode,parent);
  if (metadata == null || metadata.fullClassName == null) {
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + classNode);
  }
  if (metadata.hasSuperClass() && !metadata.superClassNameNode.isQualifiedName()) {
    compiler.report(JSError.make(metadata.superClassNameNode,DYNAMIC_EXTENDS_TYPE));
    return;
  }
  Preconditions.checkState(NodeUtil.isStatement(metadata.insertionPoint),"String_Node_Str",metadata.insertionPoint);
  Node constructor=null;
  JSDocInfo ctorJSDocInfo=null;
  Node classMembers=classNode.getLastChild();
  for (  Node member : classMembers.children()) {
    if ((member.isComputedProp() && (member.getBooleanProp(Node.COMPUTED_PROP_GETTER) || member.getBooleanProp(Node.COMPUTED_PROP_SETTER))) || (member.isGetterDef() || member.isSetterDef())) {
      visitNonMethodMember(member,metadata);
    }
 else     if (member.isMemberFunctionDef() && member.getString().equals("String_Node_Str")) {
      ctorJSDocInfo=member.getJSDocInfo();
      constructor=member.getFirstChild().detach();
      if (!metadata.anonymous) {
        constructor.replaceChild(constructor.getFirstChild(),metadata.classNameNode.cloneNode());
      }
    }
 else     if (member.isEmpty()) {
    }
 else {
      Preconditions.checkState(member.isMemberFunctionDef() || member.isComputedProp(),"String_Node_Str",member);
      Preconditions.checkState(!member.getBooleanProp(Node.COMPUTED_PROP_VARIABLE),"String_Node_Str",member);
      visitMethod(member,metadata);
    }
  }
  if (metadata.definePropertiesObjForPrototype.hasChildren()) {
    compiler.ensureLibraryInjected("String_Node_Str",false);
    Node definePropsCall=IR.exprResult(IR.call(NodeUtil.newQName(compiler,"String_Node_Str"),NodeUtil.newQName(compiler,metadata.fullClassName + "String_Node_Str"),metadata.definePropertiesObjForPrototype));
    definePropsCall.useSourceInfoIfMissingFromForTree(classNode);
    metadata.insertNodeAndAdvance(definePropsCall);
  }
  if (metadata.definePropertiesObjForClass.hasChildren()) {
    compiler.ensureLibraryInjected("String_Node_Str",false);
    Node definePropsCall=IR.exprResult(IR.call(NodeUtil.newQName(compiler,"String_Node_Str"),NodeUtil.newQName(compiler,metadata.fullClassName),metadata.definePropertiesObjForClass));
    definePropsCall.useSourceInfoIfMissingFromForTree(classNode);
    metadata.insertNodeAndAdvance(definePropsCall);
  }
  checkNotNull(constructor);
  JSDocInfo classJSDoc=NodeUtil.getBestJSDocInfo(classNode);
  JSDocInfoBuilder newInfo=JSDocInfoBuilder.maybeCopyFrom(classJSDoc);
  newInfo.recordConstructor();
  Node enclosingStatement=NodeUtil.getEnclosingStatement(classNode);
  if (metadata.hasSuperClass()) {
    String superClassString=metadata.superClassNameNode.getQualifiedName();
    if (newInfo.isInterfaceRecorded()) {
      newInfo.recordExtendedInterface(new JSTypeExpression(new Node(Token.BANG,IR.string(superClassString)),metadata.superClassNameNode.getSourceFileName()));
    }
 else {
      if (shouldAddInheritsPolyfill && !classNode.isFromExterns()) {
        Node classNameNode=NodeUtil.newQName(compiler,metadata.fullClassName).useSourceInfoIfMissingFrom(metadata.classNameNode);
        Node superClassNameNode=metadata.superClassNameNode.cloneTree();
        Node inherits=IR.call(NodeUtil.newQName(compiler,INHERITS),classNameNode,superClassNameNode);
        Node inheritsCall=IR.exprResult(inherits);
        compiler.ensureLibraryInjected("String_Node_Str",false);
        inheritsCall.useSourceInfoIfMissingFromForTree(metadata.superClassNameNode);
        enclosingStatement.getParent().addChildAfter(inheritsCall,enclosingStatement);
      }
      newInfo.recordBaseType(new JSTypeExpression(new Node(Token.BANG,IR.string(superClassString)),metadata.superClassNameNode.getSourceFileName()));
    }
  }
  addTypeDeclarations(metadata,enclosingStatement);
  updateClassJsDoc(ctorJSDocInfo,newInfo);
  if (NodeUtil.isStatement(classNode)) {
    constructor.getFirstChild().setString("String_Node_Str");
    Node ctorVar=IR.let(metadata.classNameNode.cloneNode(),constructor);
    ctorVar.useSourceInfoIfMissingFromForTree(classNode);
    parent.replaceChild(classNode,ctorVar);
  }
 else {
    parent.replaceChild(classNode,constructor);
  }
  NodeUtil.markFunctionsDeleted(classNode,compiler);
  if (NodeUtil.isStatement(constructor)) {
    constructor.setJSDocInfo(newInfo.build());
  }
 else   if (parent.isName()) {
    Node var=parent.getParent();
    var.setJSDocInfo(newInfo.build());
  }
 else   if (constructor.getParent().isName()) {
    Node var=constructor.getGrandparent();
    var.setJSDocInfo(newInfo.build());
  }
 else   if (parent.isAssign()) {
    parent.setJSDocInfo(newInfo.build());
  }
 else {
    throw new IllegalStateException("String_Node_Str" + parent);
  }
  constructor.putBooleanProp(Node.IS_ES6_CLASS,true);
  t.reportCodeChange();
}