Skip to content

Commit

Permalink
feat: rosetta go support (#3376)
Browse files Browse the repository at this point in the history
Adds Go renderer for jsii-rosetta to support translating documentations
snippets to Go.

Fixes #2439

---

By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
  • Loading branch information
MrArnoldPalmer committed Feb 24, 2022
1 parent 6b4289c commit 015e663
Show file tree
Hide file tree
Showing 93 changed files with 1,594 additions and 16 deletions.
11 changes: 9 additions & 2 deletions packages/jsii-rosetta/lib/jsii/jsii-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { hasAnyFlag, analyzeStructType, JsiiSymbol } from './jsii-utils';
export type JsiiType =
| { kind: 'unknown' }
| { kind: 'error'; message: string }
| { kind: 'map'; elementType: JsiiType }
| { kind: 'list'; elementType: JsiiType }
| { kind: 'map' | 'list'; elementType: JsiiType; elementTypeSymbol: ts.Symbol | undefined }
| { kind: 'namedType'; name: string }
| { kind: 'builtIn'; builtIn: BuiltInType };

Expand All @@ -28,6 +27,7 @@ export function determineJsiiType(typeChecker: ts.TypeChecker, type: ts.Type): J
elementType: mapValuesType.elementType
? determineJsiiType(typeChecker, mapValuesType.elementType)
: { kind: 'builtIn', builtIn: 'any' },
elementTypeSymbol: mapValuesType.elementType?.symbol,
};
}

Expand All @@ -38,12 +38,14 @@ export function determineJsiiType(typeChecker: ts.TypeChecker, type: ts.Type): J
return {
kind: 'list',
elementType: determineJsiiType(typeChecker, typeRef.typeArguments[0]),
elementTypeSymbol: typeRef.typeArguments[0].symbol,
};
}

return {
kind: 'list',
elementType: { kind: 'builtIn', builtIn: 'any' },
elementTypeSymbol: undefined,
};
}

Expand All @@ -66,6 +68,11 @@ export function determineJsiiType(typeChecker: ts.TypeChecker, type: ts.Type): J
message: `Type unions or intersections are not supported in examples, got: ${typeChecker.typeToString(type)}`,
};
}

if ((type.flags & (ts.TypeFlags.Void | ts.TypeFlags.VoidLike)) !== 0) {
return { kind: 'builtIn', builtIn: 'void' };
}

return { kind: 'unknown' };
}

Expand Down
2 changes: 2 additions & 0 deletions packages/jsii-rosetta/lib/languages/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ export class CSharpVisitor extends DefaultVisitor<CSharpLanguageContext> {
return 'string';
case 'any':
return 'object';
case 'void':
return 'void';
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/jsii-rosetta/lib/languages/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export abstract class DefaultVisitor<C> implements AstHandler<C> {
return new OTree([JSON.stringify(node.text)]);
}

public numericLiteral(node: ts.NumericLiteral, _children: AstRenderer<C>): OTree {
return new OTree([node.text]);
}

public identifier(node: ts.Identifier, _children: AstRenderer<C>): OTree {
return new OTree([node.text]);
}
Expand Down
Loading

0 comments on commit 015e663

Please sign in to comment.