Skip to content

Commit 09f41bc

Browse files
committed
Throw ParseError for invalid extends clause and add test cases
1 parent 40903a9 commit 09f41bc

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

javascript/extractor/src/com/semmle/ts/extractor/TypeScriptASTConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ private List<ITypeExpression> convertSuperInterfaceClause(JsonArray supers) thro
931931
for (JsonElement elt : supers) {
932932
JsonObject superType = elt.getAsJsonObject();
933933
ITypeExpression objectType = convertChildAsType(superType, "expression");
934-
if (objectType == null) continue;
934+
if (objectType == null) throw new ParseError("Invalid extends clause: expected a type expression", getSourceLocation(superType).getStart());
935935
List<ITypeExpression> typeArguments = convertChildrenAsTypes(superType, "typeArguments");
936936
if (typeArguments.isEmpty()) {
937937
result.add(objectType);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Invalid extends (foo.bar), (foo).bar, foo[bar], foo?.bar, foo!.bar, foo(), import.meta {}
2+
interface Employee extends Person {
3+
position: string;
4+
salary: number;
5+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#10000=@"/invalidExtends.ts;sourcefile"
2+
files(#10000,"/invalidExtends.ts")
3+
#10001=@"/;folder"
4+
folders(#10001,"/")
5+
containerparent(#10001,#10000)
6+
#10002=@"loc,{#10000},0,0,0,0"
7+
locations_default(#10002,#10000,0,0,0,0)
8+
hasLocation(#10000,#10002)
9+
#20000=@"global_scope"
10+
scopes(#20000,0)
11+
#20001=@"script;{#10000},1,1"
12+
toplevels(#20001,0)
13+
#20002=@"loc,{#10000},1,1,1,1"
14+
locations_default(#20002,#10000,1,1,1,1)
15+
hasLocation(#20001,#20002)
16+
#20003=*
17+
js_parse_errors(#20003,#20001,"Error: Invalid extends clause: expected a type expression","interface Invalid extends (foo.bar), (foo).bar, foo[bar], foo?.bar, foo!.bar, foo(), import.meta {}
18+
")
19+
#20004=@"loc,{#10000},1,27,1,27"
20+
locations_default(#20004,#10000,1,27,1,27)
21+
hasLocation(#20003,#20004)
22+
#20005=*
23+
lines(#20005,#20001,"interface Invalid extends (foo.bar), (foo).bar, foo[bar], foo?.bar, foo!.bar, foo(), import.meta {}","
24+
")
25+
#20006=@"loc,{#10000},1,1,1,99"
26+
locations_default(#20006,#10000,1,1,1,99)
27+
hasLocation(#20005,#20006)
28+
#20007=*
29+
lines(#20007,#20001,"interface Employee extends Person {","
30+
")
31+
#20008=@"loc,{#10000},2,1,2,35"
32+
locations_default(#20008,#10000,2,1,2,35)
33+
hasLocation(#20007,#20008)
34+
#20009=*
35+
lines(#20009,#20001," position: string;","
36+
")
37+
#20010=@"loc,{#10000},3,1,3,21"
38+
locations_default(#20010,#10000,3,1,3,21)
39+
hasLocation(#20009,#20010)
40+
indentation(#10000,3," ",4)
41+
#20011=*
42+
lines(#20011,#20001," salary: number;","
43+
")
44+
#20012=@"loc,{#10000},4,1,4,19"
45+
locations_default(#20012,#10000,4,1,4,19)
46+
hasLocation(#20011,#20012)
47+
indentation(#10000,4," ",4)
48+
#20013=*
49+
lines(#20013,#20001,"}","
50+
")
51+
#20014=@"loc,{#10000},5,1,5,1"
52+
locations_default(#20014,#10000,5,1,5,1)
53+
hasLocation(#20013,#20014)
54+
numlines(#20001,5,0,0)
55+
numlines(#10000,5,0,0)
56+
filetype(#10000,"typescript")

0 commit comments

Comments
 (0)