private goName()

in src/languages/go.ts [1009:1049]


  private goName(input: string, renderer: GoRenderer, symbol: ts.Symbol | undefined) {
    let text = input.replace(/[^a-z0-9_]/gi, '');

    // Symbols can be an index signature, if this is a dot-style access to a map member. In this
    // case we should not cache against the symbol as this would cause all such accesses to the same
    // object to return the same text, which would be incorrect!
    const indexSignature = ts.SymbolFlags.Signature | ts.SymbolFlags.Transient;
    const cacheKey = symbol != null && (symbol.flags & indexSignature) === indexSignature ? input : symbol ?? input;

    const prev = this.idMap.get(cacheKey) ?? this.idMap.get(input);

    if (prev) {
      // If an identifier has been renamed go get it
      text = prev.formatted;
    } else if (renderer.currentContext.isExported && !renderer.currentContext.inMapLiteral) {
      // Uppercase exported and public symbols/members
      text = ucFirst(text);
    } else if (!renderer.currentContext.inMapLiteral) {
      // Lowercase unexported items that are capitalized in TS like structs/interfaces/classes
      text = lcFirst(text);
    }

    text = prefixReserved(text);

    if (text !== input && prev == null) {
      this.idMap.set(cacheKey, { formatted: text, type: getDeclarationType(renderer.currentContext) });
    }

    if (
      // Non-pointer references to parameters need to be de-referenced
      (!renderer.currentContext.isPtr &&
        !renderer.currentContext.isParameterName &&
        symbol?.valueDeclaration?.kind === ts.SyntaxKind.Parameter &&
        !renderer.currentContext.isPtrAssignmentRValue) ||
      // Pointer reference to non-interfaces are prefixed with *
      (renderer.currentContext.isPtr && prev && prev?.type !== DeclarationType.INTERFACE)
    ) {
      return `*${text}`;
    }
    return text;
  }