From 0603fcb08dc9ec5e7ca66d5af3e46dbb8c084cc2 Mon Sep 17 00:00:00 2001 From: fisker Date: Sun, 23 Nov 2025 14:17:07 +0800 Subject: [PATCH] chore: check `VariableDeclaration` syntax error against tsNode --- packages/typescript-estree/src/convert.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index d578c2b012cb..2631cb401e23 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -985,28 +985,27 @@ export class Converter { case SyntaxKind.VariableDeclaration: { const definite = !!node.exclamationToken; - const init = this.convertChild(node.initializer); - const id = this.convertBindingNameWithTypeAnnotation( - node.name, - node.type, - node, - ); + if (definite) { - if (init) { + if (node.initializer) { this.#throwError( node, 'Declarations with initializers cannot also have definite assignment assertions.', ); - } else if ( - id.type !== AST_NODE_TYPES.Identifier || - !id.typeAnnotation - ) { + } else if (node.name.kind !== SyntaxKind.Identifier || !node.type) { this.#throwError( node, 'Declarations with definite assignment assertions must also have type annotations.', ); } } + + const init = this.convertChild(node.initializer); + const id = this.convertBindingNameWithTypeAnnotation( + node.name, + node.type, + node, + ); return this.createNode(node, { type: AST_NODE_TYPES.VariableDeclarator, definite,