parent
9889c21aaa
commit
2f7045720a
@ -9,6 +9,7 @@ import {
|
|||||||
import * as o from './output_ast';
|
import * as o from './output_ast';
|
||||||
import {EmitterVisitorContext} from './abstract_emitter';
|
import {EmitterVisitorContext} from './abstract_emitter';
|
||||||
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';
|
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';
|
||||||
|
import {sanitizeIdentifier} from '../util';
|
||||||
|
|
||||||
export function jitStatements(sourceUrl: string, statements: o.Statement[],
|
export function jitStatements(sourceUrl: string, statements: o.Statement[],
|
||||||
resultVar: string): any {
|
resultVar: string): any {
|
||||||
@ -36,13 +37,10 @@ class JitEmitterVisitor extends AbstractJsEmitterVisitor {
|
|||||||
if (id === -1) {
|
if (id === -1) {
|
||||||
id = this._evalArgValues.length;
|
id = this._evalArgValues.length;
|
||||||
this._evalArgValues.push(value);
|
this._evalArgValues.push(value);
|
||||||
this._evalArgNames.push(sanitizeJitArgName(`jit_${ast.value.name}${id}`));
|
var name = isPresent(ast.value.name) ? sanitizeIdentifier(ast.value.name) : 'val';
|
||||||
|
this._evalArgNames.push(sanitizeIdentifier(`jit_${name}${id}`));
|
||||||
}
|
}
|
||||||
ctx.print(this._evalArgNames[id]);
|
ctx.print(this._evalArgNames[id]);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitizeJitArgName(name: string): string {
|
|
||||||
return StringWrapper.replaceAll(name, /[\.\/]/g, '_');
|
|
||||||
}
|
|
||||||
|
@ -24,7 +24,7 @@ import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/metadata
|
|||||||
import {reflector} from 'angular2/src/core/reflection/reflection';
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
||||||
import {Injectable, Inject, Optional} from 'angular2/src/core/di';
|
import {Injectable, Inject, Optional} from 'angular2/src/core/di';
|
||||||
import {PLATFORM_DIRECTIVES, PLATFORM_PIPES} from 'angular2/src/core/platform_directives_and_pipes';
|
import {PLATFORM_DIRECTIVES, PLATFORM_PIPES} from 'angular2/src/core/platform_directives_and_pipes';
|
||||||
import {MODULE_SUFFIX} from './util';
|
import {MODULE_SUFFIX, sanitizeIdentifier} from './util';
|
||||||
import {assertArrayOfStrings} from './assertions';
|
import {assertArrayOfStrings} from './assertions';
|
||||||
import {getUrlScheme} from 'angular2/src/compiler/url_resolver';
|
import {getUrlScheme} from 'angular2/src/compiler/url_resolver';
|
||||||
import {Provider} from 'angular2/src/core/di/provider';
|
import {Provider} from 'angular2/src/core/di/provider';
|
||||||
@ -52,20 +52,18 @@ export class RuntimeMetadataResolver {
|
|||||||
@Optional() @Inject(PLATFORM_DIRECTIVES) private _platformDirectives: Type[],
|
@Optional() @Inject(PLATFORM_DIRECTIVES) private _platformDirectives: Type[],
|
||||||
@Optional() @Inject(PLATFORM_PIPES) private _platformPipes: Type[]) {}
|
@Optional() @Inject(PLATFORM_PIPES) private _platformPipes: Type[]) {}
|
||||||
|
|
||||||
/**
|
private sanitizeTokenName(token: any): string {
|
||||||
* Wrap the stringify method to avoid naming things `function (arg1...) {`
|
let identifier = stringify(token);
|
||||||
*/
|
if (identifier.indexOf('(') >= 0) {
|
||||||
private sanitizeName(obj: any): string {
|
// case: anonymous functions!
|
||||||
let result = StringWrapper.replaceAll(stringify(obj), /[\s-]/g, '_');
|
let found = this._anonymousTypes.get(token);
|
||||||
if (result.indexOf('(') < 0) {
|
if (isBlank(found)) {
|
||||||
return result;
|
this._anonymousTypes.set(token, this._anonymousTypeIndex++);
|
||||||
|
found = this._anonymousTypes.get(token);
|
||||||
|
}
|
||||||
|
identifier = `anonymous_token_${found}_`;
|
||||||
}
|
}
|
||||||
let found = this._anonymousTypes.get(obj);
|
return sanitizeIdentifier(identifier);
|
||||||
if (isBlank(found)) {
|
|
||||||
this._anonymousTypes.set(obj, this._anonymousTypeIndex++);
|
|
||||||
found = this._anonymousTypes.get(obj);
|
|
||||||
}
|
|
||||||
return `anonymous_type_${found}_`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDirectiveMetadata(directiveType: Type): cpl.CompileDirectiveMetadata {
|
getDirectiveMetadata(directiveType: Type): cpl.CompileDirectiveMetadata {
|
||||||
@ -130,7 +128,7 @@ export class RuntimeMetadataResolver {
|
|||||||
|
|
||||||
getTypeMetadata(type: Type, moduleUrl: string): cpl.CompileTypeMetadata {
|
getTypeMetadata(type: Type, moduleUrl: string): cpl.CompileTypeMetadata {
|
||||||
return new cpl.CompileTypeMetadata({
|
return new cpl.CompileTypeMetadata({
|
||||||
name: this.sanitizeName(type),
|
name: this.sanitizeTokenName(type),
|
||||||
moduleUrl: moduleUrl,
|
moduleUrl: moduleUrl,
|
||||||
runtime: type,
|
runtime: type,
|
||||||
diDeps: this.getDependenciesMetadata(type, null)
|
diDeps: this.getDependenciesMetadata(type, null)
|
||||||
@ -139,7 +137,7 @@ export class RuntimeMetadataResolver {
|
|||||||
|
|
||||||
getFactoryMetadata(factory: Function, moduleUrl: string): cpl.CompileFactoryMetadata {
|
getFactoryMetadata(factory: Function, moduleUrl: string): cpl.CompileFactoryMetadata {
|
||||||
return new cpl.CompileFactoryMetadata({
|
return new cpl.CompileFactoryMetadata({
|
||||||
name: this.sanitizeName(factory),
|
name: this.sanitizeTokenName(factory),
|
||||||
moduleUrl: moduleUrl,
|
moduleUrl: moduleUrl,
|
||||||
runtime: factory,
|
runtime: factory,
|
||||||
diDeps: this.getDependenciesMetadata(factory, null)
|
diDeps: this.getDependenciesMetadata(factory, null)
|
||||||
@ -227,17 +225,16 @@ export class RuntimeMetadataResolver {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getRuntimeIdentifier(value: any): cpl.CompileIdentifierMetadata {
|
|
||||||
return new cpl.CompileIdentifierMetadata({runtime: value, name: this.sanitizeName(value)});
|
|
||||||
}
|
|
||||||
|
|
||||||
getTokenMetadata(token: any): cpl.CompileTokenMetadata {
|
getTokenMetadata(token: any): cpl.CompileTokenMetadata {
|
||||||
token = resolveForwardRef(token);
|
token = resolveForwardRef(token);
|
||||||
var compileToken;
|
var compileToken;
|
||||||
if (isString(token)) {
|
if (isString(token)) {
|
||||||
compileToken = new cpl.CompileTokenMetadata({value: token});
|
compileToken = new cpl.CompileTokenMetadata({value: token});
|
||||||
} else {
|
} else {
|
||||||
compileToken = new cpl.CompileTokenMetadata({identifier: this.getRuntimeIdentifier(token)});
|
compileToken = new cpl.CompileTokenMetadata({
|
||||||
|
identifier: new cpl.CompileIdentifierMetadata(
|
||||||
|
{runtime: token, name: this.sanitizeTokenName(token)})
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return compileToken;
|
return compileToken;
|
||||||
}
|
}
|
||||||
@ -266,7 +263,9 @@ export class RuntimeMetadataResolver {
|
|||||||
return new cpl.CompileProviderMetadata({
|
return new cpl.CompileProviderMetadata({
|
||||||
token: this.getTokenMetadata(provider.token),
|
token: this.getTokenMetadata(provider.token),
|
||||||
useClass: isPresent(provider.useClass) ? this.getTypeMetadata(provider.useClass, null) : null,
|
useClass: isPresent(provider.useClass) ? this.getTypeMetadata(provider.useClass, null) : null,
|
||||||
useValue: isPresent(provider.useValue) ? this.getRuntimeIdentifier(provider.useValue) : null,
|
useValue: isPresent(provider.useValue) ?
|
||||||
|
new cpl.CompileIdentifierMetadata({runtime: provider.useValue}) :
|
||||||
|
null,
|
||||||
useFactory: isPresent(provider.useFactory) ?
|
useFactory: isPresent(provider.useFactory) ?
|
||||||
this.getFactoryMetadata(provider.useFactory, null) :
|
this.getFactoryMetadata(provider.useFactory, null) :
|
||||||
null,
|
null,
|
||||||
|
@ -23,3 +23,7 @@ export function splitAtColon(input: string, defaultValues: string[]): string[] {
|
|||||||
return defaultValues;
|
return defaultValues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sanitizeIdentifier(name: string): string {
|
||||||
|
return StringWrapper.replaceAll(name, /\W/g, '_');
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
import {isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||||
import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||||
|
import {BaseException} from 'angular2/src/facade/exceptions';
|
||||||
|
|
||||||
import * as o from '../output/output_ast';
|
import * as o from '../output/output_ast';
|
||||||
import {Identifiers, identifierToken} from '../identifiers';
|
import {Identifiers, identifierToken} from '../identifiers';
|
||||||
@ -47,7 +48,7 @@ export class CompileView implements NameResolver {
|
|||||||
public dirtyParentQueriesMethod: CompileMethod;
|
public dirtyParentQueriesMethod: CompileMethod;
|
||||||
public updateViewQueriesMethod: CompileMethod;
|
public updateViewQueriesMethod: CompileMethod;
|
||||||
public detectChangesInInputsMethod: CompileMethod;
|
public detectChangesInInputsMethod: CompileMethod;
|
||||||
public detectChangesHostPropertiesMethod: CompileMethod;
|
public detectChangesRenderPropertiesMethod: CompileMethod;
|
||||||
public afterContentLifecycleCallbacksMethod: CompileMethod;
|
public afterContentLifecycleCallbacksMethod: CompileMethod;
|
||||||
public afterViewLifecycleCallbacksMethod: CompileMethod;
|
public afterViewLifecycleCallbacksMethod: CompileMethod;
|
||||||
public destroyMethod: CompileMethod;
|
public destroyMethod: CompileMethod;
|
||||||
@ -78,7 +79,7 @@ export class CompileView implements NameResolver {
|
|||||||
this.dirtyParentQueriesMethod = new CompileMethod(this);
|
this.dirtyParentQueriesMethod = new CompileMethod(this);
|
||||||
this.updateViewQueriesMethod = new CompileMethod(this);
|
this.updateViewQueriesMethod = new CompileMethod(this);
|
||||||
this.detectChangesInInputsMethod = new CompileMethod(this);
|
this.detectChangesInInputsMethod = new CompileMethod(this);
|
||||||
this.detectChangesHostPropertiesMethod = new CompileMethod(this);
|
this.detectChangesRenderPropertiesMethod = new CompileMethod(this);
|
||||||
|
|
||||||
this.afterContentLifecycleCallbacksMethod = new CompileMethod(this);
|
this.afterContentLifecycleCallbacksMethod = new CompileMethod(this);
|
||||||
this.afterViewLifecycleCallbacksMethod = new CompileMethod(this);
|
this.afterViewLifecycleCallbacksMethod = new CompileMethod(this);
|
||||||
@ -124,7 +125,18 @@ export class CompileView implements NameResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createPipe(name: string): o.Expression {
|
createPipe(name: string): o.Expression {
|
||||||
var pipeMeta: CompilePipeMetadata = this.pipeMetas.find((pipeMeta) => pipeMeta.name == name);
|
var pipeMeta: CompilePipeMetadata = null;
|
||||||
|
for (var i = this.pipeMetas.length - 1; i >= 0; i--) {
|
||||||
|
var localPipeMeta = this.pipeMetas[i];
|
||||||
|
if (localPipeMeta.name == name) {
|
||||||
|
pipeMeta = localPipeMeta;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isBlank(pipeMeta)) {
|
||||||
|
throw new BaseException(
|
||||||
|
`Illegal state: Could not find pipe ${name} although the parser should have detected this error!`);
|
||||||
|
}
|
||||||
var pipeFieldName = pipeMeta.pure ? `_pipe_${name}` : `_pipe_${name}_${this.pipes.size}`;
|
var pipeFieldName = pipeMeta.pure ? `_pipe_${name}` : `_pipe_${name}_${this.pipes.size}`;
|
||||||
var pipeExpr = this.pipes.get(pipeFieldName);
|
var pipeExpr = this.pipes.get(pipeFieldName);
|
||||||
if (isBlank(pipeExpr)) {
|
if (isBlank(pipeExpr)) {
|
||||||
|
@ -71,7 +71,7 @@ export function bindRenderText(boundText: BoundTextAst, compileNode: CompileNode
|
|||||||
view.bindings.push(new CompileBinding(compileNode, boundText));
|
view.bindings.push(new CompileBinding(compileNode, boundText));
|
||||||
var currValExpr = createCurrValueExpr(bindingIndex);
|
var currValExpr = createCurrValueExpr(bindingIndex);
|
||||||
var valueField = createBindFieldExpr(bindingIndex);
|
var valueField = createBindFieldExpr(bindingIndex);
|
||||||
view.detectChangesInInputsMethod.resetDebugInfo(compileNode.nodeIndex, boundText);
|
view.detectChangesRenderPropertiesMethod.resetDebugInfo(compileNode.nodeIndex, boundText);
|
||||||
|
|
||||||
bind(view, currValExpr, valueField, boundText.value, o.THIS_EXPR.prop('context'),
|
bind(view, currValExpr, valueField, boundText.value, o.THIS_EXPR.prop('context'),
|
||||||
[
|
[
|
||||||
@ -79,7 +79,7 @@ export function bindRenderText(boundText: BoundTextAst, compileNode: CompileNode
|
|||||||
.callMethod('setText', [compileNode.renderNode, currValExpr])
|
.callMethod('setText', [compileNode.renderNode, currValExpr])
|
||||||
.toStmt()
|
.toStmt()
|
||||||
],
|
],
|
||||||
view.detectChangesInInputsMethod);
|
view.detectChangesRenderPropertiesMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindAndWriteToRenderer(boundProps: BoundElementPropertyAst[], context: o.Expression,
|
function bindAndWriteToRenderer(boundProps: BoundElementPropertyAst[], context: o.Expression,
|
||||||
@ -89,7 +89,7 @@ function bindAndWriteToRenderer(boundProps: BoundElementPropertyAst[], context:
|
|||||||
boundProps.forEach((boundProp) => {
|
boundProps.forEach((boundProp) => {
|
||||||
var bindingIndex = view.bindings.length;
|
var bindingIndex = view.bindings.length;
|
||||||
view.bindings.push(new CompileBinding(compileElement, boundProp));
|
view.bindings.push(new CompileBinding(compileElement, boundProp));
|
||||||
view.detectChangesHostPropertiesMethod.resetDebugInfo(compileElement.nodeIndex, boundProp);
|
view.detectChangesRenderPropertiesMethod.resetDebugInfo(compileElement.nodeIndex, boundProp);
|
||||||
var fieldExpr = createBindFieldExpr(bindingIndex);
|
var fieldExpr = createBindFieldExpr(bindingIndex);
|
||||||
var currValExpr = createCurrValueExpr(bindingIndex);
|
var currValExpr = createCurrValueExpr(bindingIndex);
|
||||||
var renderMethod: string;
|
var renderMethod: string;
|
||||||
@ -125,7 +125,7 @@ function bindAndWriteToRenderer(boundProps: BoundElementPropertyAst[], context:
|
|||||||
.toStmt());
|
.toStmt());
|
||||||
|
|
||||||
bind(view, currValExpr, fieldExpr, boundProp.value, context, updateStmts,
|
bind(view, currValExpr, fieldExpr, boundProp.value, context, updateStmts,
|
||||||
view.detectChangesHostPropertiesMethod);
|
view.detectChangesRenderPropertiesMethod);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,8 +538,8 @@ function generateDetectChangesMethod(view: CompileView): o.Statement[] {
|
|||||||
var stmts = [];
|
var stmts = [];
|
||||||
if (view.detectChangesInInputsMethod.isEmpty() && view.updateContentQueriesMethod.isEmpty() &&
|
if (view.detectChangesInInputsMethod.isEmpty() && view.updateContentQueriesMethod.isEmpty() &&
|
||||||
view.afterContentLifecycleCallbacksMethod.isEmpty() &&
|
view.afterContentLifecycleCallbacksMethod.isEmpty() &&
|
||||||
view.detectChangesHostPropertiesMethod.isEmpty() && view.updateViewQueriesMethod.isEmpty() &&
|
view.detectChangesRenderPropertiesMethod.isEmpty() &&
|
||||||
view.afterViewLifecycleCallbacksMethod.isEmpty()) {
|
view.updateViewQueriesMethod.isEmpty() && view.afterViewLifecycleCallbacksMethod.isEmpty()) {
|
||||||
return stmts;
|
return stmts;
|
||||||
}
|
}
|
||||||
ListWrapper.addAll(stmts, view.detectChangesInInputsMethod.finish());
|
ListWrapper.addAll(stmts, view.detectChangesInInputsMethod.finish());
|
||||||
@ -551,7 +551,7 @@ function generateDetectChangesMethod(view: CompileView): o.Statement[] {
|
|||||||
if (afterContentStmts.length > 0) {
|
if (afterContentStmts.length > 0) {
|
||||||
stmts.push(new o.IfStmt(o.not(DetectChangesVars.throwOnChange), afterContentStmts));
|
stmts.push(new o.IfStmt(o.not(DetectChangesVars.throwOnChange), afterContentStmts));
|
||||||
}
|
}
|
||||||
ListWrapper.addAll(stmts, view.detectChangesHostPropertiesMethod.finish());
|
ListWrapper.addAll(stmts, view.detectChangesRenderPropertiesMethod.finish());
|
||||||
stmts.push(o.THIS_EXPR.callMethod('detectViewChildrenChanges', [DetectChangesVars.throwOnChange])
|
stmts.push(o.THIS_EXPR.callMethod('detectViewChildrenChanges', [DetectChangesVars.throwOnChange])
|
||||||
.toStmt());
|
.toStmt());
|
||||||
var afterViewStmts =
|
var afterViewStmts =
|
||||||
|
150
modules/angular2/test/core/linker/regression_integration_spec.ts
Normal file
150
modules/angular2/test/core/linker/regression_integration_spec.ts
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
import {
|
||||||
|
AsyncTestCompleter,
|
||||||
|
beforeEach,
|
||||||
|
ddescribe,
|
||||||
|
xdescribe,
|
||||||
|
describe,
|
||||||
|
el,
|
||||||
|
dispatchEvent,
|
||||||
|
expect,
|
||||||
|
iit,
|
||||||
|
inject,
|
||||||
|
beforeEachProviders,
|
||||||
|
it,
|
||||||
|
xit,
|
||||||
|
containsRegexp,
|
||||||
|
stringifyElement,
|
||||||
|
TestComponentBuilder,
|
||||||
|
fakeAsync,
|
||||||
|
tick,
|
||||||
|
clearPendingTimers,
|
||||||
|
ComponentFixture
|
||||||
|
} from 'angular2/testing_internal';
|
||||||
|
|
||||||
|
import {IS_DART} from 'angular2/src/facade/lang';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Component,
|
||||||
|
Pipe,
|
||||||
|
PipeTransform,
|
||||||
|
provide,
|
||||||
|
ViewMetadata,
|
||||||
|
PLATFORM_PIPES,
|
||||||
|
OpaqueToken,
|
||||||
|
Injector
|
||||||
|
} from 'angular2/core';
|
||||||
|
import {CompilerConfig} from 'angular2/compiler';
|
||||||
|
|
||||||
|
export function main() {
|
||||||
|
if (IS_DART) {
|
||||||
|
declareTests(false);
|
||||||
|
} else {
|
||||||
|
describe('jit', () => {
|
||||||
|
beforeEachProviders(
|
||||||
|
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, true)})]);
|
||||||
|
declareTests(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('no jit', () => {
|
||||||
|
beforeEachProviders(
|
||||||
|
() => [provide(CompilerConfig, {useValue: new CompilerConfig(true, false, false)})]);
|
||||||
|
declareTests(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function declareTests(isJit: boolean) {
|
||||||
|
// Place to put reproductions for regressions
|
||||||
|
describe('regressions', () => {
|
||||||
|
|
||||||
|
describe('platform pipes', () => {
|
||||||
|
beforeEachProviders(() => [provide(PLATFORM_PIPES, {useValue: [PlatformPipe], multi: true})]);
|
||||||
|
|
||||||
|
it('should overwrite them by custom pipes',
|
||||||
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
tcb.overrideView(
|
||||||
|
MyComp, new ViewMetadata({template: '{{true | somePipe}}', pipes: [CustomPipe]}))
|
||||||
|
.createAsync(MyComp)
|
||||||
|
.then((fixture) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.nativeElement).toHaveText('someCustomPipe');
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('providers', () => {
|
||||||
|
function createInjector(tcb: TestComponentBuilder, proviers: any[]): Promise<Injector> {
|
||||||
|
return tcb.overrideProviders(MyComp, [proviers])
|
||||||
|
.createAsync(MyComp)
|
||||||
|
.then((fixture) => fixture.componentInstance.injector);
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should support providers with an OpaqueToken that contains a `.` in the name',
|
||||||
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
var token = new OpaqueToken('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;
|
||||||
|
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 OpaqueToken that has a StringMap as value',
|
||||||
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
var token1 = new OpaqueToken('someToken');
|
||||||
|
var token2 = new OpaqueToken('someToken');
|
||||||
|
var tokenValue1 = {'a': 1};
|
||||||
|
var tokenValue2 = {'a': 1};
|
||||||
|
createInjector(
|
||||||
|
tcb,
|
||||||
|
[provide(token1, {useValue: tokenValue1}), provide(token2, {useValue: tokenValue2})])
|
||||||
|
.then((injector: Injector) => {
|
||||||
|
expect(injector.get(token1)).toEqual(tokenValue1);
|
||||||
|
expect(injector.get(token2)).toEqual(tokenValue2);
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow logging a previous elements class binding via interpolation',
|
||||||
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
tcb.overrideTemplate(MyComp, `<div [class.a]="true" #el>Class: {{el.className}}</div>`)
|
||||||
|
.createAsync(MyComp)
|
||||||
|
.then((fixture) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.nativeElement).toHaveText('Class: a');
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({selector: 'my-comp', template: ''})
|
||||||
|
class MyComp {
|
||||||
|
constructor(public injector: Injector) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Pipe({name: 'somePipe', pure: true})
|
||||||
|
class PlatformPipe implements PipeTransform {
|
||||||
|
transform(value: any, args: any[]): any { return 'somePlatformPipe'; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Pipe({name: 'somePipe', pure: true})
|
||||||
|
class CustomPipe implements PipeTransform {
|
||||||
|
transform(value: any, args: any[]): any { return 'someCustomPipe'; }
|
||||||
|
}
|
@ -88,6 +88,8 @@ const ALL_PIPES = CONST_EXPR([
|
|||||||
forwardRef(() => PipeNeedsService),
|
forwardRef(() => PipeNeedsService),
|
||||||
forwardRef(() => PurePipe),
|
forwardRef(() => PurePipe),
|
||||||
forwardRef(() => ImpurePipe),
|
forwardRef(() => ImpurePipe),
|
||||||
|
forwardRef(() => DuplicatePipe1),
|
||||||
|
forwardRef(() => DuplicatePipe2),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@Directive({selector: '[simpleDirective]'})
|
@Directive({selector: '[simpleDirective]'})
|
||||||
@ -254,6 +256,15 @@ export class PipeNeedsService implements PipeTransform {
|
|||||||
transform(value: any, args: any[] = null): any { return this; }
|
transform(value: any, args: any[] = null): any { return this; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Pipe({name: 'duplicatePipe'})
|
||||||
|
export class DuplicatePipe1 implements PipeTransform {
|
||||||
|
transform(value: any, args: any[] = null): any { return this; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Pipe({name: 'duplicatePipe'})
|
||||||
|
export class DuplicatePipe2 implements PipeTransform {
|
||||||
|
transform(value: any, args: any[] = null): any { return this; }
|
||||||
|
}
|
||||||
|
|
||||||
@Component({selector: 'root'})
|
@Component({selector: 'root'})
|
||||||
class TestComp {
|
class TestComp {
|
||||||
@ -628,6 +639,11 @@ export function main() {
|
|||||||
expect(el.children[0].inject(SimpleDirective).value.service).toEqual('pipeService');
|
expect(el.children[0].inject(SimpleDirective).value.service).toEqual('pipeService');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should overwrite pipes with later entry in the pipes array', fakeAsync(() => {
|
||||||
|
var el = createComp('<div [simpleDirective]="true | duplicatePipe"></div>', tcb);
|
||||||
|
expect(el.children[0].inject(SimpleDirective).value).toBeAnInstanceOf(DuplicatePipe2);
|
||||||
|
}));
|
||||||
|
|
||||||
it('should inject ChangeDetectorRef into pipes', fakeAsync(() => {
|
it('should inject ChangeDetectorRef into pipes', fakeAsync(() => {
|
||||||
var el = createComp(
|
var el = createComp(
|
||||||
'<div [simpleDirective]="true | pipeNeedsChangeDetectorRef" directiveNeedsChangeDetectorRef></div>',
|
'<div [simpleDirective]="true | pipeNeedsChangeDetectorRef" directiveNeedsChangeDetectorRef></div>',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user