📄 Reference.ts
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 5 |
🧱 Classes | 1 |
📦 Imports | 4 |
📐 Interfaces | 1 |
🎯 Enums | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/scope-manager/src/referencer/Reference.ts
📦 Imports¶
Name | Source |
---|---|
TSESTree |
@typescript-eslint/types |
Scope |
../scope |
Variable |
../variable |
createIdGenerator |
../ID |
Functions¶
Reference.isWrite(): boolean
¶
-
JSDoc:
-
Return Type:
boolean
Reference.isRead(): boolean
¶
-
JSDoc:
-
Return Type:
boolean
Reference.isReadOnly(): boolean
¶
-
JSDoc:
-
Return Type:
boolean
Reference.isWriteOnly(): boolean
¶
-
JSDoc:
-
Return Type:
boolean
Reference.isReadWrite(): boolean
¶
-
JSDoc:
-
Return Type:
boolean
Classes¶
Reference
¶
Class Code
export class Reference {
/**
* A unique ID for this instance - primarily used to help debugging and testing
*/
public readonly $id: number = generator();
/**
* The read-write mode of the reference.
*/
readonly #flag: ReferenceFlag;
/**
* Reference to the enclosing Scope.
* @public
*/
public readonly from: Scope;
/**
* Identifier syntax node.
* @public
*/
public readonly identifier: TSESTree.Identifier | TSESTree.JSXIdentifier;
/**
* `true` if this writing reference is a variable initializer or a default value.
* @public
*/
public readonly init?: boolean;
public readonly maybeImplicitGlobal?: ReferenceImplicitGlobal | null;
/**
* The {@link Variable} object that this reference refers to. If such variable was not defined, this is `null`.
* @public
*/
public resolved: Variable | null;
/**
* If reference is writeable, this is the node being written to it.
* @public
*/
public readonly writeExpr?: TSESTree.Node | null;
/**
* In some cases, a reference may be a type, value or both a type and value reference.
*/
readonly #referenceType: ReferenceTypeFlag;
constructor(
identifier: TSESTree.Identifier | TSESTree.JSXIdentifier,
scope: Scope,
flag: ReferenceFlag,
writeExpr?: TSESTree.Node | null,
maybeImplicitGlobal?: ReferenceImplicitGlobal | null,
init?: boolean,
referenceType = ReferenceTypeFlag.Value,
) {
this.identifier = identifier;
this.from = scope;
this.resolved = null;
this.#flag = flag;
if (this.isWrite()) {
this.writeExpr = writeExpr;
this.init = init;
}
this.maybeImplicitGlobal = maybeImplicitGlobal;
this.#referenceType = referenceType;
}
/**
* True if this reference can reference types
*/
public get isTypeReference(): boolean {
return (this.#referenceType & ReferenceTypeFlag.Type) !== 0;
}
/**
* True if this reference can reference values
*/
public get isValueReference(): boolean {
return (this.#referenceType & ReferenceTypeFlag.Value) !== 0;
}
/**
* Whether the reference is writeable.
* @public
*/
public isWrite(): boolean {
return !!(this.#flag & ReferenceFlag.Write);
}
/**
* Whether the reference is readable.
* @public
*/
public isRead(): boolean {
return !!(this.#flag & ReferenceFlag.Read);
}
/**
* Whether the reference is read-only.
* @public
*/
public isReadOnly(): boolean {
return this.#flag === ReferenceFlag.Read;
}
/**
* Whether the reference is write-only.
* @public
*/
public isWriteOnly(): boolean {
return this.#flag === ReferenceFlag.Write;
}
/**
* Whether the reference is read-write.
* @public
*/
public isReadWrite(): boolean {
return this.#flag === ReferenceFlag.ReadWrite;
}
}
Methods¶
isWrite(): boolean
¶
isRead(): boolean
¶
isReadOnly(): boolean
¶
isWriteOnly(): boolean
¶
isReadWrite(): boolean
¶
Interfaces¶
ReferenceImplicitGlobal
¶
Interface Code
Properties¶
Name | Type | Optional | Description |
---|---|---|---|
node |
TSESTree.Node |
✗ | |
pattern |
TSESTree.BindingName |
✗ | |
ref |
Reference |
✓ |
Enums¶
enum ReferenceFlag
¶
Members¶
Name | Value | Description |
---|---|---|
Read |
1 |
|
Write |
2 |
|
ReadWrite |
3 |
enum ReferenceTypeFlag
¶
Members¶
Name | Value | Description |
---|---|---|
Value |
1 |
|
Type |
2 |