diff --git a/packages/core/src/util.ts b/packages/core/src/util.ts index 217bb6ffff..800f571091 100644 --- a/packages/core/src/util.ts +++ b/packages/core/src/util.ts @@ -69,6 +69,11 @@ export function stringify(token: any): string { } const res = token.toString(); + + if (res == null) { + return '' + res; + } + const newLineIndex = res.indexOf('\n'); return newLineIndex === -1 ? res : res.substring(0, newLineIndex); } diff --git a/packages/core/test/util_spec.ts b/packages/core/test/util_spec.ts new file mode 100644 index 0000000000..f1138eaa69 --- /dev/null +++ b/packages/core/test/util_spec.ts @@ -0,0 +1,19 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {stringify} from '../src/util'; + +export function main() { + describe('stringify', () => { + it('should return string undefined when toString returns undefined', + () => expect(stringify({toString: (): string => undefined})).toBe('undefined')); + + it('should return string null when toString returns null', + () => expect(stringify({toString: (): string => null})).toBe('null')); + }); +}