2525 * SOFTWARE
2626 */
2727
28- import * as eslint from "eslint" ;
2928import { VisitorKeys } from "eslint-visitor-keys" ;
3029import { Visitor , VisitorOptions } from "esrecurse" ;
3130import * as ESTree from "estree" ;
@@ -101,7 +100,7 @@ export type PatternVisitorCallback = (
101100/**
102101 * Manages the scope hierarchy of an AST.
103102 */
104- export class ScopeManager implements eslint . Scope . ScopeManager {
103+ export class ScopeManager {
105104 /**
106105 * Creates a new ScopeManager instance.
107106 * @param options Options for scope analysis.
@@ -172,9 +171,7 @@ export class ScopeManager implements eslint.Scope.ScopeManager {
172171/**
173172 * Base export class for all scopes.
174173 */
175- export class Scope < TVariable extends Variable = Variable , TReference extends Reference = Reference >
176- implements eslint . Scope . Scope
177- {
174+ export class Scope < TVariable extends Variable = Variable , TReference extends Reference = Reference > {
178175 /**
179176 * Creates a new Scope instance.
180177 * @param scopeManager The scope manager this scope belongs to.
@@ -194,7 +191,19 @@ export class Scope<TVariable extends Variable = Variable, TReference extends Ref
194191 /**
195192 * The type of the scope (e.g., 'global', 'function').
196193 */
197- type : eslint . Scope . Scope [ "type" ] ;
194+ type :
195+ | "block"
196+ | "catch"
197+ | "class"
198+ | "class-field-initializer"
199+ | "class-static-block"
200+ | "for"
201+ | "function"
202+ | "function-expression-name"
203+ | "global"
204+ | "module"
205+ | "switch"
206+ | "with" ;
198207
199208 /**
200209 * Whether the scope is in strict mode.
@@ -239,18 +248,18 @@ export class Scope<TVariable extends Variable = Variable, TReference extends Ref
239248 /**
240249 * Map of variable names to variables.
241250 */
242- set : eslint . Scope . Scope [ "set" ] ;
251+ set : Map < string , TVariable > ;
243252
244253 /**
245254 * The tainted variables of this scope.
246255 * @deprecated
247256 */
248- taints : Map < string , Variable > ;
257+ taints : Map < string , TVariable > ;
249258
250259 /**
251260 * References that pass through this scope to outer scopes.
252261 */
253- through : eslint . Scope . Scope [ "through" ] ;
262+ through : TReference [ ] ;
254263
255264 /**
256265 * Dynamic flag for certain scope types.
@@ -275,7 +284,7 @@ export class Scope<TVariable extends Variable = Variable, TReference extends Ref
275284 * @param ident An AST node to get their reference object.
276285 * @deprecated
277286 */
278- resolve ( ident : ESTree . Identifier ) : Reference | null ;
287+ resolve ( ident : ESTree . Identifier ) : TReference | null ;
279288
280289 /**
281290 * Whether the reference is static.
@@ -348,7 +357,7 @@ export class FunctionExpressionNameScope extends Scope {
348357 * @param block The AST node that created this scope.
349358 */
350359 constructor ( scopeManager : ScopeManager , upperScope : Scope , block : ESTree . Node ) ;
351-
360+
352361 type : "function-expression-name" ;
353362
354363 functionExpressionScope : true ;
@@ -516,7 +525,7 @@ export class ClassStaticBlockScope extends Scope {
516525/**
517526 * Represents a variable in a scope.
518527 */
519- export class Variable < TReference extends Reference = Reference > implements eslint . Scope . Variable {
528+ export class Variable < TReference extends Reference = Reference > {
520529 /**
521530 * Creates a new Variable instance.
522531 * @param name The name of the variable.
@@ -547,7 +556,7 @@ export class Variable<TReference extends Reference = Reference> implements eslin
547556 /**
548557 * Definitions of this variable.
549558 */
550- defs : eslint . Scope . Definition [ ] ;
559+ defs : Definition [ ] ;
551560
552561 /**
553562 * Whether the variable is tainted (e.g., potentially modified externally).
@@ -565,7 +574,7 @@ export class Variable<TReference extends Reference = Reference> implements eslin
565574/**
566575 * Represents a reference to a variable.
567576 */
568- export class Reference implements eslint . Scope . Reference {
577+ export class Reference {
569578 /**
570579 * Creates a new Reference instance.
571580 * @param ident The identifier node of the reference.
@@ -605,12 +614,12 @@ export class Reference implements eslint.Scope.Reference {
605614 /**
606615 * Whether this is a write operation.
607616 */
608- isWrite : eslint . Scope . Reference [ "isWrite" ] ;
617+ isWrite ( ) : boolean ;
609618
610619 /**
611620 * Whether this is a read operation.
612621 */
613- isRead : eslint . Scope . Reference [ "isRead" ] ;
622+ isRead ( ) : boolean ;
614623
615624 /**
616625 * The scope where the reference occurs.
@@ -664,9 +673,8 @@ export class Reference implements eslint.Scope.Reference {
664673
665674/**
666675 * Represents a variable definition.
667- * @todo extends eslint.Scope.Definition for this class
668676 */
669- export class Definition {
677+ export const Definition : {
670678 /**
671679 * Creates a new Definition instance.
672680 * @param type The type of definition (e.g., 'Variable', 'Parameter').
@@ -676,34 +684,57 @@ export class Definition {
676684 * @param index The index of the definition in a pattern, if applicable.
677685 * @param kind The kind of variable (e.g., 'var', 'let', 'const'), if applicable.
678686 */
679- constructor (
680- type : eslint . Scope . Definition [ "type" ] ,
681- name : eslint . Scope . Definition [ "name" ] ,
682- node : eslint . Scope . Definition [ "node" ] ,
683- parent : eslint . Scope . Definition [ "parent" ] ,
687+ new (
688+ type : Definition [ "type" ] ,
689+ name : ESTree . Identifier ,
690+ node : Definition [ "node" ] ,
691+ parent : Definition [ "parent" ] ,
684692 index : number | null ,
685693 kind : string | null ,
686- ) ;
687-
688- /**
689- * The type of definition (e.g., 'Variable', 'Parameter').
690- */
691- type : eslint . Scope . Definition [ "type" ] ;
694+ ) : Definition ;
695+ } ;
696+
697+ export type Definition = (
698+ | { type : "CatchClause" ; node : ESTree . CatchClause ; parent : null }
699+ | {
700+ type : "ClassName" ;
701+ node : ESTree . ClassDeclaration | ESTree . ClassExpression ;
702+ parent : null ;
703+ } | {
704+ type : "FunctionName" ;
705+ node : ESTree . FunctionDeclaration | ESTree . FunctionExpression ;
706+ parent : null ;
707+ } | {
708+ type : "ImplicitGlobalVariable" ;
709+ node :
710+ | ESTree . AssignmentExpression
711+ | ESTree . ForInStatement
712+ | ESTree . ForOfStatement ;
713+ parent : null ;
714+ } | {
715+ type : "ImportBinding" ;
716+ node :
717+ | ESTree . ImportSpecifier
718+ | ESTree . ImportDefaultSpecifier
719+ | ESTree . ImportNamespaceSpecifier ;
720+ parent : ESTree . ImportDeclaration ;
721+ } | {
722+ type : "Parameter" ;
723+ node :
724+ | ESTree . FunctionDeclaration
725+ | ESTree . FunctionExpression
726+ | ESTree . ArrowFunctionExpression ;
727+ parent : null ;
728+ } | {
729+ type : "Variable" ;
730+ node : ESTree . VariableDeclarator ;
731+ parent : ESTree . VariableDeclaration ;
732+ } ) & {
692733
693734 /**
694735 * The identifier node of the definition.
695736 */
696- name : eslint . Scope . Definition [ "name" ] ;
697-
698- /**
699- * The AST node where the definition occurs.
700- */
701- node : eslint . Scope . Definition [ "node" ] ;
702-
703- /**
704- * The parent node, if applicable.
705- */
706- parent : eslint . Scope . Definition [ "parent" ] ;
737+ name : ESTree . Identifier ;
707738
708739 /**
709740 * The index of the definition in a pattern, if applicable.
@@ -716,7 +747,7 @@ export class Definition {
716747 * @deprecated
717748 */
718749 kind : string | null ;
719- }
750+ } ;
720751
721752/**
722753 * Visitor for destructuring patterns.
0 commit comments