Skip to content

Commit 1299534

Browse files
author
Andy Hanson
committed
Add assertion
1 parent 4071d50 commit 1299534

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/compiler/utilities.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,12 +1861,12 @@ namespace ts {
18611861
}
18621862

18631863
// True if the given identifier, string literal, or number literal is the name of a declaration node
1864-
export function isDeclarationName(name: Node): boolean {
1864+
export function isDeclarationName(name: Node, parent: Node = name.parent): boolean {
18651865
switch (name.kind) {
18661866
case SyntaxKind.Identifier:
18671867
case SyntaxKind.StringLiteral:
18681868
case SyntaxKind.NumericLiteral:
1869-
return isDeclaration(name.parent) && name.parent.name === name;
1869+
return isDeclaration(parent) && parent.name === name;
18701870
default:
18711871
return false;
18721872
}
@@ -4300,7 +4300,10 @@ namespace ts {
43004300

43014301
/** @internal */
43024302
export function isNamedDeclaration(node: Node): node is NamedDeclaration & { name: DeclarationName } {
4303-
return !!(node as NamedDeclaration).name;
4303+
const name = (node as NamedDeclaration).name;
4304+
// Need to pass in parent as this is called from the binder before parent is set.
4305+
Debug.assert(!name || isDeclaration(node) && node.name === name, "A 'name' property should always be a DeclarationName.");
4306+
return !!name;
43044307
}
43054308

43064309
export function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined {

0 commit comments

Comments
 (0)