Skip to content

Commit 11f460c

Browse files
committed
JS: Generalize KeyofTypeExpr to UnaryTypeExpr
1 parent 8304ce1 commit 11f460c

7 files changed

Lines changed: 27 additions & 16 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.semmle.ts.ast.InterfaceTypeExpr;
3636
import com.semmle.ts.ast.IntersectionTypeExpr;
3737
import com.semmle.ts.ast.IsTypeExpr;
38-
import com.semmle.ts.ast.KeyofTypeExpr;
38+
import com.semmle.ts.ast.UnaryTypeExpr;
3939
import com.semmle.ts.ast.KeywordTypeExpr;
4040
import com.semmle.ts.ast.MappedTypeExpr;
4141
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -619,7 +619,7 @@ public R visit(TupleTypeExpr nd, C c) {
619619
}
620620

621621
@Override
622-
public R visit(KeyofTypeExpr nd, C c) {
622+
public R visit(UnaryTypeExpr nd, C c) {
623623
return visit((TypeExpression) nd, c);
624624
}
625625

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.semmle.ts.ast.InterfaceTypeExpr;
3232
import com.semmle.ts.ast.IntersectionTypeExpr;
3333
import com.semmle.ts.ast.IsTypeExpr;
34-
import com.semmle.ts.ast.KeyofTypeExpr;
34+
import com.semmle.ts.ast.UnaryTypeExpr;
3535
import com.semmle.ts.ast.KeywordTypeExpr;
3636
import com.semmle.ts.ast.MappedTypeExpr;
3737
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -700,8 +700,8 @@ public INode visit(TupleTypeExpr nd, Void c) {
700700
}
701701

702702
@Override
703-
public INode visit(KeyofTypeExpr nd, Void c) {
704-
return new KeyofTypeExpr(visit(nd.getLoc()), copy(nd.getElementType()));
703+
public INode visit(UnaryTypeExpr nd, Void c) {
704+
return new UnaryTypeExpr(visit(nd.getLoc()), nd.getKind(), copy(nd.getElementType()));
705705
}
706706

707707
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.semmle.ts.ast.InterfaceTypeExpr;
3232
import com.semmle.ts.ast.IntersectionTypeExpr;
3333
import com.semmle.ts.ast.IsTypeExpr;
34-
import com.semmle.ts.ast.KeyofTypeExpr;
34+
import com.semmle.ts.ast.UnaryTypeExpr;
3535
import com.semmle.ts.ast.KeywordTypeExpr;
3636
import com.semmle.ts.ast.MappedTypeExpr;
3737
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -250,7 +250,7 @@ public interface Visitor<C, R> {
250250

251251
public R visit(TupleTypeExpr nd, C c);
252252

253-
public R visit(KeyofTypeExpr nd, C c);
253+
public R visit(UnaryTypeExpr nd, C c);
254254

255255
public R visit(GenericTypeExpr nd, C c);
256256

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
import com.semmle.ts.ast.InterfaceTypeExpr;
126126
import com.semmle.ts.ast.IntersectionTypeExpr;
127127
import com.semmle.ts.ast.IsTypeExpr;
128-
import com.semmle.ts.ast.KeyofTypeExpr;
128+
import com.semmle.ts.ast.UnaryTypeExpr;
129129
import com.semmle.ts.ast.KeywordTypeExpr;
130130
import com.semmle.ts.ast.MappedTypeExpr;
131131
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -1672,7 +1672,7 @@ public Label visit(TupleTypeExpr nd, Context c) {
16721672
}
16731673

16741674
@Override
1675-
public Label visit(KeyofTypeExpr nd, Context c) {
1675+
public Label visit(UnaryTypeExpr nd, Context c) {
16761676
Label key = super.visit(nd, c);
16771677
visit(nd.getElementType(), key, 0, IdContext.typeBind);
16781678
return key;

javascript/extractor/src/com/semmle/js/extractor/TypeExprKinds.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.semmle.ts.ast.InterfaceTypeExpr;
1818
import com.semmle.ts.ast.IntersectionTypeExpr;
1919
import com.semmle.ts.ast.IsTypeExpr;
20-
import com.semmle.ts.ast.KeyofTypeExpr;
20+
import com.semmle.ts.ast.UnaryTypeExpr;
2121
import com.semmle.ts.ast.KeywordTypeExpr;
2222
import com.semmle.ts.ast.MappedTypeExpr;
2323
import com.semmle.ts.ast.OptionalTypeExpr;
@@ -126,7 +126,7 @@ public Integer visit(TupleTypeExpr nd, Void c) {
126126
}
127127

128128
@Override
129-
public Integer visit(KeyofTypeExpr nd, Void c) {
129+
public Integer visit(UnaryTypeExpr nd, Void c) {
130130
return keyofTypeExpr;
131131
}
132132

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
import com.semmle.ts.ast.InterfaceTypeExpr;
127127
import com.semmle.ts.ast.IntersectionTypeExpr;
128128
import com.semmle.ts.ast.IsTypeExpr;
129-
import com.semmle.ts.ast.KeyofTypeExpr;
129+
import com.semmle.ts.ast.UnaryTypeExpr;
130130
import com.semmle.ts.ast.KeywordTypeExpr;
131131
import com.semmle.ts.ast.MappedTypeExpr;
132132
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -2130,7 +2130,7 @@ private Node convertTypeOfExpression(JsonObject node, SourceLocation loc) throws
21302130
private Node convertTypeOperator(JsonObject node, SourceLocation loc) throws ParseError {
21312131
String operator = syntaxKinds.get("" + node.get("operator").getAsInt()).getAsString();
21322132
if (operator.equals("KeyOfKeyword")) {
2133-
return new KeyofTypeExpr(loc, convertChildAsType(node, "type"));
2133+
return new UnaryTypeExpr(loc, UnaryTypeExpr.Kind.Keyof, convertChildAsType(node, "type"));
21342134
}
21352135
if (operator.equals("UniqueKeyword")) {
21362136
return new KeywordTypeExpr(loc, "unique symbol");

javascript/extractor/src/com/semmle/ts/ast/KeyofTypeExpr.java renamed to javascript/extractor/src/com/semmle/ts/ast/UnaryTypeExpr.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,29 @@
44
import com.semmle.js.ast.Visitor;
55

66
/** A type of form <tt>keyof T</tt> where <tt>T</tt> is a type. */
7-
public class KeyofTypeExpr extends TypeExpression {
7+
public class UnaryTypeExpr extends TypeExpression {
88
private final ITypeExpression elementType;
9+
private final Kind kind;
910

10-
public KeyofTypeExpr(SourceLocation loc, ITypeExpression elementType) {
11-
super("KeyofTypeExpr", loc);
11+
public enum Kind {
12+
Keyof,
13+
Readonly
14+
}
15+
16+
public UnaryTypeExpr(SourceLocation loc, Kind kind, ITypeExpression elementType) {
17+
super("UnaryTypeExpr", loc);
18+
this.kind = kind;
1219
this.elementType = elementType;
1320
}
1421

1522
public ITypeExpression getElementType() {
1623
return elementType;
1724
}
1825

26+
public Kind getKind() {
27+
return kind;
28+
}
29+
1930
@Override
2031
public <C, R> R accept(Visitor<C, R> v, C c) {
2132
return v.visit(this, c);

0 commit comments

Comments
 (0)