fix(compiler): stringify `Object.create(null)` tokens (#16848)

PR Close #16848
This commit is contained in:
Pete Bacon Darwin 2019-03-22 09:42:52 +00:00 committed by Kara Erickson
parent fad03c3c14
commit 5e53956c2b
2 changed files with 10 additions and 2 deletions

View File

@ -184,6 +184,10 @@ export function stringify(token: any): string {
return `${token.name}`; return `${token.name}`;
} }
if (!token.toString) {
return 'object';
}
// WARNING: do not try to `JSON.stringify(token)` here // WARNING: do not try to `JSON.stringify(token)` here
// see https://github.com/angular/angular/issues/23440 // see https://github.com/angular/angular/issues/23440
const res = token.toString(); const res = token.toString();

View File

@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {fakeAsync} from '@angular/core/testing/src/fake_async'; import {escapeRegExp, splitAtColon, stringify, utf8Encode} from '../src/util';
import {SyncAsync, escapeRegExp, splitAtColon, utf8Encode} from '../src/util';
{ {
describe('util', () => { describe('util', () => {
@ -75,5 +74,10 @@ import {SyncAsync, escapeRegExp, splitAtColon, utf8Encode} from '../src/util';
([input, output]: [string, string]) => { expect(utf8Encode(input)).toEqual(output); }); ([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'); });
});
}); });
} }