TS: Support const type assertions

This commit is contained in:
Asger F
2019-04-10 12:54:42 +01:00
parent d5ae69d40a
commit c1c7ebfc48
9 changed files with 51 additions and 9 deletions

View File

@@ -0,0 +1,6 @@
test_ConstKeyword
| tst.ts:1:19:1:23 | const |
| tst.ts:2:10:2:14 | const |
test_ConstTypeAssertion
| tst.ts:1:9:1:23 | [1, 2] as const |
| tst.ts:2:9:2:21 | <const>[1, 2] |

View File

@@ -0,0 +1,9 @@
import javascript
query predicate test_ConstKeyword(TypeExpr t) {
t.isConstKeyword()
}
query predicate test_ConstTypeAssertion(TypeAssertion t) {
t.getTypeAnnotation().isConstKeyword()
}

View File

@@ -0,0 +1,2 @@
var x = [1, 2] as const;
var x = <const>[1, 2];

View File

@@ -80,6 +80,16 @@
| tst.ts:38:5:38:24 | tupleWithRestElement | [number, ...string[]] |
| tst.ts:39:5:39:36 | tupleWi ... lements | [number, string?, ...number[]] |
| tst.ts:40:5:40:15 | unknownType | unknown |
| tst.ts:42:5:42:21 | constArrayLiteral | readonly [1, 2] |
| tst.ts:42:25:42:30 | [1, 2] | readonly [1, 2] |
| tst.ts:42:25:42:39 | [1, 2] as const | readonly [1, 2] |
| tst.ts:42:26:42:26 | 1 | 1 |
| tst.ts:42:29:42:29 | 2 | 2 |
| tst.ts:43:5:43:22 | constObjectLiteral | { readonly foo: "foo"; } |
| tst.ts:43:26:43:39 | { foo: "foo" } | { readonly foo: "foo"; } |
| tst.ts:43:26:43:48 | { foo: ... s const | { readonly foo: "foo"; } |
| tst.ts:43:28:43:30 | foo | "foo" |
| tst.ts:43:33:43:37 | "foo" | "foo" |
| type_alias.ts:3:5:3:5 | b | boolean |
| type_definition_objects.ts:1:13:1:17 | dummy | typeof dummy.ts |
| type_definition_objects.ts:1:24:1:32 | "./dummy" | any |

View File

@@ -68,6 +68,8 @@
| tst.ts:39:60:39:65 | number | number |
| tst.ts:39:60:39:67 | number[] | number[] |
| tst.ts:40:18:40:24 | unknown | unknown |
| tst.ts:42:35:42:39 | const | any |
| tst.ts:43:44:43:48 | const | any |
| type_alias.ts:1:6:1:6 | B | boolean |
| type_alias.ts:1:10:1:16 | boolean | boolean |
| type_alias.ts:3:8:3:8 | B | boolean |

View File

@@ -8,3 +8,9 @@
| tst.ts:39:5:39:36 | tupleWi ... lements | [number, string?, ...number[]] | 0 | number | 1 | number |
| tst.ts:39:5:39:36 | tupleWi ... lements | [number, string?, ...number[]] | 1 | string | 1 | number |
| tst.ts:39:5:39:36 | tupleWi ... lements | [number, string?, ...number[]] | 2 | number | 1 | number |
| tst.ts:42:5:42:21 | constArrayLiteral | readonly [1, 2] | 0 | 1 | 2 | no-rest |
| tst.ts:42:5:42:21 | constArrayLiteral | readonly [1, 2] | 1 | 2 | 2 | no-rest |
| tst.ts:42:25:42:30 | [1, 2] | readonly [1, 2] | 0 | 1 | 2 | no-rest |
| tst.ts:42:25:42:30 | [1, 2] | readonly [1, 2] | 1 | 2 | 2 | no-rest |
| tst.ts:42:25:42:39 | [1, 2] as const | readonly [1, 2] | 0 | 1 | 2 | no-rest |
| tst.ts:42:25:42:39 | [1, 2] as const | readonly [1, 2] | 1 | 2 | 2 | no-rest |

View File

@@ -37,4 +37,7 @@ let tupleWithOptionalElement: [number, string, number?];
let emptyTuple: [];
let tupleWithRestElement: [number, ...string[]];
let tupleWithOptionalAndRestElements: [number, string?, ...number[]];
let unknownType: unknown;
let unknownType: unknown;
let constArrayLiteral = [1, 2] as const;
let constObjectLiteral = { foo: "foo" } as const;