Add support for Literal Type parms

This commit is contained in:
Kenneth Pouncey 2018-03-20 07:27:52 +01:00
Родитель 8966f427fb
Коммит 7e14f3c8c9
5 изменённых файлов: 48 добавлений и 2 удалений

Просмотреть файл

@ -67,11 +67,30 @@ const ValueTypeTextMap = [
return emitFunctionType(node, context);
case SyntaxKind.TypeQuery:
return emitTypeQuery(node, context);
case SyntaxKind.LastTypeNode:
return emitLastTypeNodeAsType(node, context);
default:
throw new Error(`Unknown TypeNode kind ${SyntaxKind[node.getKind()]}`);
}
}
// This is a little weird but we will treat it as a string for now untill we run across something different.
export function emitLastTypeNodeAsType(node: sast.Node, context: ContextInterface): string {
// const source: string[] = [];
// addWhitespace(source, node, context);
// if (TypeGuards.isLiteralTypeNode(node))
// {
// const literal = node.getLiteral();
// source.push(emit(literal, context));
// }
// endNode(node, context);
// return source.join('');
return _emitType("string", node, context);
}
export function emitTypeQuery(node: sast.Node, context: ContextInterface): string {
const source: string[] = [];

Просмотреть файл

@ -37,7 +37,7 @@ export function TsToCSharpGenerator(node: SourceFile, context: ContextInterface)
const source: string[] = [];
emitUsings(source, context);
emitDefaultNameSpace(source, context, true);
//console.log("Identifying interfaces for later class implementations")
@ -442,6 +442,19 @@ function visitHeritageClauses(source: string[],
// tslint:disable-next-line cyclomatic-complexity
function visitMethodSignature(node: sast.MethodSignature, context: ContextInterface): string {
const source: string[] = [];
// We will skip KeyOf Maps for now.
const types = node.getTypeParameters();
if (types && types.length > 0)
{
const keyof = types[0];
if (TypeGuards.isTypeParameterDeclaration(keyof))
{
endNode(node, context);
return source.join('');
}
}
addLeadingComment(source, node, context);
// This will generate an Export attribute as well as takes into account whitespace

Просмотреть файл

@ -73,6 +73,7 @@ const interfaceCases = [
{should: "should generate interface with method with rest any parms", file: "MethodWithRestAnyParms"},
{should: "should generate interface with method with rest type ref parms", file: "MethodWithRestTypeRefParms"},
{should: "should generate interface with method with rest string parms", file: "MethodWithRestStringParms"},
{should: "should generate interface with method with literal type parms", file: "MethodWithLiteralTypeParm"},
{should: "should generate interface with method leading and trailing comments", file: "MethodComments"},
{should: "should generate interface with method that returns number array", file: "MethodReturnNumberArray"},
{should: "should generate interface with method that returns number array or null", file: "MethodReturnNumberArrayOrNull"},
@ -105,7 +106,7 @@ const interfaceCases = [
{should: "should generate interface with string array property", file: "StringArrayProperty"},
{should: "should generate interface with nullable string array property", file: "StringArrayOrNullProperty"},
{should: "should generate interface with type query property", file: "TypeQueryProperty"},
{should: "should generate interfaces extending one interface", file: "Extends2"},
{should: "should generate multiple interfaces extending multiple interfaces", file: "Extends3"},

Просмотреть файл

@ -0,0 +1,8 @@
interface Element : Node, GlobalEventHandlers, ElementTraversal, NodeSelector, ChildNode, ParentNode {
[Export("getElementsByTagNameNS")]
HTMLCollectionOf<HTMLElement> getElementsByTagNameNS(string namespaceURI, string localName);
[Export("getElementsByTagNameNS")]
HTMLCollectionOf<SVGElement> getElementsByTagNameNS(string namespaceURI, string localName);
[Export("getElementsByTagNameNS")]
HTMLCollectionOf<Element> getElementsByTagNameNS(string namespaceURI, string localName);
}

5
test/definitions/interfaces/MethodWithLiteralTypeParm.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,5 @@
interface Element extends Node, GlobalEventHandlers, ElementTraversal, NodeSelector, ChildNode, ParentNode {
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf<Element>;
}