Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc86fee

Browse files
committed
fix(compiler): support string tokens with . inside.
1 parent 386cc5d commit cc86fee

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

modules/angular2/src/compiler/compile_metadata.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from 'angular2/src/core/change_detection/change_detection';
2626
import {ViewEncapsulation, VIEW_ENCAPSULATION_VALUES} from 'angular2/src/core/metadata/view';
2727
import {CssSelector} from 'angular2/src/compiler/selector';
28-
import {splitAtColon} from './util';
28+
import {splitAtColon, sanitizeIdentifier} from './util';
2929
import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/metadata/lifecycle_hooks';
3030
import {getUrlScheme} from './url_resolver';
3131

@@ -318,7 +318,9 @@ export class CompileTokenMetadata implements CompileMetadataWithIdentifier {
318318
(isPresent(ak) && ak == token2.assetCacheKey);
319319
}
320320

321-
get name(): string { return isPresent(this.value) ? this.value : this.identifier.name; }
321+
get name(): string {
322+
return isPresent(this.value) ? sanitizeIdentifier(this.value) : this.identifier.name;
323+
}
322324
}
323325

324326
export class CompileTokenMap<VALUE> {

modules/angular2/test/core/linker/regression_integration_spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ function declareTests(isJit: boolean) {
9292
});
9393
}));
9494

95+
it('should support providers with string token with a `.` in it',
96+
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
97+
var token = 'a.b';
98+
var tokenValue = 1;
99+
createInjector(tcb, [provide(token, {useValue: tokenValue})])
100+
.then((injector: Injector) => {
101+
expect(injector.get(token)).toEqual(tokenValue);
102+
async.done();
103+
});
104+
}));
105+
95106
it('should support providers with an anonymous function',
96107
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
97108
var token = () => true;

0 commit comments

Comments
 (0)