8000 fix: add missing scope types to `Scope.type` (#20110) · eslint/eslint@7d61b7f · GitHub
[go: up one dir, main page]

Skip to content

Commit 7d61b7f

Browse files
authored
fix: add missing scope types to Scope.type (#20110)
* fix: add missing scope types to `Scope.type` * update custom-rules.md * add line break between footnotes
1 parent 1ace67d commit 7d61b7f

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

docs/src/extend/custom-rules.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -872,26 +872,28 @@ You can view scope information for any JavaScript code using [Code Explorer](htt
872872

873873
The following table contains a list of AST node types and the scope type that they correspond to. For more information about the scope types, refer to the [`Scope` object documentation](./scope-manager-interface#scope-interface).
874874

875-
| AST Node Type | Scope Type |
876-
| :------------------------ | :--------- |
877-
| `Program` | `global` |
878-
| `FunctionDeclaration` | `function` |
879-
| `FunctionExpression` | `function` |
880-
| `ArrowFunctionExpression` | `function` |
881-
| `ClassDeclaration` | `class` |
882-
| `ClassExpression` | `class` |
883-
| `BlockStatement` ※1 | `block` |
884-
| `SwitchStatement` ※1 | `switch` |
885-
| `ForStatement` ※2 | `for` |
886-
| `ForInStatement` ※2 | `for` |
887-
| `ForOfStatement` ※2 | `for` |
888-
| `WithStatement` | `with` |
889-
| `CatchClause` | `catch` |
890-
| others | ※3 |
875+
| AST Node Type | Scope Type |
876+
| :------------------------ | :------------------- |
877+
| `Program` | `global` |
878+
| `FunctionDeclaration` | `function` |
879+
| `FunctionExpression` | `function` |
880+
| `ArrowFunctionExpression` | `function` |
881+
| `ClassDeclaration` | `class` |
882+
| `ClassExpression` | `class` |
883+
| `StaticBlock` | `class-static-block` |
884+
| `BlockStatement` ※1 | `block` |
885+
| `SwitchStatement` ※1 | `switch` |
886+
| `ForStatement` ※2 | `for` |
887+
| `ForInStatement` ※2 | `for` |
888+
| `ForOfStatement` ※2 | `for` |
889+
| `WithStatement` | `with` |
890+
| `CatchClause` | `catch` |
891+
| others | ※3 ※4 |
891892

892893
**※1** Only if the configured parser provided the block-scope feature. The default parser provides the block-scope feature if `parserOptions.ecmaVersion` is not less than `6`.<br>
893894
**※2** Only if the `for` statement defines the iteration variable as a block-scoped variable (E.g., `for (let i = 0;;) {}`).<br>
894-
**※3** The scope of the closest ancestor node which has own scope. If the closest ancestor node has multiple scopes then it chooses the innermost scope (E.g., the `Program` node has a `global` scope and a `module` scope if `Program#sourceType` is `"module"`. The innermost scope is the `module` scope.).
895+
**※3** The scope of the closest ancestor node which has own scope. If the closest ancestor node has multiple scopes then it chooses the innermost scope (E.g., the `Program` node has a `global` scope and a `module` scope if `Program#sourceType` is `"module"`. The innermost scope is the `module` scope.).<br>
896+
**※4** Each `PropertyDefinition#value` node (it can be any expression node type), has a `class-field-initializer` scope. For example, in `class C { field = 1 }`, the `Literal` node that represents `1` has a `class-field-initializer` scope. If the node has other scopes, the `class-field-initializer` scope will be the outermost one. For example, in `class C { field = () => {} }`, the `ArrowFunctionExpression` node has two scopes: `class-field-initializer` and `function`.
895897

896898
#### Scope Variables
897899

lib/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export namespace Scope {
9292
| "block"
9393
| "catch"
9494
| "class"
95+
| "class-field-initializer"
96+
| "class-static-block"
9597
| "for"
9698
| "function"
9799
| "function-expression-name"

0 commit comments

Comments
 (0)
0