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:
parent
044355ba5f
commit
09441107c1
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue