diff --git a/modules/@angular/compiler/src/compile_metadata.ts b/modules/@angular/compiler/src/compile_metadata.ts index 87b1ff572bcf90..cdbe6fe8c80643 100644 --- a/modules/@angular/compiler/src/compile_metadata.ts +++ b/modules/@angular/compiler/src/compile_metadata.ts @@ -81,6 +81,7 @@ function _sanitizeIdentifier(name: string): string { } let _anonymousTypeIndex = 0; +const symbols = new Map(); export function identifierName(compileIdentifier: CompileIdentifierMetadata): string { if (!compileIdentifier || !compileIdentifier.reference) { @@ -90,6 +91,14 @@ export function identifierName(compileIdentifier: CompileIdentifierMetadata): st if (ref instanceof StaticSymbol) { return ref.name; } + if (typeof ref === 'symbol') { + if (symbols.has(ref)) { + return symbols.get(ref); + } + const symbolStr = ref.toString().replace(/\(|\)/g, '_'); + symbols.set(ref, symbolStr); + return symbolStr; + } if (ref['__anonymousType']) { return ref['__anonymousType']; } diff --git a/modules/@angular/compiler/test/integration_spec.ts b/modules/@angular/compiler/test/integration_spec.ts index 95051bc68881bd..25753f46555dbb 100644 --- a/modules/@angular/compiler/test/integration_spec.ts +++ b/modules/@angular/compiler/test/integration_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Component, Directive, Input} from '@angular/core'; +import {Component, Directive, Inject, Input} from '@angular/core'; import {ComponentFixture, TestBed, async} from '@angular/core/testing'; import {By} from '@angular/platform-browser/src/dom/debug/by'; import {expect} from '@angular/platform-browser/testing/matchers'; @@ -38,6 +38,23 @@ export function main() { })); }); + it('should not throw when Symbol is used as DI token', async(() => { + const SOME_SYMBOL = Symbol('SomeSymbol'); + + @Component({selector: 'symbol', template: ''}) + class CmpWithSymbol { + constructor(@Inject(SOME_SYMBOL) public symbol: string) {} + } + + TestBed.configureTestingModule({ + declarations: [CmpWithSymbol], + providers: [{provide: SOME_SYMBOL, useValue: 'value'}] + }); + + const fixture = TestBed.createComponent(CmpWithSymbol); + fixture.detectChanges(); + expect(fixture.componentInstance.symbol).toEqual('value'); + })); }); }