src/com/google/javascript/jscomp/Es6RewriteClass.java
/**
   * Add declarations for properties that were defined with a getter and/or setter, so that the
   * typechecker knows those properties exist on the class. This is a temporary solution.
   * Eventually, the type checker should understand Object.defineProperties calls directly.
   */
Add declarations for properties that were defined with a getter and/or setter, so that the
typechecker knows those properties exist on the class. This is a temporary solution.
Eventually, the type checker should understand Object.defineProperties calls directly.
Add declarations for properties that were defined with a getter and / or setter so that the typechecker knows those properties exist on the class . This is a temporary solution . Eventually the type checker should understand Object . defineProperties calls directly .
private void addTypeDeclarations(
      Scope scope, ClassDeclarationMetadata metadata, Node insertionPoint) {
    for (Map.Entry<String, JSDocInfo> entry : metadata.getPrototypeMembersToDeclare().entrySet()) {
      String declaredMember = entry.getKey();
      Node declaration =
          astFactory.createGetProp(metadata.getClassPrototypeNode().cloneTree(), declaredMember);
      declaration.setJSDocInfo(entry.getValue());
      declaration =
          IR.exprResult(declaration).useSourceInfoIfMissingFromForTree(metadata.getClassNameNode());
      insertionPoint.getParent().addChildAfter(declaration, insertionPoint);
      insertionPoint = declaration;
    }
    for (Map.Entry<String, JSDocInfo> entry : metadata.getClassMembersToDeclare().entrySet()) {
      String declaredMember = entry.getKey();
      Node declaration =
          astFactory.createGetProp(metadata.getFullClassNameNode().cloneTree(), declaredMember);
      declaration.setJSDocInfo(entry.getValue());
      declaration =
          IR.exprResult(declaration).useSourceInfoIfMissingFromForTree(metadata.getClassNameNode());
      insertionPoint.getParent().addChildAfter(declaration, insertionPoint);
      insertionPoint = declaration;
    }
    for (Map.Entry<String, JSDocInfo> entry :
        metadata.getPrototypeComputedPropsToDeclare().entrySet()) {
      String declaredMember = entry.getKey();
      Node computedPropertyQName = astFactory.createQName(scope, declaredMember);
      Node declaration =
          astFactory.createGetElem(
              metadata.getClassPrototypeNode().cloneTree(), computedPropertyQName);
      declaration.setJSDocInfo(entry.getValue());
      declaration =
          IR.exprResult(declaration).useSourceInfoIfMissingFromForTree(metadata.getClassNameNode());
      insertionPoint.getParent().addChildAfter(declaration, insertionPoint);
      insertionPoint = declaration;
    }
  }
private void addTypeDeclarations ( Scope scope , ClassDeclarationMetadata metadata , Node insertionPoint ) { for ( Map . Entry < String , JSDocInfo > entry : metadata . getPrototypeMembersToDeclare ( ) . entrySet ( ) ) { String declaredMember = entry . getKey ( ) ; Node declaration = astFactory . createGetProp ( metadata . getClassPrototypeNode ( ) . cloneTree ( ) , declaredMember ) ; declaration . setJSDocInfo ( entry . getValue ( ) ) ; declaration = IR . exprResult ( declaration ) . useSourceInfoIfMissingFromForTree ( metadata . getClassNameNode ( ) ) ; insertionPoint . getParent ( ) . addChildAfter ( declaration , insertionPoint ) ; insertionPoint = declaration ; } for ( Map . Entry < String , JSDocInfo > entry : metadata . getClassMembersToDeclare ( ) . entrySet ( ) ) { String declaredMember = entry . getKey ( ) ; Node declaration = astFactory . createGetProp ( metadata . getFullClassNameNode ( ) . cloneTree ( ) , declaredMember ) ; declaration . setJSDocInfo ( entry . getValue ( ) ) ; declaration = IR . exprResult ( declaration ) . useSourceInfoIfMissingFromForTree ( metadata . getClassNameNode ( ) ) ; insertionPoint . getParent ( ) . addChildAfter ( declaration , insertionPoint ) ; insertionPoint = declaration ; } for ( Map . Entry < String , JSDocInfo > entry : metadata . getPrototypeComputedPropsToDeclare ( ) . entrySet ( ) ) { String declaredMember = entry . getKey ( ) ; Node computedPropertyQName = astFactory . createQName ( scope , declaredMember ) ; Node declaration = astFactory . createGetElem ( metadata . getClassPrototypeNode ( ) . cloneTree ( ) , computedPropertyQName ) ; declaration . setJSDocInfo ( entry . getValue ( ) ) ; declaration = IR . exprResult ( declaration ) . useSourceInfoIfMissingFromForTree ( metadata . getClassNameNode ( ) ) ; insertionPoint . getParent ( ) . addChildAfter ( declaration , insertionPoint ) ; insertionPoint = declaration ; } }
Add declarations for properties that were defined with a getter and/or setter, so that the
 typechecker knows those properties exist on the class.
Add declarations for properties that were defined with a getter and / or setter so that the typechecker knows those properties exist on the class .
// Note that at the moment we only allow qualified names as the keys for class computed // properties. // TODO(bradfordcsmith): Clone the original declared member qualified name instead of creating // it from scratch from the string form. That way we would just reuse the type information, // instead of AstFactory having to re-create it.