tools: added experimentalDecorators flag to tsconfig

This commit is contained in:
vsavkin
2015-07-08 10:28:47 -07:00
parent e0fb50cc3c
commit 4656c6f5cf
20 changed files with 159 additions and 146 deletions
@@ -27,14 +27,14 @@ export function main() {
});
it("should return a proto change detector when one is available", () => {
var map = {'id': (registry, def) => proto};
var cd = new PreGeneratedChangeDetection(null, map);
var map = {'id': (def) => proto};
var cd = new PreGeneratedChangeDetection(map);
expect(cd.createProtoChangeDetector(def)).toBe(proto)
});
it("should delegate to dynamic change detection otherwise", () => {
var cd = new PreGeneratedChangeDetection(null, {});
var cd = new PreGeneratedChangeDetection({});
expect(cd.createProtoChangeDetector(def)).toBeAnInstanceOf(DynamicProtoChangeDetector);
});
});
@@ -66,20 +66,19 @@ const _DEFAULT_CONTEXT = CONST_EXPR(new Object());
*/
export function main() {
ListWrapper.forEach(['dynamic', 'JIT', 'Pregen'], (cdType) => {
if (cdType == "JIT" && IS_DARTIUM) return;
if (cdType == "Pregen" && !IS_DARTIUM) return;
describe(`${cdType} Change Detector`, () => {
function _getProtoChangeDetector(def: ChangeDetectorDefinition, registry = null) {
function _getProtoChangeDetector(def: ChangeDetectorDefinition) {
switch (cdType) {
case 'dynamic':
return new DynamicProtoChangeDetector(registry, def);
return new DynamicProtoChangeDetector(def);
case 'JIT':
return new JitProtoChangeDetector(registry, def);
return new JitProtoChangeDetector(def);
case 'Pregen':
return getFactoryById(def.id)(registry, def);
return getFactoryById(def.id)(def);
default:
return null;
}
@@ -87,9 +86,7 @@ export function main() {
function _createWithoutHydrate(expression: string) {
var dispatcher = new TestDispatcher();
var registry = null;
var cd = _getProtoChangeDetector(getDefinition(expression).cdDef, registry)
.instantiate(dispatcher);
var cd = _getProtoChangeDetector(getDefinition(expression).cdDef).instantiate(dispatcher);
return new _ChangeDetectorAndDispatcher(cd, dispatcher);
}
@@ -98,9 +95,9 @@ export function main() {
registry = null) {
var dispatcher = new TestDispatcher();
var testDef = getDefinition(expression);
var protoCd = _getProtoChangeDetector(testDef.cdDef, registry);
var protoCd = _getProtoChangeDetector(testDef.cdDef);
var cd = protoCd.instantiate(dispatcher);
cd.hydrate(context, testDef.locals, null);
cd.hydrate(context, testDef.locals, null, registry);
return new _ChangeDetectorAndDispatcher(cd, dispatcher);
}
@@ -298,7 +295,7 @@ export function main() {
it('should support interpolation', () => {
var val = _createChangeDetector('interpolation', new TestData('value'));
val.changeDetector.hydrate(new TestData('value'), null, null);
val.changeDetector.hydrate(new TestData('value'), null, null, null);
val.changeDetector.detectChanges();
@@ -361,8 +358,8 @@ export function main() {
it('should happen directly, without invoking the dispatcher', () => {
var val = _createWithoutHydrate('directNoDispatcher');
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null,
new FakeDirectives([directive1], []));
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []),
null);
val.changeDetector.detectChanges();
expect(val.dispatcher.loggedValues).toEqual([]);
expect(directive1.a).toEqual(42);
@@ -371,7 +368,8 @@ export function main() {
describe('onChange', () => {
it('should notify the directive when a group of records changes', () => {
var cd = _createWithoutHydrate('groupChanges').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
null);
cd.detectChanges();
expect(directive1.changes).toEqual({'a': 1, 'b': 2});
expect(directive2.changes).toEqual({'a': 3});
@@ -382,7 +380,7 @@ export function main() {
it('should notify the directive when it is checked', () => {
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.detectChanges();
expect(directive1.onCheckCalled).toBe(true);
@@ -395,7 +393,7 @@ export function main() {
it('should not call onCheck in detectNoChanges', () => {
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.checkNoChanges();
@@ -407,7 +405,7 @@ export function main() {
it('should notify the directive after it has been checked the first time', () => {
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.detectChanges();
@@ -423,7 +421,7 @@ export function main() {
it('should not call onInit in detectNoChanges', () => {
var cd = _createWithoutHydrate('directiveOnInit').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.checkNoChanges();
@@ -434,7 +432,8 @@ export function main() {
describe('onAllChangesDone', () => {
it('should be called after processing all the children', () => {
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
null);
cd.detectChanges();
@@ -462,7 +461,7 @@ export function main() {
it('should not be called when onAllChangesDone is false', () => {
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.detectChanges();
@@ -478,7 +477,7 @@ export function main() {
td1 = new TestDirective(() => onChangesDoneCalls.push(td1));
var td2;
td2 = new TestDirective(() => onChangesDoneCalls.push(td2));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []));
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([td1, td2], []), null);
cd.detectChanges();
@@ -499,8 +498,10 @@ export function main() {
parentDirective =
new TestDirective(() => { orderOfOperations.push(parentDirective); });
parent.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([parentDirective], []));
child.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directiveInShadowDom], []));
parent.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([parentDirective], []),
null);
child.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directiveInShadowDom], []),
null);
parent.detectChanges();
expect(orderOfOperations).toEqual([parentDirective, directiveInShadowDom]);
@@ -515,7 +516,8 @@ export function main() {
directive.a = 'aaa';
var val = _createWithoutHydrate('readingDirectives');
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive], []));
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive], []),
null);
val.changeDetector.detectChanges();
@@ -625,13 +627,13 @@ export function main() {
var cd = _createWithoutHydrate('emptyUsingDefaultStrategy').changeDetector;
expect(cd.mode).toEqual(null);
cd.hydrate(_DEFAULT_CONTEXT, null, null);
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
expect(cd.mode).toEqual(CHECK_ALWAYS);
});
it('should set the mode to CHECK_ONCE when the push change detection is used', () => {
var cd = _createWithoutHydrate('emptyUsingOnPushStrategy').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, null);
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
expect(cd.mode).toEqual(CHECK_ONCE);
});
@@ -639,7 +641,7 @@ export function main() {
it('should not check a detached change detector', () => {
var val = _createChangeDetector('a', new TestData('value'));
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null);
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null, null);
val.changeDetector.mode = DETACHED;
val.changeDetector.detectChanges();
@@ -649,7 +651,7 @@ export function main() {
it('should not check a checked change detector', () => {
var val = _createChangeDetector('a', new TestData('value'));
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null);
val.changeDetector.hydrate(_DEFAULT_CONTEXT, null, null, null);
val.changeDetector.mode = CHECKED;
val.changeDetector.detectChanges();
@@ -658,7 +660,7 @@ export function main() {
it('should change CHECK_ONCE to CHECKED', () => {
var cd = _createChangeDetector('10').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, null);
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
cd.mode = CHECK_ONCE;
cd.detectChanges();
@@ -668,7 +670,7 @@ export function main() {
it('should not change the CHECK_ALWAYS', () => {
var cd = _createChangeDetector('10').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, null);
cd.hydrate(_DEFAULT_CONTEXT, null, null, null);
cd.mode = CHECK_ALWAYS;
cd.detectChanges();
@@ -682,7 +684,7 @@ export function main() {
beforeEach(() => {
checkedDetector = _createWithoutHydrate('emptyUsingOnPushStrategy').changeDetector;
checkedDetector.hydrate(_DEFAULT_CONTEXT, null, null);
checkedDetector.hydrate(_DEFAULT_CONTEXT, null, null, null);
checkedDetector.mode = CHECKED;
var targetDirective = new TestData(null);
@@ -691,7 +693,7 @@ export function main() {
it('should set the mode to CHECK_ONCE when a binding is updated', () => {
var cd = _createWithoutHydrate('onPushRecordsUsingDefaultStrategy').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, directives);
cd.hydrate(_DEFAULT_CONTEXT, null, directives, null);
expect(checkedDetector.mode).toEqual(CHECKED);
@@ -735,13 +737,13 @@ export function main() {
it('should be able to rehydrate a change detector', () => {
var cd = _createChangeDetector('name').changeDetector;
cd.hydrate('some context', null, null);
cd.hydrate('some context', null, null, null);
expect(cd.hydrated()).toBe(true);
cd.dehydrate();
expect(cd.hydrated()).toBe(false);
cd.hydrate('other context', null, null);
cd.hydrate('other context', null, null, null);
expect(cd.hydrated()).toBe(true);
});
@@ -242,7 +242,7 @@ class TestNode extends TreeNode<TestNode> {
export function main() {
var defaultPreBuiltObjects = new PreBuiltObjects(null, <any>new DummyView(1), null);
// An injector with more than 10 bindings will switch to the dynamic strategy
var dynamicBindings = [];
@@ -562,7 +562,7 @@ export function main() {
var extraBindings = context['bindings'];
describe(`${context['strategy']} strategy`, () => {
describe("hydrate", () => {
it("should instantiate directives that have no dependencies", () => {
var bindings = ListWrapper.concat([SimpleDirective], extraBindings);
@@ -610,15 +610,15 @@ export function main() {
(val) => `${val}-injectable2`,
['injectable1'])
];
var inj = injector(ListWrapper.concat(
[DirectiveBinding.createFromType(SimpleDirective,
[DirectiveBinding.createFromType(SimpleDirective,
new dirAnn.Directive({hostInjector: hostInjector}))],
extraBindings));
expect(inj.get('injectable2')).toEqual('injectable1-injectable2');
});
it("should instantiate viewInjector injectables that have dependencies", () => {
var viewInjector = [
bind('injectable1')
@@ -628,15 +628,15 @@ export function main() {
(val) => `${val}-injectable2`,
['injectable1'])
];
var inj = injector(ListWrapper.concat(
[DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
viewInjector: viewInjector}))], extraBindings),
viewInjector: viewInjector}))], extraBindings),
null, true);
expect(inj.get('injectable2')).toEqual('injectable1-injectable2');
});
it("should instantiate components that depend on viewInjector bindings", () => {
var inj = injector(
ListWrapper.concat([DirectiveBinding.createFromType(NeedsService, new dirAnn.Component({
@@ -658,7 +658,7 @@ export function main() {
.toThrowError(containsRegexp(
`No provider for service! (${stringify(NeedsService) } -> service)`));
});
it("should instantiate directives that depend on hostInjector bindings of other directives", () => {
var shadowInj = hostShadowInjectors(
ListWrapper.concat([DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
@@ -668,7 +668,7 @@ export function main() {
);
expect(shadowInj.get(NeedsService).service).toEqual('hostService');
});
it("should instantiate directives that depend on imperativley created injector bindings", () => {
var imperativelyCreatedInjector = Injector.resolveAndCreate([
bind("service").toValue('appService')
@@ -899,7 +899,7 @@ export function main() {
});
it('should inject ChangeDetectorRef', () => {
var cd = new DynamicChangeDetector(null, null, null, null, [], []);
var cd = new DynamicChangeDetector(null, null, null, [], []);
var view = <any>new DummyView();
var childView = new DummyView();
childView.changeDetector = cd;
@@ -219,24 +219,15 @@ export function main() {
}));
describe('pipes', () => {
beforeEachBindings(() => {
return [
bind(ChangeDetection)
.toFactory(() => new DynamicChangeDetection(
new PipeRegistry({"double": [new DoublePipeFactory()]})),
[])
];
});
it("should support pipes in bindings",
inject([TestComponentBuilder, AsyncTestCompleter],
(tcb: TestComponentBuilder, async) => {
tcb.overrideView(MyComp, new viewAnn.View({
tcb.overrideView(MyCompWithPipes, new viewAnn.View({
template: '<div my-dir #dir="mydir" [elprop]="ctxProp | double"></div>',
directives: [MyDir]
}))
.createAsync(MyComp)
.createAsync(MyCompWithPipes)
.then((rootTC) => {
rootTC.componentInstance.ctxProp = 'a';
rootTC.detectChanges();
@@ -1410,6 +1401,21 @@ class PushCmpWithRef {
propagate() { this.ref.requestCheck(); }
}
@Injectable()
class PipeRegistryWithDouble extends PipeRegistry {
constructor() { super({"double": [new DoublePipeFactory()]}); }
}
@Component({
selector: 'my-comp-with-pipes',
viewInjector: [new Binding(PipeRegistry, {toClass: PipeRegistryWithDouble})]
})
@View({directives: []})
@Injectable()
class MyCompWithPipes {
ctxProp: string = "initial value";
}
@Component({selector: 'my-comp'})
@View({directives: []})
@Injectable()
@@ -1424,13 +1430,6 @@ class MyComp {
}
}
@Component({selector: 'component-with-pipes', properties: ["prop"]})
@View({template: ''})
@Injectable()
class ComponentWithPipes {
prop: string;
}
@Component({selector: 'child-cmp', properties: ['dirProp'], viewInjector: [MyService]})
@View({directives: [MyDir], template: '{{ctxProp}}'})
@Injectable()
@@ -27,7 +27,7 @@ void initReflector(reflector) {
}
class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
final dynamic _dispatcher;
final _gen.PipeRegistry _pipeRegistry;
_gen.PipeRegistry _pipeRegistry;
final _gen.List<_gen.ProtoRecord> _protos;
final _gen.List<_gen.DirectiveRecord> _directiveRecords;
dynamic _locals = null;
@@ -37,8 +37,8 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
dynamic _myNum0 = _gen.ChangeDetectionUtil.uninitialized();
dynamic _interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
_MyComponent_ChangeDetector0(this._dispatcher, this._pipeRegistry,
this._protos, this._directiveRecords)
_MyComponent_ChangeDetector0(
this._dispatcher, this._protos, this._directiveRecords)
: super("MyComponent_comp_0");
void detectChangesInRecords(throwOnChange) {
@@ -100,12 +100,13 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
_dispatcher.notifyOnAllChangesDone();
}
void hydrate(MyComponent context, locals, directives) {
void hydrate(MyComponent context, locals, directives, pipeRegistry) {
mode = 'ALWAYS_CHECK';
_context = context;
_locals = locals;
_alreadyChecked = false;
_pipeRegistry = pipeRegistry;
}
void dehydrate() {
@@ -113,14 +114,14 @@ class _MyComponent_ChangeDetector0 extends _gen.AbstractChangeDetector {
_myNum0 = _gen.ChangeDetectionUtil.uninitialized();
_interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
_locals = null;
_pipeRegistry = null;
}
hydrated() => _context != null;
static _gen.ProtoChangeDetector newProtoChangeDetector(
_gen.PipeRegistry registry, _gen.ChangeDetectorDefinition def) {
_gen.ChangeDetectorDefinition def) {
return new _gen.PregenProtoChangeDetector(
(a, b, c, d) => new _MyComponent_ChangeDetector0(a, b, c, d), registry,
def);
(a, b, c) => new _MyComponent_ChangeDetector0(a, b, c), def);
}
}