@@ -23,7 +23,7 @@ namespace ts {
23
23
}
24
24
const xs: number[] = [1,2,3];
25
25
`
26
- } ] , ( ) => void 0 , ScriptTarget . ES3 , /*useCaseSensitiveFileNames*/ true , "" , NewLineKind . CarriageReturnLineFeed ) ;
26
+ } ] , ( ) => void 0 , ScriptTarget . ES3 , /*useCaseSensitiveFileNames*/ true , "" , NewLineKind . CarriageReturnLineFeed ) ;
27
27
program = ts . createProgram ( [ "test.ts" ] , ts . defaultInitCompilerOptions , host ) ;
28
28
const diag = ts . getPreEmitDiagnostics ( program ) ;
29
29
if ( diag . length ) {
@@ -87,42 +87,42 @@ namespace ts {
87
87
} ) ;
88
88
89
89
it ( "can get string literal types" , ( ) => {
90
- assert ( ( checker . getStringLiteralType ( "foobar" ) as LiteralType ) . text === "foobar" ) ;
90
+ assert ( ( checker . getLiteralType ( "foobar" ) as LiteralType ) . value === "foobar" ) ;
91
91
} ) ;
92
92
93
93
it ( "can get numeber literal types" , ( ) => {
94
- assert ( ( checker . getNumberLiteralType ( "42" ) as LiteralType ) . text === "42" ) ;
94
+ assert ( ( checker . getLiteralType ( 42 ) as LiteralType ) . value === "42" ) ;
95
95
} ) ;
96
96
97
97
it ( "doesn't choke on exceptional input to literal type getters" , ( ) => {
98
- assert . equal ( ( checker . getStringLiteralType ( "" ) as LiteralType ) . text , "" ) ;
99
- assert . throws ( ( ) => checker . getStringLiteralType ( undefined ) , Error , "Debug Failure. False expression:" ) ;
98
+ assert . equal ( ( checker . getLiteralType ( "" ) as LiteralType ) . value , "" ) ;
99
+ assert . throws ( ( ) => checker . getLiteralType ( /*content*/ undefined ) , Error , "Debug Failure. False expression:" ) ;
100
100
/* tslint:disable:no-null-keyword */
101
- assert . throws ( ( ) => checker . getStringLiteralType ( null ) , Error , "Debug Failure. False expression:" ) ;
101
+ assert . throws ( ( ) => checker . getLiteralType ( /*content*/ null ) , Error , "Debug Failure. False expression:" ) ;
102
102
/* tslint:enable:no-null-keyword */
103
103
let hugeStringLiteral = map ( new Array ( 2 ** 16 - 1 ) , ( ) => "a" ) . join ( ) ;
104
- assert . equal ( ( checker . getStringLiteralType ( hugeStringLiteral ) as LiteralType ) . text , hugeStringLiteral ) ;
104
+ assert . equal ( ( checker . getLiteralType ( hugeStringLiteral ) as LiteralType ) . value , hugeStringLiteral ) ;
105
105
hugeStringLiteral = undefined ;
106
106
107
107
108
- assert . throws ( ( ) => checker . getNumberLiteralType ( undefined ) , Error , "Debug Failure. False expression:" ) ;
108
+ assert . throws ( ( ) => checker . getLiteralType ( /*content*/ undefined ) , Error , "Debug Failure. False expression:" ) ;
109
109
/* tslint:disable:no-null-keyword */
110
- assert . throws ( ( ) => checker . getNumberLiteralType ( null ) , Error , "Debug Failure. False expression:" ) ;
110
+ assert . throws ( ( ) => checker . getLiteralType ( /*content*/ null ) , Error , "Debug Failure. False expression:" ) ;
111
111
/* tslint:enable:no-null-keyword */
112
112
113
113
const sanityChecks = [ "000" , "0b0" , "0x0" , "0.0" , "0e-0" , "-010" , "-0b10" , "-0x10" , "-0o10" , "-10.0" , "-1e-1" , "NaN" , "Infinity" , "-Infinity" ] ;
114
114
forEach ( sanityChecks , num => {
115
- assert . equal ( ( checker . getNumberLiteralType ( num ) as LiteralType ) . text , num , `${ num } did not match.` ) ;
115
+ assert . equal ( ( checker . getLiteralType ( num ) as LiteralType ) . value , num , `${ num } did not match.` ) ;
116
116
} ) ;
117
117
118
118
const insanityChecks = [ [ 0 , "0" ] , [ 0b0 , "0" ] , [ - 10 , "-10" ] , [ NaN , "NaN" ] , [ Infinity , "Infinity" ] , [ - Infinity , "-Infinity" ] ] ;
119
119
forEach ( insanityChecks , ( [ num , expected ] ) => {
120
- assert . equal ( ( checker . getNumberLiteralType ( num as any ) as LiteralType ) . text , expected , `${ JSON . stringify ( num ) } should be ${ expected } ` ) ;
120
+ assert . equal ( ( checker . getLiteralType ( num as any ) as LiteralType ) . value , expected , `${ JSON . stringify ( num ) } should be ${ expected } ` ) ;
121
121
} ) ;
122
122
123
123
const instabilityChecks = [ { foo : 42 } , new Date ( 42 ) , [ 42 ] , new Number ( 42 ) , new String ( "42" ) ] ;
124
124
forEach ( instabilityChecks , ( bad ) => {
125
- assert . throws ( ( ) => checker . getNumberLiteralType ( bad as any ) ) ;
125
+ assert . throws ( ( ) => checker . getLiteralType ( bad as any ) ) ;
126
126
} ) ;
127
127
} ) ;
128
128
@@ -152,7 +152,7 @@ namespace ts {
152
152
assert . notEqual ( checker . lookupGlobalType ( "Function" ) , innerFunction , "Inner function type should be different than global" ) ;
153
153
const brandNameType = checker . getTypeOfSymbol ( innerFunction . getProperty ( "myBrand" ) ) ;
154
154
assert . notEqual ( brandNameType , checker . getUnknownType ( ) , "Brand type on inner function should not be unknown" ) ;
155
- assert . equal ( brandNameType , checker . getNumberLiteralType ( "42" ) , "Brand type should be 42" ) ;
155
+ assert . equal ( brandNameType , checker . getLiteralType ( 42 ) , "Brand type should be 42" ) ;
156
156
157
157
let skipped = false ;
158
158
const functionBody2 = forEachChild ( program . getSourceFile ( "test.ts" ) , node => node . kind === SyntaxKind . FunctionDeclaration ? skipped ? ( node as FunctionDeclaration ) : ( skipped = true , undefined ) : undefined ) . body ;
0 commit comments