Skip to content

Commit a5f2c94

Browse files
committed
JS: Add UnionOrIntersectionTypeExpr
1 parent ec55c84 commit a5f2c94

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

javascript/ql/lib/semmle/javascript/TypeScript.qll

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -896,21 +896,28 @@ class ArrayTypeExpr extends @array_typeexpr, TypeExpr {
896896
override string getAPrimaryQlClass() { result = "ArrayTypeExpr" }
897897
}
898898

899+
private class RawUnionOrIntersectionTypeExpr = @union_typeexpr or @intersection_typeexpr;
900+
899901
/**
900-
* A union type, such as `string|number|boolean`.
902+
* A union or intersection type, such as `string|number|boolean` or `A & B`.
901903
*/
902-
class UnionTypeExpr extends @union_typeexpr, TypeExpr {
903-
/** Gets the `n`th type in the union, starting at 0. */
904+
class UnionOrIntersectionTypeExpr extends RawUnionOrIntersectionTypeExpr, TypeExpr {
905+
/** Gets the `n`th type in the union or intersection, starting at 0. */
904906
TypeExpr getElementType(int n) { result = this.getChildTypeExpr(n) }
905907

906-
/** Gets any of the types in the union. */
908+
/** Gets any of the types in the union or intersection. */
907909
TypeExpr getAnElementType() { result = this.getElementType(_) }
908910

909-
/** Gets the number of types in the union. This is always at least two. */
911+
/** Gets the number of types in the union or intersection. This is always at least two. */
910912
int getNumElementType() { result = count(this.getAnElementType()) }
911913

912914
override TypeExpr getAnUnderlyingType() { result = this.getAnElementType().getAnUnderlyingType() }
915+
}
913916

917+
/**
918+
* A union type, such as `string|number|boolean`.
919+
*/
920+
class UnionTypeExpr extends @union_typeexpr, UnionOrIntersectionTypeExpr {
914921
override string getAPrimaryQlClass() { result = "UnionTypeExpr" }
915922
}
916923

@@ -932,18 +939,7 @@ class IndexedAccessTypeExpr extends @indexed_access_typeexpr, TypeExpr {
932939
*
933940
* In general, there are can more than two operands to an intersection type.
934941
*/
935-
class IntersectionTypeExpr extends @intersection_typeexpr, TypeExpr {
936-
/** Gets the `n`th operand of the intersection type, starting at 0. */
937-
TypeExpr getElementType(int n) { result = this.getChildTypeExpr(n) }
938-
939-
/** Gets any of the operands to the intersection type. */
940-
TypeExpr getAnElementType() { result = this.getElementType(_) }
941-
942-
/** Gets the number of operands to the intersection type. This is always at least two. */
943-
int getNumElementType() { result = count(this.getAnElementType()) }
944-
945-
override TypeExpr getAnUnderlyingType() { result = this.getAnElementType().getAnUnderlyingType() }
946-
942+
class IntersectionTypeExpr extends @intersection_typeexpr, UnionOrIntersectionTypeExpr {
947943
override string getAPrimaryQlClass() { result = "IntersectionTypeExpr" }
948944
}
949945

0 commit comments

Comments
 (0)