From eacc9e65416a747525f97e06f808b9e719556461 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 7 Jul 2016 16:35:13 -0700 Subject: [PATCH] refactor: misc cleanup --- .../common/src/directives/core_directives.ts | 2 - .../common/src/directives/ng_class.ts | 10 +- .../@angular/common/src/directives/ng_if.ts | 8 +- .../common/src/directives/ng_style.ts | 6 +- .../common/src/directives/ng_switch.ts | 13 +- .../src/directives/ng_template_outlet.ts | 11 +- .../common/test/directives/ng_for_spec.ts | 18 ++- modules/@angular/compiler/core_private.ts | 2 +- modules/@angular/compiler/src/identifiers.ts | 8 +- .../src/view_compiler/property_binder.ts | 6 +- modules/@angular/core/private_export.ts | 4 +- .../src/change_detection/change_detection.ts | 2 +- .../change_detection/change_detection_util.ts | 4 +- .../@angular/core/src/linker/view_utils.ts | 22 ++-- .../change_detection_integration_spec.ts | 115 +++++++----------- tools/public_api_guard/common/index.d.ts | 4 +- 16 files changed, 107 insertions(+), 128 deletions(-) diff --git a/modules/@angular/common/src/directives/core_directives.ts b/modules/@angular/common/src/directives/core_directives.ts index 4e49cfa1fc..34c2ae7bfd 100644 --- a/modules/@angular/common/src/directives/core_directives.ts +++ b/modules/@angular/common/src/directives/core_directives.ts @@ -16,8 +16,6 @@ import {NgStyle} from './ng_style'; import {NgSwitch, NgSwitchCase, NgSwitchDefault} from './ng_switch'; import {NgTemplateOutlet} from './ng_template_outlet'; - - /** * A collection of Angular core directives that are likely to be used in each and every Angular * application. diff --git a/modules/@angular/common/src/directives/ng_class.ts b/modules/@angular/common/src/directives/ng_class.ts index b58459bf80..baf1e0b641 100644 --- a/modules/@angular/common/src/directives/ng_class.ts +++ b/modules/@angular/common/src/directives/ng_class.ts @@ -6,12 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import {CollectionChangeRecord, Directive, DoCheck, ElementRef, IterableDiffer, IterableDiffers, KeyValueChangeRecord, KeyValueDiffer, KeyValueDiffers, OnDestroy, Renderer} from '@angular/core'; +import {CollectionChangeRecord, Directive, DoCheck, ElementRef, Input, IterableDiffer, IterableDiffers, KeyValueChangeRecord, KeyValueDiffer, KeyValueDiffers, OnDestroy, Renderer} from '@angular/core'; import {StringMapWrapper, isListLikeIterable} from '../facade/collection'; import {isArray, isPresent, isString} from '../facade/lang'; + /** * The `NgClass` directive conditionally adds and removes CSS classes on an HTML element based on * an expression's evaluation result. @@ -73,7 +74,7 @@ import {isArray, isPresent, isString} from '../facade/lang'; * * @stable */ -@Directive({selector: '[ngClass]', inputs: ['rawClass: ngClass', 'initialClasses: class']}) +@Directive({selector: '[ngClass]'}) export class NgClass implements DoCheck, OnDestroy { private _iterableDiffer: IterableDiffer; private _keyValueDiffer: KeyValueDiffer; @@ -84,6 +85,8 @@ export class NgClass implements DoCheck, OnDestroy { private _iterableDiffers: IterableDiffers, private _keyValueDiffers: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer) {} + + @Input('class') set initialClasses(v: string) { this._applyInitialClasses(true); this._initialClasses = isPresent(v) && isString(v) ? v.split(' ') : []; @@ -91,7 +94,8 @@ export class NgClass implements DoCheck, OnDestroy { this._applyClasses(this._rawClass, false); } - set rawClass(v: string|string[]|Set|{[key: string]: any}) { + @Input() + set ngClass(v: string|string[]|Set|{[key: string]: any}) { this._cleanupClasses(this._rawClass); if (isString(v)) { diff --git a/modules/@angular/common/src/directives/ng_if.ts b/modules/@angular/common/src/directives/ng_if.ts index f747456e1b..9e7d462aa7 100644 --- a/modules/@angular/common/src/directives/ng_if.ts +++ b/modules/@angular/common/src/directives/ng_if.ts @@ -6,11 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, TemplateRef, ViewContainerRef} from '@angular/core'; +import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core'; import {isBlank} from '../facade/lang'; + /** * Removes or recreates a portion of the DOM tree based on an {expression}. * @@ -35,14 +36,15 @@ import {isBlank} from '../facade/lang'; * * @stable */ -@Directive({selector: '[ngIf]', inputs: ['ngIf']}) +@Directive({selector: '[ngIf]'}) export class NgIf { private _prevCondition: boolean = null; constructor(private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef) { } - set ngIf(newCondition: any /* boolean */) { + @Input() + set ngIf(newCondition: any) { if (newCondition && (isBlank(this._prevCondition) || !this._prevCondition)) { this._prevCondition = true; this._viewContainer.createEmbeddedView(this._templateRef); diff --git a/modules/@angular/common/src/directives/ng_style.ts b/modules/@angular/common/src/directives/ng_style.ts index 1ec73d17a6..ef2096c02e 100644 --- a/modules/@angular/common/src/directives/ng_style.ts +++ b/modules/@angular/common/src/directives/ng_style.ts @@ -6,11 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, DoCheck, ElementRef, KeyValueChangeRecord, KeyValueDiffer, KeyValueDiffers, Renderer} from '@angular/core'; +import {Directive, DoCheck, ElementRef, Input, KeyValueChangeRecord, KeyValueDiffer, KeyValueDiffers, Renderer} from '@angular/core'; import {isBlank, isPresent} from '../facade/lang'; + /** * The `NgStyle` directive changes styles based on a result of expression evaluation. * @@ -74,7 +75,8 @@ export class NgStyle implements DoCheck { constructor( private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer) {} - set rawStyle(v: {[key: string]: string}) { + @Input() + set ngStyle(v: {[key: string]: string}) { this._rawStyle = v; if (isBlank(this._differ) && isPresent(v)) { this._differ = this._differs.find(this._rawStyle).create(null); diff --git a/modules/@angular/common/src/directives/ng_switch.ts b/modules/@angular/common/src/directives/ng_switch.ts index bdb472a0cd..2d4cb36cd3 100644 --- a/modules/@angular/common/src/directives/ng_switch.ts +++ b/modules/@angular/common/src/directives/ng_switch.ts @@ -6,12 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import {Directive, Host, TemplateRef, ViewContainerRef} from '@angular/core'; +import {Directive, Host, Input, TemplateRef, ViewContainerRef} from '@angular/core'; -import {ListWrapper, Map} from '../facade/collection'; +import {ListWrapper} from '../facade/collection'; import {isBlank, isPresent, normalizeBlank} from '../facade/lang'; -const _CASE_DEFAULT = /*@ts2dart_const*/ new Object(); +const _CASE_DEFAULT = new Object(); // TODO: remove when fully deprecated let _warned: boolean = false; @@ -83,13 +83,14 @@ export class SwitchView { * * @experimental */ -@Directive({selector: '[ngSwitch]', inputs: ['ngSwitch']}) +@Directive({selector: '[ngSwitch]'}) export class NgSwitch { private _switchValue: any; private _useDefault: boolean = false; private _valueViews = new Map(); private _activeViews: SwitchView[] = []; + @Input() set ngSwitch(value: any) { // Empty the currently active ViewContainers this._emptyAllActiveViews(); @@ -183,7 +184,7 @@ export class NgSwitch { * * @experimental */ -@Directive({selector: '[ngSwitchCase],[ngSwitchWhen]', inputs: ['ngSwitchCase', 'ngSwitchWhen']}) +@Directive({selector: '[ngSwitchCase],[ngSwitchWhen]'}) export class NgSwitchCase { // `_CASE_DEFAULT` is used as a marker for a not yet initialized value /** @internal */ @@ -199,11 +200,13 @@ export class NgSwitchCase { this._view = new SwitchView(viewContainer, templateRef); } + @Input() set ngSwitchCase(value: any) { this._switch._onCaseValueChanged(this._value, value, this._view); this._value = value; } + @Input() set ngSwitchWhen(value: any) { if (!_warned) { _warned = true; diff --git a/modules/@angular/common/src/directives/ng_template_outlet.ts b/modules/@angular/common/src/directives/ng_template_outlet.ts index 12b89902f1..9ea61e661d 100644 --- a/modules/@angular/common/src/directives/ng_template_outlet.ts +++ b/modules/@angular/common/src/directives/ng_template_outlet.ts @@ -7,11 +7,8 @@ */ import {Directive, EmbeddedViewRef, Input, TemplateRef, ViewContainerRef} from '@angular/core'; - import {isPresent} from '../facade/lang'; - - /** * Creates and inserts an embedded view based on a prepared `TemplateRef`. * You can attach a context object to the `EmbeddedViewRef` by setting `[ngOutletContext]`. @@ -21,8 +18,12 @@ import {isPresent} from '../facade/lang'; * Note: using the key `$implicit` in the context object will set it's value as default. * * ### Syntax - * - `` + * + * ``` + * + * ``` * * @experimental */ diff --git a/modules/@angular/common/test/directives/ng_for_spec.ts b/modules/@angular/common/test/directives/ng_for_spec.ts index 2219ff9299..a55c651245 100644 --- a/modules/@angular/common/test/directives/ng_for_spec.ts +++ b/modules/@angular/common/test/directives/ng_for_spec.ts @@ -9,12 +9,10 @@ import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xit,} from '@angular/core/testing/testing_internal'; import {AsyncTestCompleter} from '@angular/core/testing/testing_internal'; import {TestComponentBuilder} from '@angular/compiler/testing'; - import {ListWrapper} from '../../src/facade/collection'; import {IS_DART} from '../../src/facade/lang'; import {Component, TemplateRef, ContentChild} from '@angular/core'; -import {NgFor} from '@angular/common'; -import {NgIf} from '@angular/common'; +import {NgFor, NgIf} from '@angular/common'; import {expect} from '@angular/platform-browser/testing/matchers'; import {By} from '@angular/platform-browser/src/dom/debug/by'; @@ -475,19 +473,18 @@ export function main() { inject( [TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { - var template = + const template = ``; tcb.overrideTemplate(TestComponent, template) .createAsync(TestComponent) .then((fixture) => { - var buildItemList = - () => { - fixture.debugElement.componentInstance.items = [{'id': 'a'}]; - fixture.detectChanges(); - return fixture.debugElement.queryAll(By.css('p'))[0]; - } + var buildItemList = () => { + fixture.debugElement.componentInstance.items = [{'id': 'a'}]; + fixture.detectChanges(); + return fixture.debugElement.queryAll(By.css('p'))[0]; + }; var firstP = buildItemList(); var finalP = buildItemList(); @@ -495,6 +492,7 @@ export function main() { async.done(); }); })); + it('should update implicit local variable on view', inject( [TestComponentBuilder, AsyncTestCompleter], diff --git a/modules/@angular/compiler/core_private.ts b/modules/@angular/compiler/core_private.ts index 2c0e252b30..e9c70fbbce 100644 --- a/modules/@angular/compiler/core_private.ts +++ b/modules/@angular/compiler/core_private.ts @@ -43,7 +43,7 @@ export var VIEW_ENCAPSULATION_VALUES: typeof t.VIEW_ENCAPSULATION_VALUES = export var DebugContext: typeof t.DebugContext = r.DebugContext; export var StaticNodeDebugInfo: typeof t.StaticNodeDebugInfo = r.StaticNodeDebugInfo; export var devModeEqual: typeof t.devModeEqual = r.devModeEqual; -export var uninitialized: typeof t.uninitialized = r.uninitialized; +export var UNINITIALIZED: typeof t.UNINITIALIZED = r.UNINITIALIZED; export var ValueUnwrapper: typeof t.ValueUnwrapper = r.ValueUnwrapper; export var TemplateRef_: typeof t.TemplateRef_ = r.TemplateRef_; export type RenderDebugInfo = t.RenderDebugInfo; diff --git a/modules/@angular/compiler/src/identifiers.ts b/modules/@angular/compiler/src/identifiers.ts index f97f6d3e91..bf07e272d4 100644 --- a/modules/@angular/compiler/src/identifiers.ts +++ b/modules/@angular/compiler/src/identifiers.ts @@ -8,7 +8,7 @@ import {ANALYZE_FOR_PRECOMPILE, AppModuleFactory, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core'; -import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppModuleInjector, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NoOpAnimationPlayer as NoOpAnimationPlayer_, StaticNodeDebugInfo, TemplateRef_, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles, uninitialized} from '../core_private'; +import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppModuleInjector, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NoOpAnimationPlayer as NoOpAnimationPlayer_, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles} from '../core_private'; import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata'; import {assetUrl} from './util'; @@ -40,7 +40,7 @@ var impChangeDetectionStrategy = ChangeDetectionStrategy; var impStaticNodeDebugInfo = StaticNodeDebugInfo; var impRenderer = Renderer; var impSimpleChange = SimpleChange; -var impUninitialized = uninitialized; +var impUNINITIALIZED = UNINITIALIZED; var impChangeDetectorStatus = ChangeDetectorStatus; var impFlattenNestedViewRenderNodes = flattenNestedViewRenderNodes; var impDevModeEqual = devModeEqual; @@ -158,8 +158,8 @@ export class Identifiers { {name: 'Renderer', moduleUrl: assetUrl('core', 'render/api'), runtime: impRenderer}); static SimpleChange = new CompileIdentifierMetadata( {name: 'SimpleChange', moduleUrl: CD_MODULE_URL, runtime: impSimpleChange}); - static uninitialized = new CompileIdentifierMetadata( - {name: 'uninitialized', moduleUrl: CD_MODULE_URL, runtime: impUninitialized}); + static UNINITIALIZED = new CompileIdentifierMetadata( + {name: 'UNINITIALIZED', moduleUrl: CD_MODULE_URL, runtime: impUNINITIALIZED}); static ChangeDetectorStatus = new CompileIdentifierMetadata( {name: 'ChangeDetectorStatus', moduleUrl: CD_MODULE_URL, runtime: impChangeDetectorStatus}); static checkBinding = new CompileIdentifierMetadata( diff --git a/modules/@angular/compiler/src/view_compiler/property_binder.ts b/modules/@angular/compiler/src/view_compiler/property_binder.ts index 75f1d8542c..6ef701ed8d 100644 --- a/modules/@angular/compiler/src/view_compiler/property_binder.ts +++ b/modules/@angular/compiler/src/view_compiler/property_binder.ts @@ -50,7 +50,7 @@ function bind( // private is fine here as no child view will reference the cached value... view.fields.push(new o.ClassField(fieldExpr.name, null, [o.StmtModifier.Private])); view.createMethod.addStmt( - o.THIS_EXPR.prop(fieldExpr.name).set(o.importExpr(Identifiers.uninitialized)).toStmt()); + o.THIS_EXPR.prop(fieldExpr.name).set(o.importExpr(Identifiers.UNINITIALIZED)).toStmt()); if (checkExpression.needsValueUnwrapper) { var initValueUnwrapperStmt = DetectChangesVars.valUnwrapper.callMethod('reset', []).toStmt(); @@ -153,14 +153,14 @@ function bindAndWriteToRenderer( var oldRenderVar = o.variable('oldRenderVar'); updateStmts.push(oldRenderVar.set(oldRenderValue).toDeclStmt()); updateStmts.push(new o.IfStmt( - oldRenderVar.equals(o.importExpr(Identifiers.uninitialized)), + oldRenderVar.equals(o.importExpr(Identifiers.UNINITIALIZED)), [oldRenderVar.set(emptyStateValue).toStmt()])); // ... => void var newRenderVar = o.variable('newRenderVar'); updateStmts.push(newRenderVar.set(renderValue).toDeclStmt()); updateStmts.push(new o.IfStmt( - newRenderVar.equals(o.importExpr(Identifiers.uninitialized)), + newRenderVar.equals(o.importExpr(Identifiers.UNINITIALIZED)), [newRenderVar.set(emptyStateValue).toStmt()])); updateStmts.push( diff --git a/modules/@angular/core/private_export.ts b/modules/@angular/core/private_export.ts index 907e20f9eb..f46baf03cd 100644 --- a/modules/@angular/core/private_export.ts +++ b/modules/@angular/core/private_export.ts @@ -72,7 +72,7 @@ export declare namespace __core_private_types__ { export var DebugContext: typeof debug_context.DebugContext; export var StaticNodeDebugInfo: typeof debug_context.StaticNodeDebugInfo; export var devModeEqual: typeof change_detection_util.devModeEqual; - export var uninitialized: typeof change_detection_util.uninitialized; + export var UNINITIALIZED: typeof change_detection_util.UNINITIALIZED; export var ValueUnwrapper: typeof change_detection_util.ValueUnwrapper; export type RenderDebugInfo = api.RenderDebugInfo; export var RenderDebugInfo: typeof api.RenderDebugInfo; @@ -152,7 +152,7 @@ export var __core_private__ = { DebugContext: debug_context.DebugContext, StaticNodeDebugInfo: debug_context.StaticNodeDebugInfo, devModeEqual: change_detection_util.devModeEqual, - uninitialized: change_detection_util.uninitialized, + UNINITIALIZED: change_detection_util.UNINITIALIZED, ValueUnwrapper: change_detection_util.ValueUnwrapper, RenderDebugInfo: api.RenderDebugInfo, TemplateRef_: template_ref.TemplateRef_, diff --git a/modules/@angular/core/src/change_detection/change_detection.ts b/modules/@angular/core/src/change_detection/change_detection.ts index c90f3dd9bf..6e7a64de0e 100644 --- a/modules/@angular/core/src/change_detection/change_detection.ts +++ b/modules/@angular/core/src/change_detection/change_detection.ts @@ -12,7 +12,7 @@ import {IterableDifferFactory, IterableDiffers} from './differs/iterable_differs import {KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs'; export {SimpleChanges} from '../metadata/lifecycle_hooks'; -export {SimpleChange, ValueUnwrapper, WrappedValue, devModeEqual, looseIdentical, uninitialized} from './change_detection_util'; +export {SimpleChange, UNINITIALIZED, ValueUnwrapper, WrappedValue, devModeEqual, looseIdentical} from './change_detection_util'; export {ChangeDetectorRef} from './change_detector_ref'; export {CHANGE_DETECTION_STRATEGY_VALUES, ChangeDetectionStrategy, ChangeDetectorStatus, isDefaultChangeDetectionStrategy} from './constants'; export {CollectionChangeRecord, DefaultIterableDifferFactory} from './differs/default_iterable_differ'; diff --git a/modules/@angular/core/src/change_detection/change_detection_util.ts b/modules/@angular/core/src/change_detection/change_detection_util.ts index 80b22a480e..1b5af4cf51 100644 --- a/modules/@angular/core/src/change_detection/change_detection_util.ts +++ b/modules/@angular/core/src/change_detection/change_detection_util.ts @@ -11,7 +11,7 @@ import {isPrimitive, looseIdentical} from '../facade/lang'; export {looseIdentical} from '../facade/lang'; -export var uninitialized: Object = /*@ts2dart_const*/ new Object(); +export const UNINITIALIZED = new Object(); export function devModeEqual(a: any, b: any): boolean { if (isListLikeIterable(a) && isListLikeIterable(b)) { @@ -78,5 +78,5 @@ export class SimpleChange { /** * Check whether the new value is the first value assigned. */ - isFirstChange(): boolean { return this.previousValue === uninitialized; } + isFirstChange(): boolean { return this.previousValue === UNINITIALIZED; } } diff --git a/modules/@angular/core/src/linker/view_utils.ts b/modules/@angular/core/src/linker/view_utils.ts index b47a7fd107..299108f51a 100644 --- a/modules/@angular/core/src/linker/view_utils.ts +++ b/modules/@angular/core/src/linker/view_utils.ts @@ -8,7 +8,7 @@ import {APP_ID} from '../application_tokens'; import {devModeEqual} from '../change_detection/change_detection'; -import {uninitialized} from '../change_detection/change_detection_util'; +import {UNINITIALIZED} from '../change_detection/change_detection_util'; import {Inject, Injectable} from '../di/decorators'; import {ListWrapper, StringMapWrapper} from '../facade/collection'; import {BaseException} from '../facade/exceptions'; @@ -176,7 +176,7 @@ export const EMPTY_MAP = /*@ts2dart_const*/ {}; export function pureProxy1(fn: (p0: P0) => R): (p0: P0) => R { var result: R; var v0: any /** TODO #9100 */; - v0 = uninitialized; + v0 = UNINITIALIZED; return (p0) => { if (!looseIdentical(v0, p0)) { v0 = p0; @@ -189,7 +189,7 @@ export function pureProxy1(fn: (p0: P0) => R): (p0: P0) => R { export function pureProxy2(fn: (p0: P0, p1: P1) => R): (p0: P0, p1: P1) => R { var result: R; var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */; - v0 = v1 = uninitialized; + v0 = v1 = UNINITIALIZED; return (p0, p1) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1)) { v0 = p0; @@ -204,7 +204,7 @@ export function pureProxy3(fn: (p0: P0, p1: P1, p2: P2) => R): ( p0: P0, p1: P1, p2: P2) => R { var result: R; var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */, v2: any /** TODO #9100 */; - v0 = v1 = v2 = uninitialized; + v0 = v1 = v2 = UNINITIALIZED; return (p0, p1, p2) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2)) { v0 = p0; @@ -221,7 +221,7 @@ export function pureProxy4(fn: (p0: P0, p1: P1, p2: P2, p3: P var result: R; var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */, v2: any /** TODO #9100 */, v3: any /** TODO #9100 */; - v0 = v1 = v2 = v3 = uninitialized; + v0 = v1 = v2 = v3 = UNINITIALIZED; return (p0, p1, p2, p3) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2) || !looseIdentical(v3, p3)) { @@ -241,7 +241,7 @@ export function pureProxy5( var result: R; var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */, v2: any /** TODO #9100 */, v3: any /** TODO #9100 */, v4: any /** TODO #9100 */; - v0 = v1 = v2 = v3 = v4 = uninitialized; + v0 = v1 = v2 = v3 = v4 = UNINITIALIZED; return (p0, p1, p2, p3, p4) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2) || !looseIdentical(v3, p3) || !looseIdentical(v4, p4)) { @@ -263,7 +263,7 @@ export function pureProxy6( var result: R; var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */, v2: any /** TODO #9100 */, v3: any /** TODO #9100 */, v4: any /** TODO #9100 */, v5: any /** TODO #9100 */; - v0 = v1 = v2 = v3 = v4 = v5 = uninitialized; + v0 = v1 = v2 = v3 = v4 = v5 = UNINITIALIZED; return (p0, p1, p2, p3, p4, p5) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2) || !looseIdentical(v3, p3) || !looseIdentical(v4, p4) || !looseIdentical(v5, p5)) { @@ -286,7 +286,7 @@ export function pureProxy7( var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */, v2: any /** TODO #9100 */, v3: any /** TODO #9100 */, v4: any /** TODO #9100 */, v5: any /** TODO #9100 */, v6: any /** TODO #9100 */; - v0 = v1 = v2 = v3 = v4 = v5 = v6 = uninitialized; + v0 = v1 = v2 = v3 = v4 = v5 = v6 = UNINITIALIZED; return (p0, p1, p2, p3, p4, p5, p6) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2) || !looseIdentical(v3, p3) || !looseIdentical(v4, p4) || !looseIdentical(v5, p5) || @@ -311,7 +311,7 @@ export function pureProxy8( var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */, v2: any /** TODO #9100 */, v3: any /** TODO #9100 */, v4: any /** TODO #9100 */, v5: any /** TODO #9100 */, v6: any /** TODO #9100 */, v7: any /** TODO #9100 */; - v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = uninitialized; + v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = UNINITIALIZED; return (p0, p1, p2, p3, p4, p5, p6, p7) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2) || !looseIdentical(v3, p3) || !looseIdentical(v4, p4) || !looseIdentical(v5, p5) || @@ -337,7 +337,7 @@ export function pureProxy9( var v0: any /** TODO #9100 */, v1: any /** TODO #9100 */, v2: any /** TODO #9100 */, v3: any /** TODO #9100 */, v4: any /** TODO #9100 */, v5: any /** TODO #9100 */, v6: any /** TODO #9100 */, v7: any /** TODO #9100 */, v8: any /** TODO #9100 */; - v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = uninitialized; + v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = UNINITIALIZED; return (p0, p1, p2, p3, p4, p5, p6, p7, p8) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2) || !looseIdentical(v3, p3) || !looseIdentical(v4, p4) || !looseIdentical(v5, p5) || @@ -365,7 +365,7 @@ export function pureProxy10( v3: any /** TODO #9100 */, v4: any /** TODO #9100 */, v5: any /** TODO #9100 */, v6: any /** TODO #9100 */, v7: any /** TODO #9100 */, v8: any /** TODO #9100 */, v9: any /** TODO #9100 */; - v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = uninitialized; + v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = v8 = v9 = UNINITIALIZED; return (p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) => { if (!looseIdentical(v0, p0) || !looseIdentical(v1, p1) || !looseIdentical(v2, p2) || !looseIdentical(v3, p3) || !looseIdentical(v4, p4) || !looseIdentical(v5, p5) || diff --git a/modules/@angular/core/test/linker/change_detection_integration_spec.ts b/modules/@angular/core/test/linker/change_detection_integration_spec.ts index ad7203beeb..d8f2524d95 100644 --- a/modules/@angular/core/test/linker/change_detection_integration_spec.ts +++ b/modules/@angular/core/test/linker/change_detection_integration_spec.ts @@ -6,39 +6,28 @@ * found in the LICENSE file at https://angular.io/license */ -import {TestComponentBuilder} from '@angular/compiler/testing'; +import {AsyncPipe, NgFor} from '@angular/common'; +import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry'; +import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/test/test_bindings'; +import {MockSchemaRegistry, TestComponentBuilder} from '@angular/compiler/testing'; +import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, DoCheck, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, RenderComponentType, Renderer, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, ViewContainerRef, ViewMetadata, WrappedValue, forwardRef} from '@angular/core'; +import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer'; import {ComponentFixture, configureCompiler, configureModule, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal'; - -import {isBlank, NumberWrapper, ConcreteType,} from '../../src/facade/lang'; -import {BaseException} from '../../src/facade/exceptions'; -import {StringMapWrapper} from '../../src/facade/collection'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; - -import {PipeTransform, ChangeDetectionStrategy, WrappedValue,} from '@angular/core/src/change_detection/change_detection'; - -import {OnDestroy} from '@angular/core/src/metadata/lifecycle_hooks'; - -import {IS_DART, Type} from '../../src/facade/lang'; -import {EventEmitter, ObservableWrapper} from '../../src/facade/async'; - - -import {Component, DebugElement, Directive, TemplateRef, ChangeDetectorRef, ViewContainerRef, Input, Output, forwardRef, ViewMetadata, Pipe, RootRenderer, Renderer, RenderComponentType, Injectable, provide, OnInit, DoCheck, OnChanges, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked, Injector} from '@angular/core'; -import {NgFor, NgIf} from '@angular/common'; import {By} from '@angular/platform-browser/src/dom/debug/by'; -import {AsyncPipe} from '@angular/common'; - -import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry'; -import {MockSchemaRegistry} from '@angular/compiler/testing'; -import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/test/test_bindings'; -import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer'; +import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DomRootRenderer} from '@angular/platform-browser/src/dom/dom_renderer'; +import {EventEmitter} from '../../src/facade/async'; +import {StringMapWrapper} from '../../src/facade/collection'; +import {BaseException} from '../../src/facade/exceptions'; +import {ConcreteType, IS_DART, NumberWrapper, Type, isBlank} from '../../src/facade/lang'; + export function main() { - var tcb: TestComponentBuilder; - var elSchema: MockSchemaRegistry; - var renderLog: RenderLog; - var directiveLog: DirectiveLog; + let tcb: TestComponentBuilder; + let elSchema: MockSchemaRegistry; + let renderLog: RenderLog; + let directiveLog: DirectiveLog; function createCompFixture(template: string): ComponentFixture; function createCompFixture(template: string, compType: ConcreteType): ComponentFixture; @@ -79,7 +68,7 @@ export function main() { function _bindAndCheckSimpleValue( expression: any, compType: ConcreteType = TestComponent): string[] { - var ctx = _bindSimpleValue(expression, compType); + const ctx = _bindSimpleValue(expression, compType); ctx.detectChanges(false); return renderLog.log; } @@ -298,7 +287,7 @@ export function main() { it('should support function calls', fakeAsync(() => { var ctx = _bindSimpleValue('a()(99)', TestData); - ctx.componentInstance.a = () => (a: any /** TODO #9100 */) => a; + ctx.componentInstance.a = () => (a: any) => a; ctx.detectChanges(false); expect(renderLog.log).toEqual(['someProp=99']); })); @@ -1182,13 +1171,13 @@ class DirectiveLog { @Pipe({name: 'countingPipe'}) class CountingPipe implements PipeTransform { state: number = 0; - transform(value: any /** TODO #9100 */) { return `${value} state:${this.state ++}`; } + transform(value: any) { return `${value} state:${this.state ++}`; } } @Pipe({name: 'countingImpurePipe', pure: false}) class CountingImpurePipe implements PipeTransform { state: number = 0; - transform(value: any /** TODO #9100 */) { return `${value} state:${this.state ++}`; } + transform(value: any) { return `${value} state:${this.state ++}`; } } @Pipe({name: 'pipeWithOnDestroy'}) @@ -1197,24 +1186,22 @@ class PipeWithOnDestroy implements PipeTransform, OnDestroy { ngOnDestroy() { this.directiveLog.add('pipeWithOnDestroy', 'ngOnDestroy'); } - transform(value: any /** TODO #9100 */): any /** TODO #9100 */ { return null; } + transform(value: any): any { return null; } } @Pipe({name: 'identityPipe'}) class IdentityPipe implements PipeTransform { - transform(value: any /** TODO #9100 */) { return value; } + transform(value: any) { return value; } } @Pipe({name: 'wrappedPipe'}) class WrappedPipe implements PipeTransform { - transform(value: any /** TODO #9100 */) { return WrappedValue.wrap(value); } + transform(value: any) { return WrappedValue.wrap(value); } } @Pipe({name: 'multiArgPipe'}) class MultiArgPipe implements PipeTransform { - transform( - value: any /** TODO #9100 */, arg1: any /** TODO #9100 */, arg2: any /** TODO #9100 */, - arg3 = 'default') { + transform(value: any, arg1: any, arg2: any, arg3 = 'default') { return `${value} ${arg1} ${arg2} ${arg3}`; } } @@ -1272,13 +1259,21 @@ class EmitterDirective { @Output('event') emitter = new EventEmitter(); } +@Directive({selector: '[gh-9882]'}) +class Gh9882 implements AfterContentInit { + constructor(private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef) { + } + + ngAfterContentInit(): any { this._viewContainer.createEmbeddedView(this._templateRef); } +} + @Directive({selector: '[testDirective]', exportAs: 'testDirective'}) class TestDirective implements OnInit, DoCheck, OnChanges, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked, OnDestroy { - @Input() a: any /** TODO #9100 */; - @Input() b: any /** TODO #9100 */; - changes: any /** TODO #9100 */; - event: any /** TODO #9100 */; + @Input() a: any; + @Input() b: any; + changes: any; + event: any; eventEmitter: EventEmitter = new EventEmitter(); @Input('testDirective') name: string; @@ -1287,7 +1282,7 @@ class TestDirective implements OnInit, DoCheck, OnChanges, AfterContentInit, Aft constructor(public log: DirectiveLog) {} - onEvent(event: any /** TODO #9100 */) { this.event = event; } + onEvent(event: any) { this.event = event; } ngDoCheck() { this.log.add(this.name, 'ngDoCheck'); } @@ -1298,12 +1293,10 @@ class TestDirective implements OnInit, DoCheck, OnChanges, AfterContentInit, Aft } } - ngOnChanges(changes: any /** TODO #9100 */) { + ngOnChanges(changes: SimpleChanges) { this.log.add(this.name, 'ngOnChanges'); - var r = {}; - StringMapWrapper.forEach( - changes, (c: any /** TODO #9100 */, key: any /** TODO #9100 */) => - (r as any /** TODO #9100 */)[key] = c.currentValue); + const r: {[k: string]: string} = {}; + StringMapWrapper.forEach(changes, (c: SimpleChange, key: string) => r[key] = c.currentValue); this.changes = r; if (this.throwOn == 'ngOnChanges') { throw new BaseException('Boom!'); @@ -1407,9 +1400,9 @@ class Person { this.address = address; } - sayHi(m: any /** TODO #9100 */) { return `Hi, ${m}`; } + sayHi(m: any): string { return `Hi, ${m}`; } - passThrough(val: any /** TODO #9100 */) { return val; } + passThrough(val: any): any { return val; } toString(): string { var address = this.address == null ? '' : ' address=' + this.address.toString(); @@ -1422,7 +1415,7 @@ class Address { cityGetterCalls: number = 0; zipCodeGetterCalls: number = 0; - constructor(public _city: string, public _zipcode: any /** TODO #9100 */ = null) {} + constructor(public _city: string, public _zipcode: any = null) {} get city() { this.cityGetterCalls++; @@ -1441,21 +1434,6 @@ class Address { toString(): string { return isBlank(this.city) ? '-' : this.city } } -class Logical { - trueCalls: number = 0; - falseCalls: number = 0; - - getTrue() { - this.trueCalls++; - return true; - } - - getFalse() { - this.falseCalls++; - return false; - } -} - @Component({selector: 'root'}) class Uninitialized { value: any = null; @@ -1465,10 +1443,3 @@ class Uninitialized { class TestData { public a: any; } - -@Component({selector: 'root'}) -class TestDataWithGetter { - public fn: Function; - - get a() { return this.fn(); } -} diff --git a/tools/public_api_guard/common/index.d.ts b/tools/public_api_guard/common/index.d.ts index fbd6d10718..5d0ab618ec 100644 --- a/tools/public_api_guard/common/index.d.ts +++ b/tools/public_api_guard/common/index.d.ts @@ -289,7 +289,7 @@ export declare const NG_VALUE_ACCESSOR: OpaqueToken; /** @stable */ export declare class NgClass implements DoCheck, OnDestroy { initialClasses: string; - rawClass: string | string[] | Set | { + ngClass: string | string[] | Set | { [key: string]: any; }; constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer); @@ -460,7 +460,7 @@ export declare class NgSelectOption implements OnDestroy { /** @stable */ export declare class NgStyle implements DoCheck { - rawStyle: { + ngStyle: { [key: string]: string; }; constructor(_differs: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer);