refactor: misc cleanup

This commit is contained in:
Victor Berchet 2016-07-07 16:35:13 -07:00
parent 749dec7dfb
commit eacc9e6541
16 changed files with 107 additions and 128 deletions

View File

@ -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.

View File

@ -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<string>|{[key: string]: any}) {
@Input()
set ngClass(v: string|string[]|Set<string>|{[key: string]: any}) {
this._cleanupClasses(this._rawClass);
if (isString(v)) {

View File

@ -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<Object>) {
}
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);

View File

@ -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);

View File

@ -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<any, SwitchView[]>();
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;

View File

@ -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
* - `<template [ngTemplateOutlet]="templateRefExpression"
* [ngOutletContext]="objectExpression"></template>`
*
* ```
* <template [ngTemplateOutlet]="templateRefExpression"
* [ngOutletContext]="objectExpression">
* </template>
* ```
*
* @experimental
*/

View File

@ -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 =
`<template ngFor let-item [ngForOf]="items" [ngForTrackBy]="trackById" let-i="index">
<p>{{items[i]}}</p>
</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],

View File

@ -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;

View File

@ -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(

View File

@ -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(

View File

@ -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_,

View File

@ -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';

View File

@ -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; }
}

View File

@ -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<P0, R>(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<P0, R>(fn: (p0: P0) => R): (p0: P0) => R {
export function pureProxy2<P0, P1, R>(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<P0, P1, P2, R>(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<P0, P1, P2, P3, R>(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<P0, P1, P2, P3, P4, R>(
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<P0, P1, P2, P3, P4, P5, R>(
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<P0, P1, P2, P3, P4, P5, P6, 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 */,
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<P0, P1, P2, P3, P4, P5, P6, P7, 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 */,
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<P0, P1, P2, P3, P4, P5, P6, P7, P8, 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 */,
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<P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, R>(
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) ||

View File

@ -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<T>(template: string): ComponentFixture<TestComponent>;
function createCompFixture<T>(template: string, compType: ConcreteType<T>): ComponentFixture<T>;
@ -79,7 +68,7 @@ export function main() {
function _bindAndCheckSimpleValue(
expression: any, compType: ConcreteType<any> = 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<string>();
}
@Directive({selector: '[gh-9882]'})
class Gh9882 implements AfterContentInit {
constructor(private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef<Object>) {
}
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<string> = new EventEmitter<string>();
@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(); }
}

View File

@ -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<string> | {
ngClass: string | string[] | Set<string> | {
[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);