From 86f49628b57851223525b54d167318f9f8add6fa Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 22 Aug 2022 11:03:34 -0400 Subject: [PATCH] Make canHaveModifiers/Decorators public --- src/compiler/factory/utilities.ts | 40 ------------------- src/compiler/factory/utilitiesPublic.ts | 40 +++++++++++++++++++ .../reference/api/tsserverlibrary.d.ts | 2 + tests/baselines/reference/api/typescript.d.ts | 2 + 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 9a02483f07dc1..9fbbdb165d22b 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -877,17 +877,6 @@ namespace ts { || kind === SyntaxKind.SetAccessor; } - export function canHaveDecorators(node: Node): node is HasDecorators { - const kind = node.kind; - return kind === SyntaxKind.Parameter - || kind === SyntaxKind.PropertyDeclaration - || kind === SyntaxKind.MethodDeclaration - || kind === SyntaxKind.GetAccessor - || kind === SyntaxKind.SetAccessor - || kind === SyntaxKind.ClassExpression - || kind === SyntaxKind.ClassDeclaration; - } - export function canHaveIllegalDecorators(node: Node): node is HasIllegalDecorators { const kind = node.kind; return kind === SyntaxKind.PropertyAssignment @@ -909,35 +898,6 @@ namespace ts { || kind === SyntaxKind.ExportAssignment; } - export function canHaveModifiers(node: Node): node is HasModifiers { - const kind = node.kind; - return kind === SyntaxKind.TypeParameter - || kind === SyntaxKind.Parameter - || kind === SyntaxKind.PropertySignature - || kind === SyntaxKind.PropertyDeclaration - || kind === SyntaxKind.MethodSignature - || kind === SyntaxKind.MethodDeclaration - || kind === SyntaxKind.Constructor - || kind === SyntaxKind.GetAccessor - || kind === SyntaxKind.SetAccessor - || kind === SyntaxKind.IndexSignature - || kind === SyntaxKind.ConstructorType - || kind === SyntaxKind.FunctionExpression - || kind === SyntaxKind.ArrowFunction - || kind === SyntaxKind.ClassExpression - || kind === SyntaxKind.VariableStatement - || kind === SyntaxKind.FunctionDeclaration - || kind === SyntaxKind.ClassDeclaration - || kind === SyntaxKind.InterfaceDeclaration - || kind === SyntaxKind.TypeAliasDeclaration - || kind === SyntaxKind.EnumDeclaration - || kind === SyntaxKind.ModuleDeclaration - || kind === SyntaxKind.ImportEqualsDeclaration - || kind === SyntaxKind.ImportDeclaration - || kind === SyntaxKind.ExportAssignment - || kind === SyntaxKind.ExportDeclaration; - } - export function canHaveIllegalModifiers(node: Node): node is HasIllegalModifiers { const kind = node.kind; return kind === SyntaxKind.ClassStaticBlockDeclaration diff --git a/src/compiler/factory/utilitiesPublic.ts b/src/compiler/factory/utilitiesPublic.ts index 9dd28667eb0e1..c51a2466ff5b2 100644 --- a/src/compiler/factory/utilitiesPublic.ts +++ b/src/compiler/factory/utilitiesPublic.ts @@ -2,4 +2,44 @@ namespace ts { export function setTextRange(range: T, location: TextRange | undefined): T { return location ? setTextRangePosEnd(range, location.pos, location.end) : range; } + + export function canHaveModifiers(node: Node): node is HasModifiers { + const kind = node.kind; + return kind === SyntaxKind.TypeParameter + || kind === SyntaxKind.Parameter + || kind === SyntaxKind.PropertySignature + || kind === SyntaxKind.PropertyDeclaration + || kind === SyntaxKind.MethodSignature + || kind === SyntaxKind.MethodDeclaration + || kind === SyntaxKind.Constructor + || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.IndexSignature + || kind === SyntaxKind.ConstructorType + || kind === SyntaxKind.FunctionExpression + || kind === SyntaxKind.ArrowFunction + || kind === SyntaxKind.ClassExpression + || kind === SyntaxKind.VariableStatement + || kind === SyntaxKind.FunctionDeclaration + || kind === SyntaxKind.ClassDeclaration + || kind === SyntaxKind.InterfaceDeclaration + || kind === SyntaxKind.TypeAliasDeclaration + || kind === SyntaxKind.EnumDeclaration + || kind === SyntaxKind.ModuleDeclaration + || kind === SyntaxKind.ImportEqualsDeclaration + || kind === SyntaxKind.ImportDeclaration + || kind === SyntaxKind.ExportAssignment + || kind === SyntaxKind.ExportDeclaration; + } + + export function canHaveDecorators(node: Node): node is HasDecorators { + const kind = node.kind; + return kind === SyntaxKind.Parameter + || kind === SyntaxKind.PropertyDeclaration + || kind === SyntaxKind.MethodDeclaration + || kind === SyntaxKind.GetAccessor + || kind === SyntaxKind.SetAccessor + || kind === SyntaxKind.ClassExpression + || kind === SyntaxKind.ClassDeclaration; + } } \ No newline at end of file diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 05fed42876185..5f5edb8b2c10b 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4834,6 +4834,8 @@ declare namespace ts { } declare namespace ts { function setTextRange(range: T, location: TextRange | undefined): T; + function canHaveModifiers(node: Node): node is HasModifiers; + function canHaveDecorators(node: Node): node is HasDecorators; } declare namespace ts { /** diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index ddaab547b5439..85470b6407cbe 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4834,6 +4834,8 @@ declare namespace ts { } declare namespace ts { function setTextRange(range: T, location: TextRange | undefined): T; + function canHaveModifiers(node: Node): node is HasModifiers; + function canHaveDecorators(node: Node): node is HasDecorators; } declare namespace ts { /**