@@ -4,13 +4,13 @@ import { findVariable } from "./find-variable.mjs"
44/** @typedef {import("./types.mjs").StaticValue } StaticValue */
55/** @typedef {import("eslint").Scope.Scope } Scope */
66/** @typedef {import("estree").Node } Node */
7- /** @typedef {import("eslint").Rule .Node } RuleNode */
8- /** @typedef {import("eslint").Rule.NodeTypes } NodeTypes */
9- /** @typedef {import("estree") .MemberExpression } MemberExpression */
10- /** @typedef {import("estree") .Property } Property */
11- /** @typedef {import("estree") .RegExpLiteral } RegExpLiteral */
12- /** @typedef {import("estree") .BigIntLiteral } BigIntLiteral */
13- /** @typedef {import("estree ").SimpleLiteral } SimpleLiteral */
7+ /** @typedef {import("@typescript- eslint/types ").TSESTree .Node } TSESTreeNode */
8+ /** @typedef {import("@typescript- eslint/types ").TSESTree.AST_NODE_TYPES } TSESTreeNodeTypes */
9+ /** @typedef {import("@typescript-eslint/types").TSESTree .MemberExpression } MemberExpression */
10+ /** @typedef {import("@typescript-eslint/types").TSESTree .Property } Property */
11+ /** @typedef {import("@typescript-eslint/types").TSESTree .RegExpLiteral } RegExpLiteral */
12+ /** @typedef {import("@typescript-eslint/types").TSESTree .BigIntLiteral } BigIntLiteral */
13+ /** @typedef {import("@typescript-eslint/types ").TSESTree.Literal } Literal */
1414
1515const globalObject =
1616 typeof globalThis !== "undefined"
@@ -236,7 +236,7 @@ function isGetter(object, name) {
236236
237237/**
238238 * Get the element values of a given node list.
239- * @param {(Node|null)[] } nodeList The node list to get values.
239+ * @param {(Node|TSESTreeNode| null)[] } nodeList The node list to get values.
240240 * @param {Scope|undefined|null } initialScope The initial scope to find variables.
241241 * @returns {any[]|null } The value list if all nodes are constant. Otherwise, null.
242242 */
@@ -284,14 +284,14 @@ function isEffectivelyConst(variable) {
284284}
285285
286286/**
287- * @template {NodeTypes } T
287+ * @template {TSESTreeNodeTypes } T
288288 * @callback VisitorCallback
289- * @param {RuleNode & { type: T } } node
289+ * @param {TSESTreeNode & { type: T } } node
290290 * @param {Scope|undefined|null } initialScope
291291 * @returns {StaticValue | null }
292292 */
293293/**
294- * @typedef { { [K in NodeTypes ]?: VisitorCallback<K> } } Operations
294+ * @typedef { { [K in TSESTreeNodeTypes ]?: VisitorCallback<K> } } Operations
295295 */
296296/**
297297 * @type {Operations }
@@ -542,7 +542,7 @@ const operations = Object.freeze({
542542
543543 Literal ( node ) {
544544 const literal =
545- /** @type {Partial<SimpleLiteral > & Partial<RegExpLiteral> & Partial<BigIntLiteral> } */ (
545+ /** @type {Partial<Literal > & Partial<RegExpLiteral> & Partial<BigIntLiteral> } */ (
546546 node
547547 )
548548 //istanbul ignore if : this is implementation-specific behavior.
@@ -749,18 +749,33 @@ const operations = Object.freeze({
749749
750750 return null
751751 } ,
752+ TSAsExpression ( node , initialScope ) {
753+ return getStaticValueR ( node . expression , initialScope )
754+ } ,
755+ TSSatisfiesExpression ( node , initialScope ) {
756+ return getStaticValueR ( node . expression , initialScope )
757+ } ,
758+ TSTypeAssertion ( node , initialScope ) {
759+ return getStaticValueR ( node . expression , initialScope )
760+ } ,
761+ TSNonNullExpression ( node , initialScope ) {
762+ return getStaticValueR ( node . expression , initialScope )
763+ } ,
764+ TSInstantiationExpression ( node , initialScope ) {
765+ return getStaticValueR ( node . expression , initialScope )
766+ } ,
752767} )
753768
754769/**
755770 * Get the value of a given node if it's a static value.
756- * @param {Node|null|undefined } node The node to get.
771+ * @param {Node|TSESTreeNode| null|undefined } node The node to get.
757772 * @param {Scope|undefined|null } initialScope The scope to start finding variable.
758773 * @returns {StaticValue|null } The static value of the node, or `null`.
759774 */
760775function getStaticValueR ( node , initialScope ) {
761776 if ( node != null && Object . hasOwnProperty . call ( operations , node . type ) ) {
762777 return /** @type {VisitorCallback<any> } */ ( operations [ node . type ] ) (
763- /** @type {RuleNode } */ ( node ) ,
778+ /** @type {TSESTreeNode } */ ( node ) ,
764779 initialScope ,
765780 )
766781 }
0 commit comments