3 This document was written based on the implementation of [eslint-scope](https://github.com/eslint/eslint-scope), a fork of [escope](https://github.com/estools/escope), and deprecates some members ESLint is not using.
7 ## ScopeManager interface
9 `ScopeManager` object has all variable scopes.
16 * **Description:** All scopes.
21 * **Description:** The root scope.
25 #### acquire(node, inner = false)
28 * `node` (`ASTNode`) ... An AST node to get their scope.
29 * `inner` (`boolean`) ... If the node has multiple scope, this returns the outermost scope normally. If `inner` is `true` then this returns the innermost scope. Default is `false`.
30 * **Return type:** `Scope | null`
31 * **Description:** Get the scope of a given AST node. The gotten scope's `block` property is the node. This method never returns `function-expression-name` scope. If the node does not have their scope, this returns `null`.
33 #### getDeclaredVariables(node)
36 * `node` (`ASTNode`) ... An AST node to get their variables.
37 * **Return type:** `Variable[]`
38 * **Description:** Get the variables that a given AST node defines. The gotten variables' `def[].node`/`def[].parent` property is the node. If the node does not define any variable, this returns an empty array.
40 ### Deprecated members
42 Those members are defined but not used in ESLint.
47 * **Return type:** `boolean`
48 * **Description:** `true` if this program is module.
50 #### isImpliedStrict()
53 * **Return type:** `boolean`
54 * **Description:** `true` if this program is strict mode implicitly. I.e., `options.impliedStrict === true`.
56 #### isStrictModeSupported()
59 * **Return type:** `boolean`
60 * **Description:** `true` if this program supports strict mode. I.e., `options.ecmaVersion >= 5`.
65 * `node` (`ASTNode`) ... An AST node to get their scope.
66 * **Return type:** `Scope[] | null`
67 * **Description:** Get the scopes of a given AST node. The gotten scopes' `block` property is the node. If the node does not have their scope, this returns `null`.
73 `Scope` object has all variables and references in the scope.
80 * **Description:** The type of this scope. This is one of `"block"`, `"catch"`, `"class"`, `"for"`, `"function"`, `"function-expression-name"`, `"global"`, `"module"`, `"switch"`, `"with"`
85 * **Description:** `true` if this scope is strict mode.
89 * **Type:** `Scope | null`
90 * **Description:** The parent scope. If this is the global scope then this property is `null`.
95 * **Description:** The array of child scopes. This does not include grandchild scopes.
100 * **Description:** The scope which hosts variables which are defined by `var` declarations.
104 * **Type:** `ASTNode`
105 * **Description:** The AST node which created this scope.
109 * **Type:** `Variable[]`
110 * **Description:** The array of all variables which are defined on this scope. This does not include variables which are defined in child scopes.
114 * **Type:** `Map<string, Variable>`
115 * **Description:** The map from variable names to variable objects.
117 > I hope to rename `set` field or replace by a method.
121 * **Type:** `Reference[]`
122 * **Description:** The array of all references on this scope. This does not include references in child scopes.
126 * **Type:** `Reference[]`
127 * **Description:** The array of references which could not be resolved in this scope.
129 #### functionExpressionScope
131 * **Type:** `boolean`
132 * **Description:** `true` if this scope is `"function-expression-name"` scope.
134 > I hope to deprecate `functionExpressionScope` field as replacing by `scope.type === "function-expression-name"`.
136 ### Deprecated members
138 Those members are defined but not used in ESLint.
142 * **Type:** `Map<string, boolean>`
143 * **Description:** The map from variable names to `tainted` flag.
147 * **Type:** `boolean`
148 * **Description:** `true` if this scope is dynamic. I.e., the type of this scope is `"global"` or `"with"`.
150 #### directCallToEvalScope
152 * **Type:** `boolean`
153 * **Description:** `true` if this scope contains `eval()` invocations.
157 * **Type:** `boolean`
158 * **Description:** `true` if this scope contains `this`.
163 * `node` (`ASTNode`) ... An AST node to get their reference object. The type of the node must be `"Identifier"`.
164 * **Return type:** `Reference | null`
165 * **Description:** Returns `this.references.find(r => r.identifier === node)`.
170 * **Return type:** `boolean`
171 * **Description:** Returns `!this.dynamic`.
173 #### isArgumentsMaterialized()
176 * **Return type:** `boolean`
177 * **Description:** `true` if this is a `"function"` scope which has used `arguments` variable.
179 #### isThisMaterialized()
182 * **Return type:** `boolean`
183 * **Description:** Returns `this.thisFound`.
185 #### isUsedName(name)
188 * `name` (`string`) ... The name to check.
189 * **Return type:** `boolean`
190 * **Description:** `true` if a given name is used in variable names or reference names.
194 ## Variable interface
196 `Variable` object is variable's information.
203 * **Description:** The name of this variable.
207 * **Type:** `ASTNode[]`
208 * **Description:** The array of `Identifier` nodes which define this variable. If this variable is redeclared, this array includes two or more nodes.
210 > I hope to deprecate `identifiers` field as replacing by `defs[].name` field.
214 * **Type:** `Reference[]`
215 * **Description:** The array of the references of this variable.
219 * **Type:** `Definition[]`
220 * **Description:** The array of the definitions of this variable.
222 ### Deprecated members
224 Those members are defined but not used in ESLint.
228 * **Type:** `boolean`
229 * **Description:** The `tainted` flag. (always `false`)
233 * **Type:** `boolean`
234 * **Description:** The `stack` flag. (I'm not sure what this means.)
238 ## Reference interface
240 `Reference` object is reference's information.
246 * **Type:** `ASTNode`
247 * **Description:** The `Identifier` node of this reference.
252 * **Description:** The `Scope` object that this reference is on.
256 * **Type:** `Variable | null`
257 * **Description:** The `Variable` object that this reference refers. If such variable was not defined, this is `null`.
261 * **Type:** `ASTNode | null`
262 * **Description:** The ASTNode object which is right-hand side.
266 * **Type:** `boolean`
267 * **Description:** `true` if this writing reference is a variable initializer or a default value.
274 * **Return type:** `boolean`
275 * **Description:** `true` if this reference is writing.
280 * **Return type:** `boolean`
281 * **Description:** `true` if this reference is reading.
286 * **Return type:** `boolean`
287 * **Description:** `true` if this reference is writing but not reading.
292 * **Return type:** `boolean`
293 * **Description:** `true` if this reference is reading but not writing.
298 * **Return type:** `boolean`
299 * **Description:** `true` if this reference is reading and writing.
301 ### Deprecated members
303 Those members are defined but not used in ESLint.
307 * **Type:** `boolean`
308 * **Description:** The `tainted` flag. (always `false`)
313 * **Description:** `1` is reading, `2` is writing, `3` is reading/writing.
317 * **Type:** `boolean`
318 * **Description:** The `partial` flag.
323 * **Return type:** `boolean`
324 * **Description:** `true` if this reference is resolved statically.
328 ## Definition interface
330 `Definition` object is variable definition's information.
337 * **Description:** The type of this definition. One of `"CatchClause"`, `"ClassName"`, `"FunctionName"`, `"ImplicitGlobalVariable"`, `"ImportBinding"`, `"Parameter"`, and `"Variable"`.
341 * **Type:** `ASTNode`
342 * **Description:** The `Identifier` node of this definition.
346 * **Type:** `ASTNode`
347 * **Description:** The enclosing node of the name.
350 |:---------------------------|:-----|
351 | `"CatchClause"` | `CatchClause`
352 | `"ClassName"` | `ClassDeclaration` or `ClassExpression`
353 | `"FunctionName"` | `FunctionDeclaration` or `FunctionExpression`
354 | `"ImplicitGlobalVariable"` | `Program`
355 | `"ImportBinding"` | `ImportSpecifier`, `ImportDefaultSpecifier`, or `ImportNamespaceSpecifier`
356 | `"Parameter"` | `FunctionDeclaration`, `FunctionExpression`, or `ArrowFunctionExpression`
357 | `"Variable"` | `VariableDeclarator`
361 * **Type:** `ASTNode | undefined | null`
362 * **Description:** The enclosing statement node of the name.
365 |:---------------------------|:-------|
366 | `"CatchClause"` | `null`
367 | `"ClassName"` | `null`
368 | `"FunctionName"` | `null`
369 | `"ImplicitGlobalVariable"` | `null`
370 | `"ImportBinding"` | `ImportDeclaration`
371 | `"Parameter"` | `null`
372 | `"Variable"` | `VariableDeclaration`
374 ### Deprecated members
376 Those members are defined but not used in ESLint.
380 * **Type:** `number | undefined | null`
381 * **Description:** The index in the declaration statement.
385 * **Type:** `string | undefined | null`
386 * **Description:** The kind of the declaration statement.