1
+ /// <reference path='fourslash.ts'/>
2
+
3
+ ////const /*1*/a = 10;
4
+ ////function foo() {
5
+ //// const /*2*/b = /*3*/a;
6
+ //// if (b) {
7
+ //// const /*4*/b1 = 10;
8
+ //// }
9
+ //// }
10
+ ////module m {
11
+ //// const /*5*/c = 10;
12
+ //// export const /*6*/d = 10;
13
+ //// if (c) {
14
+ //// const /*7*/e = 10;
15
+ //// }
16
+ //// }
17
+ ////const /*8*/f: () => number = () => 10;
18
+ ////const /*9*/g = /*10*/f;
19
+ /////*11*/f();
20
+ ////const /*12*/h: { (a: string): number; (a: number): string; } = a => a;
21
+ ////const /*13*/i = /*14*/h;
22
+ /////*15*/h(10);
23
+ /////*16*/h("hello");
24
+
25
+ var marker = 0 ;
26
+ function verifyConst ( name : string , typeDisplay : ts . SymbolDisplayPart [ ] , optionalNameDisplay ?: ts . SymbolDisplayPart [ ] , optionalKindModifiers ?: string ) {
27
+ marker ++ ;
28
+ goTo . marker ( marker . toString ( ) ) ;
29
+ verify . verifyQuickInfoDisplayParts ( "const" , optionalKindModifiers || "" , { start : test . markerByName ( marker . toString ( ) ) . position , length : name . length } ,
30
+ [ { text : "const" , kind : "keyword" } ,
31
+ { text : " " , kind : "space" } ] . concat ( optionalNameDisplay || [ { text : name , kind : "localName" } ] ) . concat (
32
+ { text : ":" , kind : "punctuation" } , { text : " " , kind : "space" } ) . concat ( typeDisplay ) ,
33
+ [ ] ) ;
34
+ }
35
+
36
+ var numberTypeDisplay : ts . SymbolDisplayPart [ ] = [ { text : "number" , kind : "keyword" } ] ;
37
+
38
+ verifyConst ( "a" , numberTypeDisplay ) ;
39
+ verifyConst ( "b" , numberTypeDisplay ) ;
40
+ verifyConst ( "a" , numberTypeDisplay ) ;
41
+ verifyConst ( "b1" , numberTypeDisplay ) ;
42
+ verifyConst ( "c" , numberTypeDisplay ) ;
43
+ verifyConst ( "d" , numberTypeDisplay , [ { text : "m" , kind : "moduleName" } , { text : "." , kind : "punctuation" } , { text : "d" , kind : "localName" } ] , "export" ) ;
44
+ verifyConst ( "e" , numberTypeDisplay ) ;
45
+
46
+ var functionTypeReturningNumber : ts . SymbolDisplayPart [ ] = [ { text : "(" , kind : "punctuation" } , { text : ")" , kind : "punctuation" } ,
47
+ { text : " " , kind : "space" } , { text : "=>" , kind : "punctuation" } , { text : " " , kind : "space" } , { text : "number" , kind : "keyword" } ] ;
48
+ verifyConst ( "f" , functionTypeReturningNumber ) ;
49
+ verifyConst ( "g" , functionTypeReturningNumber ) ;
50
+ verifyConst ( "f" , functionTypeReturningNumber ) ;
51
+ verifyConst ( "f" , functionTypeReturningNumber ) ;
52
+
53
+
54
+ function getFunctionType ( parametertype : string , returnType : string , isArrow ?: boolean ) : ts . SymbolDisplayPart [ ] {
55
+ var functionTypeDisplay = [ { text : "(" , kind : "punctuation" } , { text : "a" , kind : "parameterName" } , { text : ":" , kind : "punctuation" } ,
56
+ { text : " " , kind : "space" } , { text : parametertype , kind : "keyword" } , { text : ")" , kind : "punctuation" } ] ;
57
+
58
+ if ( isArrow ) {
59
+ functionTypeDisplay = functionTypeDisplay . concat ( { text : " " , kind : "space" } , { text : "=>" , kind : "punctuation" } ) ;
60
+ }
61
+ else {
62
+ functionTypeDisplay = functionTypeDisplay . concat ( { text : ":" , kind : "punctuation" } ) ;
63
+ }
64
+
65
+ return functionTypeDisplay . concat ( { text : " " , kind : "space" } , { text : returnType , kind : "keyword" } ) ;
66
+ }
67
+
68
+ var typeLiteralWithOverloadCall : ts . SymbolDisplayPart [ ] = [ { text : "{" , kind : "punctuation" } , { text : "\n" , kind : "lineBreak" } ,
69
+ { text : " " , kind : "space" } ] . concat ( getFunctionType ( "string" , "number" ) ) . concat (
70
+ { text : ";" , kind : "punctuation" } , { text : "\n" , kind : "lineBreak" } ,
71
+ { text : " " , kind : "space" } ) . concat ( getFunctionType ( "number" , "string" ) ) . concat (
72
+ { text : ";" , kind : "punctuation" } , { text : "\n" , kind : "lineBreak" } , { text : "}" , kind : "punctuation" } ) ;
73
+
74
+ verifyConst ( "h" , typeLiteralWithOverloadCall ) ;
75
+ verifyConst ( "i" , typeLiteralWithOverloadCall ) ;
76
+ verifyConst ( "h" , typeLiteralWithOverloadCall ) ;
77
+
78
+ var overloadDisplay : ts . SymbolDisplayPart [ ] = [ { text : " " , kind : "space" } , { text : "(" , kind : "punctuation" } ,
79
+ { text : "+" , kind : "operator" } , { text : "1" , kind : "numericLiteral" } ,
80
+ { text : " " , kind : "space" } , { text : "overload" , kind : "text" } , { text : ")" , kind : "punctuation" } ] ;
81
+
82
+ verifyConst ( "h" , getFunctionType ( "number" , "string" , /*isArrow*/ true ) . concat ( overloadDisplay ) ) ;
83
+ verifyConst ( "h" , getFunctionType ( "string" , "number" , /*isArrow*/ true ) . concat ( overloadDisplay ) ) ;
0 commit comments