Skip to content

Commit 5e53956

Browse files
petebacondarwinkara
authored andcommitted
fix(compiler): stringify Object.create(null) tokens (#16848)
PR Close #16848
1 parent fad03c3 commit 5e53956

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎packages/compiler/src/util.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ export function stringify(token: any): string {
184184
return `${token.name}`;
185185
}
186186

187+
if (!token.toString) {
188+
return 'object';
189+
}
190+
187191
// WARNING: do not try to `JSON.stringify(token)` here
188192
// see https://github.com/angular/angular/issues/23440
189193
const res = token.toString();

‎packages/compiler/test/util_spec.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

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

1211
{
1312
describe('util', () => {
@@ -75,5 +74,10 @@ import {SyncAsync, escapeRegExp, splitAtColon, utf8Encode} from '../src/util';
7574
([input, output]: [string, string]) => { expect(utf8Encode(input)).toEqual(output); });
7675
});
7776
});
77+
78+
describe('stringify()', () => {
79+
it('should handle objects with no prototype.',
80+
() => { expect(stringify(Object.create(null))).toEqual('object'); });
81+
});
7882
});
7983
}

0 commit comments

Comments
 (0)