7 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.
11 ## ScopeManager interface
13 `ScopeManager` object has all variable scopes.
20 * **Description:** All scopes.
25 * **Description:** The root scope.
29 #### acquire(node, inner = false)
32 * `node` (`ASTNode`) ... An AST node to get their scope.
33 * `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`.
34 * **Return type:** `Scope | null`
35 * **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`.
37 #### getDeclaredVariables(node)
40 * `node` (`ASTNode`) ... An AST node to get their variables.
41 * **Return type:** `Variable[]`
42 * **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.
44 ### Deprecated members
46 Those members are defined but not used in ESLint.
51 * **Return type:** `boolean`
52 * **Description:** `true` if this program is module.
54 #### isImpliedStrict()
57 * **Return type:** `boolean`
58 * **Description:** `true` if this program is strict mode implicitly. I.e., `options.impliedStrict === true`.
60 #### isStrictModeSupported()
63 * **Return type:** `boolean`
64 * **Description:** `true` if this program supports strict mode. I.e., `options.ecmaVersion >= 5`.
69 * `node` (`ASTNode`) ... An AST node to get their scope.
70 * **Return type:** `Scope[] | null`
71 * **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`.
77 `Scope` object has all variables and references in the scope.
84 * **Description:** The type of this scope. This is one of `"block"`, `"catch"`, `"class"`, `"class-field-initializer"`, `"class-static-block"`, `"for"`, `"function"`, `"function-expression-name"`, `"global"`, `"module"`, `"switch"`, `"with"`.
89 * **Description:** `true` if this scope is strict mode.
93 * **Type:** `Scope | null`
94 * **Description:** The parent scope. If this is the global scope then this property is `null`.
99 * **Description:** The array of child scopes. This does not include grandchild scopes.
104 * **Description:** The nearest ancestor whose `type` is one of `"class-field-initializer"`, `"class-static-block"`, `"function"`, `"global"`, or `"module"`. For the aforementioned scopes this is a self-reference.
106 > This represents the lowest enclosing function or top-level scope. Class field initializers and class static blocks are implicit functions. Historically, this was the scope which hosts variables that are defined by `var` declarations, and thus the name `variableScope`.
110 * **Type:** `ASTNode`
111 * **Description:** The AST node which created this scope.
115 * **Type:** `Variable[]`
116 * **Description:** The array of all variables which are defined on this scope. This does not include variables which are defined in child scopes.
120 * **Type:** `Map<string, Variable>`
121 * **Description:** The map from variable names to variable objects.
123 > I hope to rename `set` field or replace by a method.
127 * **Type:** `Reference[]`
128 * **Description:** The array of all references on this scope. This does not include references in child scopes.
132 * **Type:** `Reference[]`
133 * **Description:** The array of references which could not be resolved in this scope.
135 #### functionExpressionScope
137 * **Type:** `boolean`
138 * **Description:** `true` if this scope is `"function-expression-name"` scope.
140 > I hope to deprecate `functionExpressionScope` field as replacing by `scope.type === "function-expression-name"`.
142 ### Deprecated members
144 Those members are defined but not used in ESLint.
148 * **Type:** `Map<string, boolean>`
149 * **Description:** The map from variable names to `tainted` flag.
153 * **Type:** `boolean`
154 * **Description:** `true` if this scope is dynamic. I.e., the type of this scope is `"global"` or `"with"`.
156 #### directCallToEvalScope
158 * **Type:** `boolean`
159 * **Description:** `true` if this scope contains `eval()` invocations.
163 * **Type:** `boolean`
164 * **Description:** `true` if this scope contains `this`.
169 * `node` (`ASTNode`) ... An AST node to get their reference object. The type of the node must be `"Identifier"`.
170 * **Return type:** `Reference | null`
171 * **Description:** Returns `this.references.find(r => r.identifier === node)`.
176 * **Return type:** `boolean`
177 * **Description:** Returns `!this.dynamic`.
179 #### isArgumentsMaterialized()
182 * **Return type:** `boolean`
183 * **Description:** `true` if this is a `"function"` scope which has used `arguments` variable.
185 #### isThisMaterialized()
188 * **Return type:** `boolean`
189 * **Description:** Returns `this.thisFound`.
191 #### isUsedName(name)
194 * `name` (`string`) ... The name to check.
195 * **Return type:** `boolean`
196 * **Description:** `true` if a given name is used in variable names or reference names.
200 ## Variable interface
202 `Variable` object is variable's information.
209 * **Description:** The name of this variable.
214 * **Description:** The scope in which this variable is defined.
218 * **Type:** `ASTNode[]`
219 * **Description:** The array of `Identifier` nodes which define this variable. If this variable is redeclared, this array includes two or more nodes.
221 > I hope to deprecate `identifiers` field as replacing by `defs[].name` field.
225 * **Type:** `Reference[]`
226 * **Description:** The array of the references of this variable.
230 * **Type:** `Definition[]`
231 * **Description:** The array of the definitions of this variable.
233 ### Deprecated members
235 Those members are defined but not used in ESLint.
239 * **Type:** `boolean`
240 * **Description:** The `tainted` flag. (always `false`)
244 * **Type:** `boolean`
245 * **Description:** The `stack` flag. (I'm not sure what this means.)
249 ## Reference interface
251 `Reference` object is reference's information.
257 * **Type:** `ASTNode`
258 * **Description:** The `Identifier` node of this reference.
263 * **Description:** The `Scope` object that this reference is on.
267 * **Type:** `Variable | null`
268 * **Description:** The `Variable` object that this reference refers. If such variable was not defined, this is `null`.
272 * **Type:** `ASTNode | null`
273 * **Description:** The ASTNode object which is right-hand side.
277 * **Type:** `boolean`
278 * **Description:** `true` if this writing reference is a variable initializer or a default value.
285 * **Return type:** `boolean`
286 * **Description:** `true` if this reference is writing.
291 * **Return type:** `boolean`
292 * **Description:** `true` if this reference is reading.
297 * **Return type:** `boolean`
298 * **Description:** `true` if this reference is writing but not reading.
303 * **Return type:** `boolean`
304 * **Description:** `true` if this reference is reading but not writing.
309 * **Return type:** `boolean`
310 * **Description:** `true` if this reference is reading and writing.
312 ### Deprecated members
314 Those members are defined but not used in ESLint.
318 * **Type:** `boolean`
319 * **Description:** The `tainted` flag. (always `false`)
324 * **Description:** `1` is reading, `2` is writing, `3` is reading/writing.
328 * **Type:** `boolean`
329 * **Description:** The `partial` flag.
334 * **Return type:** `boolean`
335 * **Description:** `true` if this reference is resolved statically.
339 ## Definition interface
341 `Definition` object is variable definition's information.
348 * **Description:** The type of this definition. One of `"CatchClause"`, `"ClassName"`, `"FunctionName"`, `"ImplicitGlobalVariable"`, `"ImportBinding"`, `"Parameter"`, and `"Variable"`.
352 * **Type:** `ASTNode`
353 * **Description:** The `Identifier` node of this definition.
357 * **Type:** `ASTNode`
358 * **Description:** The enclosing node of the name.
361 |:---------------------------|:-----|
362 | `"CatchClause"` | `CatchClause`
363 | `"ClassName"` | `ClassDeclaration` or `ClassExpression`
364 | `"FunctionName"` | `FunctionDeclaration` or `FunctionExpression`
365 | `"ImplicitGlobalVariable"` | `Program`
366 | `"ImportBinding"` | `ImportSpecifier`, `ImportDefaultSpecifier`, or `ImportNamespaceSpecifier`
367 | `"Parameter"` | `FunctionDeclaration`, `FunctionExpression`, or `ArrowFunctionExpression`
368 | `"Variable"` | `VariableDeclarator`
372 * **Type:** `ASTNode | undefined | null`
373 * **Description:** The enclosing statement node of the name.
376 |:---------------------------|:-------|
377 | `"CatchClause"` | `null`
378 | `"ClassName"` | `null`
379 | `"FunctionName"` | `null`
380 | `"ImplicitGlobalVariable"` | `null`
381 | `"ImportBinding"` | `ImportDeclaration`
382 | `"Parameter"` | `null`
383 | `"Variable"` | `VariableDeclaration`
385 ### Deprecated members
387 Those members are defined but not used in ESLint.
391 * **Type:** `number | undefined | null`
392 * **Description:** The index in the declaration statement.
396 * **Type:** `string | undefined | null`
397 * **Description:** The kind of the declaration statement.