Fix declaration emit when first generic function type in type argument position specified using space

This commit is contained in:
Sheetal Nandi
2016-04-18 16:08:52 -07:00
parent 06f54b9124
commit 685900c2a3
2 changed files with 17 additions and 92 deletions

View File

@@ -1377,6 +1377,7 @@ namespace ts {
function emitSignatureDeclaration(node: SignatureDeclaration) {
const prevEnclosingDeclaration = enclosingDeclaration;
enclosingDeclaration = node;
let closeParenthesizedFunctionType = false;
if (node.kind === SyntaxKind.IndexSignature) {
// Index signature can have readonly modifier
@@ -1388,6 +1389,16 @@ namespace ts {
if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) {
write("new ");
}
else if (node.kind === SyntaxKind.FunctionType) {
const currentOutput = writer.getText();
// Do not generate incorrect type when function type with type parameters is type argument
// This could happen if user used space between two '<' making it error free
// e.g var x: A< <Tany>(a: Tany)=>Tany>;
if (node.typeParameters && currentOutput.charAt(currentOutput.length - 1) === "<") {
closeParenthesizedFunctionType = true;
write("(");
}
}
emitTypeParameters(node.typeParameters);
write("(");
}
@@ -1421,6 +1432,9 @@ namespace ts {
write(";");
writeLine();
}
else if (closeParenthesizedFunctionType) {
write(")");
}
function getReturnTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
let diagnosticMessage: DiagnosticMessage;

View File

@@ -52,104 +52,15 @@ var prop4; // parenthesized first type argument
//// [declarationEmitFirstTypeArgumentGenericFunctionType.d.ts]
declare class X<A> {
}
declare var prop11: X<<Tany>() => Tany>;
declare var prop11: X<(<Tany>() => Tany)>;
declare var prop12: X<(<Tany>() => Tany)>;
declare function f1(): X<(<Tany>() => Tany)>;
declare function f2(): X<(<Tany>() => Tany)>;
declare function f3(): X<<Tany>() => Tany>;
declare function f3(): X<(<Tany>() => Tany)>;
declare function f4(): X<(<Tany>() => Tany)>;
declare class Y<A, B> {
}
declare var prop2: Y<string[], <Tany>() => Tany>;
declare var prop2: Y<string[], <Tany>() => Tany>;
declare var prop3: Y<<Tany>() => Tany, <Tany>() => Tany>;
declare var prop3: Y<(<Tany>() => Tany), <Tany>() => Tany>;
declare var prop4: Y<(<Tany>() => Tany), <Tany>() => Tany>;
//// [DtsFileErrors]
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(3,21): error TS2314: Generic type 'X<A>' requires 1 type argument(s).
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(3,22): error TS1005: '=' expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(3,24): error TS2304: Cannot find name 'Tany'.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(3,30): error TS1109: Expression expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(3,32): error TS1005: ';' expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(3,35): error TS2304: Cannot find name 'Tany'.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(3,40): error TS1109: Expression expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(7,24): error TS2314: Generic type 'X<A>' requires 1 type argument(s).
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(7,25): error TS1144: '{' or ';' expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(7,27): error TS2304: Cannot find name 'Tany'.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(7,33): error TS1109: Expression expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(7,35): error TS1005: ';' expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(7,38): error TS2304: Cannot find name 'Tany'.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(7,43): error TS1109: Expression expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,20): error TS2314: Generic type 'Y<A, B>' requires 2 type argument(s).
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,21): error TS1005: '=' expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,23): error TS2304: Cannot find name 'Tany'.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,29): error TS1109: Expression expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,31): error TS1005: ';' expected.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,34): error TS2304: Cannot find name 'Tany'.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,52): error TS2304: Cannot find name 'Tany'.
tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts(13,57): error TS1109: Expression expected.
==== tests/cases/compiler/declarationEmitFirstTypeArgumentGenericFunctionType.d.ts (22 errors) ====
declare class X<A> {
}
declare var prop11: X<<Tany>() => Tany>;
~
!!! error TS2314: Generic type 'X<A>' requires 1 type argument(s).
~~
!!! error TS1005: '=' expected.
~~~~
!!! error TS2304: Cannot find name 'Tany'.
~
!!! error TS1109: Expression expected.
~~
!!! error TS1005: ';' expected.
~~~~
!!! error TS2304: Cannot find name 'Tany'.
~
!!! error TS1109: Expression expected.
declare var prop12: X<(<Tany>() => Tany)>;
declare function f1(): X<(<Tany>() => Tany)>;
declare function f2(): X<(<Tany>() => Tany)>;
declare function f3(): X<<Tany>() => Tany>;
~
!!! error TS2314: Generic type 'X<A>' requires 1 type argument(s).
~~
!!! error TS1144: '{' or ';' expected.
~~~~
!!! error TS2304: Cannot find name 'Tany'.
~
!!! error TS1109: Expression expected.
~~
!!! error TS1005: ';' expected.
~~~~
!!! error TS2304: Cannot find name 'Tany'.
~
!!! error TS1109: Expression expected.
declare function f4(): X<(<Tany>() => Tany)>;
declare class Y<A, B> {
}
declare var prop2: Y<string[], <Tany>() => Tany>;
declare var prop2: Y<string[], <Tany>() => Tany>;
declare var prop3: Y<<Tany>() => Tany, <Tany>() => Tany>;
~
!!! error TS2314: Generic type 'Y<A, B>' requires 2 type argument(s).
~~
!!! error TS1005: '=' expected.
~~~~
!!! error TS2304: Cannot find name 'Tany'.
~
!!! error TS1109: Expression expected.
~~
!!! error TS1005: ';' expected.
~~~~
!!! error TS2304: Cannot find name 'Tany'.
~~~~
!!! error TS2304: Cannot find name 'Tany'.
~
!!! error TS1109: Expression expected.
declare var prop4: Y<(<Tany>() => Tany), <Tany>() => Tany>;