Expose hasOnlyExpressionInitializer as a public type guard (#33229)

Exposes `hasOnlyExpressionInitializer` as a public function so users of
TypeScript compiler APIs do not have to roll their own
`HasExpressionInitializer` type guards.

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
hafiz 2020-02-04 16:01:20 -08:00 committed by GitHub
parent 044355ba5f
commit 09441107c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -2507,9 +2507,19 @@ namespace ts {
}
/** True if has initializer node attached to it. */
/* @internal */
export function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer {
return hasInitializer(node) && !isForStatement(node) && !isForInStatement(node) && !isForOfStatement(node) && !isJsxAttribute(node);
switch (node.kind) {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Parameter:
case SyntaxKind.BindingElement:
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.EnumMember:
return true;
default:
return false;
}
}
export function isObjectLiteralElement(node: Node): node is ObjectLiteralElement {

View file

@ -3787,6 +3787,8 @@ declare namespace ts {
function isJSDocCommentContainingNode(node: Node): boolean;
function isSetAccessor(node: Node): node is SetAccessorDeclaration;
function isGetAccessor(node: Node): node is GetAccessorDeclaration;
/** True if has initializer node attached to it. */
function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer;
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
function isStringLiteralLike(node: Node): node is StringLiteralLike;
}

View file

@ -3787,6 +3787,8 @@ declare namespace ts {
function isJSDocCommentContainingNode(node: Node): boolean;
function isSetAccessor(node: Node): node is SetAccessorDeclaration;
function isGetAccessor(node: Node): node is GetAccessorDeclaration;
/** True if has initializer node attached to it. */
function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer;
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
function isStringLiteralLike(node: Node): node is StringLiteralLike;
}