Skip to content

AST tightening: around init/definite combinations on let/var/const declarators #9221

@Josh-Cena

Description

@Josh-Cena

Suggestion

In #9211: we are planning to enforce the following invariants in our AST for VariableDeclaration, specifically the declarators in declarations:

  • definite can only be true if declare: false and kind: "let" | "var", so the following are all parsing errors:
    const x! = 1;
    declare let x!: string;
  • If definite: true, then init: null, and the identifier has a type annotation:
    let x! = 1;
    let x!;
  • If declare: true and kind: "let" | "var", then init: null:
    declare let x = 1;
  • If declare: false and kind: "const" then init is non-null:
    const x;

@sosukesuzuki @fisker Do these look safe to you?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ASTPRs and Issues about the AST structureenhancementNew feature or requestlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: typescript-estreeIssues related to @typescript-eslint/typescript-estree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions