mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user