From f7c2d1024fc3ee087dd66e6fc230e5d5837658f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mis=CC=8Cko=20Hevery?= Date: Mon, 20 Mar 2017 15:04:20 -0700 Subject: [PATCH] Revert "fix(compiler): shouldn't throw when Symbol is used as DI token (#13701)" (#15319) This reverts commit 8b5c6b2732f03927b5b697d22c5d84e8fab7e225. This feature is not compatible with the `Injector.get` which now only takes `Type` or `InjectableToken`. `Symbol` is not a valid type. Closes #15183 PR Close #15319 --- packages/compiler/src/compile_metadata.ts | 14 ----------- packages/compiler/test/integration_spec.ts | 27 +--------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/packages/compiler/src/compile_metadata.ts b/packages/compiler/src/compile_metadata.ts index 19c6ec7c70afc..eac362f4ac788 100644 --- a/packages/compiler/src/compile_metadata.ts +++ b/packages/compiler/src/compile_metadata.ts @@ -80,8 +80,6 @@ function _sanitizeIdentifier(name: string): string { } let _anonymousTypeIndex = 0; -let symbolId = 0; -const symbolIds = new Map(); export function identifierName(compileIdentifier: CompileIdentifierMetadata): string { if (!compileIdentifier || !compileIdentifier.reference) { @@ -91,14 +89,6 @@ export function identifierName(compileIdentifier: CompileIdentifierMetadata): st if (ref instanceof StaticSymbol) { return ref.name; } - if (isSymbol(ref)) { - if (symbolIds.has(ref)) { - return symbolIds.get(ref); - } - const symbolStr = `_symbol_${_sanitizeIdentifier(ref.toString())}_${symbolId++}`; - symbolIds.set(ref, symbolStr); - return symbolStr; - } if (ref['__anonymousType']) { return ref['__anonymousType']; } @@ -113,10 +103,6 @@ export function identifierName(compileIdentifier: CompileIdentifierMetadata): st return identifier; } -function isSymbol(sym: any): sym is Symbol { - return typeof sym === 'symbol'; -} - export function identifierModuleUrl(compileIdentifier: CompileIdentifierMetadata): string { const ref = compileIdentifier.reference; if (ref instanceof StaticSymbol) { diff --git a/packages/compiler/test/integration_spec.ts b/packages/compiler/test/integration_spec.ts index 60dadec980fb3..a4d995a2b4bc8 100644 --- a/packages/compiler/test/integration_spec.ts +++ b/packages/compiler/test/integration_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {Component, Directive, Inject, Input} from '@angular/core'; +import {Component, Directive, 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/src/matchers'; @@ -38,31 +38,6 @@ export function main() { })); }); - it('should not throw when Symbol is used as DI token', async(() => { - const SOME_SYMBOL = Symbol('Symbol'); - const ANOTHER_SYMBOL = Symbol('Symbol'); - - @Component({selector: 'symbol', template: ''}) - class CmpWithSymbol { - constructor( - @Inject(SOME_SYMBOL) public symbol: string, - @Inject(ANOTHER_SYMBOL) public anotherSymbol: string) {} - } - - TestBed.configureTestingModule({ - declarations: [CmpWithSymbol], - providers: [ - {provide: SOME_SYMBOL, useValue: 'value'}, - {provide: SOME_SYMBOL, useValue: 'override'}, - {provide: ANOTHER_SYMBOL, useValue: 'another value'} - ] - }); - - const fixture = TestBed.createComponent(CmpWithSymbol); - fixture.detectChanges(); - expect(fixture.componentInstance.symbol).toEqual('override'); - expect(fixture.componentInstance.anotherSymbol).toEqual('another value'); - })); }); }