Skip to content

⬅️ Back to Table of Contents

📄 spec.ts

📊 Analysis Summary

Metric Count
📦 Imports 8
📐 Interfaces 7
📑 Type Aliases 3

📚 Table of Contents

🛠️ File Location:

📂 packages/ast-spec/src/declaration/VariableDeclaration/spec.ts

📦 Imports

Name Source
AST_NODE_TYPES ../../ast-node-types
BaseNode ../../base/BaseNode
LetOrConstOrVarDeclarator ../../special/VariableDeclarator/spec
UsingInForOfDeclarator ../../special/VariableDeclarator/spec
UsingInNormalContextDeclarator ../../special/VariableDeclarator/spec
VariableDeclaratorDefiniteAssignment ../../special/VariableDeclarator/spec
VariableDeclaratorMaybeInit ../../special/VariableDeclarator/spec
VariableDeclaratorNoInit ../../special/VariableDeclarator/spec

Interfaces

LetOrConstOrVarDeclarationBase

Interface Code
interface LetOrConstOrVarDeclarationBase extends BaseNode {
  type: AST_NODE_TYPES.VariableDeclaration;
  /**
   * The variables declared by this declaration.
   * Always non-empty.
   * @example
   * ```ts
   * let x;
   * let y, z;
   * ```
   */
  declarations: LetOrConstOrVarDeclarator[];
  /**
   * Whether the declaration is `declare`d
   * @example
   * ```ts
   * declare const x = 1;
   * ```
   */
  declare: boolean;
  /**
   * The keyword used to declare the variable(s)
   * @example
   * ```ts
   * const x = 1;
   * let y = 2;
   * var z = 3;
   * ```
   */
  kind: 'const' | 'let' | 'var';
}

Properties

Name Type Optional Description
type AST_NODE_TYPES.VariableDeclaration
declarations LetOrConstOrVarDeclarator[]
declare boolean
kind 'const' | 'let' | 'var'

LetOrVarDeclaredDeclaration

Interface Code
export interface LetOrVarDeclaredDeclaration
  extends LetOrConstOrVarDeclarationBase {
  /**
   * In a `declare let` declaration, the declarators must not have definite assignment
   * assertions or initializers.
   *
   * @example
   * ```ts
   * using x = 1;
   * using y =1, z = 2;
   * ```
   */
  declarations: VariableDeclaratorNoInit[];
  declare: true;
  kind: 'let' | 'var';
}

Properties

Name Type Optional Description
declarations VariableDeclaratorNoInit[]
declare true
kind 'let' | 'var'

LetOrVarNonDeclaredDeclaration

Interface Code
export interface LetOrVarNonDeclaredDeclaration
  extends LetOrConstOrVarDeclarationBase {
  /**
   * In a `let`/`var` declaration, the declarators may have definite assignment
   * assertions or initializers, but not both.
   */
  declarations: (
    | VariableDeclaratorDefiniteAssignment
    | VariableDeclaratorMaybeInit
  )[];
  declare: false;
  kind: 'let' | 'var';
}

Properties

Name Type Optional Description
declarations `(
VariableDeclaratorDefiniteAssignment
VariableDeclaratorMaybeInit
)[]`
declare false
kind 'let' | 'var'

ConstDeclaration

Interface Code
export interface ConstDeclaration extends LetOrConstOrVarDeclarationBase {
  /**
   * In a `declare const` declaration, the declarators may have initializers, but
   * not definite assignment assertions. Each declarator cannot have both an
   * initializer and a type annotation.
   *
   * Even if the declaration has no `declare`, it may still be ambient and have
   * no initializer.
   */
  declarations: VariableDeclaratorMaybeInit[];
  kind: 'const';
}

Properties

Name Type Optional Description
declarations VariableDeclaratorMaybeInit[]
kind 'const'

UsingDeclarationBase

Interface Code
interface UsingDeclarationBase extends BaseNode {
  type: AST_NODE_TYPES.VariableDeclaration;
  /**
   * This value will always be `false`
   * because 'declare' modifier cannot appear on a 'using' declaration.
   */
  declare: false;
  /**
   * The keyword used to declare the variable(s)
   * @example
   * ```ts
   * using x = 1;
   * await using y = 2;
   * ```
   */
  kind: 'await using' | 'using';
}

Properties

Name Type Optional Description
type AST_NODE_TYPES.VariableDeclaration
declare false
kind 'await using' | 'using'

UsingInNormalContextDeclaration

Interface Code
export interface UsingInNormalContextDeclaration extends UsingDeclarationBase {
  /**
   * The variables declared by this declaration.
   * Always non-empty.
   * @example
   * ```ts
   * using x = 1;
   * using y = 1, z = 2;
   * ```
   */
  declarations: UsingInNormalContextDeclarator[];
}

Properties

Name Type Optional Description
declarations UsingInNormalContextDeclarator[]

UsingInForOfDeclaration

Interface Code
export interface UsingInForOfDeclaration extends UsingDeclarationBase {
  /**
   * The variables declared by this declaration.
   * Always has exactly one element.
   * @example
   * ```ts
   * for (using x of y) {}
   * ```
   */
  declarations: [UsingInForOfDeclarator];
}

Properties

Name Type Optional Description
declarations [UsingInForOfDeclarator]

Type Aliases

LetOrConstOrVarDeclaration

type LetOrConstOrVarDeclaration = | ConstDeclaration
  | LetOrVarDeclaredDeclaration
  | LetOrVarNonDeclaredDeclaration;

UsingDeclaration

type UsingDeclaration = | UsingInForOfDeclaration
  | UsingInNormalContextDeclaration;

VariableDeclaration

type VariableDeclaration = LetOrConstOrVarDeclaration | UsingDeclaration;