Sitelet https://github.com/angular/angular/commit/964b261a866cec4e283ee13efd58a2e402aed211
Skip to content

Commit 964b261

Browse files
arturovtAndrewKushnir
authored andcommitted
refactor(compiler): improve stringify (#60013)
This is the same change that was made in this commit (cf3a507). See its description for clarification. PR Close #60013
1 parent 075145e commit 964b261

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

‎packages/compiler/src/util.ts‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,16 @@ export function stringify(token: any): string {
8585
}
8686

8787
if (Array.isArray(token)) {
88-
return '[' + token.map(stringify).join(', ') + ']';
88+
return `[${token.map(stringify).join(', ')}]`;
8989
}
9090

9191
if (token == null) {
9292
return '' + token;
9393
}
9494

95-
if (token.overriddenName) {
96-
return `${token.overriddenName}`;
97-
}
98-
99-
if (token.name) {
100-
return `${token.name}`;
95+
const name = token.overriddenName || token.name;
96+
if (name) {
97+
return `${name}`;
10198
}
10299

103100
if (!token.toString) {
@@ -106,14 +103,14 @@ export function stringify(token: any): string {
106103

107104
// WARNING: do not try to `JSON.stringify(token)` here
108105
// see https://github.com/angular/angular/issues/23440
109-
const res = token.toString();
106+
const result = token.toString();
110107

111-
if (res == null) {
112-
return '' + res;
108+
if (result == null) {
109+
return '' + result;
113110
}
114111

115-
const newLineIndex = res.indexOf('\n');
116-
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
112+
const newLineIndex = result.indexOf('\n');
113+
return newLineIndex >= 0 ? result.slice(0, newLineIndex) : result;
117114
}
118115

119116
export class Version {

0 commit comments

Comments
 (0)