Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea583fe

Browse files
committed
add basic support for named tuple elements
1 parent 2612e0c commit ea583fe

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

javascript/extractor/src/com/semmle/js/parser/TypeScriptASTConverter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ private Node convertNodeUntyped(JsonObject node, String defaultKind) throws Pars
585585
return convertTryStatement(node, loc);
586586
case "TupleType":
587587
return convertTupleType(node, loc);
588+
case "NamedTupleMember":
589+
return convertNamedTupleMember(node, loc);
588590
case "TypeAliasDeclaration":
589591
return convertTypeAliasDeclaration(node, loc);
590592
case "TypeAssertionExpression":
@@ -2180,6 +2182,10 @@ private Node convertTupleType(JsonObject node, SourceLocation loc) throws ParseE
21802182
return new TupleTypeExpr(loc, convertChildrenAsTypes(node, "elements"));
21812183
}
21822184

2185+
private Node convertNamedTupleMember(JsonObject node, SourceLocation loc) throws ParseError {
2186+
return convertChild(node, "type");
2187+
}
2188+
21832189
private Node convertTypeAliasDeclaration(JsonObject node, SourceLocation loc) throws ParseError {
21842190
TypeAliasDeclaration typeAlias =
21852191
new TypeAliasDeclaration(

javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tests.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ test_VariableTypes
111111
| tst.ts:157:32:157:34 | arr | arr | tst.ts:157:37:157:56 | readonly [any, ...T] |
112112
| tst.ts:164:47:164:50 | arr1 | arr1 | tst.ts:164:53:164:53 | T |
113113
| tst.ts:164:56:164:59 | arr2 | arr2 | tst.ts:164:62:164:62 | U |
114+
| tst.ts:169:31:169:31 | x | x | tst.ts:169:34:169:64 | [first: ... number] |
114115
test_QualifiedTypeAccess
115116
| tst.ts:63:19:63:21 | N.I | tst.ts:63:19:63:19 | N | tst.ts:63:21:63:21 | I |
116117
| tst.ts:64:20:64:24 | N.M.I | tst.ts:64:20:64:22 | N.M | tst.ts:64:24:64:24 | I |
@@ -205,6 +206,8 @@ test_TupleTypeExpr
205206
| tst.ts:157:46:157:56 | [any, ...T] | 1 | 2 | tst.ts:157:52:157:55 | ...T |
206207
| tst.ts:164:66:164:77 | [...T, ...U] | 0 | 2 | tst.ts:164:67:164:70 | ...T |
207208
| tst.ts:164:66:164:77 | [...T, ...U] | 1 | 2 | tst.ts:164:73:164:76 | ...U |
209+
| tst.ts:169:34:169:64 | [first: ... number] | 0 | 2 | tst.ts:169:42:169:47 | number |
210+
| tst.ts:169:34:169:64 | [first: ... number] | 1 | 2 | tst.ts:169:58:169:63 | number |
208211
test_FieldTypes
209212
| tst.ts:15:3:15:22 | numberField: number; | tst.ts:15:16:15:21 | number |
210213
| tst.ts:16:3:16:22 | stringField: string; | tst.ts:16:16:16:21 | string |
@@ -280,6 +283,7 @@ test_ReturnTypes
280283
| tst.ts:142:1:146:1 | functio ... )\\n }\\n} | function assert | tst.ts:142:48:142:64 | asserts condition |
281284
| tst.ts:148:1:152:1 | functio ... ;\\n }\\n} | function assertIsString | tst.ts:148:36:148:56 | asserts ... string |
282285
| tst.ts:164:1:166:1 | functio ... rr2];\\n} | function concat | tst.ts:164:66:164:77 | [...T, ...U] |
286+
| tst.ts:169:1:172:1 | functio ... + b;\\n} | function labelOnTupleElements | tst.ts:169:68:169:73 | number |
283287
test_KeyofTypeExpr
284288
| tst.ts:49:16:49:30 | keyof Interface | tst.ts:49:22:49:30 | Interface |
285289
| tst.ts:113:26:113:35 | keyof Node | tst.ts:113:32:113:35 | Node |

javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tst.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ function tail<T extends any[]>(arr: readonly [any, ...T]) {
163163
type Arr = readonly any[];
164164
function concat<T extends Arr, U extends Arr>(arr1: T, arr2: U): [...T, ...U] {
165165
return [...arr1, ...arr2];
166+
}
167+
168+
// labelled tuple elements
169+
function labelOnTupleElements(x: [first: number, second: number]): number {
170+
let [a, b] = x;
171+
return a + b;
166172
}

0 commit comments

Comments
 (0)