JS: Deprecate everything that depends on type extraction

This commit is contained in:
Asger F
2025-06-02 14:34:28 +02:00
parent f5ac3fd611
commit ee9c4fa763
7 changed files with 73 additions and 75 deletions

View File

@@ -47,7 +47,7 @@ import semmle.javascript.NodeJS
import semmle.javascript.NPM
import semmle.javascript.Paths
import semmle.javascript.Promises
import semmle.javascript.CanonicalNames
deprecated import semmle.javascript.CanonicalNames
import semmle.javascript.RangeAnalysis
import semmle.javascript.Regexp
import semmle.javascript.Routing

View File

@@ -1,6 +1,7 @@
/**
* Provides classes for working with name resolution of namespaces and types.
*/
deprecated module;
import javascript
@@ -18,7 +19,7 @@ import javascript
*
* This class is only populated when full TypeScript extraction is enabled.
*/
class CanonicalName extends @symbol {
deprecated class CanonicalName extends @symbol {
/**
* Gets the parent of this canonical name, that is, the prefix of its qualified name.
*/
@@ -218,7 +219,7 @@ class CanonicalName extends @symbol {
/**
* The canonical name for a type.
*/
class TypeName extends CanonicalName {
deprecated class TypeName extends CanonicalName {
TypeName() {
exists(TypeReference ref | type_symbol(ref, this)) or
exists(TypeDefinition def | ast_node_symbol(def, this)) or
@@ -261,7 +262,7 @@ class TypeName extends CanonicalName {
/**
* The canonical name for a namespace.
*/
class Namespace extends CanonicalName {
deprecated class Namespace extends CanonicalName {
Namespace() {
this.getAChild().isExportedMember() or
exists(NamespaceDefinition def | ast_node_symbol(def, this)) or
@@ -309,7 +310,7 @@ class Namespace extends CanonicalName {
/**
* The canonical name for a function.
*/
class CanonicalFunctionName extends CanonicalName {
deprecated class CanonicalFunctionName extends CanonicalName {
CanonicalFunctionName() {
exists(Function fun | ast_node_symbol(fun, this)) or
exists(InvokeExpr invoke | ast_node_symbol(invoke, this))

View File

@@ -119,7 +119,7 @@ class ClassOrInterface extends @class_or_interface, TypeParameterized {
*
* Anonymous classes and interfaces do not have a canonical name.
*/
TypeName getTypeName() { result.getADefinition() = this }
deprecated TypeName getTypeName() { result.getADefinition() = this }
/**
* Gets the ClassOrInterface corresponding to either a super type or an implemented interface.

View File

@@ -176,7 +176,7 @@ class Expr extends @expr, ExprOrStmt, ExprOrType, AST::ValueNode {
* Has no result if the expression is in a JavaScript file or in a TypeScript
* file that was extracted without type information.
*/
Type getType() { ast_node_type(this, result) }
deprecated Type getType() { ast_node_type(this, result) }
/**
* Holds if the syntactic context that the expression appears in relies on the expression
@@ -993,7 +993,7 @@ class InvokeExpr extends @invokeexpr, Expr {
*
* This predicate is only populated for files extracted with full TypeScript extraction.
*/
CallSignatureType getResolvedSignature() { invoke_expr_signature(this, result) }
deprecated CallSignatureType getResolvedSignature() { invoke_expr_signature(this, result) }
/**
* Gets the index of the targeted call signature among the overload signatures
@@ -1008,7 +1008,7 @@ class InvokeExpr extends @invokeexpr, Expr {
*
* This predicate is only populated for files extracted with full TypeScript extraction.
*/
CanonicalFunctionName getResolvedCalleeName() { ast_node_symbol(this, result) }
deprecated CanonicalFunctionName getResolvedCalleeName() { ast_node_symbol(this, result) }
/**
* Gets the statically resolved target function, as determined by the TypeScript type system, if any.
@@ -1016,11 +1016,7 @@ class InvokeExpr extends @invokeexpr, Expr {
* Note that the resolved function may be overridden in a subclass and thus is not
* necessarily the actual target of this invocation at runtime.
*/
Function getResolvedCallee() {
TypeResolution::callTarget(this, result)
or
result = this.getResolvedCalleeName().getImplementation()
}
Function getResolvedCallee() { TypeResolution::callTarget(this, result) }
}
/**

View File

@@ -434,12 +434,12 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
*
* This predicate is only populated for files extracted with full TypeScript extraction.
*/
CanonicalFunctionName getCanonicalName() { ast_node_symbol(this, result) }
deprecated CanonicalFunctionName getCanonicalName() { ast_node_symbol(this, result) }
/**
* Gets the call signature of this function, as determined by the TypeScript compiler, if any.
*/
CallSignatureType getCallSignature() { declared_function_signature(this, result) }
deprecated CallSignatureType getCallSignature() { declared_function_signature(this, result) }
}
/**

View File

@@ -135,7 +135,7 @@ class TypeAnnotation extends @type_annotation, NodeInStmtContainer {
*
* Note that this has no result for JSDoc type annotations.
*/
Type getType() { none() }
deprecated Type getType() { none() }
/**
* Gets the class referenced by this type annotation, if any.

View File

@@ -32,7 +32,7 @@ class NamespaceDefinition extends Stmt, @namespace_definition, AST::ValueNode {
/**
* Gets the canonical name of the namespace being defined.
*/
Namespace getNamespace() { result.getADefinition() = this }
deprecated Namespace getNamespace() { result.getADefinition() = this }
}
/**
@@ -112,12 +112,12 @@ class TypeDefinition extends AstNode, @type_definition {
/**
* Gets the canonical name of the type being defined.
*/
TypeName getTypeName() { result.getADefinition() = this }
deprecated TypeName getTypeName() { result.getADefinition() = this }
/**
* Gets the type defined by this declaration.
*/
Type getType() { ast_node_type(this.getIdentifier(), result) }
deprecated Type getType() { ast_node_type(this.getIdentifier(), result) }
override string getAPrimaryQlClass() { result = "TypeDefinition" }
}
@@ -269,7 +269,7 @@ class TypeAliasDeclaration extends @type_alias_declaration, TypeParameterized, S
/**
* Gets the canonical name of the type being defined.
*/
TypeName getTypeName() { result.getADefinition() = this }
deprecated TypeName getTypeName() { result.getADefinition() = this }
override string getAPrimaryQlClass() { result = "TypeAliasDeclaration" }
}
@@ -549,7 +549,7 @@ class LocalNamespaceName extends @local_namespace_name, LexicalName {
/**
* Gets the canonical name of the namespace referenced by this name.
*/
Namespace getNamespace() { result = this.getADeclaration().getNamespace() }
deprecated Namespace getNamespace() { result = this.getADeclaration().getNamespace() }
override DeclarationSpace getDeclarationSpace() { result = "namespace" }
}
@@ -569,7 +569,7 @@ class TypeExpr extends ExprOrType, @typeexpr, TypeAnnotation {
* Has no result if this occurs in a TypeScript file that was extracted
* without type information.
*/
override Type getType() { ast_node_type(this, result) }
deprecated override Type getType() { ast_node_type(this, result) }
override Stmt getEnclosingStmt() { result = ExprOrType.super.getEnclosingStmt() }
@@ -693,7 +693,7 @@ class TypeAccess extends @typeaccess, TypeExpr, TypeRef {
/**
* Gets the canonical name of the type being accessed.
*/
TypeName getTypeName() { ast_node_symbol(this, result) }
deprecated TypeName getTypeName() { ast_node_symbol(this, result) }
override string getAPrimaryQlClass() { result = "TypeAccess" }
}
@@ -1380,7 +1380,7 @@ class LocalNamespaceDecl extends VarDecl, NamespaceRef {
/**
* Gets the canonical name of the namespace being defined or aliased by this name.
*/
Namespace getNamespace() { ast_node_symbol(this, result) }
deprecated Namespace getNamespace() { ast_node_symbol(this, result) }
}
/**
@@ -1398,7 +1398,7 @@ class NamespaceAccess extends TypeExpr, NamespaceRef, @namespace_access {
/**
* Gets the canonical name of the namespace being accessed.
*/
Namespace getNamespace() { ast_node_symbol(this, result) }
deprecated Namespace getNamespace() { ast_node_symbol(this, result) }
override string getAPrimaryQlClass() { result = "NamespaceAccess" }
}
@@ -1507,7 +1507,7 @@ class EnumDeclaration extends NamespaceDefinition, @enum_declaration, AST::Value
/**
* Gets the canonical name of the type being defined.
*/
TypeName getTypeName() { ast_node_symbol(this, result) }
deprecated TypeName getTypeName() { ast_node_symbol(this, result) }
/**
* Gets the local namespace name introduced by the enumeration, for use in
@@ -1595,7 +1595,7 @@ class EnumMember extends AstNode, @enum_member {
/**
* Gets the canonical name of the type defined by this enum member.
*/
TypeName getTypeName() { ast_node_symbol(this, result) }
deprecated TypeName getTypeName() { ast_node_symbol(this, result) }
override string getAPrimaryQlClass() { result = "EnumMember" }
}
@@ -1776,7 +1776,7 @@ class TypeRootFolder extends Folder {
* For instance, there may be many AST nodes representing different uses of the
* `number` keyword, but there only exists one `number` type.
*/
class Type extends @type {
deprecated class Type extends @type {
/**
* Gets a string representation of this type.
*/
@@ -1975,7 +1975,7 @@ class Type extends @type {
/**
* A union type or intersection type, such as `string | number` or `T & U`.
*/
class UnionOrIntersectionType extends Type, @union_or_intersection_type {
deprecated class UnionOrIntersectionType extends Type, @union_or_intersection_type {
/**
* Gets the `i`th member of this union or intersection, starting at 0.
*/
@@ -1998,12 +1998,12 @@ class UnionOrIntersectionType extends Type, @union_or_intersection_type {
* Note that the `boolean` type is represented as the union `true | false`,
* but is still displayed as `boolean` in string representations.
*/
class UnionType extends UnionOrIntersectionType, @union_type { }
deprecated class UnionType extends UnionOrIntersectionType, @union_type { }
/**
* An intersection type, such as `T & {x: number}`.
*/
class IntersectionType extends UnionOrIntersectionType, @intersection_type { }
deprecated class IntersectionType extends UnionOrIntersectionType, @intersection_type { }
/**
* A type that describes a JavaScript `Array` object.
@@ -2016,7 +2016,7 @@ class IntersectionType extends UnionOrIntersectionType, @intersection_type { }
* Foreign array-like objects such as `HTMLCollection` are not normal JavaScript arrays,
* and their corresponding types are not considered array types either.
*/
class ArrayType extends Type {
deprecated class ArrayType extends Type {
ArrayType() {
this instanceof @tuple_type or
this.(TypeReference).hasQualifiedName("Array") or
@@ -2032,7 +2032,7 @@ class ArrayType extends Type {
/**
* An array type such as `Array<string>`, or equivalently, `string[]`.
*/
class PlainArrayType extends ArrayType, TypeReference {
deprecated class PlainArrayType extends ArrayType, TypeReference {
PlainArrayType() { this.hasQualifiedName("Array") }
override Type getNumberIndexType() { result = this.getTypeArgument(0) }
@@ -2041,14 +2041,14 @@ class PlainArrayType extends ArrayType, TypeReference {
/**
* A read-only array type such as `ReadonlyArray<string>`.
*/
class ReadonlyArrayType extends ArrayType, TypeReference {
deprecated class ReadonlyArrayType extends ArrayType, TypeReference {
ReadonlyArrayType() { this.hasQualifiedName("ReadonlyArray") }
}
/**
* A tuple type, such as `[number, string]`.
*/
class TupleType extends ArrayType, @tuple_type {
deprecated class TupleType extends ArrayType, @tuple_type {
/**
* Gets the `i`th member of this tuple type, starting at 0.
*/
@@ -2104,32 +2104,32 @@ class TupleType extends ArrayType, @tuple_type {
/**
* The predefined `any` type.
*/
class AnyType extends Type, @any_type { }
deprecated class AnyType extends Type, @any_type { }
/**
* The predefined `unknown` type.
*/
class UnknownType extends Type, @unknown_type { }
deprecated class UnknownType extends Type, @unknown_type { }
/**
* The predefined `string` type.
*/
class StringType extends Type, @string_type { }
deprecated class StringType extends Type, @string_type { }
/**
* The predefined `number` type.
*/
class NumberType extends Type, @number_type { }
deprecated class NumberType extends Type, @number_type { }
/**
* The predefined `bigint` type.
*/
class BigIntType extends Type, @bigint_type { }
deprecated class BigIntType extends Type, @bigint_type { }
/**
* A boolean, number, or string literal type.
*/
class LiteralType extends Type, @literal_type {
deprecated class LiteralType extends Type, @literal_type {
/**
* Gets the string value of this literal.
*/
@@ -2139,7 +2139,7 @@ class LiteralType extends Type, @literal_type {
/**
* The boolean literal type `true` or `false`.
*/
class BooleanLiteralType extends LiteralType, @boolean_literal_type {
deprecated class BooleanLiteralType extends LiteralType, @boolean_literal_type {
/**
* Gets the boolean value represented by this type.
*/
@@ -2153,7 +2153,7 @@ class BooleanLiteralType extends LiteralType, @boolean_literal_type {
/**
* A number literal as a static type.
*/
class NumberLiteralType extends LiteralType, @number_literal_type {
deprecated class NumberLiteralType extends LiteralType, @number_literal_type {
override string getStringValue() { type_literal_value(this, result) }
/**
@@ -2170,14 +2170,14 @@ class NumberLiteralType extends LiteralType, @number_literal_type {
/**
* A string literal as a static type.
*/
class StringLiteralType extends LiteralType, @string_literal_type {
deprecated class StringLiteralType extends LiteralType, @string_literal_type {
override string getStringValue() { type_literal_value(this, result) }
}
/**
* A bigint literal as a static type.
*/
class BigIntLiteralType extends LiteralType {
deprecated class BigIntLiteralType extends LiteralType {
override string getStringValue() { type_literal_value(this, result) }
/**
@@ -2194,7 +2194,7 @@ class BigIntLiteralType extends LiteralType {
/**
* The `boolean` type, internally represented as the union type `true | false`.
*/
class BooleanType extends UnionType {
deprecated class BooleanType extends UnionType {
BooleanType() {
this.getAnElementType() instanceof @true_type and
this.getAnElementType() instanceof @false_type and
@@ -2205,7 +2205,7 @@ class BooleanType extends UnionType {
/**
* The `string` type or a string literal type.
*/
class StringLikeType extends Type {
deprecated class StringLikeType extends Type {
StringLikeType() {
this instanceof StringType or
this instanceof StringLiteralType
@@ -2215,7 +2215,7 @@ class StringLikeType extends Type {
/**
* The `number` type or a number literal type.
*/
class NumberLikeType extends Type {
deprecated class NumberLikeType extends Type {
NumberLikeType() {
this instanceof NumberType or
this instanceof NumberLiteralType
@@ -2225,7 +2225,7 @@ class NumberLikeType extends Type {
/**
* The `boolean`, `true,` or `false` type.
*/
class BooleanLikeType extends Type {
deprecated class BooleanLikeType extends Type {
BooleanLikeType() {
this instanceof BooleanType or
this instanceof BooleanLiteralType
@@ -2235,37 +2235,37 @@ class BooleanLikeType extends Type {
/**
* The `void` type.
*/
class VoidType extends Type, @void_type { }
deprecated class VoidType extends Type, @void_type { }
/**
* The `undefined` type.
*/
class UndefinedType extends Type, @undefined_type { }
deprecated class UndefinedType extends Type, @undefined_type { }
/**
* The `null` type.
*/
class NullType extends Type, @null_type { }
deprecated class NullType extends Type, @null_type { }
/**
* The `never` type.
*/
class NeverType extends Type, @never_type { }
deprecated class NeverType extends Type, @never_type { }
/**
* The `symbol` type or a specific `unique symbol` type.
*/
class SymbolType extends Type, @symbol_type { }
deprecated class SymbolType extends Type, @symbol_type { }
/**
* The `symbol` type.
*/
class PlainSymbolType extends SymbolType, @plain_symbol_type { }
deprecated class PlainSymbolType extends SymbolType, @plain_symbol_type { }
/**
* A `unique symbol` type.
*/
class UniqueSymbolType extends SymbolType, @unique_symbol_type {
deprecated class UniqueSymbolType extends SymbolType, @unique_symbol_type {
/**
* Gets the canonical name of the variable exposing the symbol.
*/
@@ -2294,12 +2294,12 @@ class UniqueSymbolType extends SymbolType, @unique_symbol_type {
/**
* The `object` type.
*/
class ObjectKeywordType extends Type, @objectkeyword_type { }
deprecated class ObjectKeywordType extends Type, @objectkeyword_type { }
/**
* A type that refers to a class, interface, enum, or enum member.
*/
class TypeReference extends Type, @type_reference {
deprecated class TypeReference extends Type, @type_reference {
/**
* Gets the canonical name of the type being referenced.
*/
@@ -2352,7 +2352,7 @@ class TypeReference extends Type, @type_reference {
/**
* A type that refers to a class, possibly with type arguments.
*/
class ClassType extends TypeReference {
deprecated class ClassType extends TypeReference {
ClassDefinition declaration;
ClassType() { declaration = this.getADefinition() }
@@ -2366,7 +2366,7 @@ class ClassType extends TypeReference {
/**
* A type that refers to an interface, possibly with type arguents.
*/
class InterfaceType extends TypeReference {
deprecated class InterfaceType extends TypeReference {
InterfaceDeclaration declaration;
InterfaceType() { declaration = this.getADefinition() }
@@ -2380,7 +2380,7 @@ class InterfaceType extends TypeReference {
/**
* A type that refers to an enum.
*/
class EnumType extends TypeReference {
deprecated class EnumType extends TypeReference {
EnumDeclaration declaration;
EnumType() { declaration = this.getADefinition() }
@@ -2394,7 +2394,7 @@ class EnumType extends TypeReference {
/**
* A type that refers to the value of an enum member.
*/
class EnumLiteralType extends TypeReference {
deprecated class EnumLiteralType extends TypeReference {
EnumMember declaration;
EnumLiteralType() { declaration = this.getADefinition() }
@@ -2408,7 +2408,7 @@ class EnumLiteralType extends TypeReference {
/**
* A type that refers to a type alias.
*/
class TypeAliasReference extends TypeReference {
deprecated class TypeAliasReference extends TypeReference {
TypeAliasReference() { type_alias(this, _) }
/**
@@ -2422,12 +2422,12 @@ class TypeAliasReference extends TypeReference {
/**
* An anonymous interface type, such as `{ x: number }`.
*/
class AnonymousInterfaceType extends Type, @object_type { }
deprecated class AnonymousInterfaceType extends Type, @object_type { }
/**
* A type that refers to a type variable.
*/
class TypeVariableType extends Type, @typevariable_type {
deprecated class TypeVariableType extends Type, @typevariable_type {
/**
* Gets a syntactic declaration of this type variable.
*
@@ -2467,7 +2467,7 @@ class TypeVariableType extends Type, @typevariable_type {
/**
* A type that refers to a type variable declared on a class, interface or function.
*/
class CanonicalTypeVariableType extends TypeVariableType, @canonical_type_variable_type {
deprecated class CanonicalTypeVariableType extends TypeVariableType, @canonical_type_variable_type {
override TypeName getHostType() { result = this.getCanonicalName().getParent() }
override CanonicalName getCanonicalName() { type_symbol(this, result) }
@@ -2487,7 +2487,7 @@ class CanonicalTypeVariableType extends TypeVariableType, @canonical_type_variab
* - `<T>(x: T) => T`
* - `<S, T>(x: S, y: T) => T`.
*/
class LexicalTypeVariableType extends TypeVariableType, @lexical_type_variable_type {
deprecated class LexicalTypeVariableType extends TypeVariableType, @lexical_type_variable_type {
override string getName() {
types(this, _, result) // The toString value contains the name.
}
@@ -2504,7 +2504,7 @@ class LexicalTypeVariableType extends TypeVariableType, @lexical_type_variable_t
* }
* ```
*/
class ThisType extends Type, @this_type {
deprecated class ThisType extends Type, @this_type {
/**
* Gets the type containing the `this` type.
*/
@@ -2517,7 +2517,7 @@ class ThisType extends Type, @this_type {
* The type of a named value, `typeof X`, typically denoting the type of
* a class constructor, namespace object, enum object, or module object.
*/
class TypeofType extends Type, @typeof_type {
deprecated class TypeofType extends Type, @typeof_type {
/**
* Gets the canonical name of the named value.
*/
@@ -2592,7 +2592,7 @@ module SignatureKind {
/**
* A function or constructor signature in a TypeScript type.
*/
class CallSignatureType extends @signature_type {
deprecated class CallSignatureType extends @signature_type {
/**
* Gets a value indicating if this is a function or constructor signature.
*/
@@ -2741,12 +2741,13 @@ class CallSignatureType extends @signature_type {
/**
* A function call signature in a type, that is, a signature without the `new` keyword.
*/
class FunctionCallSignatureType extends CallSignatureType, @function_signature_type { }
deprecated class FunctionCallSignatureType extends CallSignatureType, @function_signature_type { }
/**
* A constructor call signature in a type, that is, a signature with the `new` keyword.
*/
class ConstructorCallSignatureType extends CallSignatureType, @constructor_signature_type { }
deprecated class ConstructorCallSignatureType extends CallSignatureType, @constructor_signature_type
{ }
/**
* A type name that defines a promise.
@@ -2756,7 +2757,7 @@ class ConstructorCallSignatureType extends CallSignatureType, @constructor_signa
* - It has one type parameter, say, `T`
* - It has a `then` method whose first argument is a callback that takes a `T` as argument.
*/
private class PromiseTypeName extends TypeName {
deprecated private class PromiseTypeName extends TypeName {
PromiseTypeName() {
// The name must suggest it is a promise.
this.getName().matches(["%Promise", "%PromiseLike", "%Thenable", "%Deferred"]) and
@@ -2780,7 +2781,7 @@ private class PromiseTypeName extends TypeName {
* This includes types whose name and `then` method signature suggest it is a promise,
* such as `PromiseLike<T>` and `Thenable<T>`.
*/
class PromiseType extends TypeReference {
deprecated class PromiseType extends TypeReference {
PromiseType() {
this.getNumTypeArgument() = 1 and
this.getTypeName() instanceof PromiseTypeName