Skip to content

Commit 1468e81

Browse files
committed
Ensure interface extends valid expr.
1 parent 40903a9 commit 1468e81

File tree

7 files changed

+466
-13
lines changed

7 files changed

+466
-13
lines changed

javascript/extractor/src/com/semmle/js/ast/MemberExpression.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@ public int getSymbol() {
6969
public void setSymbol(int symbol) {
7070
this.symbol = symbol;
7171
}
72+
73+
@Override
74+
public boolean isValidExpression() {
75+
return object instanceof ITypeExpression || object instanceof DynamicImport;
76+
}
7277
}

javascript/extractor/src/com/semmle/ts/ast/ITypeExpression.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
* however, some expressions such as {@link Literal} type may occur in a type annotation because the
1111
* TypeScript AST does not distinguish <code>null</code> literals from the <code>null</code> type.
1212
*/
13-
public interface ITypeExpression extends INode, ITypedAstNode {}
13+
public interface ITypeExpression extends INode, ITypedAstNode {
14+
public default boolean isValidExpression() { return true; }
15+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,7 @@ private Node convertOptionalType(JsonObject node, SourceLocation loc) throws Par
19071907
}
19081908

19091909
private ITypeExpression asType(Node node) {
1910-
return node instanceof ITypeExpression ? (ITypeExpression) node : null;
1910+
return node instanceof ITypeExpression && ((ITypeExpression)node).isValidExpression() ? (ITypeExpression) node : null;
19111911
}
19121912

19131913
private List<ITypeExpression> convertChildrenAsTypes(JsonObject node, String child)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface Invalid extends (foo.bar) {}
2+
interface Invalid extends (foo).bar {}
3+
interface Invalid extends foo[bar] {}
4+
interface Invalid extends foo?.bar {}
5+
interface Invalid extends foo!.bar {}
6+
interface Invalid extends foo() {}

0 commit comments

Comments
 (0)