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
@@ -52,7 +52,7 @@ export class AbstractChangeDetector implements ChangeDetector {
detectChangesInRecords(throwOnChange: boolean): void {}
hydrate(context: any, locals: Locals, directives: any): void {}
hydrate(context: any, locals: Locals, directives: any, pipes: any): void {}
dehydrate(): void {}
@@ -107,11 +107,10 @@ export class PreGeneratedChangeDetection extends ChangeDetection {
_dynamicChangeDetection: ChangeDetection;
_protoChangeDetectorFactories: StringMap<string, Function>;
constructor(private registry: PipeRegistry,
@Inject(PROTO_CHANGE_DETECTOR_KEY) @Optional()
constructor(@Inject(PROTO_CHANGE_DETECTOR_KEY) @Optional()
protoChangeDetectorsForTest?: StringMap<string, Function>) {
super();
this._dynamicChangeDetection = new DynamicChangeDetection(registry);
this._dynamicChangeDetection = new DynamicChangeDetection();
this._protoChangeDetectorFactories = isPresent(protoChangeDetectorsForTest) ?
protoChangeDetectorsForTest :
preGeneratedProtoDetectors;
@@ -122,8 +121,7 @@ export class PreGeneratedChangeDetection extends ChangeDetection {
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
var id = definition.id;
if (StringMapWrapper.contains(this._protoChangeDetectorFactories, id)) {
return StringMapWrapper.get(this._protoChangeDetectorFactories, id)(this.registry,
definition);
return StringMapWrapper.get(this._protoChangeDetectorFactories, id)(definition);
}
return this._dynamicChangeDetection.createProtoChangeDetector(definition);
}
@@ -139,10 +137,8 @@ export class PreGeneratedChangeDetection extends ChangeDetection {
*/
@Injectable()
export class DynamicChangeDetection extends ChangeDetection {
constructor(private registry: PipeRegistry) { super(); }
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
return new DynamicProtoChangeDetector(this.registry, definition);
return new DynamicProtoChangeDetector(definition);
}
}
@@ -157,12 +153,10 @@ export class DynamicChangeDetection extends ChangeDetection {
@Injectable()
@CONST()
export class JitChangeDetection extends ChangeDetection {
constructor(public registry: PipeRegistry) { super(); }
static isSupported(): boolean { return JitProtoChangeDetector.isSupported(); }
createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector {
return new JitProtoChangeDetector(this.registry, definition);
return new JitProtoChangeDetector(definition);
}
}
@@ -67,14 +67,14 @@ export class ChangeDetectorJITGenerator {
generate(): Function {
var typeName = _sanitizeName(`ChangeDetector_${this.id}`);
var classDefinition = `
var ${typeName} = function ${typeName}(dispatcher, pipeRegistry, protos, directiveRecords) {
var ${typeName} = function ${typeName}(dispatcher, protos, directiveRecords) {
${ABSTRACT_CHANGE_DETECTOR}.call(this, ${JSON.stringify(this.id)});
${DISPATCHER_ACCESSOR} = dispatcher;
${PIPE_REGISTRY_ACCESSOR} = pipeRegistry;
${PROTOS_ACCESSOR} = protos;
${DIRECTIVES_ACCESSOR} = directiveRecords;
${LOCALS_ACCESSOR} = null;
${CURRENT_PROTO} = null;
${CURRENT_PROTO} = null;
${PIPE_REGISTRY_ACCESSOR} = null;
${ALREADY_CHECKED_ACCESSOR} = false;
${this._genFieldDefinitions()}
}
@@ -91,32 +91,33 @@ export class ChangeDetectorJITGenerator {
this.throwError(${CURRENT_PROTO}, e, e.stack);
}
}
${typeName}.prototype.__detectChangesInRecords = function(throwOnChange) {
${CURRENT_PROTO} = null;
${this._genLocalDefinitions()}
${this._genChangeDefinitions()}
var ${IS_CHANGED_LOCAL} = false;
var ${CHANGES_LOCAL} = null;
context = ${CONTEXT_ACCESSOR};
${this.records.map((r) => this._genRecord(r)).join("\n")}
${ALREADY_CHECKED_ACCESSOR} = true;
}
${typeName}.prototype.callOnAllChangesDone = function() {
${this._genCallOnAllChangesDoneBody()}
}
${typeName}.prototype.hydrate = function(context, locals, directives) {
${typeName}.prototype.hydrate = function(context, locals, directives, pipeRegistry) {
${MODE_ACCESSOR} = "${ChangeDetectionUtil.changeDetectionMode(this.changeDetectionStrategy)}";
${CONTEXT_ACCESSOR} = context;
${LOCALS_ACCESSOR} = locals;
${this._genHydrateDirectives()}
${this._genHydrateDetectors()}
${PIPE_REGISTRY_ACCESSOR} = pipeRegistry;
${ALREADY_CHECKED_ACCESSOR} = false;
}
@@ -124,14 +125,15 @@ export class ChangeDetectorJITGenerator {
${this._genPipeOnDestroy()}
${this._genFieldDefinitions()}
${LOCALS_ACCESSOR} = null;
${PIPE_REGISTRY_ACCESSOR} = null;
}
${typeName}.prototype.hydrated = function() {
return ${CONTEXT_ACCESSOR} !== null;
}
return function(dispatcher, pipeRegistry) {
return new ${typeName}(dispatcher, pipeRegistry, protos, directiveRecords);
return function(dispatcher) {
return new ${typeName}(dispatcher, protos, directiveRecords);
}
`;
return new Function('AbstractChangeDetector', 'ChangeDetectionUtil', 'protos',
@@ -18,10 +18,10 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
prevContexts: List<any>;
directives: any = null;
alreadyChecked: boolean = false;
private pipeRegistry: PipeRegistry = null;
constructor(id: string, private changeControlStrategy: string, private dispatcher: any,
private pipeRegistry: PipeRegistry, private protos: List<ProtoRecord>,
private directiveRecords: List<any>) {
private protos: List<ProtoRecord>, private directiveRecords: List<any>) {
super(id);
this.values = ListWrapper.createFixedSize(protos.length + 1);
this.pipes = ListWrapper.createFixedSize(protos.length + 1);
@@ -35,12 +35,13 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
ListWrapper.fill(this.changes, false);
}
hydrate(context: any, locals: Locals, directives: any) {
hydrate(context: any, locals: Locals, directives: any, pipeRegistry: PipeRegistry): void {
this.mode = ChangeDetectionUtil.changeDetectionMode(this.changeControlStrategy);
this.values[0] = context;
this.locals = locals;
this.directives = directives;
this.alreadyChecked = false;
this.pipeRegistry = pipeRegistry;
}
dehydrate() {
@@ -51,6 +52,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
ListWrapper.fill(this.pipes, null);
ListWrapper.fill(this.prevContexts, uninitialized);
this.locals = null;
this.pipeRegistry = null;
}
_destroyPipes() {
@@ -51,7 +51,7 @@ export interface ChangeDetector {
removeChild(cd: ChangeDetector): void;
removeShadowDomChild(cd: ChangeDetector): void;
remove(): void;
hydrate(context: any, locals: Locals, directives: any): void;
hydrate(context: any, locals: Locals, directives: any, pipeRegistry: any): void;
dehydrate(): void;
markPathToRootAsCheckOnce(): void;
@@ -3,7 +3,7 @@ library change_detection.jit_proto_change_detector;
import 'interfaces.dart' show ChangeDetector, ProtoChangeDetector;
class JitProtoChangeDetector implements ProtoChangeDetector {
JitProtoChangeDetector(registry, definition) : super();
JitProtoChangeDetector(definition) : super();
static bool isSupported() => false;
@@ -9,15 +9,13 @@ import {ProtoRecordBuilder} from './proto_change_detector';
export class JitProtoChangeDetector implements ProtoChangeDetector {
_factory: Function;
constructor(private _pipeRegistry, private definition: ChangeDetectorDefinition) {
constructor(private definition: ChangeDetectorDefinition) {
this._factory = this._createFactory(definition);
}
static isSupported(): boolean { return true; }
instantiate(dispatcher: any): ChangeDetector {
return this._factory(dispatcher, this._pipeRegistry);
}
instantiate(dispatcher: any): ChangeDetector { return this._factory(dispatcher); }
_createFactory(definition: ChangeDetectorDefinition) {
var recordBuilder = new ProtoRecordBuilder();
@@ -3,7 +3,6 @@ library angular2.src.change_detection.pregen_proto_change_detector;
import 'package:angular2/src/change_detection/coalesce.dart';
import 'package:angular2/src/change_detection/directive_record.dart';
import 'package:angular2/src/change_detection/interfaces.dart';
import 'package:angular2/src/change_detection/pipes/pipe_registry.dart';
import 'package:angular2/src/change_detection/proto_change_detector.dart';
import 'package:angular2/src/change_detection/proto_record.dart';
@@ -25,10 +24,10 @@ export 'package:angular2/src/change_detection/change_detection_util.dart'
export 'package:angular2/src/facade/lang.dart' show looseIdentical;
typedef ProtoChangeDetector PregenProtoChangeDetectorFactory(
PipeRegistry registry, ChangeDetectorDefinition definition);
ChangeDetectorDefinition definition);
typedef ChangeDetector InstantiateMethod(dynamic dispatcher,
PipeRegistry registry, List<ProtoRecord> protoRecords,
List<ProtoRecord> protoRecords,
List<DirectiveRecord> directiveRecords);
/// Implementation of [ProtoChangeDetector] for use by pre-generated change
@@ -44,29 +43,28 @@ class PregenProtoChangeDetector extends ProtoChangeDetector {
final InstantiateMethod _instantiateMethod;
// [ChangeDetector] dependencies.
final PipeRegistry _pipeRegistry;
final List<ProtoRecord> _protoRecords;
final List<DirectiveRecord> _directiveRecords;
/// Internal ctor.
PregenProtoChangeDetector._(this.id, this._instantiateMethod,
this._pipeRegistry, this._protoRecords, this._directiveRecords);
this._protoRecords, this._directiveRecords);
static bool isSupported() => true;
factory PregenProtoChangeDetector(InstantiateMethod instantiateMethod,
PipeRegistry registry, ChangeDetectorDefinition def) {
ChangeDetectorDefinition def) {
// TODO(kegluneq): Pre-generate these (#2067).
var recordBuilder = new ProtoRecordBuilder();
def.bindingRecords.forEach((b) {
recordBuilder.add(b, def.variableNames);
});
var protoRecords = coalesce(recordBuilder.records);
return new PregenProtoChangeDetector._(def.id, instantiateMethod, registry,
return new PregenProtoChangeDetector._(def.id, instantiateMethod,
protoRecords, def.directiveRecords);
}
@override
instantiate(dynamic dispatcher) => _instantiateMethod(
dispatcher, _pipeRegistry, _protoRecords, _directiveRecords);
dispatcher, _protoRecords, _directiveRecords);
}
@@ -28,7 +28,6 @@ import {
import {ChangeDetector, ProtoChangeDetector, ChangeDetectorDefinition} from './interfaces';
import {ChangeDetectionUtil} from './change_detection_util';
import {DynamicChangeDetector} from './dynamic_change_detector';
import {PipeRegistry} from './pipes/pipe_registry';
import {BindingRecord} from './binding_record';
import {DirectiveRecord, DirectiveIndex} from './directive_record';
@@ -39,14 +38,13 @@ import {ProtoRecord, RecordType} from './proto_record';
export class DynamicProtoChangeDetector implements ProtoChangeDetector {
_records: List<ProtoRecord>;
constructor(private _pipeRegistry: PipeRegistry, private definition: ChangeDetectorDefinition) {
constructor(private definition: ChangeDetectorDefinition) {
this._records = this._createRecords(definition);
}
instantiate(dispatcher: any): ChangeDetector {
return new DynamicChangeDetector(this.definition.id, this.definition.strategy, dispatcher,
this._pipeRegistry, this._records,
this.definition.directiveRecords);
this._records, this.definition.directiveRecords);
}
_createRecords(definition: ChangeDetectorDefinition) {
@@ -54,27 +54,29 @@ import {
onAllChangesDone
} from 'angular2/src/core/annotations_impl/annotations';
import {hasLifecycleHook} from './directive_lifecycle_reflector';
import {ChangeDetector, ChangeDetectorRef} from 'angular2/change_detection';
import {ChangeDetector, ChangeDetectorRef, PipeRegistry} from 'angular2/change_detection';
import {QueryList} from './query_list';
import {reflector} from 'angular2/src/reflection/reflection';
import {DirectiveMetadata} from 'angular2/src/render/api';
var _staticKeys;
class StaticKeys {
export class StaticKeys {
viewManagerId: number;
protoViewId: number;
viewContainerId: number;
changeDetectorRefId: number;
elementRefId: number;
pipeRegistryKey: Key;
constructor() {
// TODO: vsavkin Key.annotate(Key.get(AppView), 'static')
this.viewManagerId = Key.get(avmModule.AppViewManager).id;
this.protoViewId = Key.get(ProtoViewRef).id;
this.viewContainerId = Key.get(ViewContainerRef).id;
this.changeDetectorRefId = Key.get(ChangeDetectorRef).id;
this.elementRefId = Key.get(ElementRef).id;
// not an id because the public API of injector works only with keys and tokens
this.pipeRegistryKey = Key.get(PipeRegistry);
}
static instance(): StaticKeys {
@@ -529,14 +531,15 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
// |boundary
// |
// this._injector
var parent = this._getParentInjector(imperativelyCreatedInjector, host);
var parent = this._closestBoundaryInjector(imperativelyCreatedInjector, host);
this._reattachInjector(this._injector, parent, true);
}
}
private _getParentInjector(injector: Injector, host: ElementInjector): Injector {
if (isPresent(injector)) {
return injector;
private _closestBoundaryInjector(imperativelyCreatedInjector: Injector,
host: ElementInjector): Injector {
if (isPresent(imperativelyCreatedInjector)) {
return imperativelyCreatedInjector;
} else if (isPresent(host)) {
return host._injector;
} else {
@@ -549,6 +552,11 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
injector.internalStrategy.hydrate();
}
getPipeRegistry(): PipeRegistry {
var pipeRegistryKey = StaticKeys.instance().pipeRegistryKey;
return this._injector.getOptional(pipeRegistryKey);
}
hasVariableBinding(name: string): boolean {
var vb = this._proto.directiveVariableBindings;
return isPresent(vb) && vb.has(name);
@@ -141,12 +141,11 @@ export class AppViewManagerUtils {
var elementInjector = contextView.elementInjectors[contextBoundElementIndex];
var injector = isPresent(bindings) ? Injector.fromResolvedBindings(bindings) : null;
this._hydrateView(view, injector, elementInjector.getHost(), contextView.context,
contextView.locals);
}
_hydrateView(view: viewModule.AppView, injector: Injector,
_hydrateView(view: viewModule.AppView, imperativelyCreatedInjector: Injector,
hostElementInjector: eli.ElementInjector, context: Object, parentLocals: Locals) {
view.context = context;
view.locals.parent = parentLocals;
@@ -156,13 +155,24 @@ export class AppViewManagerUtils {
var elementInjector = view.elementInjectors[i];
if (isPresent(elementInjector)) {
elementInjector.hydrate(injector, hostElementInjector, view.preBuiltObjects[i]);
elementInjector.hydrate(imperativelyCreatedInjector, hostElementInjector,
view.preBuiltObjects[i]);
this._populateViewLocals(view, elementInjector);
this._setUpEventEmitters(view, elementInjector, i);
this._setUpHostActions(view, elementInjector, i);
}
}
view.changeDetector.hydrate(view.context, view.locals, view);
var pipeRegistry = this._getPipeRegistry(imperativelyCreatedInjector, hostElementInjector);
view.changeDetector.hydrate(view.context, view.locals, view, pipeRegistry);
}
_getPipeRegistry(imperativelyCreatedInjector: Injector,
hostElementInjector: eli.ElementInjector) {
var pipeRegistryKey = eli.StaticKeys.instance().pipeRegistryKey;
if (isPresent(imperativelyCreatedInjector))
return imperativelyCreatedInjector.getOptional(pipeRegistryKey);
if (isPresent(hostElementInjector)) return hostElementInjector.getPipeRegistry();
return null;
}
_populateViewLocals(view: viewModule.AppView, elementInjector: eli.ElementInjector): void {
@@ -125,7 +125,7 @@ class _CodegenState {
buf.write('''
class $_changeDetectorTypeName extends $_BASE_CLASS {
final dynamic $_DISPATCHER_ACCESSOR;
final $_GEN_PREFIX.PipeRegistry $_PIPE_REGISTRY_ACCESSOR;
$_GEN_PREFIX.PipeRegistry $_PIPE_REGISTRY_ACCESSOR;
final $_GEN_PREFIX.List<$_GEN_PREFIX.ProtoRecord> $_PROTOS_ACCESSOR;
final $_GEN_PREFIX.List<$_GEN_PREFIX.DirectiveRecord>
$_DIRECTIVES_ACCESSOR;
@@ -141,7 +141,6 @@ class _CodegenState {
$_changeDetectorTypeName(
this.$_DISPATCHER_ACCESSOR,
this.$_PIPE_REGISTRY_ACCESSOR,
this.$_PROTOS_ACCESSOR,
this.$_DIRECTIVES_ACCESSOR) : super(${JSON.encode(_changeDetectorDefId)});
@@ -155,7 +154,7 @@ class _CodegenState {
this.throwError($_CURRENT_PROTO, e, s);
}
}
void __detectChangesInRecords(throwOnChange) {
${_genLocalDefinitions()}
${_genChangeDefinitons()}
@@ -168,18 +167,19 @@ class _CodegenState {
$_ALREADY_CHECKED_ACCESSOR = true;
}
void callOnAllChangesDone() {
${_getCallOnAllChangesDoneBody()}
}
void hydrate($_contextTypeName context, locals, directives) {
void hydrate($_contextTypeName context, locals, directives, pipeRegistry) {
$_MODE_ACCESSOR = '$_changeDetectionMode';
$_CONTEXT_ACCESSOR = context;
$_LOCALS_ACCESSOR = locals;
${_genHydrateDirectives()}
${_genHydrateDetectors()}
$_ALREADY_CHECKED_ACCESSOR = false;
$_PIPE_REGISTRY_ACCESSOR = pipeRegistry;
}
void dehydrate() {
@@ -190,17 +190,17 @@ class _CodegenState {
: '$f = $_UTIL.uninitialized();';
}).join('')}
$_LOCALS_ACCESSOR = null;
$_PIPE_REGISTRY_ACCESSOR = null;
}
hydrated() => $_CONTEXT_ACCESSOR != null;
static $_GEN_PREFIX.ProtoChangeDetector
$PROTO_CHANGE_DETECTOR_FACTORY_METHOD(
$_GEN_PREFIX.PipeRegistry registry,
$_GEN_PREFIX.ChangeDetectorDefinition def) {
return new $_GEN_PREFIX.PregenProtoChangeDetector(
(a, b, c, d) => new $_changeDetectorTypeName(a, b, c, d),
registry, def);
(a, b, c) => new $_changeDetectorTypeName(a, b, c),
def);
}
}
''');