Skip to content

⬅️ Back to Table of Contents

📄 Reference

📊 Analysis Summary

Metric Count
🔧 Functions 5
🧱 Classes 1
📦 Imports 5
📐 Interfaces 1
🎯 Enums 2

📚 Table of Contents

🛠️ File Location:

📂 packages/scope-manager/src/referencer/Reference.ts

📦 Imports

Name Source
NodeWithParent @typescript-eslint/types
TSESTree @typescript-eslint/types
Scope ../scope
Variable ../variable
createIdGenerator ../ID

Functions

Reference.isWrite(): boolean

Whether the reference is writeable.

Tags: @public

Raw JSDoc
/**
   * Whether the reference is writeable.
   * @public
   */
Code
public isWrite(): boolean {
    return !!(this.#flag & ReferenceFlag.Write);
  }

Reference.isRead(): boolean

Whether the reference is readable.

Tags: @public

Raw JSDoc
/**
   * Whether the reference is readable.
   * @public
   */
Code
public isRead(): boolean {
    return !!(this.#flag & ReferenceFlag.Read);
  }

Reference.isReadOnly(): boolean

Whether the reference is read-only.

Tags: @public

Raw JSDoc
/**
   * Whether the reference is read-only.
   * @public
   */
Code
public isReadOnly(): boolean {
    return this.#flag === ReferenceFlag.Read;
  }

Reference.isWriteOnly(): boolean

Whether the reference is write-only.

Tags: @public

Raw JSDoc
/**
   * Whether the reference is write-only.
   * @public
   */
Code
public isWriteOnly(): boolean {
    return this.#flag === ReferenceFlag.Write;
  }

Reference.isReadWrite(): boolean

Whether the reference is read-write.

Tags: @public

Raw JSDoc
/**
   * Whether the reference is read-write.
   * @public
   */
Code
public isReadWrite(): boolean {
    return this.#flag === ReferenceFlag.ReadWrite;
  }

Classes

Reference

A Reference represents a single occurrence of an identifier in code.

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 (5) — full entries under Functions

Method Signature
isWrite (): boolean
isRead (): boolean
isReadOnly (): boolean
isWriteOnly (): boolean
isReadWrite (): boolean

Interfaces

ReferenceImplicitGlobal

Interface Code
export interface ReferenceImplicitGlobal {
  node: NodeWithParent;
  pattern: TSESTree.BindingName;
  ref?: Reference;
}

Properties

Name Type Optional Description
node NodeWithParent not shown
pattern TSESTree.BindingName not shown
ref Reference not shown

Enums

enum ReferenceFlag

Enum Code
export enum ReferenceFlag {
  Read = 0x1,
  Write = 0x2,
  ReadWrite = 0x3,
}

Members

Name Value Description
Read 1 not shown
Write 2 not shown
ReadWrite 3 not shown

enum ReferenceTypeFlag

Enum Code
export enum ReferenceTypeFlag {
  Value = 0x1,
  Type = 0x2,
}

Members

Name Value Description
Value 1 not shown
Type 2 not shown

Generated by Syntax Scribe