mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
JS: Add TypeAnnotations class
This commit is contained in:
@@ -49,6 +49,7 @@ import semmle.javascript.StringConcatenation
|
||||
import semmle.javascript.StringOps
|
||||
import semmle.javascript.Templates
|
||||
import semmle.javascript.Tokens
|
||||
import semmle.javascript.TypeAnnotations
|
||||
import semmle.javascript.TypeScript
|
||||
import semmle.javascript.Util
|
||||
import semmle.javascript.Variables
|
||||
|
||||
70
javascript/ql/src/semmle/javascript/TypeAnnotations.qll
Normal file
70
javascript/ql/src/semmle/javascript/TypeAnnotations.qll
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Provides classes for reasoning about type annotations independently of dialect.
|
||||
*/
|
||||
|
||||
import javascript
|
||||
|
||||
/**
|
||||
* A type annotation, either in the form of a TypeScript type or a JSDoc comment.
|
||||
*/
|
||||
class TypeAnnotation extends @type_annotation {
|
||||
/** Gets a string representation of this type. */
|
||||
string toString() { none() }
|
||||
|
||||
/** Holds if this is the `any` type. */
|
||||
predicate isAny() { none() }
|
||||
|
||||
/** Holds if this is the `string` type. Does not hold for the (rarely used) `String` type. */
|
||||
predicate isString() { none() }
|
||||
|
||||
/** Holds if this is the `string` or `String` type. */
|
||||
predicate isStringy() { none() }
|
||||
|
||||
/** Holds if this is the `number` type. Does not hold for the (rarely used) `Number` type. */
|
||||
predicate isNumber() { none() }
|
||||
|
||||
/** Holds if this is the `number` or `Number`s type. */
|
||||
predicate isNumbery() { none() }
|
||||
|
||||
/** Holds if this is the `boolean` type. Does not hold for the (rarely used) `Boolean` type. */
|
||||
predicate isBoolean() { none() }
|
||||
|
||||
/** Holds if this is the `boolean` or `Boolean` type. */
|
||||
predicate isBooleany() { none() }
|
||||
|
||||
/** Holds if this is the `undefined` type. */
|
||||
predicate isUndefined() { none() }
|
||||
|
||||
/** Holds if this is the `null` type. */
|
||||
predicate isNull() { none() }
|
||||
|
||||
/** Holds if this is the `void` type. */
|
||||
predicate isVoid() { none() }
|
||||
|
||||
/** Holds if this is the `never` type, or an equivalent type representing the empty set of values. */
|
||||
predicate isNever() { none() }
|
||||
|
||||
/** Holds if this is the `this` type. */
|
||||
predicate isThis() { none() }
|
||||
|
||||
/** Holds if this is the `symbol` type. */
|
||||
predicate isSymbol() { none() }
|
||||
|
||||
/** Holds if this is the `unique symbol` type. */
|
||||
predicate isUniqueSymbol() { none() }
|
||||
|
||||
/** Holds if this is the `Function` type. */
|
||||
predicate isRawFunction() { none() }
|
||||
|
||||
/** Holds if this is the `object` type. */
|
||||
predicate isObjectKeyword() { none() }
|
||||
|
||||
/** Holds if this is the `unknown` type. */
|
||||
predicate isUnknownKeyword() { none() }
|
||||
|
||||
/** Holds if this is the `bigint` type. */
|
||||
predicate isBigInt() { none() }
|
||||
|
||||
/** Holds if this is the `const` keyword, occurring in a type assertion such as `x as const`. */
|
||||
predicate isConstKeyword() { none() }
|
||||
}
|
||||
@@ -528,66 +528,9 @@ class LocalNamespaceName extends @local_namespace_name, LexicalName {
|
||||
* This class includes only explicit type annotations -
|
||||
* types inferred by the TypeScript compiler are not type expressions.
|
||||
*/
|
||||
class TypeExpr extends ExprOrType, @typeexpr {
|
||||
class TypeExpr extends ExprOrType, @typeexpr, TypeAnnotation {
|
||||
override string toString() { typeexprs(this, _, _, _, result) }
|
||||
|
||||
/** Holds if this is the `any` type. */
|
||||
predicate isAny() { none() }
|
||||
|
||||
/** Holds if this is the `string` type. Does not hold for the (rarely used) `String` type. */
|
||||
predicate isString() { none() }
|
||||
|
||||
/** Holds if this is the `string` or `String` type. */
|
||||
predicate isStringy() { none() }
|
||||
|
||||
/** Holds if this is the `number` type. Does not hold for the (rarely used) `Number` type. */
|
||||
predicate isNumber() { none() }
|
||||
|
||||
/** Holds if this is the `number` or `Number`s type. */
|
||||
predicate isNumbery() { none() }
|
||||
|
||||
/** Holds if this is the `boolean` type. Does not hold for the (rarely used) `Boolean` type. */
|
||||
predicate isBoolean() { none() }
|
||||
|
||||
/** Holds if this is the `boolean` or `Boolean` type. */
|
||||
predicate isBooleany() { none() }
|
||||
|
||||
/** Holds if this is the `undefined` type. */
|
||||
predicate isUndefined() { none() }
|
||||
|
||||
/** Holds if this is the `null` type. */
|
||||
predicate isNull() { none() }
|
||||
|
||||
/** Holds if this is the `void` type. */
|
||||
predicate isVoid() { none() }
|
||||
|
||||
/** Holds if this is the `never` type. */
|
||||
predicate isNever() { none() }
|
||||
|
||||
/** Holds if this is the `this` type. */
|
||||
predicate isThis() { none() }
|
||||
|
||||
/** Holds if this is the `symbol` type. */
|
||||
predicate isSymbol() { none() }
|
||||
|
||||
/** Holds if this is the `unique symbol` type. */
|
||||
predicate isUniqueSymbol() { none() }
|
||||
|
||||
/** Holds if this is the `Function` type. */
|
||||
predicate isRawFunction() { none() }
|
||||
|
||||
/** Holds if this is the `object` type. */
|
||||
predicate isObjectKeyword() { none() }
|
||||
|
||||
/** Holds if this is the `unknown` type. */
|
||||
predicate isUnknownKeyword() { none() }
|
||||
|
||||
/** Holds if this is the `bigint` type. */
|
||||
predicate isBigInt() { none() }
|
||||
|
||||
/** Holds if this is the `const` keyword, occurring in a type assertion such as `x as const`. */
|
||||
predicate isConstKeyword() { none() }
|
||||
|
||||
/** Gets this type expression, with any surrounding parentheses removed. */
|
||||
override TypeExpr stripParens() { result = this }
|
||||
|
||||
|
||||
@@ -232,6 +232,7 @@ isDelegating (int yield: @yieldexpr ref);
|
||||
@exprortype = @expr | @typeexpr;
|
||||
@exprparent = @exprorstmt | @property | @functiontypeexpr;
|
||||
@arraylike = @arrayexpr | @arraypattern;
|
||||
@type_annotation = @typeexpr | @jsdoc_type_expr;
|
||||
|
||||
case @expr.kind of
|
||||
0 = @label
|
||||
|
||||
Reference in New Issue
Block a user