Skip to content

Commit 1d1e75e

Browse files
committed
Revert "fix(compiler): Pretty print object instead of [Object object] (angular#22689)" (angular#23442)
This reverts commit 8555a3a. Reverted because of angular#23440 PR Close angular#23442
1 parent acf6781 commit 1d1e75e

File tree

4 files changed

+7
-42
lines changed

4 files changed

+7
-42
lines changed

packages/compiler/src/util.ts

+4-17
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ export interface OutputContext {
163163
importExpr(reference: any, typeParams?: o.Type[]|null, useSummaries?: boolean): o.Expression;
164164
}
165165

166-
const MAX_LENGTH_STRINGIFY = 100;
167-
168166
export function stringify(token: any): string {
169167
if (typeof token === 'string') {
170168
return token;
@@ -186,27 +184,16 @@ export function stringify(token: any): string {
186184
return `${token.name}`;
187185
}
188186

189-
let res;
190-
try {
191-
res = JSON.stringify(token);
192-
} catch {
193-
res = token.toString();
194-
}
187+
// WARNING: do not try to `JSON.stringify(token)` here
188+
// see https://github.com/angular/angular/issues/23440
189+
const res = token.toString();
195190

196191
if (res == null) {
197192
return '' + res;
198193
}
199194

200195
const newLineIndex = res.indexOf('\n');
201-
if (0 < newLineIndex) {
202-
res = res.substring(0, newLineIndex);
203-
}
204-
205-
if (MAX_LENGTH_STRINGIFY < res.length) {
206-
res = res.substring(0, MAX_LENGTH_STRINGIFY) + '...';
207-
}
208-
209-
return res;
196+
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
210197
}
211198

212199
/**

packages/compiler/test/metadata_resolver_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ import {TEST_COMPILER_PROVIDERS} from './test_bindings';
409409

410410
expect(() => { resolver.getNgModuleMetadata(InvalidModule); })
411411
.toThrowError(
412-
`Unexpected value '{"ngModule":true}' imported by the module 'InvalidModule'. Please add a @NgModule annotation.`);
412+
`Unexpected value '[object Object]' imported by the module 'InvalidModule'. Please add a @NgModule annotation.`);
413413
}));
414414
});
415415

packages/compiler/test/util_spec.ts

+2-21
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
*/
88

99
import {fakeAsync} from '@angular/core/testing/src/fake_async';
10-
11-
import {SyncAsync, escapeRegExp, splitAtColon, stringify, utf8Encode} from '../src/util';
10+
import {SyncAsync, escapeRegExp, splitAtColon, utf8Encode} from '../src/util';
1211

1312
{
1413
describe('util', () => {
@@ -76,23 +75,5 @@ import {SyncAsync, escapeRegExp, splitAtColon, stringify, utf8Encode} from '../s
7675
([input, output]: [string, string]) => { expect(utf8Encode(input)).toEqual(output); });
7776
});
7877
});
79-
80-
describe('stringify', () => {
81-
it('should pretty print an Object', () => {
82-
const result = stringify({hello: 'world'});
83-
expect(result).toBe('{"hello":"world"}');
84-
});
85-
86-
it('should truncate large object', () => {
87-
const result = stringify({
88-
selector: 'app-root',
89-
preserveWhitespaces: false,
90-
templateUrl: './app.component.ng.html',
91-
styleUrls: ['./app.component.css']
92-
});
93-
expect(result).toBe(
94-
'{"selector":"app-root","preserveWhitespaces":false,"templateUrl":"./app.component.ng.html","styleUrl...');
95-
});
96-
});
9778
});
98-
}
79+
}

packages/core/test/bundling/hello_world_r2/bundle.golden_symbols.json

-3
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,6 @@
10041004
{
10051005
"name": "LiteralPrimitive"
10061006
},
1007-
{
1008-
"name": "MAX_LENGTH_STRINGIFY"
1009-
},
10101007
{
10111008
"name": "MEANING_SEPARATOR"
10121009
},

0 commit comments

Comments
 (0)