Skip to content

Commit 758c21b

Browse files
committed
Expose a public isHasExpressionInitializer type guard
Exposes `isHasExpressionInitializer` a public function so users of TypeScript compiler APIs do not have to roll their own `HasExpressionInitializer` type guards. Closes #33115.
1 parent f41472b commit 758c21b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/compiler/utilities.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7059,6 +7059,22 @@ namespace ts {
70597059
return hasInitializer(node) && !isForStatement(node) && !isForInStatement(node) && !isForOfStatement(node) && !isJsxAttribute(node);
70607060
}
70617061

7062+
/** True if has an expression initializer node attached to it. */
7063+
export function isHasExpressionInitializer(node: Node): node is HasExpressionInitializer {
7064+
switch(node.kind) {
7065+
case SyntaxKind.VariableDeclaration:
7066+
case SyntaxKind.PropertyDeclaration:
7067+
case SyntaxKind.BindingElement:
7068+
case SyntaxKind.PropertySignature:
7069+
case SyntaxKind.PropertyDeclaration:
7070+
case SyntaxKind.PropertyAssignment:
7071+
case SyntaxKind.EnumMember:
7072+
return true;
7073+
default:
7074+
return false;
7075+
}
7076+
}
7077+
70627078
export function isObjectLiteralElement(node: Node): node is ObjectLiteralElement {
70637079
return node.kind === SyntaxKind.JsxAttribute || node.kind === SyntaxKind.JsxSpreadAttribute || isObjectLiteralElementLike(node);
70647080
}

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,6 +3612,8 @@ declare namespace ts {
36123612
function isJSDocCommentContainingNode(node: Node): boolean;
36133613
function isSetAccessor(node: Node): node is SetAccessorDeclaration;
36143614
function isGetAccessor(node: Node): node is GetAccessorDeclaration;
3615+
/** True if has an expression initializer node attached to it. */
3616+
function isHasExpressionInitializer(node: Node): node is HasExpressionInitializer;
36153617
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
36163618
function isStringLiteralLike(node: Node): node is StringLiteralLike;
36173619
}

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,6 +3612,8 @@ declare namespace ts {
36123612
function isJSDocCommentContainingNode(node: Node): boolean;
36133613
function isSetAccessor(node: Node): node is SetAccessorDeclaration;
36143614
function isGetAccessor(node: Node): node is GetAccessorDeclaration;
3615+
/** True if has an expression initializer node attached to it. */
3616+
function isHasExpressionInitializer(node: Node): node is HasExpressionInitializer;
36153617
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
36163618
function isStringLiteralLike(node: Node): node is StringLiteralLike;
36173619
}

0 commit comments

Comments
 (0)