mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(compiler): improve stringify (#60013)
This is the same change that was made in this commit (cf3a5073ec). See its description for clarification.
PR Close #60013
This commit is contained in:
parent
075145ef93
commit
964b261a86
1 changed files with 9 additions and 12 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue