版本

ScopeManager

此文件基於 eslint-scopeescope 的分支)的實作撰寫,並棄用 ESLint 未使用的一些成員。


ScopeManager 介面

ScopeManager 物件擁有所有的變數作用域。

欄位

scopes

  • 類型: Scope[]
  • 描述: 所有作用域。

globalScope

  • 類型: Scope
  • 描述: 根作用域。

方法

acquire(node, inner = false)

  • 參數
    • node (ASTNode) … 取得其作用域的 AST 節點。
    • inner (boolean) … 如果節點有多個作用域,則此參數通常會傳回最外層的作用域。如果 innertrue,則此參數會傳回最內層的作用域。預設值為 false
  • 回傳類型: Scope | null
  • 描述: 取得給定 AST 節點的作用域。所取得的作用域的 block 屬性為該節點。此方法永遠不會傳回 function-expression-name 作用域。如果節點沒有作用域,則此方法會傳回 null

getDeclaredVariables(node)

  • 參數
    • node (ASTNode) … 取得其變數的 AST 節點。
  • 回傳類型: Variable[]
  • 描述: 取得給定 AST 節點定義的變數。所取得的變數的 def[].node/def[].parent 屬性為該節點。如果節點沒有定義任何變數,則此方法會傳回空陣列。

已棄用的成員

這些成員已定義,但未在 ESLint 中使用。

isModule()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此程式是模組,則為 true

isImpliedStrict()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此程式是隱式嚴格模式,則為 true。例如,options.impliedStrict === true

isStrictModeSupported()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此程式支援嚴格模式,則為 true。例如,options.ecmaVersion >= 5

acquireAll(node)

  • 參數
    • node (ASTNode) … 取得其作用域的 AST 節點。
  • 回傳類型: Scope[] | null
  • 描述: 取得給定 AST 節點的作用域。所取得的作用域的 block 屬性為該節點。如果節點沒有作用域,則此方法會傳回 null

Scope 介面

Scope 物件具有作用域中的所有變數和參考。

欄位

type

  • 類型: string
  • 描述: 此作用域的類型。這是 "block""catch""class""class-field-initializer""class-static-block""for""function""function-expression-name""global""module""switch""with" 其中之一。

isStrict

  • 類型: boolean
  • 描述: 如果此作用域是嚴格模式,則為 true

upper

  • 類型: Scope | null
  • 描述: 父作用域。如果這是全域作用域,則此屬性為 null

childScopes

  • 類型: Scope[]
  • 描述: 子作用域的陣列。這不包含孫子作用域。

variableScope

  • 類型: Scope
  • 描述: 最接近的祖先,其 type"class-field-initializer""class-static-block""function""global""module" 其中之一。對於上述作用域,這是自我參照。

這表示最低的封閉函式或頂層作用域。類別欄位初始化器和類別靜態區塊是隱式函式。從歷史來看,這是託管由 var 宣告定義的變數的作用域,因此稱為 variableScope

block

  • 類型: ASTNode
  • 描述: 建立此作用域的 AST 節點。

variables

  • 類型: Variable[]
  • 描述: 在此作用域中定義的所有變數的陣列。這不包含在子作用域中定義的變數。

set

  • 類型: Map<string, Variable>
  • 描述: 從變數名稱到變數物件的對應。

我希望重新命名 set 欄位或替換為方法。

references

  • 類型: Reference[]
  • 描述: 在此作用域中的所有參考的陣列。這不包含子作用域中的參考。

through

  • 類型: Reference[]
  • 描述: 無法在此作用域中解析的參考陣列。

functionExpressionScope

  • 類型: boolean
  • 描述: 如果此作用域是 "function-expression-name" 作用域,則為 true

我希望棄用 functionExpressionScope 欄位,並以 scope.type === "function-expression-name" 取代。

已棄用的成員

這些成員已定義,但未在 ESLint 中使用。

taints

  • 類型: Map<string, boolean>
  • 描述: 從變數名稱到 tainted 旗標的對應。

dynamic

  • 類型: boolean
  • 描述: 如果此作用域是動態的,則為 true。例如,此作用域的類型為 "global""with"

directCallToEvalScope

  • 類型: boolean
  • 描述: 如果此作用域包含 eval() 呼叫,則為 true

thisFound

  • 類型: boolean
  • 描述: 如果此作用域包含 this,則為 true

resolve(node)

  • 參數
    • node (ASTNode) … 取得其參考物件的 AST 節點。節點的類型必須為 "Identifier"
  • 回傳類型: Reference | null
  • 描述: 傳回 this.references.find(r => r.identifier === node)

isStatic()

  • 參數
  • 回傳類型: boolean
  • 描述: 傳回 !this.dynamic

isArgumentsMaterialized()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果這是使用了 arguments 變數的 "function" 作用域,則為 true

isThisMaterialized()

  • 參數
  • 回傳類型: boolean
  • 描述: 傳回 this.thisFound

isUsedName(name)

  • 參數
    • name (string) … 要檢查的名稱。
  • 回傳類型: boolean
  • 描述: 如果給定的名稱用於變數名稱或參考名稱中,則為 true

Variable 介面

Variable 物件是變數的資訊。

欄位

name

  • 類型: string
  • 描述: 此變數的名稱。

scope

  • 類型: Scope
  • 描述: 定義此變數的作用域。

identifiers

  • 類型: ASTNode[]
  • 描述: 定義此變數的 Identifier 節點陣列。如果重新宣告此變數,則此陣列會包含兩個或多個節點。

我希望棄用 identifiers 欄位,並以 defs[].name 欄位取代。

references

  • 類型: Reference[]
  • 描述: 此變數的參考陣列。

defs

  • 類型: Definition[]
  • 描述: 此變數的定義陣列。

已棄用的成員

這些成員已定義,但未在 ESLint 中使用。

tainted

  • 類型: boolean
  • 描述: tainted 旗標。(永遠為 false

stack

  • 類型: boolean
  • 描述: stack 旗標。(我不確定這代表什麼。)

Reference 介面

Reference 物件是參考的資訊。

欄位

identifier

  • 類型: ASTNode
  • 描述: 此參考的 Identifier 節點。

from

  • 類型: Scope
  • 描述: 此參考所在的 Scope 物件。

resolved

  • 類型: Variable | null
  • 描述: 此參考指向的 Variable 物件。如果未定義此類變數,則此為 null

writeExpr

  • 類型: ASTNode | null
  • 描述: 右側的 ASTNode 物件。

init

  • 類型: boolean
  • 描述: 如果此寫入參考是變數初始化器或預設值,則為 true

方法

isWrite()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此參考正在寫入,則為 true

isRead()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此參考正在讀取,則為 true

isWriteOnly()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此參考正在寫入但未讀取,則為 true

isReadOnly()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此參考正在讀取但未寫入,則為 true

isReadWrite()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此參考正在讀取和寫入,則為 true

已棄用的成員

這些成員已定義,但未在 ESLint 中使用。

tainted

  • 類型: boolean
  • 描述: tainted 旗標。(永遠為 false

flag

  • 類型: number
  • 描述: 1 代表讀取,2 代表寫入,3 代表讀取/寫入。

partial

  • 類型: boolean
  • 描述: partial 旗標。

isStatic()

  • 參數
  • 回傳類型: boolean
  • 描述: 如果此參考是靜態解析的,則為 true

Definition 介面

Definition 物件是變數定義的資訊。

欄位

type

  • 類型: string
  • 描述: 此定義的類型。為 "CatchClause""ClassName""FunctionName""ImplicitGlobalVariable""ImportBinding""Parameter""Variable" 其中之一。

name

  • 類型: ASTNode
  • 描述: 此定義的 Identifier 節點。

node

  • 類型: ASTNode
  • 描述: 名稱的封閉節點。
type node
"CatchClause" CatchClause
"ClassName" ClassDeclarationClassExpression
"FunctionName" FunctionDeclarationFunctionExpression
"ImplicitGlobalVariable" 程式
"ImportBinding" ImportSpecifierImportDefaultSpecifierImportNamespaceSpecifier
"Parameter" FunctionDeclarationFunctionExpressionArrowFunctionExpression
"Variable" VariableDeclarator

parent

  • 類型: ASTNode | undefined | null
  • 描述: 名稱的封閉陳述式節點。
type parent
"CatchClause" null
"ClassName" null
"FunctionName" null
"ImplicitGlobalVariable" null
"ImportBinding" ImportDeclaration
"Parameter" null
"Variable" VariableDeclaration

已棄用的成員

這些成員已定義,但未在 ESLint 中使用。

index

  • 類型: number | undefined | null
  • 描述: 宣告陳述式中的索引。

kind

  • 類型: string | undefined | null
  • 描述: 宣告陳述式的類型。
變更語言