Generic function type aliases

This commit is contained in:
dcodeIO
2018-03-12 17:44:09 +01:00
parent 423533c6b0
commit 7870e3ac18
14 changed files with 380 additions and 470 deletions

View File

@ -1979,7 +1979,7 @@ export class Parser extends DiagnosticEmitter {
return this.parseTryStatement(tn);
}
case Token.TYPE: {
return this.parseTypeDeclaration(tn, null);
return this.parseTypeDeclaration(tn);
}
case Token.VOID: {
return this.parseVoidStatement(tn);
@ -2429,17 +2429,29 @@ export class Parser extends DiagnosticEmitter {
decorators: DecoratorNode[] | null = null
): TypeDeclaration | null {
// at 'type': Identifier '=' Type ';'?
// at 'type': Identifier ('<' TypeParameters '>')? '=' Type ';'?
var startPos = decorators && decorators.length ? decorators[0].range.start
: modifiers && modifiers.length ? modifiers[0].range.start
: tn.tokenPos;
if (tn.skip(Token.IDENTIFIER)) {
var name = Node.createIdentifierExpression(tn.readIdentifier(), tn.range());
var typeParameters: TypeParameterNode[] | null = null;
if (tn.skip(Token.LESSTHAN)) {
typeParameters = this.parseTypeParameters(tn);
if (!typeParameters) return null;
}
if (tn.skip(Token.EQUALS)) {
var type = this.parseType(tn);
if (!type) return null;
var ret = Node.createTypeDeclaration(name, type, modifiers, decorators, tn.range(startPos, tn.pos));
var ret = Node.createTypeDeclaration(
name,
typeParameters,
type,
modifiers,
decorators,
tn.range(startPos, tn.pos)
);
tn.skip(Token.SEMICOLON);
return ret;
} else {