Skip to content

Commit 1f5d7dc

Browse files
petebacondarwinjosephperrott
authored andcommitted
refactor(compiler-cli): function declarations must have names (angular#38866)
The `AstFactory.createFunctionDeclaration()` was allowing `null` to be passed as the function `name` value. This is not actually possible, since function declarations must always have a name. PR Close angular#38866
1 parent 8c16330 commit 1f5d7dc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export interface AstFactory<TStatement, TExpression> {
9797
* @param parameters the names of the function's parameters.
9898
* @param body a statement (or a block of statements) that are the body of the function.
9999
*/
100-
createFunctionDeclaration(functionName: string|null, parameters: string[], body: TStatement):
100+
createFunctionDeclaration(functionName: string, parameters: string[], body: TStatement):
101101
TStatement;
102102

103103
/**

packages/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ export class TypeScriptAstFactory implements AstFactory<ts.Statement, ts.Express
7979

8080
createExpressionStatement = ts.createExpressionStatement;
8181

82-
createFunctionDeclaration(functionName: string|null, parameters: string[], body: ts.Statement):
82+
createFunctionDeclaration(functionName: string, parameters: string[], body: ts.Statement):
8383
ts.Statement {
8484
if (!ts.isBlock(body)) {
8585
throw new Error(`Invalid syntax, expected a block, but got ${ts.SyntaxKind[body.kind]}.`);
8686
}
8787
return ts.createFunctionDeclaration(
88-
undefined, undefined, undefined, functionName ?? undefined, undefined,
88+
undefined, undefined, undefined, functionName, undefined,
8989
parameters.map(param => ts.createParameter(undefined, undefined, undefined, param)),
9090
undefined, body);
9191
}

0 commit comments

Comments
 (0)