merge()

in lib/merge.ts [14:58]


  merge(t?: ts.TypeNode) {
    if (t) {
      // TODO(jacobr): get a better unique name for a type.
      switch (t.kind) {
        case ts.SyntaxKind.NullKeyword:
          // No need to include the null type as all Dart types are nullable anyway.
          return;
        case ts.SyntaxKind.UnionType:
          let union = <ts.UnionTypeNode>t;
          union.types.forEach(this.merge.bind(this));
          return;
        case ts.SyntaxKind.IntersectionType:
          // Arbitrarily pick the first type of the intersection type as the merged type.
          // TODO(jacobr): re-evaluate this logic.
          let intersection = <ts.IntersectionTypeNode>t;
          this.merge(intersection.types[0]);
          return;
        case ts.SyntaxKind.TypePredicate:
          this.merge((t as ts.TypePredicateNode).type);
          return;
        case ts.SyntaxKind.TypeReference:
          // We need to follow Alias types as Dart does not support them for non
          // function types. TODO(jacobr): handle them for Function types?
          const typeRef = <ts.TypeReferenceNode>t;
          const decl =
              this.fc.getTypeDeclarationOfSymbol(this.fc.getSymbolAtLocation(typeRef.typeName));
          if (decl && ts.isTypeAliasDeclaration(decl)) {
            const alias = decl;
            if (!base.supportedTypeDeclaration(alias)) {
              if (typeRef.typeArguments) {
                console.log(
                    'Warning: typeReference with arguements not supported yet:' + t.getText());
              }

              this.merge(alias.type);
            }
            return;
          }
          break;
        default:
          break;
      }
      this.types.set(this.fc.generateDartTypeName(t, {insideComment: true}), t);
    }
  }