refactor(compiler): improve stringify (#60013)

This is the same change that was made in this commit (https://github.com/angular/angular/commit/cf3a5073ece9eb313bb4832b3f78aa1bfeca09c6). See its description for clarification.

PR Close #60013
This commit is contained in:
arturovt
2025-02-19 17:35:20 +02:00
committed by Andrew Kushnir
parent 075145ef93
commit 964b261a86
+9 -12
View File
@@ -85,19 +85,16 @@ export function stringify(token: any): string {
}
if (Array.isArray(token)) {
return '[' + token.map(stringify).join(', ') + ']';
return `[${token.map(stringify).join(', ')}]`;
}
if (token == null) {
return '' + token;
}
if (token.overriddenName) {
return `${token.overriddenName}`;
}
if (token.name) {
return `${token.name}`;
const name = token.overriddenName || token.name;
if (name) {
return `${name}`;
}
if (!token.toString) {
@@ -106,14 +103,14 @@ export function stringify(token: any): string {
// WARNING: do not try to `JSON.stringify(token)` here
// see https://github.com/angular/angular/issues/23440
const res = token.toString();
const result = token.toString();
if (res == null) {
return '' + res;
if (result == null) {
return '' + result;
}
const newLineIndex = res.indexOf('\n');
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
const newLineIndex = result.indexOf('\n');
return newLineIndex >= 0 ? result.slice(0, newLineIndex) : result;
}
export class Version {