Skip to content

Commit

Permalink
fix(compiler): stringify Object.create(null) tokens (#16848)
Browse files Browse the repository at this point in the history
PR Close #16848
  • Loading branch information
petebacondarwin authored and kara committed Jun 21, 2019
1 parent fad03c3 commit 5e53956
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/compiler/src/util.ts
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions packages/compiler/test/util_spec.ts
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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'); });
});
});
}

0 comments on commit 5e53956

Please sign in to comment.