From 3796771ef66d83ae87115103a2e4405b01c5bb3f Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:54 -0800 Subject: [PATCH 01/34] Add isAutoAccessorPropertyDeclaration AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 5 +++++ packages/typescript/src/ast/is.ts | 6 ++++++ packages/typescript/test/astPredicates.test.ts | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 packages/typescript/test/astPredicates.test.ts diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 18867bd9e13c9..6833cc84f978a 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -58,6 +58,11 @@ export { TokenFlags } from "../../enums/tokenFlags.js"; export * from "./ast.generated.ts"; export * as factory from "./factory.generated.ts"; +declare const autoAccessorBrand: unique symbol; +export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { + readonly [autoAccessorBrand]: void; +} + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index c9f8fe7b76e9a..7c09e648cfa6f 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -6,6 +6,7 @@ import { NodeFlags } from "../../enums/nodeFlags.js"; import { OuterExpressionKinds } from "../../enums/outerExpressionKinds.js"; import { ScriptKind } from "../../enums/scriptKind.js"; import { SyntaxKind } from "../../enums/syntaxKind.js"; +import type * as ast from "./ast.ts"; import type { AsExpression, BindingPattern, @@ -70,6 +71,11 @@ import { export * from "./is.generated.ts"; +export function isAutoAccessorPropertyDeclaration(node: Node): node is ast.AutoAccessorPropertyDeclaration { + return node.kind === SyntaxKind.PropertyDeclaration && + !!((node as ast.PropertyDeclaration).modifierFlags & ModifierFlags.Accessor); +} + type JSDocNamespaceDeclaration = ModuleDeclaration; type WrappedExpression = diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts new file mode 100644 index 0000000000000..d5fe245352fc9 --- /dev/null +++ b/packages/typescript/test/astPredicates.test.ts @@ -0,0 +1,18 @@ +import * as ast from "@typescript/typescript/ast"; +import * as factory from "@typescript/typescript/ast/factory"; +import assert from "node:assert/strict"; +import { test } from "node:test"; + +test("isAutoAccessorPropertyDeclaration distinguishes accessor modifiers from accessors", () => { + const name = factory.createIdentifier("value"); + const property: ast.Node = factory.createPropertyDeclaration([factory.createToken(ast.SyntaxKind.AccessorKeyword)], name); + assert.ok(ast.isAutoAccessorPropertyDeclaration(property)); + const narrowed: ast.AutoAccessorPropertyDeclaration = property; + assert.equal(narrowed.name, name); + assert.equal(ast.isAutoAccessorPropertyDeclaration(factory.createPropertyDeclaration(undefined, name)), false); + assert.equal(ast.isAutoAccessorPropertyDeclaration(factory.createGetAccessorDeclaration(undefined, name, undefined, [])), false); + const ordinary = factory.createPropertyDeclaration(undefined, name); + if (!ast.isAutoAccessorPropertyDeclaration(ordinary)) { + assert.equal(ordinary.name, name); + } +}); From f5704d790915b33a78fb9610db19a17049667a04 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:54 -0800 Subject: [PATCH 02/34] Add isCallChain AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 6 ++++++ packages/typescript/src/ast/is.ts | 5 +++++ packages/typescript/test/astPredicates.test.ts | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 6833cc84f978a..9cc9695c2d11c 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -7,6 +7,7 @@ import type { LanguageVariant } from "../../enums/languageVariant.js"; import type { NodeFlags } from "../../enums/nodeFlags.js"; import type { ScriptKind } from "../../enums/scriptKind.js"; import { SyntaxKind } from "../../enums/syntaxKind.js"; +import type * as generated from "./ast.generated.ts"; import type { AssertionExpression, BindingElement, @@ -63,6 +64,11 @@ export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { readonly [autoAccessorBrand]: void; } +declare const optionalChainBrand: unique symbol; +export interface CallChain extends generated.CallExpression { + readonly [optionalChainBrand]: void; +} + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 7c09e648cfa6f..6b5dc2432e086 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -50,6 +50,7 @@ import type { TypeNode, UnaryExpressionBase, } from "./ast.ts"; +import * as guards from "./is.generated.ts"; import { isBinaryExpression, isClassLikeDeclaration, @@ -583,3 +584,7 @@ export function isJsxTagNameExpression(node: Node): node is JsxTagNameExpression || kind === SyntaxKind.PropertyAccessExpression || kind === SyntaxKind.JsxNamespacedName; } + +export function isCallChain(node: Node): node is ast.CallChain { + return guards.isCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index d5fe245352fc9..71de00547432c 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -16,3 +16,17 @@ test("isAutoAccessorPropertyDeclaration distinguishes accessor modifiers from ac assert.equal(ordinary.name, name); } }); + +test("isCallChain recognizes continuations without a question-dot token", () => { + const name = factory.createIdentifier("f"); + const call: ast.Node = factory.createCallExpression(name, undefined, undefined, [], ast.NodeFlags.OptionalChain); + assert.ok(ast.isCallChain(call)); + const narrowed: ast.CallChain = call; + assert.equal(narrowed.questionDotToken, undefined); + const ordinary = factory.createCallExpression(name, undefined, undefined, [], ast.NodeFlags.None); + if (!ast.isCallChain(ordinary)) { + assert.equal(ordinary.arguments.length, 0); + } + assert.equal(ast.isCallChain(ordinary), false); + assert.equal(ast.isCallChain(factory.createNonNullExpression(name, ast.NodeFlags.OptionalChain)), false); +}); From 6c5be79abd83d881ea1cebf6b13db99f2c37471f Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:54 -0800 Subject: [PATCH 03/34] Add isClassElement AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 16 ++++++++++++++++ packages/typescript/test/astPredicates.test.ts | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 6b5dc2432e086..e70ea79f4a489 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -588,3 +588,19 @@ export function isJsxTagNameExpression(node: Node): node is JsxTagNameExpression export function isCallChain(node: Node): node is ast.CallChain { return guards.isCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } + +export function isClassElement(node: Node): node is ast.ClassElement { + switch (node.kind) { + case SyntaxKind.Constructor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.IndexSignature: + case SyntaxKind.ClassStaticBlockDeclaration: + case SyntaxKind.SemicolonClassElement: + return true; + default: + return false; + } +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 71de00547432c..b344ec021c00e 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -30,3 +30,12 @@ test("isCallChain recognizes continuations without a question-dot token", () => assert.equal(ast.isCallChain(ordinary), false); assert.equal(ast.isCallChain(factory.createNonNullExpression(name, ast.NodeFlags.OptionalChain)), false); }); + +test("isClassElement includes static blocks and index signatures but not interface properties", () => { + const signature: ast.Node = factory.createIndexSignatureDeclaration(undefined, []); + assert.ok(ast.isClassElement(signature)); + const narrowed: ast.ClassElement = signature; + assert.equal(narrowed, signature); + assert.ok(ast.isClassElement(factory.createClassStaticBlockDeclaration(undefined, factory.createBlock([])))); + assert.equal(ast.isClassElement(factory.createPropertySignatureDeclaration(undefined, factory.createIdentifier("x"))), false); +}); From 89ff33bd75375425aaaed2fa5b05ffaf42b2a902 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:54 -0800 Subject: [PATCH 04/34] Add isConstTypeReference AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 5 +++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index e70ea79f4a489..397d60d51d0ac 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -604,3 +604,8 @@ export function isClassElement(node: Node): node is ast.ClassElement { return false; } } + +export function isConstTypeReference(node: Node): boolean { + return guards.isTypeReferenceNode(node) && isIdentifier(node.typeName) && + node.typeName.text === "const" && !node.typeArguments; +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index b344ec021c00e..ba0e6d7e2e21c 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -39,3 +39,13 @@ test("isClassElement includes static blocks and index signatures but not interfa assert.ok(ast.isClassElement(factory.createClassStaticBlockDeclaration(undefined, factory.createBlock([])))); assert.equal(ast.isClassElement(factory.createPropertySignatureDeclaration(undefined, factory.createIdentifier("x"))), false); }); + +test("isConstTypeReference rejects qualified names and even empty type argument lists", () => { + const name = factory.createIdentifier("const"); + const reference = factory.createTypeReferenceNode(name); + assert.ok(ast.isConstTypeReference(reference)); + assert.equal(reference.typeName, name); + assert.equal(ast.isConstTypeReference(factory.createTypeReferenceNode(name, [])), false); + assert.equal(ast.isConstTypeReference(factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier("ns"), name))), false); + assert.equal(ast.isConstTypeReference(factory.createIdentifier("const")), false); +}); From ac330e038b4c80e2028a7a1ac132b0e4ad38a07a Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:54 -0800 Subject: [PATCH 05/34] Add isDeclarationStatement AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 22 ++++++++++ .../typescript/test/astPredicates.test.ts | 41 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 397d60d51d0ac..b457d4a13b887 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -609,3 +609,25 @@ export function isConstTypeReference(node: Node): boolean { return guards.isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.text === "const" && !node.typeArguments; } + +export function isDeclarationStatement(node: Node): node is ast.Statement & ast.Declaration { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.MissingDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.JSTypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.JSImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportDeclaration: + case SyntaxKind.ExportAssignment: + case SyntaxKind.NamespaceExportDeclaration: + return true; + default: + return false; + } +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index ba0e6d7e2e21c..7bfafa4d17800 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -2,6 +2,17 @@ import * as ast from "@typescript/typescript/ast"; import * as factory from "@typescript/typescript/ast/factory"; import assert from "node:assert/strict"; import { test } from "node:test"; +import { fileURLToPath } from "node:url"; +import { API } from "./sync/api.testUtils.ts"; +import { createVirtualFileSystem } from "./testUtils.ts"; + +function createAPI(): API { + return new API({ + cwd: fileURLToPath(new URL("../../../", import.meta.url)), + tsserverPath: fileURLToPath(new URL(`../../../built/local/tsc${process.platform === "win32" ? ".exe" : ""}`, import.meta.url)), + fs: createVirtualFileSystem({}), + }); +} test("isAutoAccessorPropertyDeclaration distinguishes accessor modifiers from accessors", () => { const name = factory.createIdentifier("value"); @@ -49,3 +60,33 @@ test("isConstTypeReference rejects qualified names and even empty type argument assert.equal(ast.isConstTypeReference(factory.createTypeReferenceNode(factory.createQualifiedName(factory.createIdentifier("ns"), name))), false); assert.equal(ast.isConstTypeReference(factory.createIdentifier("const")), false); }); + +test("isDeclarationStatement does not classify variable statements as declaration statements", () => { + const declaration: ast.Node = factory.createExportDeclaration(); + assert.ok(ast.isDeclarationStatement(declaration)); + const narrowed: ast.Statement & ast.Declaration = declaration; + assert.equal(narrowed, declaration); + assert.ok(ast.isDeclarationStatement(factory.createMissingDeclaration())); + assert.equal(ast.isDeclarationStatement(factory.createVariableStatement(undefined, factory.createVariableDeclarationList([], ast.NodeFlags.Const))), false); + assert.equal(ast.isDeclarationStatement(factory.createBlock([])), false); +}); + +test("isDeclarationStatement includes declarations produced by JavaScript JSDoc", () => { + using api = createAPI(); + const source = api.createSourceFile( + "/declarations.js", + `/** @typedef {string} Name */ +/** @callback Callback + * @returns {void} + */ +/** @import { Value } from "./types" */ +`, + ).sourceFile; + const declarations = source.statements.filter(node => node.kind === ast.SyntaxKind.JSTypeAliasDeclaration || node.kind === ast.SyntaxKind.JSImportDeclaration); + assert.deepEqual(declarations.map(node => node.kind), [ + ast.SyntaxKind.JSTypeAliasDeclaration, + ast.SyntaxKind.JSTypeAliasDeclaration, + ast.SyntaxKind.JSImportDeclaration, + ]); + assert.ok(declarations.every(ast.isDeclarationStatement)); +}); From c8d9b6c103f245d624001ed27b022ff63fcb5fb9 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:54 -0800 Subject: [PATCH 06/34] Add isElementAccessChain AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 4 ++++ packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 9cc9695c2d11c..7db8400a10de9 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -69,6 +69,10 @@ export interface CallChain extends generated.CallExpression { readonly [optionalChainBrand]: void; } +export interface ElementAccessChain extends generated.ElementAccessExpression { + readonly [optionalChainBrand]: void; +} + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index b457d4a13b887..8ac5fc07ecb91 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -631,3 +631,7 @@ export function isDeclarationStatement(node: Node): node is ast.Statement & ast. return false; } } + +export function isElementAccessChain(node: Node): node is ast.ElementAccessChain { + return guards.isElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 7bfafa4d17800..5bf25e859f6ab 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -90,3 +90,14 @@ test("isDeclarationStatement includes declarations produced by JavaScript JSDoc" ]); assert.ok(declarations.every(ast.isDeclarationStatement)); }); + +test("isElementAccessChain uses the chain flag rather than the question-dot token", () => { + const name = factory.createIdentifier("obj"); + const index = factory.createStringLiteral("key", ast.TokenFlags.None); + const access: ast.Node = factory.createElementAccessExpression(name, undefined, index, ast.NodeFlags.OptionalChain); + assert.ok(ast.isElementAccessChain(access)); + const narrowed: ast.ElementAccessChain = access; + assert.equal(narrowed.argumentExpression, index); + assert.equal(ast.isElementAccessChain(factory.createElementAccessExpression(name, undefined, index, ast.NodeFlags.None)), false); + assert.equal(ast.isElementAccessChain(factory.createPropertyAccessExpression(name, undefined, name, ast.NodeFlags.OptionalChain)), false); +}); From 8655e20bb9fb8882751f63523aeb28f012934c80 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:54 -0800 Subject: [PATCH 07/34] Add isEmptyBindingElement AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 5 ++++ .../typescript/test/astPredicates.test.ts | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 8ac5fc07ecb91..ebe7ee928530c 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -635,3 +635,8 @@ export function isDeclarationStatement(node: Node): node is ast.Statement & ast. export function isElementAccessChain(node: Node): node is ast.ElementAccessChain { return guards.isElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } + +export function isEmptyBindingElement(node: ast.BindingElement | ast.ArrayBindingElement): boolean { + return guards.isOmittedExpression(node) || !node.name || + isBindingPattern(node.name) && node.name.elements.every(isEmptyBindingElement); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 5bf25e859f6ab..b56c457733cab 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -101,3 +101,28 @@ test("isElementAccessChain uses the chain flag rather than the question-dot toke assert.equal(ast.isElementAccessChain(factory.createElementAccessExpression(name, undefined, index, ast.NodeFlags.None)), false); assert.equal(ast.isElementAccessChain(factory.createPropertyAccessExpression(name, undefined, name, ast.NodeFlags.OptionalChain)), false); }); + +test("isEmptyBindingElement recursively distinguishes bindings from empty nested patterns", () => { + const empty = factory.createBindingElement(undefined, undefined, factory.createObjectBindingPattern([])); + assert.ok(ast.isEmptyBindingElement(empty)); + assert.ok(ast.isEmptyBindingElement(factory.createOmittedExpression())); + assert.ok(ast.isEmptyBindingElement(factory.createBindingElement())); + const binding = factory.createBindingElement(undefined, undefined, factory.createIdentifier("value")); + assert.equal(ast.isEmptyBindingElement(binding), false); + assert.equal(ast.isEmptyBindingElement(factory.createBindingElement(undefined, undefined, factory.createArrayBindingPattern([binding]))), false); +}); + +test("isEmptyBindingElement recognizes parsed array-binding holes", () => { + using api = createAPI(); + const source = api.createSourceFile("/holes.ts", "const [, , value] = values;").sourceFile; + const statement = source.statements[0]; + assert.ok(ast.isVariableStatement(statement)); + const pattern = statement.declarationList.declarations[0].name; + assert.ok(ast.isArrayBindingPattern(pattern)); + assert.deepEqual(pattern.elements.map(element => element.kind), [ + ast.SyntaxKind.BindingElement, + ast.SyntaxKind.BindingElement, + ast.SyntaxKind.BindingElement, + ]); + assert.deepEqual(pattern.elements.map(ast.isEmptyBindingElement), [true, true, false]); +}); From ce675dc87a8205ecbc98b00a95358b9a65501e98 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:55 -0800 Subject: [PATCH 08/34] Add isEmptyBindingPattern AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 3 ++ packages/typescript/src/ast/is.ts | 4 +++ .../typescript/test/astPredicates.test.ts | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 7db8400a10de9..42587690a9a56 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -73,6 +73,9 @@ export interface ElementAccessChain extends generated.ElementAccessExpression { readonly [optionalChainBrand]: void; } +declare const emptyBindingPatternBrand: unique symbol; +export type EmptyBindingPattern = generated.BindingPattern & { readonly [emptyBindingPatternBrand]: void; }; + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index ebe7ee928530c..85e868a8a6c65 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -640,3 +640,7 @@ export function isEmptyBindingElement(node: ast.BindingElement | ast.ArrayBindin return guards.isOmittedExpression(node) || !node.name || isBindingPattern(node.name) && node.name.elements.every(isEmptyBindingElement); } + +export function isEmptyBindingPattern(node: ast.BindingName): node is ast.EmptyBindingPattern { + return isBindingPattern(node) && node.elements.every(isEmptyBindingElement); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index b56c457733cab..d90f105a6dcd0 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -126,3 +126,35 @@ test("isEmptyBindingElement recognizes parsed array-binding holes", () => { ]); assert.deepEqual(pattern.elements.map(ast.isEmptyBindingElement), [true, true, false]); }); + +test("isEmptyBindingPattern accepts nested empty patterns but not identifiers", () => { + const nested: ast.BindingName = factory.createArrayBindingPattern([ + factory.createBindingElement(undefined, undefined, factory.createObjectBindingPattern([])), + ]); + assert.ok(ast.isEmptyBindingPattern(nested)); + const narrowed: ast.EmptyBindingPattern = nested; + assert.equal(narrowed.elements.length, 1); + assert.equal(ast.isEmptyBindingPattern(factory.createIdentifier("value")), false); + assert.equal( + ast.isEmptyBindingPattern(factory.createObjectBindingPattern([ + factory.createBindingElement(undefined, undefined, factory.createIdentifier("value")), + ])), + false, + ); + const nonempty = factory.createObjectBindingPattern([ + factory.createBindingElement(undefined, undefined, factory.createIdentifier("value")), + ]); + if (!ast.isEmptyBindingPattern(nonempty)) { + assert.equal(nonempty.elements.length, 1); + } +}); + +test("isEmptyBindingPattern accepts parsed hole-only and nested empty patterns", () => { + using api = createAPI(); + const source = api.createSourceFile( + "/patterns.ts", + "const [,] = values; const [, [,], {}] = values; const [, value] = values;", + ).sourceFile; + const patterns = source.statements.filter(ast.isVariableStatement).map(statement => statement.declarationList.declarations[0].name); + assert.deepEqual(patterns.map(ast.isEmptyBindingPattern), [true, true, false]); +}); From f9143dd1935cf6bad4094d1361ad0eb2a8875676 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:55 -0800 Subject: [PATCH 09/34] Add isFunctionLike AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 85e868a8a6c65..d8ba39ddde2a8 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -644,3 +644,7 @@ export function isEmptyBindingElement(node: ast.BindingElement | ast.ArrayBindin export function isEmptyBindingPattern(node: ast.BindingName): node is ast.EmptyBindingPattern { return isBindingPattern(node) && node.elements.every(isEmptyBindingElement); } + +export function isFunctionLike(node: Node | undefined): node is ast.SignatureDeclaration | ast.JSDocSignature { + return !!node && (guards.isSignatureDeclaration(node) || guards.isJSDocSignature(node)); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index d90f105a6dcd0..f0a5161fe887c 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -158,3 +158,14 @@ test("isEmptyBindingPattern accepts parsed hole-only and nested empty patterns", const patterns = source.statements.filter(ast.isVariableStatement).map(statement => statement.declarationList.declarations[0].name); assert.deepEqual(patterns.map(ast.isEmptyBindingPattern), [true, true, false]); }); + +test("isFunctionLike includes signatures and JSDoc callbacks, not only functions with bodies", () => { + const signature: ast.Node | undefined = factory.createCallSignatureDeclaration(undefined, []); + assert.ok(ast.isFunctionLike(signature)); + const narrowed: ast.SignatureDeclaration | ast.JSDocSignature = signature; + assert.equal(narrowed.parameters.length, 0); + assert.ok(ast.isFunctionLike(factory.createJSDocSignature(undefined, []))); + assert.ok(ast.isFunctionLike(factory.createFunctionTypeNode(undefined, [], factory.createKeywordTypeNode(ast.SyntaxKind.VoidKeyword)))); + assert.equal(ast.isFunctionLike(undefined), false); + assert.equal(ast.isFunctionLike(factory.createClassStaticBlockDeclaration(undefined, factory.createBlock([]))), false); +}); From d86f2369e559f5af583c8fd1bb4311d4576d3891 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:55 -0800 Subject: [PATCH 10/34] Add isFunctionOrConstructorTypeNode AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index d8ba39ddde2a8..4b7500f4e933e 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -648,3 +648,7 @@ export function isEmptyBindingPattern(node: ast.BindingName): node is ast.EmptyB export function isFunctionLike(node: Node | undefined): node is ast.SignatureDeclaration | ast.JSDocSignature { return !!node && (guards.isSignatureDeclaration(node) || guards.isJSDocSignature(node)); } + +export function isFunctionOrConstructorTypeNode(node: Node): node is ast.FunctionTypeNode | ast.ConstructorTypeNode { + return guards.isFunctionTypeNode(node) || guards.isConstructorTypeNode(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index f0a5161fe887c..4592d87c312c4 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -169,3 +169,13 @@ test("isFunctionLike includes signatures and JSDoc callbacks, not only functions assert.equal(ast.isFunctionLike(undefined), false); assert.equal(ast.isFunctionLike(factory.createClassStaticBlockDeclaration(undefined, factory.createBlock([]))), false); }); + +test("isFunctionOrConstructorTypeNode excludes callable declaration signatures", () => { + const result = factory.createKeywordTypeNode(ast.SyntaxKind.VoidKeyword); + const type: ast.Node = factory.createFunctionTypeNode(undefined, [], result); + assert.ok(ast.isFunctionOrConstructorTypeNode(type)); + const narrowed: ast.FunctionTypeNode | ast.ConstructorTypeNode = type; + assert.equal(narrowed.type, result); + assert.ok(ast.isFunctionOrConstructorTypeNode(factory.createConstructorTypeNode(undefined, undefined, [], result))); + assert.equal(ast.isFunctionOrConstructorTypeNode(factory.createCallSignatureDeclaration(undefined, [])), false); +}); From e870e8bbb42eae48c29e71390473c6d283e0425b Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:55 -0800 Subject: [PATCH 11/34] Add isImportOrExportSpecifier AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 4b7500f4e933e..f4b11a51fa417 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -652,3 +652,7 @@ export function isFunctionLike(node: Node | undefined): node is ast.SignatureDec export function isFunctionOrConstructorTypeNode(node: Node): node is ast.FunctionTypeNode | ast.ConstructorTypeNode { return guards.isFunctionTypeNode(node) || guards.isConstructorTypeNode(node); } + +export function isImportOrExportSpecifier(node: Node): node is ast.ImportSpecifier | ast.ExportSpecifier { + return guards.isImportSpecifier(node) || guards.isExportSpecifier(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 4592d87c312c4..bc1770dc14ac6 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -179,3 +179,13 @@ test("isFunctionOrConstructorTypeNode excludes callable declaration signatures", assert.ok(ast.isFunctionOrConstructorTypeNode(factory.createConstructorTypeNode(undefined, undefined, [], result))); assert.equal(ast.isFunctionOrConstructorTypeNode(factory.createCallSignatureDeclaration(undefined, [])), false); }); + +test("isImportOrExportSpecifier distinguishes named specifiers from namespace imports", () => { + const name = factory.createIdentifier("value"); + const specifier: ast.Node = factory.createImportSpecifier(true, undefined, name); + assert.ok(ast.isImportOrExportSpecifier(specifier)); + const narrowed: ast.ImportSpecifier | ast.ExportSpecifier = specifier; + assert.equal(narrowed.isTypeOnly, true); + assert.ok(ast.isImportOrExportSpecifier(factory.createExportSpecifier(false, undefined, name))); + assert.equal(ast.isImportOrExportSpecifier(factory.createNamespaceImport(name)), false); +}); From c7d82ed3495fe0e35fb72adf79bb3417b6349ebd Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:55 -0800 Subject: [PATCH 12/34] Add isIterationStatement AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 17 +++++++++++++++++ packages/typescript/test/astPredicates.test.ts | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index f4b11a51fa417..c583103ba8f18 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -656,3 +656,20 @@ export function isFunctionOrConstructorTypeNode(node: Node): node is ast.Functio export function isImportOrExportSpecifier(node: Node): node is ast.ImportSpecifier | ast.ExportSpecifier { return guards.isImportSpecifier(node) || guards.isExportSpecifier(node); } + +export function isIterationStatement(node: Node, lookInLabeledStatements: false): node is ast.DoStatement | ast.WhileStatement | ast.ForStatement | ast.ForInStatement | ast.ForOfStatement; +export function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is ast.DoStatement | ast.WhileStatement | ast.ForStatement | ast.ForInStatement | ast.ForOfStatement | ast.LabeledStatement; +export function isIterationStatement(node: Node, lookInLabeledStatements: boolean): boolean { + switch (node.kind) { + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.DoStatement: + case SyntaxKind.WhileStatement: + return true; + case SyntaxKind.LabeledStatement: + return lookInLabeledStatements && isIterationStatement((node as ast.LabeledStatement).statement, true); + default: + return false; + } +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index bc1770dc14ac6..8fc15360599c6 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -189,3 +189,15 @@ test("isImportOrExportSpecifier distinguishes named specifiers from namespace im assert.ok(ast.isImportOrExportSpecifier(factory.createExportSpecifier(false, undefined, name))); assert.equal(ast.isImportOrExportSpecifier(factory.createNamespaceImport(name)), false); }); + +test("isIterationStatement follows labels only when requested", () => { + const empty = factory.createEmptyStatement(); + const loop: ast.Node = factory.createWhileStatement(factory.createIdentifier("condition"), empty); + assert.ok(ast.isIterationStatement(loop, false)); + const narrowed: ast.DoStatement | ast.WhileStatement | ast.ForStatement | ast.ForInStatement | ast.ForOfStatement = loop; + assert.equal(narrowed.statement, empty); + const labeled = factory.createLabeledStatement(factory.createIdentifier("outer"), factory.createLabeledStatement(factory.createIdentifier("inner"), loop)); + assert.equal(ast.isIterationStatement(labeled, false), false); + assert.equal(ast.isIterationStatement(labeled, true), true); + assert.equal(ast.isIterationStatement(factory.createLabeledStatement(factory.createIdentifier("label"), empty), true), false); +}); From 6aa16f4f6488924f8810796810c5f4afca56d06a Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:55 -0800 Subject: [PATCH 13/34] Add isJsxCallLike AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index c583103ba8f18..5f365adb3ab6f 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -673,3 +673,7 @@ export function isIterationStatement(node: Node, lookInLabeledStatements: boolea return false; } } + +export function isJsxCallLike(node: Node): node is ast.JsxOpeningElement | ast.JsxSelfClosingElement | ast.JsxOpeningFragment { + return guards.isJsxOpeningElement(node) || guards.isJsxSelfClosingElement(node) || guards.isJsxOpeningFragment(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 8fc15360599c6..7df9901251e0a 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -201,3 +201,12 @@ test("isIterationStatement follows labels only when requested", () => { assert.equal(ast.isIterationStatement(labeled, true), true); assert.equal(ast.isIterationStatement(factory.createLabeledStatement(factory.createIdentifier("label"), empty), true), false); }); + +test("isJsxCallLike includes opening fragments but excludes complete fragments", () => { + const opening: ast.Node = factory.createJsxOpeningFragment(); + assert.ok(ast.isJsxCallLike(opening)); + const narrowed: ast.JsxOpeningElement | ast.JsxSelfClosingElement | ast.JsxOpeningFragment = opening; + assert.equal(narrowed, opening); + assert.ok(ast.isJsxCallLike(factory.createJsxSelfClosingElement(factory.createIdentifier("Component"), undefined, factory.createJsxAttributes([])))); + assert.equal(ast.isJsxCallLike(factory.createJsxFragment(factory.createJsxOpeningFragment(), [], factory.createJsxClosingFragment())), false); +}); From 78dfa74f193db9a0a3723a623fac9699a30a1029 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:56 -0800 Subject: [PATCH 14/34] Add isNonNullChain AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 4 ++++ packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 42587690a9a56..7c8c9609f3b17 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -76,6 +76,10 @@ export interface ElementAccessChain extends generated.ElementAccessExpression { declare const emptyBindingPatternBrand: unique symbol; export type EmptyBindingPattern = generated.BindingPattern & { readonly [emptyBindingPatternBrand]: void; }; +export interface NonNullChain extends generated.NonNullExpression { + readonly [optionalChainBrand]: void; +} + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 5f365adb3ab6f..37ddb8f011c94 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -677,3 +677,7 @@ export function isIterationStatement(node: Node, lookInLabeledStatements: boolea export function isJsxCallLike(node: Node): node is ast.JsxOpeningElement | ast.JsxSelfClosingElement | ast.JsxOpeningFragment { return guards.isJsxOpeningElement(node) || guards.isJsxSelfClosingElement(node) || guards.isJsxOpeningFragment(node); } + +export function isNonNullChain(node: Node): node is ast.NonNullChain { + return guards.isNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 7df9901251e0a..0e6df6e43c626 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -210,3 +210,13 @@ test("isJsxCallLike includes opening fragments but excludes complete fragments", assert.ok(ast.isJsxCallLike(factory.createJsxSelfClosingElement(factory.createIdentifier("Component"), undefined, factory.createJsxAttributes([])))); assert.equal(ast.isJsxCallLike(factory.createJsxFragment(factory.createJsxOpeningFragment(), [], factory.createJsxClosingFragment())), false); }); + +test("isNonNullChain distinguishes optional-chain assertions from ordinary assertions", () => { + const name = factory.createIdentifier("value"); + const assertion: ast.Node = factory.createNonNullExpression(name, ast.NodeFlags.OptionalChain); + assert.ok(ast.isNonNullChain(assertion)); + const narrowed: ast.NonNullChain = assertion; + assert.equal(narrowed.expression, name); + assert.equal(ast.isNonNullChain(factory.createNonNullExpression(name, ast.NodeFlags.None)), false); + assert.equal(ast.isNonNullChain(factory.createCallExpression(name, undefined, undefined, [], ast.NodeFlags.OptionalChain)), false); +}); From e79c67e48b5dde15df0971f04d06540c12a501ae Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:56 -0800 Subject: [PATCH 15/34] Add isNullishCoalesce AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 37ddb8f011c94..ec2bf1ca89188 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -681,3 +681,7 @@ export function isJsxCallLike(node: Node): node is ast.JsxOpeningElement | ast.J export function isNonNullChain(node: Node): node is ast.NonNullChain { return guards.isNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } + +export function isNullishCoalesce(node: Node): boolean { + return isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.QuestionQuestionToken; +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 0e6df6e43c626..439590685b6c9 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -220,3 +220,12 @@ test("isNonNullChain distinguishes optional-chain assertions from ordinary asser assert.equal(ast.isNonNullChain(factory.createNonNullExpression(name, ast.NodeFlags.None)), false); assert.equal(ast.isNonNullChain(factory.createCallExpression(name, undefined, undefined, [], ast.NodeFlags.OptionalChain)), false); }); + +test("isNullishCoalesce distinguishes nullish coalescing from logical OR", () => { + const name = factory.createIdentifier("value"); + const expression = factory.createBinaryExpression(undefined, name, undefined, factory.createToken(ast.SyntaxKind.QuestionQuestionToken), name); + assert.ok(ast.isNullishCoalesce(expression)); + assert.equal(expression.left, name); + assert.equal(ast.isNullishCoalesce(factory.createBinaryExpression(undefined, name, undefined, factory.createToken(ast.SyntaxKind.BarBarToken), name)), false); + assert.equal(ast.isNullishCoalesce(name), false); +}); From 8836315d238a7d3d6ec02481d00cafb732db89a5 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:56 -0800 Subject: [PATCH 16/34] Add isObjectLiteralElement AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index ec2bf1ca89188..7ffb25e47e8f6 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -685,3 +685,7 @@ export function isNonNullChain(node: Node): node is ast.NonNullChain { export function isNullishCoalesce(node: Node): boolean { return isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.QuestionQuestionToken; } + +export function isObjectLiteralElement(node: Node): node is ast.ObjectLiteralElementLike | ast.JsxAttributeLike { + return guards.isObjectLiteralElementLike(node) || guards.isJsxAttributeLike(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 439590685b6c9..f9061044991c9 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -229,3 +229,14 @@ test("isNullishCoalesce distinguishes nullish coalescing from logical OR", () => assert.equal(ast.isNullishCoalesce(factory.createBinaryExpression(undefined, name, undefined, factory.createToken(ast.SyntaxKind.BarBarToken), name)), false); assert.equal(ast.isNullishCoalesce(name), false); }); + +test("isObjectLiteralElement includes JSX attributes as well as object spreads", () => { + const name = factory.createIdentifier("value"); + const attribute: ast.Node = factory.createJsxAttribute(name); + assert.ok(ast.isObjectLiteralElement(attribute)); + const narrowed: ast.ObjectLiteralElementLike | ast.JsxAttributeLike = attribute; + assert.equal(narrowed, attribute); + assert.ok(ast.isObjectLiteralElement(factory.createJsxSpreadAttribute(name))); + assert.ok(ast.isObjectLiteralElement(factory.createSpreadAssignment(name))); + assert.equal(ast.isObjectLiteralElement(factory.createPropertyDeclaration(undefined, name)), false); +}); From 8ed3266c8b8b7f99d8abe3bc977bbddacf344e25 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:56 -0800 Subject: [PATCH 17/34] Add isOptionalChain AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 6 ++++++ packages/typescript/src/ast/is.ts | 5 +++++ packages/typescript/test/astPredicates.test.ts | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 7c8c9609f3b17..86c9f65a88f8b 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -80,6 +80,12 @@ export interface NonNullChain extends generated.NonNullExpression { readonly [optionalChainBrand]: void; } +export interface PropertyAccessChain extends PropertyAccessExpression { + readonly [optionalChainBrand]: void; +} + +export type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain; + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 7ffb25e47e8f6..b44684b7e4767 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -689,3 +689,8 @@ export function isNullishCoalesce(node: Node): boolean { export function isObjectLiteralElement(node: Node): node is ast.ObjectLiteralElementLike | ast.JsxAttributeLike { return guards.isObjectLiteralElementLike(node) || guards.isJsxAttributeLike(node); } + +export function isOptionalChain(node: Node): node is ast.OptionalChain { + return !!(node.flags & NodeFlags.OptionalChain) && + (guards.isAccessExpression(node) || guards.isCallExpression(node) || guards.isNonNullExpression(node)); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index f9061044991c9..351f93e907077 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -240,3 +240,16 @@ test("isObjectLiteralElement includes JSX attributes as well as object spreads", assert.ok(ast.isObjectLiteralElement(factory.createSpreadAssignment(name))); assert.equal(ast.isObjectLiteralElement(factory.createPropertyDeclaration(undefined, name)), false); }); + +test("isOptionalChain includes non-null continuations but rejects flagged unrelated nodes", () => { + const name = factory.createIdentifier("value"); + const chain: ast.Node = factory.createNonNullExpression(name, ast.NodeFlags.OptionalChain); + assert.ok(ast.isOptionalChain(chain)); + const narrowed: ast.OptionalChain = chain; + assert.equal(narrowed.expression, name); + assert.ok(ast.isOptionalChain(factory.createCallExpression(name, undefined, undefined, [], ast.NodeFlags.OptionalChain))); + assert.equal(ast.isOptionalChain(factory.createNonNullExpression(name, ast.NodeFlags.None)), false); + const unrelated = factory.createParenthesizedExpression(name); + Object.defineProperty(unrelated, "flags", { value: ast.NodeFlags.OptionalChain }); + assert.equal(ast.isOptionalChain(unrelated), false); +}); From d43b99789f1e8a5fe13948a1af9f1da145ea09c7 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:56 -0800 Subject: [PATCH 18/34] Add isParameterPropertyDeclaration AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 5 +++++ packages/typescript/src/ast/is.ts | 5 +++++ packages/typescript/test/astPredicates.test.ts | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 86c9f65a88f8b..10a6c721761ce 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -86,6 +86,11 @@ export interface PropertyAccessChain extends PropertyAccessExpression { export type OptionalChain = PropertyAccessChain | ElementAccessChain | CallChain | NonNullChain; +declare const parameterPropertyBrand: unique symbol; +export interface ParameterPropertyDeclaration extends ParameterDeclaration { + readonly [parameterPropertyBrand]: void; +} + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index b44684b7e4767..e6a7d77c615ea 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -694,3 +694,8 @@ export function isOptionalChain(node: Node): node is ast.OptionalChain { return !!(node.flags & NodeFlags.OptionalChain) && (guards.isAccessExpression(node) || guards.isCallExpression(node) || guards.isNonNullExpression(node)); } + +export function isParameterPropertyDeclaration(node: Node, parent: Node): node is ast.ParameterPropertyDeclaration { + return guards.isParameterDeclaration(node) && !!(node.modifierFlags & ModifierFlags.ParameterPropertyModifier) && + guards.isConstructorDeclaration(parent); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 351f93e907077..e3690ad899618 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -253,3 +253,15 @@ test("isOptionalChain includes non-null continuations but rejects flagged unrela Object.defineProperty(unrelated, "flags", { value: ast.NodeFlags.OptionalChain }); assert.equal(ast.isOptionalChain(unrelated), false); }); + +test("isParameterPropertyDeclaration requires both a property modifier and a constructor", () => { + const name = factory.createIdentifier("value"); + const constructor = factory.createConstructorDeclaration(undefined, undefined, []); + const parameter: ast.Node = factory.createParameterDeclaration([factory.createToken(ast.SyntaxKind.ReadonlyKeyword)], undefined, name); + assert.ok(ast.isParameterPropertyDeclaration(parameter, constructor)); + const narrowed: ast.ParameterPropertyDeclaration = parameter; + assert.equal(narrowed.name, name); + assert.equal(ast.isParameterPropertyDeclaration(parameter, factory.createFunctionDeclaration(undefined, undefined, undefined, undefined, [])), false); + assert.equal(ast.isParameterPropertyDeclaration(factory.createParameterDeclaration(undefined, undefined, name), constructor), false); + assert.equal(ast.isParameterPropertyDeclaration(factory.createPropertyDeclaration(undefined, name), constructor), false); +}); From 23267adfcd4118ab67117dea470e7f9ac3d9027f Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:57 -0800 Subject: [PATCH 19/34] Add isPropertyAccessChain AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index e6a7d77c615ea..e58d24288c8a1 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -699,3 +699,7 @@ export function isParameterPropertyDeclaration(node: Node, parent: Node): node i return guards.isParameterDeclaration(node) && !!(node.modifierFlags & ModifierFlags.ParameterPropertyModifier) && guards.isConstructorDeclaration(parent); } + +export function isPropertyAccessChain(node: Node): node is ast.PropertyAccessChain { + return guards.isPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index e3690ad899618..412dcd6c74b7d 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -265,3 +265,13 @@ test("isParameterPropertyDeclaration requires both a property modifier and a con assert.equal(ast.isParameterPropertyDeclaration(factory.createParameterDeclaration(undefined, undefined, name), constructor), false); assert.equal(ast.isParameterPropertyDeclaration(factory.createPropertyDeclaration(undefined, name), constructor), false); }); + +test("isPropertyAccessChain includes chain continuations without their own question-dot token", () => { + const name = factory.createIdentifier("value"); + const access: ast.Node = factory.createPropertyAccessExpression(name, undefined, name, ast.NodeFlags.OptionalChain); + assert.ok(ast.isPropertyAccessChain(access)); + const narrowed: ast.PropertyAccessChain = access; + assert.equal(narrowed.name, name); + assert.equal(ast.isPropertyAccessChain(factory.createPropertyAccessExpression(name, undefined, name, ast.NodeFlags.None)), false); + assert.equal(ast.isPropertyAccessChain(factory.createElementAccessExpression(name, undefined, name, ast.NodeFlags.OptionalChain)), false); +}); From 5e6d0c57b2010cdfeaea124f988537c39f2194cf Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:57 -0800 Subject: [PATCH 20/34] Add isPropertyAccessOrQualifiedName AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index e58d24288c8a1..e38f9f0a06797 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -703,3 +703,7 @@ export function isParameterPropertyDeclaration(node: Node, parent: Node): node i export function isPropertyAccessChain(node: Node): node is ast.PropertyAccessChain { return guards.isPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } + +export function isPropertyAccessOrQualifiedName(node: Node): node is ast.PropertyAccessExpression | ast.QualifiedName { + return guards.isPropertyAccessExpression(node) || guards.isQualifiedName(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 412dcd6c74b7d..378747e7f9d6a 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -275,3 +275,13 @@ test("isPropertyAccessChain includes chain continuations without their own quest assert.equal(ast.isPropertyAccessChain(factory.createPropertyAccessExpression(name, undefined, name, ast.NodeFlags.None)), false); assert.equal(ast.isPropertyAccessChain(factory.createElementAccessExpression(name, undefined, name, ast.NodeFlags.OptionalChain)), false); }); + +test("isPropertyAccessOrQualifiedName accepts entity names and expressions, not element access", () => { + const name = factory.createIdentifier("value"); + const qualified: ast.Node = factory.createQualifiedName(name, name); + assert.ok(ast.isPropertyAccessOrQualifiedName(qualified)); + const narrowed: ast.PropertyAccessExpression | ast.QualifiedName = qualified; + assert.equal(narrowed, qualified); + assert.ok(ast.isPropertyAccessOrQualifiedName(factory.createPropertyAccessExpression(name, undefined, name, ast.NodeFlags.None))); + assert.equal(ast.isPropertyAccessOrQualifiedName(factory.createElementAccessExpression(name, undefined, name, ast.NodeFlags.None)), false); +}); From 204b190b09eaebd309a48cfb6f1c501ca2b00c07 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:57 -0800 Subject: [PATCH 21/34] Add isRestParameter AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 9 +++++++++ packages/typescript/test/astPredicates.test.ts | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index e38f9f0a06797..ecffc47dd06c3 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -707,3 +707,12 @@ export function isPropertyAccessChain(node: Node): node is ast.PropertyAccessCha export function isPropertyAccessOrQualifiedName(node: Node): node is ast.PropertyAccessExpression | ast.QualifiedName { return guards.isPropertyAccessExpression(node) || guards.isQualifiedName(node); } + +export function isRestParameter(node: ast.ParameterDeclaration | ast.JSDocParameterTag): boolean { + if (guards.isParameterDeclaration(node)) { + return node.dotDotDotToken !== undefined || node.type?.kind === SyntaxKind.JSDocVariadicType; + } + const type = node.typeExpression; + return type?.kind === SyntaxKind.JSDocVariadicType || + type?.kind === SyntaxKind.JSDocTypeExpression && (type as JSDocTypeExpression).type.kind === SyntaxKind.JSDocVariadicType; +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 378747e7f9d6a..4a93f3108c082 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -285,3 +285,14 @@ test("isPropertyAccessOrQualifiedName accepts entity names and expressions, not assert.ok(ast.isPropertyAccessOrQualifiedName(factory.createPropertyAccessExpression(name, undefined, name, ast.NodeFlags.None))); assert.equal(ast.isPropertyAccessOrQualifiedName(factory.createElementAccessExpression(name, undefined, name, ast.NodeFlags.None)), false); }); + +test("isRestParameter supports syntactic rest parameters and JSDoc variadic types", () => { + const name = factory.createIdentifier("values"); + const type = factory.createJSDocVariadicType(factory.createKeywordTypeNode(ast.SyntaxKind.StringKeyword)); + assert.ok(ast.isRestParameter(factory.createParameterDeclaration(undefined, factory.createToken(ast.SyntaxKind.DotDotDotToken), name))); + assert.ok(ast.isRestParameter(factory.createParameterDeclaration(undefined, undefined, name, undefined, type))); + assert.ok(ast.isRestParameter(factory.createJSDocParameterTag(factory.createIdentifier("param"), name, false, type, false, undefined))); + assert.ok(ast.isRestParameter(factory.createJSDocParameterTag(factory.createIdentifier("param"), name, false, factory.createJSDocTypeExpression(type), false, undefined))); + assert.equal(ast.isRestParameter(factory.createParameterDeclaration(undefined, undefined, name)), false); + assert.equal(ast.isRestParameter(factory.createJSDocParameterTag(factory.createIdentifier("param"), name, false, undefined, false, undefined)), false); +}); From 5e8adc86ea31753a90c19a48dbd5e79d5f357878 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:57 -0800 Subject: [PATCH 22/34] Add isStringLiteralOrJsxExpression AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index ecffc47dd06c3..02fc800ae012f 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -716,3 +716,7 @@ export function isRestParameter(node: ast.ParameterDeclaration | ast.JSDocParame return type?.kind === SyntaxKind.JSDocVariadicType || type?.kind === SyntaxKind.JSDocTypeExpression && (type as JSDocTypeExpression).type.kind === SyntaxKind.JSDocVariadicType; } + +export function isStringLiteralOrJsxExpression(node: Node): node is ast.StringLiteral | ast.JsxExpression { + return guards.isStringLiteral(node) || guards.isJsxExpression(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 4a93f3108c082..016d3ebda5588 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -296,3 +296,13 @@ test("isRestParameter supports syntactic rest parameters and JSDoc variadic type assert.equal(ast.isRestParameter(factory.createParameterDeclaration(undefined, undefined, name)), false); assert.equal(ast.isRestParameter(factory.createJSDocParameterTag(factory.createIdentifier("param"), name, false, undefined, false, undefined)), false); }); + +test("isStringLiteralOrJsxExpression excludes template literals and full JSX elements", () => { + const expression: ast.Node = factory.createJsxExpression(); + assert.ok(ast.isStringLiteralOrJsxExpression(expression)); + const narrowed: ast.StringLiteral | ast.JsxExpression = expression; + assert.equal(narrowed, expression); + assert.ok(ast.isStringLiteralOrJsxExpression(factory.createStringLiteral("text", ast.TokenFlags.None))); + assert.equal(ast.isStringLiteralOrJsxExpression(factory.createNoSubstitutionTemplateLiteral("text", ast.TokenFlags.None)), false); + assert.equal(ast.isStringLiteralOrJsxExpression(factory.createJsxOpeningFragment()), false); +}); From 0d7e87bcefd7959a6f59248aa527cae5f45c5056 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:57 -0800 Subject: [PATCH 23/34] Add isStringTextContainingNode AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 02fc800ae012f..38a8b2570f4ab 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -720,3 +720,7 @@ export function isRestParameter(node: ast.ParameterDeclaration | ast.JSDocParame export function isStringLiteralOrJsxExpression(node: Node): node is ast.StringLiteral | ast.JsxExpression { return guards.isStringLiteral(node) || guards.isJsxExpression(node); } + +export function isStringTextContainingNode(node: Node): node is ast.StringLiteral | ast.TemplateLiteralToken { + return guards.isStringLiteral(node) || guards.isTemplateLiteralToken(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 016d3ebda5588..baf4f838fb0bd 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -306,3 +306,15 @@ test("isStringLiteralOrJsxExpression excludes template literals and full JSX ele assert.equal(ast.isStringLiteralOrJsxExpression(factory.createNoSubstitutionTemplateLiteral("text", ast.TokenFlags.None)), false); assert.equal(ast.isStringLiteralOrJsxExpression(factory.createJsxOpeningFragment()), false); }); + +test("isStringTextContainingNode includes template fragments but not template expressions", () => { + const head: ast.Node = factory.createTemplateHead("text", "text", ast.TokenFlags.None); + assert.ok(ast.isStringTextContainingNode(head)); + const narrowed: ast.StringLiteral | ast.TemplateLiteralToken = head; + assert.equal(narrowed.text, "text"); + assert.ok(ast.isStringTextContainingNode(factory.createTemplateMiddle("middle", "middle", ast.TokenFlags.None))); + assert.ok(ast.isStringTextContainingNode(factory.createTemplateTail("tail", "tail", ast.TokenFlags.None))); + assert.ok(ast.isStringTextContainingNode(factory.createNoSubstitutionTemplateLiteral("text", ast.TokenFlags.None))); + assert.ok(ast.isStringTextContainingNode(factory.createStringLiteral("text", ast.TokenFlags.None))); + assert.equal(ast.isStringTextContainingNode(factory.createTemplateExpression(factory.createTemplateHead("", "", ast.TokenFlags.None), [])), false); +}); From c7482856dc8b6687967feb175b611e3aee07b08d Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:57 -0800 Subject: [PATCH 24/34] Add isTypeElement AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 16 ++++++++++++++++ packages/typescript/test/astPredicates.test.ts | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 38a8b2570f4ab..9255676de3f16 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -724,3 +724,19 @@ export function isStringLiteralOrJsxExpression(node: Node): node is ast.StringLi export function isStringTextContainingNode(node: Node): node is ast.StringLiteral | ast.TemplateLiteralToken { return guards.isStringLiteral(node) || guards.isTemplateLiteralToken(node); } + +export function isTypeElement(node: Node): node is ast.TypeElement { + switch (node.kind) { + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.PropertySignature: + case SyntaxKind.MethodSignature: + case SyntaxKind.IndexSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.NotEmittedTypeElement: + return true; + default: + return false; + } +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index baf4f838fb0bd..8e9ae0a8211b1 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -318,3 +318,14 @@ test("isStringTextContainingNode includes template fragments but not template ex assert.ok(ast.isStringTextContainingNode(factory.createStringLiteral("text", ast.TokenFlags.None))); assert.equal(ast.isStringTextContainingNode(factory.createTemplateExpression(factory.createTemplateHead("", "", ast.TokenFlags.None), [])), false); }); + +test("isTypeElement includes accessors and synthetic elisions but excludes method declarations", () => { + const name = factory.createIdentifier("value"); + const accessor: ast.Node = factory.createGetAccessorDeclaration(undefined, name, undefined, []); + assert.ok(ast.isTypeElement(accessor)); + const narrowed: ast.TypeElement = accessor; + assert.equal(narrowed, accessor); + assert.ok(ast.isTypeElement(factory.createNotEmittedTypeElement())); + assert.ok(ast.isTypeElement(factory.createCallSignatureDeclaration(undefined, []))); + assert.equal(ast.isTypeElement(factory.createMethodDeclaration(undefined, undefined, name, undefined, undefined, [])), false); +}); From 7e0c599d09c15b407af53f40a629a871a98374ed Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:58 -0800 Subject: [PATCH 25/34] Add isClassOrTypeElement AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 9255676de3f16..c71fb867d2f2c 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -740,3 +740,7 @@ export function isTypeElement(node: Node): node is ast.TypeElement { return false; } } + +export function isClassOrTypeElement(node: Node): node is ast.ClassElement | ast.TypeElement { + return isClassElement(node) || isTypeElement(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 8e9ae0a8211b1..26030926322bc 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -329,3 +329,12 @@ test("isTypeElement includes accessors and synthetic elisions but excludes metho assert.ok(ast.isTypeElement(factory.createCallSignatureDeclaration(undefined, []))); assert.equal(ast.isTypeElement(factory.createMethodDeclaration(undefined, undefined, name, undefined, undefined, [])), false); }); + +test("isClassOrTypeElement unifies class-only and type-only members", () => { + const member: ast.Node = factory.createClassStaticBlockDeclaration(undefined, factory.createBlock([])); + assert.ok(ast.isClassOrTypeElement(member)); + const narrowed: ast.ClassElement | ast.TypeElement = member; + assert.equal(narrowed, member); + assert.ok(ast.isClassOrTypeElement(factory.createCallSignatureDeclaration(undefined, []))); + assert.equal(ast.isClassOrTypeElement(factory.createPropertyAssignment(undefined, factory.createIdentifier("value"), undefined, undefined, factory.createNumericLiteral("1", ast.TokenFlags.None))), false); +}); From a1e498ce575564539a3643da8df7a6ee29b3e9fc Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:58 -0800 Subject: [PATCH 26/34] Add isTypeOnlyImportDeclaration AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 10 +++++++ packages/typescript/src/ast/is.ts | 18 +++++++++++++ .../typescript/test/astPredicates.test.ts | 27 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 10a6c721761ce..2122b963e279f 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -91,6 +91,16 @@ export interface ParameterPropertyDeclaration extends ParameterDeclaration { readonly [parameterPropertyBrand]: void; } +export type TypeOnlyImportDeclaration = + | generated.ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; } + | generated.ImportEqualsDeclaration & { readonly isTypeOnly: true; } + | generated.NamespaceImport & { readonly parent: generated.ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; } + | generated.ImportSpecifier + & ( + | { readonly isTypeOnly: true; } + | { readonly parent: generated.NamedImports & { readonly parent: generated.ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; }; } + ); + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index c71fb867d2f2c..7814a0db0a76a 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -744,3 +744,21 @@ export function isTypeElement(node: Node): node is ast.TypeElement { export function isClassOrTypeElement(node: Node): node is ast.ClassElement | ast.TypeElement { return isClassElement(node) || isTypeElement(node); } + +export function isTypeOnlyImportDeclaration(node: Node): node is ast.TypeOnlyImportDeclaration { + switch (node.kind) { + case SyntaxKind.ImportSpecifier: { + const specifier = node as ast.ImportSpecifier; + const clause = specifier.parent?.parent; + return specifier.isTypeOnly || !!clause && guards.isImportClause(clause) && clause.phaseModifier === SyntaxKind.TypeKeyword; + } + case SyntaxKind.NamespaceImport: + return !!node.parent && guards.isImportClause(node.parent) && node.parent.phaseModifier === SyntaxKind.TypeKeyword; + case SyntaxKind.ImportClause: + return (node as ast.ImportClause).phaseModifier === SyntaxKind.TypeKeyword; + case SyntaxKind.ImportEqualsDeclaration: + return (node as ast.ImportEqualsDeclaration).isTypeOnly; + default: + return false; + } +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 26030926322bc..a18fecb9cff8d 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -338,3 +338,30 @@ test("isClassOrTypeElement unifies class-only and type-only members", () => { assert.ok(ast.isClassOrTypeElement(factory.createCallSignatureDeclaration(undefined, []))); assert.equal(ast.isClassOrTypeElement(factory.createPropertyAssignment(undefined, factory.createIdentifier("value"), undefined, undefined, factory.createNumericLiteral("1", ast.TokenFlags.None))), false); }); + +test("isTypeOnlyImportDeclaration inherits type-only status but not defer status", () => { + const name = factory.createIdentifier("value"); + const specifier = factory.createImportSpecifier(false, undefined, name); + const bindings = factory.createNamedImports([specifier]); + const clause = factory.createImportClause(ast.SyntaxKind.TypeKeyword, undefined, bindings); + Object.defineProperty(specifier, "parent", { value: bindings }); + Object.defineProperty(bindings, "parent", { value: clause }); + const node: ast.Node = specifier; + assert.ok(ast.isTypeOnlyImportDeclaration(node)); + const narrowed: ast.TypeOnlyImportDeclaration = node; + assert.equal(narrowed, specifier); + assert.ok(ast.isTypeOnlyImportDeclaration(clause)); + assert.ok(ast.isTypeOnlyImportDeclaration(factory.createImportSpecifier(true, undefined, name))); + assert.equal(ast.isTypeOnlyImportDeclaration(factory.createImportClause(ast.SyntaxKind.DeferKeyword, name)), false); + assert.equal(ast.isTypeOnlyImportDeclaration(factory.createIdentifier("value")), false); + const valueSpecifier = factory.createImportSpecifier(false, undefined, name); + assert.equal(ast.isTypeOnlyImportDeclaration(valueSpecifier), false); + if (!ast.isTypeOnlyImportDeclaration(valueSpecifier)) { + assert.equal(valueSpecifier.name, name); + } + const namespace = factory.createNamespaceImport(name); + Object.defineProperty(namespace, "parent", { value: factory.createImportClause(ast.SyntaxKind.TypeKeyword, undefined, namespace) }); + assert.ok(ast.isTypeOnlyImportDeclaration(namespace)); + assert.ok(ast.isTypeOnlyImportDeclaration(factory.createImportEqualsDeclaration(undefined, true, name, name))); + assert.equal(ast.isTypeOnlyImportDeclaration(factory.createImportEqualsDeclaration(undefined, false, name, name)), false); +}); From 6ece3a3c3016e0ef60bf331f53058ec2b5bc6969 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:58 -0800 Subject: [PATCH 27/34] Add isTypeOnlyExportDeclaration AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 9 +++++++ packages/typescript/src/ast/is.ts | 18 +++++++++++++ .../typescript/test/astPredicates.test.ts | 25 +++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 2122b963e279f..40ca326780a30 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -101,6 +101,15 @@ export type TypeOnlyImportDeclaration = | { readonly parent: generated.NamedImports & { readonly parent: generated.ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; }; } ); +export type TypeOnlyExportDeclaration = + | generated.ExportSpecifier + & ( + | { readonly isTypeOnly: true; } + | { readonly parent: generated.NamedExports & { readonly parent: generated.ExportDeclaration & { readonly isTypeOnly: true; }; }; } + ) + | generated.ExportDeclaration & { readonly isTypeOnly: true; readonly moduleSpecifier: generated.Expression; readonly exportClause?: undefined; } + | generated.NamespaceExport & { readonly parent: generated.ExportDeclaration & { readonly isTypeOnly: true; }; }; + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 7814a0db0a76a..ed05714f72c00 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -762,3 +762,21 @@ export function isTypeOnlyImportDeclaration(node: Node): node is ast.TypeOnlyImp return false; } } + +export function isTypeOnlyExportDeclaration(node: Node): node is ast.TypeOnlyExportDeclaration { + switch (node.kind) { + case SyntaxKind.ExportSpecifier: { + const specifier = node as ast.ExportSpecifier; + const declaration = specifier.parent?.parent; + return specifier.isTypeOnly || !!declaration && guards.isExportDeclaration(declaration) && declaration.isTypeOnly; + } + case SyntaxKind.ExportDeclaration: { + const declaration = node as ast.ExportDeclaration; + return declaration.isTypeOnly && !!declaration.moduleSpecifier && !declaration.exportClause; + } + case SyntaxKind.NamespaceExport: + return !!node.parent && guards.isExportDeclaration(node.parent) && node.parent.isTypeOnly; + default: + return false; + } +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index a18fecb9cff8d..681ee2c58410c 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -365,3 +365,28 @@ test("isTypeOnlyImportDeclaration inherits type-only status but not defer status assert.ok(ast.isTypeOnlyImportDeclaration(factory.createImportEqualsDeclaration(undefined, true, name, name))); assert.equal(ast.isTypeOnlyImportDeclaration(factory.createImportEqualsDeclaration(undefined, false, name, name)), false); }); + +test("isTypeOnlyExportDeclaration distinguishes export-star from named export containers", () => { + const name = factory.createIdentifier("value"); + const specifier = factory.createExportSpecifier(false, undefined, name); + const bindings = factory.createNamedExports([specifier]); + const declaration = factory.createExportDeclaration(undefined, true, bindings); + Object.defineProperty(specifier, "parent", { value: bindings }); + Object.defineProperty(bindings, "parent", { value: declaration }); + const node: ast.Node = specifier; + assert.ok(ast.isTypeOnlyExportDeclaration(node)); + const narrowed: ast.TypeOnlyExportDeclaration = node; + assert.equal(narrowed, specifier); + assert.equal(ast.isTypeOnlyExportDeclaration(declaration), false); + assert.ok(ast.isTypeOnlyExportDeclaration(factory.createExportDeclaration(undefined, true, undefined, factory.createStringLiteral("module", ast.TokenFlags.None)))); + assert.equal(ast.isTypeOnlyExportDeclaration(factory.createExportDeclaration(undefined, false, undefined, factory.createStringLiteral("module", ast.TokenFlags.None))), false); + assert.ok(ast.isTypeOnlyExportDeclaration(factory.createExportSpecifier(true, undefined, name))); + const valueSpecifier = factory.createExportSpecifier(false, undefined, name); + assert.equal(ast.isTypeOnlyExportDeclaration(valueSpecifier), false); + if (!ast.isTypeOnlyExportDeclaration(valueSpecifier)) { + assert.equal(valueSpecifier.name, name); + } + const namespace = factory.createNamespaceExport(name); + Object.defineProperty(namespace, "parent", { value: factory.createExportDeclaration(undefined, true, namespace) }); + assert.ok(ast.isTypeOnlyExportDeclaration(namespace)); +}); From 0f57f86c1e9541a374d463e40b74f184317cdf75 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:58 -0800 Subject: [PATCH 28/34] Add isTypeOnlyImportOrExportDeclaration AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 2 ++ packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 40ca326780a30..366ca35effb0d 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -110,6 +110,8 @@ export type TypeOnlyExportDeclaration = | generated.ExportDeclaration & { readonly isTypeOnly: true; readonly moduleSpecifier: generated.Expression; readonly exportClause?: undefined; } | generated.NamespaceExport & { readonly parent: generated.ExportDeclaration & { readonly isTypeOnly: true; }; }; +export type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration; + // ── Core types ── declare const rootedPathBrand: unique symbol; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index ed05714f72c00..7aced7d140f47 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -780,3 +780,7 @@ export function isTypeOnlyExportDeclaration(node: Node): node is ast.TypeOnlyExp return false; } } + +export function isTypeOnlyImportOrExportDeclaration(node: Node): node is ast.TypeOnlyAliasDeclaration { + return isTypeOnlyImportDeclaration(node) || isTypeOnlyExportDeclaration(node); +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 681ee2c58410c..f21819d16db48 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -390,3 +390,13 @@ test("isTypeOnlyExportDeclaration distinguishes export-star from named export co Object.defineProperty(namespace, "parent", { value: factory.createExportDeclaration(undefined, true, namespace) }); assert.ok(ast.isTypeOnlyExportDeclaration(namespace)); }); + +test("isTypeOnlyImportOrExportDeclaration includes both kinds of explicit type-only aliases", () => { + const name = factory.createIdentifier("value"); + const node: ast.Node = factory.createImportSpecifier(true, undefined, name); + assert.ok(ast.isTypeOnlyImportOrExportDeclaration(node)); + const narrowed: ast.TypeOnlyAliasDeclaration = node; + assert.equal(narrowed, node); + assert.ok(ast.isTypeOnlyImportOrExportDeclaration(factory.createExportSpecifier(true, undefined, name))); + assert.equal(ast.isTypeOnlyImportOrExportDeclaration(factory.createImportClause(undefined, name)), false); +}); From b3aa44bcb27adb9a38227723e1a369a24baff4c6 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:58 -0800 Subject: [PATCH 29/34] Add isPartOfTypeOnlyImportOrExportDeclaration AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 4 ++++ packages/typescript/test/astPredicates.test.ts | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 7aced7d140f47..5bdc446f9793d 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -784,3 +784,7 @@ export function isTypeOnlyExportDeclaration(node: Node): node is ast.TypeOnlyExp export function isTypeOnlyImportOrExportDeclaration(node: Node): node is ast.TypeOnlyAliasDeclaration { return isTypeOnlyImportDeclaration(node) || isTypeOnlyExportDeclaration(node); } + +export function isPartOfTypeOnlyImportOrExportDeclaration(node: Node): boolean { + return findAncestor(node, isTypeOnlyImportOrExportDeclaration) !== undefined; +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index f21819d16db48..d06e9e82bdb25 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -400,3 +400,12 @@ test("isTypeOnlyImportOrExportDeclaration includes both kinds of explicit type-o assert.ok(ast.isTypeOnlyImportOrExportDeclaration(factory.createExportSpecifier(true, undefined, name))); assert.equal(ast.isTypeOnlyImportOrExportDeclaration(factory.createImportClause(undefined, name)), false); }); + +test("isPartOfTypeOnlyImportOrExportDeclaration includes the alias itself and its descendants", () => { + const name = factory.createIdentifier("value"); + const specifier = factory.createImportSpecifier(true, undefined, name); + Object.defineProperty(name, "parent", { value: specifier }); + assert.ok(ast.isPartOfTypeOnlyImportOrExportDeclaration(name)); + assert.ok(ast.isPartOfTypeOnlyImportOrExportDeclaration(specifier)); + assert.equal(ast.isPartOfTypeOnlyImportOrExportDeclaration(factory.createIdentifier("value")), false); +}); From 02c3691199f20b843e70f25363d6324e57ce31c9 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:59 -0800 Subject: [PATCH 30/34] Add isPartOfTypeNode AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 75 +++++++++++++++++++ .../typescript/test/astPredicates.test.ts | 49 ++++++++++++ 2 files changed, 124 insertions(+) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 5bdc446f9793d..8c84148328b6a 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -788,3 +788,78 @@ export function isTypeOnlyImportOrExportDeclaration(node: Node): node is ast.Typ export function isPartOfTypeOnlyImportOrExportDeclaration(node: Node): boolean { return findAncestor(node, isTypeOnlyImportOrExportDeclaration) !== undefined; } + +export function isPartOfTypeNode(node: Node): boolean { + function isTypeExpression(node: ExpressionWithTypeArguments): boolean { + return !!node.parent && (guards.isJSDocImplementsTag(node.parent) || guards.isJSDocAugmentsTag(node.parent) || + isPartOfTypeExpressionWithTypeArguments(node)); + } + + if (node.kind >= SyntaxKind.FirstTypeNode && node.kind <= SyntaxKind.LastTypeNode) return true; + switch (node.kind) { + case SyntaxKind.AnyKeyword: + case SyntaxKind.UnknownKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.BigIntKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.ObjectKeyword: + case SyntaxKind.UndefinedKeyword: + case SyntaxKind.NullKeyword: + case SyntaxKind.NeverKeyword: + return true; + case SyntaxKind.VoidKeyword: + return node.parent?.kind !== SyntaxKind.VoidExpression; + case SyntaxKind.ExpressionWithTypeArguments: + return isTypeExpression(node as ExpressionWithTypeArguments); + case SyntaxKind.TypeParameter: + return node.parent?.kind === SyntaxKind.MappedType || node.parent?.kind === SyntaxKind.InferType; + case SyntaxKind.Identifier: + if ( + node.parent && (guards.isQualifiedName(node.parent) && node.parent.right === node || + guards.isPropertyAccessExpression(node.parent) && node.parent.name === node) + ) { + node = node.parent; + } + // falls through + case SyntaxKind.QualifiedName: + case SyntaxKind.PropertyAccessExpression: + case SyntaxKind.ThisKeyword: { + const parent = node.parent; + if (!parent || parent.kind === SyntaxKind.TypeQuery) return false; + if (guards.isImportTypeNode(parent)) return !parent.isTypeOf; + if (parent.kind >= SyntaxKind.FirstTypeNode && parent.kind <= SyntaxKind.LastTypeNode) return true; + switch (parent.kind) { + case SyntaxKind.ExpressionWithTypeArguments: + return isTypeExpression(parent as ExpressionWithTypeArguments); + case SyntaxKind.TypeParameter: + return (parent as ast.TypeParameterDeclaration).constraint === node; + case SyntaxKind.JSDocTemplateTag: + return (parent as ast.JSDocTemplateTag).constraint === node; + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.Parameter: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.CallSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.IndexSignature: + case SyntaxKind.TypeAssertionExpression: + return "type" in parent && parent.type === node; + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TaggedTemplateExpression: + return !!(parent as ast.CallExpression | ast.NewExpression | ast.TaggedTemplateExpression).typeArguments?.includes(node as TypeNode); + } + } + } + return false; +} diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index d06e9e82bdb25..93f3b3c0e6cd2 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -409,3 +409,52 @@ test("isPartOfTypeOnlyImportOrExportDeclaration includes the alias itself and it assert.ok(ast.isPartOfTypeOnlyImportOrExportDeclaration(specifier)); assert.equal(ast.isPartOfTypeOnlyImportOrExportDeclaration(factory.createIdentifier("value")), false); }); + +test("isPartOfTypeNode classifies contextual names without recursively classifying every qualifier", async () => { + const { API } = await import("./sync/api.testUtils.ts"); + const { createVirtualFileSystem } = await import("./testUtils.ts"); + const { fileURLToPath } = await import("node:url"); + using api = new API({ + cwd: fileURLToPath(new URL("../../../", import.meta.url)), + tsserverPath: fileURLToPath(new URL(`../../../built/local/tsc${process.platform === "win32" ? ".exe" : ""}`, import.meta.url)), + fs: createVirtualFileSystem({}), + }); + const source = api.createSourceFile( + "/test.ts", + ` +let value: A.B.C; +let query: typeof A.B.C; +class Derived extends Base implements Interface {} +interface I extends Base {} +void value; +type Result = void; +type Imported = import("module").ImportedName; +type ImportQuery = typeof import("module").QueriedName; +type Mapped = { [K in keyof T]: T[K] }; +type Conditional = T extends infer U ? U : never; +f(); +`, + ).sourceFile; + const nodes: ast.Node[] = []; + function collect(node: ast.Node): void { + nodes.push(node); + node.forEachChild(child => { + collect(child); + }); + } + collect(source); + const names = nodes.filter(ast.isIdentifier).filter(node => ["A", "B", "C"].includes(node.text)); + assert.deepEqual(names.map(ast.isPartOfTypeNode), [false, false, true, false, false, false]); + const heritage = nodes.filter(ast.isHeritageClause).flatMap(clause => [...clause.types]); + assert.deepEqual(heritage.map(ast.isPartOfTypeNode), [false, true, true]); + const voids = nodes.filter(node => node.kind === ast.SyntaxKind.VoidKeyword); + assert.deepEqual(voids.map(ast.isPartOfTypeNode), [true]); + const valueUses = nodes.filter(ast.isIdentifier).filter(node => node.text === "value"); + assert.deepEqual(valueUses.map(ast.isPartOfTypeNode), [false, false]); + const importNames = nodes.filter(ast.isIdentifier).filter(node => node.text === "ImportedName" || node.text === "QueriedName"); + assert.deepEqual(importNames.map(ast.isPartOfTypeNode), [true, false]); + const parameters = nodes.filter(ast.isTypeParameterDeclaration); + assert.deepEqual(parameters.map(ast.isPartOfTypeNode), [false, true, false, true]); + const argument = nodes.find(node => ast.isIdentifier(node) && node.text === "TypeArgument"); + assert.ok(argument && ast.isPartOfTypeNode(argument)); +}); From 9b50a6ac2e9e108574def6609b45384044f454a1 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:18:59 -0800 Subject: [PATCH 31/34] Add isExternalModuleNameRelative AST predicate Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/utils.ts | 5 +++++ packages/typescript/test/astPredicates.test.ts | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/typescript/src/ast/utils.ts b/packages/typescript/src/ast/utils.ts index 1b0085e51478b..dfaecc7ae1b5f 100644 --- a/packages/typescript/src/ast/utils.ts +++ b/packages/typescript/src/ast/utils.ts @@ -4,6 +4,7 @@ import { ModifierFlags } from "../../enums/modifierFlags.js"; import { NodeFlags } from "../../enums/nodeFlags.js"; import { OuterExpressionKinds } from "../../enums/outerExpressionKinds.js"; import { SyntaxKind } from "../../enums/syntaxKind.js"; +import { isRootedDiskPath } from "../api/path.ts"; import type { __String, AccessExpression, @@ -116,6 +117,10 @@ export function isExternalModule(file: SourceFile): boolean { return file.externalModuleIndicator !== undefined; } +export function isExternalModuleNameRelative(moduleName: string): boolean { + return /^\.\.?(?:$|[\\/])/.test(moduleName) || isRootedDiskPath(moduleName); +} + function getRootDeclaration(node: Node): Node { while (node.kind === SyntaxKind.BindingElement) { node = node.parent.parent; diff --git a/packages/typescript/test/astPredicates.test.ts b/packages/typescript/test/astPredicates.test.ts index 93f3b3c0e6cd2..0f97fae203128 100644 --- a/packages/typescript/test/astPredicates.test.ts +++ b/packages/typescript/test/astPredicates.test.ts @@ -458,3 +458,12 @@ f(); const argument = nodes.find(node => ast.isIdentifier(node) && node.text === "TypeArgument"); assert.ok(argument && ast.isPartOfTypeNode(argument)); }); + +test("isExternalModuleNameRelative includes rooted disk paths but excludes URLs and bare names", () => { + for (const name of [".", "..", "./module", "../module", ".\\module", "..\\module", "/module", "C:/module", "C:\\module", "\\\\server\\share\\module"]) { + assert.ok(ast.isExternalModuleNameRelative(name), name); + } + for (const name of ["", "module", "@scope/module", ".module", ".../module", "https://example.com/module", "file:///module", "C:module"]) { + assert.equal(ast.isExternalModuleNameRelative(name), false, name); + } +}); From a3ebec95002784cf2cc58a7871e171d31e077385 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 12:50:54 -0800 Subject: [PATCH 32/34] Use named imports in AST predicates Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/ast.ts | 40 ++++-- packages/typescript/src/ast/is.ts | 206 ++++++++++++++++++++--------- 2 files changed, 167 insertions(+), 79 deletions(-) diff --git a/packages/typescript/src/ast/ast.ts b/packages/typescript/src/ast/ast.ts index 366ca35effb0d..d502577d7b256 100644 --- a/packages/typescript/src/ast/ast.ts +++ b/packages/typescript/src/ast/ast.ts @@ -7,17 +7,21 @@ import type { LanguageVariant } from "../../enums/languageVariant.js"; import type { NodeFlags } from "../../enums/nodeFlags.js"; import type { ScriptKind } from "../../enums/scriptKind.js"; import { SyntaxKind } from "../../enums/syntaxKind.js"; -import type * as generated from "./ast.generated.ts"; import type { AssertionExpression, BindingElement, + BindingPattern, + CallExpression, CaseClause, ComputedPropertyName, Decorator, DoStatement, + ElementAccessExpression, EndOfFile, EntityName, EnumMember, + ExportDeclaration, + ExportSpecifier, Expression, ExpressionStatement, ForInStatement, @@ -25,12 +29,20 @@ import type { ForStatement, Identifier, IfStatement, + ImportClause, + ImportEqualsDeclaration, + ImportSpecifier, JSDoc, JsxAttribute, JsxExpression, JsxSpreadAttribute, KeywordSyntaxKind, ModifierSyntaxKind, + NamedExports, + NamedImports, + NamespaceExport, + NamespaceImport, + NonNullExpression, ParameterDeclaration, PropertyAccessExpression, PropertyAssignment, @@ -65,18 +77,18 @@ export interface AutoAccessorPropertyDeclaration extends PropertyDeclaration { } declare const optionalChainBrand: unique symbol; -export interface CallChain extends generated.CallExpression { +export interface CallChain extends CallExpression { readonly [optionalChainBrand]: void; } -export interface ElementAccessChain extends generated.ElementAccessExpression { +export interface ElementAccessChain extends ElementAccessExpression { readonly [optionalChainBrand]: void; } declare const emptyBindingPatternBrand: unique symbol; -export type EmptyBindingPattern = generated.BindingPattern & { readonly [emptyBindingPatternBrand]: void; }; +export type EmptyBindingPattern = BindingPattern & { readonly [emptyBindingPatternBrand]: void; }; -export interface NonNullChain extends generated.NonNullExpression { +export interface NonNullChain extends NonNullExpression { readonly [optionalChainBrand]: void; } @@ -92,23 +104,23 @@ export interface ParameterPropertyDeclaration extends ParameterDeclaration { } export type TypeOnlyImportDeclaration = - | generated.ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; } - | generated.ImportEqualsDeclaration & { readonly isTypeOnly: true; } - | generated.NamespaceImport & { readonly parent: generated.ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; } - | generated.ImportSpecifier + | ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; } + | ImportEqualsDeclaration & { readonly isTypeOnly: true; } + | NamespaceImport & { readonly parent: ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; } + | ImportSpecifier & ( | { readonly isTypeOnly: true; } - | { readonly parent: generated.NamedImports & { readonly parent: generated.ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; }; } + | { readonly parent: NamedImports & { readonly parent: ImportClause & { readonly phaseModifier: SyntaxKind.TypeKeyword; }; }; } ); export type TypeOnlyExportDeclaration = - | generated.ExportSpecifier + | ExportSpecifier & ( | { readonly isTypeOnly: true; } - | { readonly parent: generated.NamedExports & { readonly parent: generated.ExportDeclaration & { readonly isTypeOnly: true; }; }; } + | { readonly parent: NamedExports & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true; }; }; } ) - | generated.ExportDeclaration & { readonly isTypeOnly: true; readonly moduleSpecifier: generated.Expression; readonly exportClause?: undefined; } - | generated.NamespaceExport & { readonly parent: generated.ExportDeclaration & { readonly isTypeOnly: true; }; }; + | ExportDeclaration & { readonly isTypeOnly: true; readonly moduleSpecifier: Expression; readonly exportClause?: undefined; } + | NamespaceExport & { readonly parent: ExportDeclaration & { readonly isTypeOnly: true; }; }; export type TypeOnlyAliasDeclaration = TypeOnlyImportDeclaration | TypeOnlyExportDeclaration; diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 8c84148328b6a..199c089a01af1 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -6,63 +6,139 @@ import { NodeFlags } from "../../enums/nodeFlags.js"; import { OuterExpressionKinds } from "../../enums/outerExpressionKinds.js"; import { ScriptKind } from "../../enums/scriptKind.js"; import { SyntaxKind } from "../../enums/syntaxKind.js"; -import type * as ast from "./ast.ts"; import type { + ArrayBindingElement, AsExpression, + AutoAccessorPropertyDeclaration, + BindingElement, + BindingName, BindingPattern, BlockOrExpression, BooleanLiteral, + CallChain, + CallExpression, + ClassElement, ComputedPropertyName, ConciseBody, + ConstructorTypeNode, + Declaration, + DoStatement, + ElementAccessChain, + EmptyBindingPattern, ExclamationToken, + ExportDeclaration, + ExportSpecifier, Expression, ExpressionWithTypeArguments, ForInitializer, ForInOrOfStatement, + ForInStatement, + ForOfStatement, ForStatement, + FunctionTypeNode, Identifier, + ImportClause, + ImportEqualsDeclaration, + ImportSpecifier, JSDocLink, JSDocLinkCode, JSDocLinkPlain, + JSDocParameterTag, + JSDocSignature, + JSDocTemplateTag, JSDocTypeExpression, JSDocTypeLiteral, + JsxAttributeLike, + JsxExpression, + JsxOpeningElement, + JsxOpeningFragment, + JsxSelfClosingElement, JsxTagNameExpression, + LabeledStatement, LeftHandSideExpression, LiteralExpression, MetaProperty, MinusToken, ModuleDeclaration, + NewExpression, Node, + NonNullChain, NonNullExpression, NullLiteral, + ObjectLiteralElementLike, + OptionalChain, + ParameterDeclaration, + ParameterPropertyDeclaration, ParenthesizedExpression, PartiallyEmittedExpression, PlusToken, PrefixUnaryExpression, + PropertyAccessChain, + PropertyAccessExpression, + PropertyDeclaration, + QualifiedName, QuestionToken, ReadonlyKeyword, SatisfiesExpression, + SignatureDeclaration, Statement, + StringLiteral, + TaggedTemplateExpression, + TemplateLiteralToken, TemplateMiddle, TemplateTail, ThisTypeNode, TypeAssertion, + TypeElement, TypeNode, + TypeOnlyAliasDeclaration, + TypeOnlyExportDeclaration, + TypeOnlyImportDeclaration, + TypeParameterDeclaration, UnaryExpressionBase, + WhileStatement, } from "./ast.ts"; -import * as guards from "./is.generated.ts"; import { + isAccessExpression, isBinaryExpression, + isCallExpression, isClassLikeDeclaration, isComputedPropertyName, + isConstructorDeclaration, + isConstructorTypeNode, + isElementAccessExpression, + isExportDeclaration, + isExportSpecifier, + isFunctionTypeNode, isHeritageClause, isIdentifier, + isImportClause, + isImportSpecifier, + isImportTypeNode, + isJSDocAugmentsTag, + isJSDocImplementsTag, isJSDocLink, isJSDocLinkCode, isJSDocLinkPlain, isJSDocNameReference, + isJSDocSignature, + isJsxAttributeLike, + isJsxExpression, + isJsxOpeningElement, + isJsxOpeningFragment, + isJsxSelfClosingElement, isLiteralExpression, + isNonNullExpression, + isObjectLiteralElementLike, + isOmittedExpression, + isParameterDeclaration, + isPropertyAccessExpression, + isQualifiedName, isShorthandPropertyAssignment, + isSignatureDeclaration, + isStringLiteral, + isTemplateLiteralToken, + isTypeReferenceNode, } from "./is.generated.ts"; import { hasExpression, @@ -72,9 +148,9 @@ import { export * from "./is.generated.ts"; -export function isAutoAccessorPropertyDeclaration(node: Node): node is ast.AutoAccessorPropertyDeclaration { +export function isAutoAccessorPropertyDeclaration(node: Node): node is AutoAccessorPropertyDeclaration { return node.kind === SyntaxKind.PropertyDeclaration && - !!((node as ast.PropertyDeclaration).modifierFlags & ModifierFlags.Accessor); + !!((node as PropertyDeclaration).modifierFlags & ModifierFlags.Accessor); } type JSDocNamespaceDeclaration = ModuleDeclaration; @@ -585,11 +661,11 @@ export function isJsxTagNameExpression(node: Node): node is JsxTagNameExpression || kind === SyntaxKind.JsxNamespacedName; } -export function isCallChain(node: Node): node is ast.CallChain { - return guards.isCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function isCallChain(node: Node): node is CallChain { + return isCallExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } -export function isClassElement(node: Node): node is ast.ClassElement { +export function isClassElement(node: Node): node is ClassElement { switch (node.kind) { case SyntaxKind.Constructor: case SyntaxKind.PropertyDeclaration: @@ -606,11 +682,11 @@ export function isClassElement(node: Node): node is ast.ClassElement { } export function isConstTypeReference(node: Node): boolean { - return guards.isTypeReferenceNode(node) && isIdentifier(node.typeName) && + return isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.text === "const" && !node.typeArguments; } -export function isDeclarationStatement(node: Node): node is ast.Statement & ast.Declaration { +export function isDeclarationStatement(node: Node): node is Statement & Declaration { switch (node.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.MissingDeclaration: @@ -632,33 +708,33 @@ export function isDeclarationStatement(node: Node): node is ast.Statement & ast. } } -export function isElementAccessChain(node: Node): node is ast.ElementAccessChain { - return guards.isElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function isElementAccessChain(node: Node): node is ElementAccessChain { + return isElementAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } -export function isEmptyBindingElement(node: ast.BindingElement | ast.ArrayBindingElement): boolean { - return guards.isOmittedExpression(node) || !node.name || +export function isEmptyBindingElement(node: BindingElement | ArrayBindingElement): boolean { + return isOmittedExpression(node) || !node.name || isBindingPattern(node.name) && node.name.elements.every(isEmptyBindingElement); } -export function isEmptyBindingPattern(node: ast.BindingName): node is ast.EmptyBindingPattern { +export function isEmptyBindingPattern(node: BindingName): node is EmptyBindingPattern { return isBindingPattern(node) && node.elements.every(isEmptyBindingElement); } -export function isFunctionLike(node: Node | undefined): node is ast.SignatureDeclaration | ast.JSDocSignature { - return !!node && (guards.isSignatureDeclaration(node) || guards.isJSDocSignature(node)); +export function isFunctionLike(node: Node | undefined): node is SignatureDeclaration | JSDocSignature { + return !!node && (isSignatureDeclaration(node) || isJSDocSignature(node)); } -export function isFunctionOrConstructorTypeNode(node: Node): node is ast.FunctionTypeNode | ast.ConstructorTypeNode { - return guards.isFunctionTypeNode(node) || guards.isConstructorTypeNode(node); +export function isFunctionOrConstructorTypeNode(node: Node): node is FunctionTypeNode | ConstructorTypeNode { + return isFunctionTypeNode(node) || isConstructorTypeNode(node); } -export function isImportOrExportSpecifier(node: Node): node is ast.ImportSpecifier | ast.ExportSpecifier { - return guards.isImportSpecifier(node) || guards.isExportSpecifier(node); +export function isImportOrExportSpecifier(node: Node): node is ImportSpecifier | ExportSpecifier { + return isImportSpecifier(node) || isExportSpecifier(node); } -export function isIterationStatement(node: Node, lookInLabeledStatements: false): node is ast.DoStatement | ast.WhileStatement | ast.ForStatement | ast.ForInStatement | ast.ForOfStatement; -export function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is ast.DoStatement | ast.WhileStatement | ast.ForStatement | ast.ForInStatement | ast.ForOfStatement | ast.LabeledStatement; +export function isIterationStatement(node: Node, lookInLabeledStatements: false): node is DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement; +export function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | LabeledStatement; export function isIterationStatement(node: Node, lookInLabeledStatements: boolean): boolean { switch (node.kind) { case SyntaxKind.ForStatement: @@ -668,48 +744,48 @@ export function isIterationStatement(node: Node, lookInLabeledStatements: boolea case SyntaxKind.WhileStatement: return true; case SyntaxKind.LabeledStatement: - return lookInLabeledStatements && isIterationStatement((node as ast.LabeledStatement).statement, true); + return lookInLabeledStatements && isIterationStatement((node as LabeledStatement).statement, true); default: return false; } } -export function isJsxCallLike(node: Node): node is ast.JsxOpeningElement | ast.JsxSelfClosingElement | ast.JsxOpeningFragment { - return guards.isJsxOpeningElement(node) || guards.isJsxSelfClosingElement(node) || guards.isJsxOpeningFragment(node); +export function isJsxCallLike(node: Node): node is JsxOpeningElement | JsxSelfClosingElement | JsxOpeningFragment { + return isJsxOpeningElement(node) || isJsxSelfClosingElement(node) || isJsxOpeningFragment(node); } -export function isNonNullChain(node: Node): node is ast.NonNullChain { - return guards.isNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function isNonNullChain(node: Node): node is NonNullChain { + return isNonNullExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } export function isNullishCoalesce(node: Node): boolean { return isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.QuestionQuestionToken; } -export function isObjectLiteralElement(node: Node): node is ast.ObjectLiteralElementLike | ast.JsxAttributeLike { - return guards.isObjectLiteralElementLike(node) || guards.isJsxAttributeLike(node); +export function isObjectLiteralElement(node: Node): node is ObjectLiteralElementLike | JsxAttributeLike { + return isObjectLiteralElementLike(node) || isJsxAttributeLike(node); } -export function isOptionalChain(node: Node): node is ast.OptionalChain { +export function isOptionalChain(node: Node): node is OptionalChain { return !!(node.flags & NodeFlags.OptionalChain) && - (guards.isAccessExpression(node) || guards.isCallExpression(node) || guards.isNonNullExpression(node)); + (isAccessExpression(node) || isCallExpression(node) || isNonNullExpression(node)); } -export function isParameterPropertyDeclaration(node: Node, parent: Node): node is ast.ParameterPropertyDeclaration { - return guards.isParameterDeclaration(node) && !!(node.modifierFlags & ModifierFlags.ParameterPropertyModifier) && - guards.isConstructorDeclaration(parent); +export function isParameterPropertyDeclaration(node: Node, parent: Node): node is ParameterPropertyDeclaration { + return isParameterDeclaration(node) && !!(node.modifierFlags & ModifierFlags.ParameterPropertyModifier) && + isConstructorDeclaration(parent); } -export function isPropertyAccessChain(node: Node): node is ast.PropertyAccessChain { - return guards.isPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); +export function isPropertyAccessChain(node: Node): node is PropertyAccessChain { + return isPropertyAccessExpression(node) && !!(node.flags & NodeFlags.OptionalChain); } -export function isPropertyAccessOrQualifiedName(node: Node): node is ast.PropertyAccessExpression | ast.QualifiedName { - return guards.isPropertyAccessExpression(node) || guards.isQualifiedName(node); +export function isPropertyAccessOrQualifiedName(node: Node): node is PropertyAccessExpression | QualifiedName { + return isPropertyAccessExpression(node) || isQualifiedName(node); } -export function isRestParameter(node: ast.ParameterDeclaration | ast.JSDocParameterTag): boolean { - if (guards.isParameterDeclaration(node)) { +export function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean { + if (isParameterDeclaration(node)) { return node.dotDotDotToken !== undefined || node.type?.kind === SyntaxKind.JSDocVariadicType; } const type = node.typeExpression; @@ -717,15 +793,15 @@ export function isRestParameter(node: ast.ParameterDeclaration | ast.JSDocParame type?.kind === SyntaxKind.JSDocTypeExpression && (type as JSDocTypeExpression).type.kind === SyntaxKind.JSDocVariadicType; } -export function isStringLiteralOrJsxExpression(node: Node): node is ast.StringLiteral | ast.JsxExpression { - return guards.isStringLiteral(node) || guards.isJsxExpression(node); +export function isStringLiteralOrJsxExpression(node: Node): node is StringLiteral | JsxExpression { + return isStringLiteral(node) || isJsxExpression(node); } -export function isStringTextContainingNode(node: Node): node is ast.StringLiteral | ast.TemplateLiteralToken { - return guards.isStringLiteral(node) || guards.isTemplateLiteralToken(node); +export function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken { + return isStringLiteral(node) || isTemplateLiteralToken(node); } -export function isTypeElement(node: Node): node is ast.TypeElement { +export function isTypeElement(node: Node): node is TypeElement { switch (node.kind) { case SyntaxKind.ConstructSignature: case SyntaxKind.CallSignature: @@ -741,47 +817,47 @@ export function isTypeElement(node: Node): node is ast.TypeElement { } } -export function isClassOrTypeElement(node: Node): node is ast.ClassElement | ast.TypeElement { +export function isClassOrTypeElement(node: Node): node is ClassElement | TypeElement { return isClassElement(node) || isTypeElement(node); } -export function isTypeOnlyImportDeclaration(node: Node): node is ast.TypeOnlyImportDeclaration { +export function isTypeOnlyImportDeclaration(node: Node): node is TypeOnlyImportDeclaration { switch (node.kind) { case SyntaxKind.ImportSpecifier: { - const specifier = node as ast.ImportSpecifier; + const specifier = node as ImportSpecifier; const clause = specifier.parent?.parent; - return specifier.isTypeOnly || !!clause && guards.isImportClause(clause) && clause.phaseModifier === SyntaxKind.TypeKeyword; + return specifier.isTypeOnly || !!clause && isImportClause(clause) && clause.phaseModifier === SyntaxKind.TypeKeyword; } case SyntaxKind.NamespaceImport: - return !!node.parent && guards.isImportClause(node.parent) && node.parent.phaseModifier === SyntaxKind.TypeKeyword; + return !!node.parent && isImportClause(node.parent) && node.parent.phaseModifier === SyntaxKind.TypeKeyword; case SyntaxKind.ImportClause: - return (node as ast.ImportClause).phaseModifier === SyntaxKind.TypeKeyword; + return (node as ImportClause).phaseModifier === SyntaxKind.TypeKeyword; case SyntaxKind.ImportEqualsDeclaration: - return (node as ast.ImportEqualsDeclaration).isTypeOnly; + return (node as ImportEqualsDeclaration).isTypeOnly; default: return false; } } -export function isTypeOnlyExportDeclaration(node: Node): node is ast.TypeOnlyExportDeclaration { +export function isTypeOnlyExportDeclaration(node: Node): node is TypeOnlyExportDeclaration { switch (node.kind) { case SyntaxKind.ExportSpecifier: { - const specifier = node as ast.ExportSpecifier; + const specifier = node as ExportSpecifier; const declaration = specifier.parent?.parent; - return specifier.isTypeOnly || !!declaration && guards.isExportDeclaration(declaration) && declaration.isTypeOnly; + return specifier.isTypeOnly || !!declaration && isExportDeclaration(declaration) && declaration.isTypeOnly; } case SyntaxKind.ExportDeclaration: { - const declaration = node as ast.ExportDeclaration; + const declaration = node as ExportDeclaration; return declaration.isTypeOnly && !!declaration.moduleSpecifier && !declaration.exportClause; } case SyntaxKind.NamespaceExport: - return !!node.parent && guards.isExportDeclaration(node.parent) && node.parent.isTypeOnly; + return !!node.parent && isExportDeclaration(node.parent) && node.parent.isTypeOnly; default: return false; } } -export function isTypeOnlyImportOrExportDeclaration(node: Node): node is ast.TypeOnlyAliasDeclaration { +export function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnlyAliasDeclaration { return isTypeOnlyImportDeclaration(node) || isTypeOnlyExportDeclaration(node); } @@ -791,7 +867,7 @@ export function isPartOfTypeOnlyImportOrExportDeclaration(node: Node): boolean { export function isPartOfTypeNode(node: Node): boolean { function isTypeExpression(node: ExpressionWithTypeArguments): boolean { - return !!node.parent && (guards.isJSDocImplementsTag(node.parent) || guards.isJSDocAugmentsTag(node.parent) || + return !!node.parent && (isJSDocImplementsTag(node.parent) || isJSDocAugmentsTag(node.parent) || isPartOfTypeExpressionWithTypeArguments(node)); } @@ -817,8 +893,8 @@ export function isPartOfTypeNode(node: Node): boolean { return node.parent?.kind === SyntaxKind.MappedType || node.parent?.kind === SyntaxKind.InferType; case SyntaxKind.Identifier: if ( - node.parent && (guards.isQualifiedName(node.parent) && node.parent.right === node || - guards.isPropertyAccessExpression(node.parent) && node.parent.name === node) + node.parent && (isQualifiedName(node.parent) && node.parent.right === node || + isPropertyAccessExpression(node.parent) && node.parent.name === node) ) { node = node.parent; } @@ -828,15 +904,15 @@ export function isPartOfTypeNode(node: Node): boolean { case SyntaxKind.ThisKeyword: { const parent = node.parent; if (!parent || parent.kind === SyntaxKind.TypeQuery) return false; - if (guards.isImportTypeNode(parent)) return !parent.isTypeOf; + if (isImportTypeNode(parent)) return !parent.isTypeOf; if (parent.kind >= SyntaxKind.FirstTypeNode && parent.kind <= SyntaxKind.LastTypeNode) return true; switch (parent.kind) { case SyntaxKind.ExpressionWithTypeArguments: return isTypeExpression(parent as ExpressionWithTypeArguments); case SyntaxKind.TypeParameter: - return (parent as ast.TypeParameterDeclaration).constraint === node; + return (parent as TypeParameterDeclaration).constraint === node; case SyntaxKind.JSDocTemplateTag: - return (parent as ast.JSDocTemplateTag).constraint === node; + return (parent as JSDocTemplateTag).constraint === node; case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.Parameter: @@ -857,7 +933,7 @@ export function isPartOfTypeNode(node: Node): boolean { case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: case SyntaxKind.TaggedTemplateExpression: - return !!(parent as ast.CallExpression | ast.NewExpression | ast.TaggedTemplateExpression).typeArguments?.includes(node as TypeNode); + return !!(parent as CallExpression | NewExpression | TaggedTemplateExpression).typeArguments?.includes(node as TypeNode); } } } From 70ad2e469c0af8adbe4a3a6b49848a02451fa0c4 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 16:38:07 -0800 Subject: [PATCH 33/34] Update packages/typescript/src/ast/is.ts Co-authored-by: Ryan Cavanaugh --- packages/typescript/src/ast/is.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 199c089a01af1..4fde754bd873d 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -929,7 +929,7 @@ export function isPartOfTypeNode(node: Node): boolean { case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: case SyntaxKind.TypeAssertionExpression: - return "type" in parent && parent.type === node; + return (parent as never as { type: unknown }).type === node; case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: case SyntaxKind.TaggedTemplateExpression: From 16006398b04bc3b126bb618205f8e5d892c51e01 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 19 Nov 2026 17:00:42 -0800 Subject: [PATCH 34/34] Update packages/typescript/src/ast/is.ts Co-authored-by: Ryan Cavanaugh --- packages/typescript/src/ast/is.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 4fde754bd873d..c298cb04f8e0a 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -929,7 +929,7 @@ export function isPartOfTypeNode(node: Node): boolean { case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: case SyntaxKind.TypeAssertionExpression: - return (parent as never as { type: unknown }).type === node; + return (parent as never as { type: unknown; }).type === node; case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: case SyntaxKind.TaggedTemplateExpression: