From cc86fee1d1e597a196c443c6bbcd9b10e539a9ba Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 21 Apr 2016 11:17:49 -0700 Subject: [PATCH] fix(compiler): support string tokens with `.` inside. --- modules/angular2/src/compiler/compile_metadata.ts | 6 ++++-- .../test/core/linker/regression_integration_spec.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/angular2/src/compiler/compile_metadata.ts b/modules/angular2/src/compiler/compile_metadata.ts index 4be4e5e215..36d63f7514 100644 --- a/modules/angular2/src/compiler/compile_metadata.ts +++ b/modules/angular2/src/compiler/compile_metadata.ts @@ -25,7 +25,7 @@ import { } from 'angular2/src/core/change_detection/change_detection'; import {ViewEncapsulation, VIEW_ENCAPSULATION_VALUES} from 'angular2/src/core/metadata/view'; import {CssSelector} from 'angular2/src/compiler/selector'; -import {splitAtColon} from './util'; +import {splitAtColon, sanitizeIdentifier} from './util'; import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/metadata/lifecycle_hooks'; import {getUrlScheme} from './url_resolver'; @@ -318,7 +318,9 @@ export class CompileTokenMetadata implements CompileMetadataWithIdentifier { (isPresent(ak) && ak == token2.assetCacheKey); } - get name(): string { return isPresent(this.value) ? this.value : this.identifier.name; } + get name(): string { + return isPresent(this.value) ? sanitizeIdentifier(this.value) : this.identifier.name; + } } export class CompileTokenMap { diff --git a/modules/angular2/test/core/linker/regression_integration_spec.ts b/modules/angular2/test/core/linker/regression_integration_spec.ts index e0993791df..1570e92c24 100644 --- a/modules/angular2/test/core/linker/regression_integration_spec.ts +++ b/modules/angular2/test/core/linker/regression_integration_spec.ts @@ -92,6 +92,17 @@ function declareTests(isJit: boolean) { }); })); + it('should support providers with string token with a `.` in it', + inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { + var token = 'a.b'; + var tokenValue = 1; + createInjector(tcb, [provide(token, {useValue: tokenValue})]) + .then((injector: Injector) => { + expect(injector.get(token)).toEqual(tokenValue); + async.done(); + }); + })); + it('should support providers with an anonymous function', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { var token = () => true;