From 952710b43bfab841a0cb2f3f5bbec3e0ad4db3ee Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sat, 3 Oct 2020 21:14:59 +0100 Subject: [PATCH] refactor(compiler-cli): ensure `isNamed....()` helpers check name is identity (#38959) Previously the `node.name` property was only checked to ensure it was defined. But that meant that it was a `ts.BindingName`, which also includes `ts.BindingPattern`, which we do not support. But these helper methods were forcefully casting the value to `ts.Identifier. Now we also check that the `node.name` is actually an `ts.Identifier`. PR Close #38959 --- packages/compiler-cli/src/ngtsc/reflection/src/util.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/reflection/src/util.ts b/packages/compiler-cli/src/ngtsc/reflection/src/util.ts index f49d0b531e..8aaffc8b24 100644 --- a/packages/compiler-cli/src/ngtsc/reflection/src/util.ts +++ b/packages/compiler-cli/src/ngtsc/reflection/src/util.ts @@ -11,15 +11,19 @@ import {ClassDeclaration} from './host'; export function isNamedClassDeclaration(node: ts.Node): node is ClassDeclaration { - return ts.isClassDeclaration(node) && (node.name !== undefined); + return ts.isClassDeclaration(node) && isIdentifier(node.name); } export function isNamedFunctionDeclaration(node: ts.Node): node is ClassDeclaration { - return ts.isFunctionDeclaration(node) && (node.name !== undefined); + return ts.isFunctionDeclaration(node) && isIdentifier(node.name); } export function isNamedVariableDeclaration(node: ts.Node): node is ClassDeclaration { - return ts.isVariableDeclaration(node) && (node.name !== undefined); + return ts.isVariableDeclaration(node) && isIdentifier(node.name); +} + +function isIdentifier(node: ts.Node|undefined): node is ts.Identifier { + return node !== undefined && ts.isIdentifier(node); }