diff --git a/packages/compiler/src/util.ts b/packages/compiler/src/util.ts index 5fb3982005..d6bba8ca32 100644 --- a/packages/compiler/src/util.ts +++ b/packages/compiler/src/util.ts @@ -184,6 +184,10 @@ export function stringify(token: any): string { return `${token.name}`; } + if (!token.toString) { + return 'object'; + } + // WARNING: do not try to `JSON.stringify(token)` here // see https://github.com/angular/angular/issues/23440 const res = token.toString(); diff --git a/packages/compiler/test/util_spec.ts b/packages/compiler/test/util_spec.ts index 188c6c3739..60a6115429 100644 --- a/packages/compiler/test/util_spec.ts +++ b/packages/compiler/test/util_spec.ts @@ -6,8 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {fakeAsync} from '@angular/core/testing/src/fake_async'; -import {SyncAsync, escapeRegExp, splitAtColon, utf8Encode} from '../src/util'; +import {escapeRegExp, splitAtColon, stringify, utf8Encode} from '../src/util'; { describe('util', () => { @@ -75,5 +74,10 @@ import {SyncAsync, escapeRegExp, splitAtColon, utf8Encode} from '../src/util'; ([input, output]: [string, string]) => { expect(utf8Encode(input)).toEqual(output); }); }); }); + + describe('stringify()', () => { + it('should handle objects with no prototype.', + () => { expect(stringify(Object.create(null))).toEqual('object'); }); + }); }); } \ No newline at end of file