From 393f703a976d20cbee871f296c65568fb43d0025 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 22 Jun 2015 17:11:55 -0700 Subject: [PATCH] fix: export top-level pipe factories as const Also appComponent(Ref|Type)Token Related to https://github.com/angular/angular/issues/1485 --- .../src/change_detection/change_detection.ts | 31 ++++++++++++------- .../src/change_detection/interfaces.ts | 2 ++ .../src/change_detection/pipes/json_pipe.ts | 3 +- .../change_detection/pipes/lowercase_pipe.ts | 3 +- .../src/change_detection/pipes/pipe.ts | 1 + .../change_detection/pipes/pipe_registry.ts | 1 + .../change_detection/pipes/promise_pipe.ts | 3 +- .../change_detection/pipes/uppercase_pipe.ts | 3 +- .../angular2/src/core/application_tokens.ts | 5 +-- 9 files changed, 35 insertions(+), 17 deletions(-) diff --git a/modules/angular2/src/change_detection/change_detection.ts b/modules/angular2/src/change_detection/change_detection.ts index 5e554702e0..8d61656755 100644 --- a/modules/angular2/src/change_detection/change_detection.ts +++ b/modules/angular2/src/change_detection/change_detection.ts @@ -14,59 +14,67 @@ import {NullPipeFactory} from './pipes/null_pipe'; import {ChangeDetection, ProtoChangeDetector, ChangeDetectorDefinition} from './interfaces'; import {Inject, Injectable, OpaqueToken, Optional} from 'angular2/di'; import {List, StringMap, StringMapWrapper} from 'angular2/src/facade/collection'; -import {CONST_EXPR, isPresent, BaseException} from 'angular2/src/facade/lang'; +import {CONST, CONST_EXPR, isPresent, BaseException} from 'angular2/src/facade/lang'; /** * Structural diffing for `Object`s and `Map`s. * * @exportedAs angular2/pipes */ -export var keyValDiff: List = [new KeyValueChangesFactory(), new NullPipeFactory()]; +export const keyValDiff: List = + CONST_EXPR([CONST_EXPR(new KeyValueChangesFactory()), CONST_EXPR(new NullPipeFactory())]); /** * Structural diffing for `Iterable` types such as `Array`s. * * @exportedAs angular2/pipes */ -export var iterableDiff: List = [new IterableChangesFactory(), new NullPipeFactory()]; +export const iterableDiff: List = + CONST_EXPR([CONST_EXPR(new IterableChangesFactory()), CONST_EXPR(new NullPipeFactory())]); /** * Async binding to such types as Observable. * * @exportedAs angular2/pipes */ -export var async: List = - [new ObservablePipeFactory(), new PromisePipeFactory(), new NullPipeFactory()]; +export const async: List = CONST_EXPR([ + CONST_EXPR(new ObservablePipeFactory()), + CONST_EXPR(new PromisePipeFactory()), + CONST_EXPR(new NullPipeFactory()) +]); /** * Uppercase text transform. * * @exportedAs angular2/pipes */ -export var uppercase: List = [new UpperCaseFactory(), new NullPipeFactory()]; +export const uppercase: List = + CONST_EXPR([CONST_EXPR(new UpperCaseFactory()), CONST_EXPR(new NullPipeFactory())]); /** * Lowercase text transform. * * @exportedAs angular2/pipes */ -export var lowercase: List = [new LowerCaseFactory(), new NullPipeFactory()]; +export const lowercase: List = + CONST_EXPR([CONST_EXPR(new LowerCaseFactory()), CONST_EXPR(new NullPipeFactory())]); /** * Json stringify transform. * * @exportedAs angular2/pipes */ -export var json: List = [new JsonPipe(), new NullPipeFactory()]; +export const json: List = + CONST_EXPR([CONST_EXPR(new JsonPipe()), CONST_EXPR(new NullPipeFactory())]); -export var defaultPipes = { +export const defaultPipes = CONST_EXPR({ "iterableDiff": iterableDiff, "keyValDiff": keyValDiff, "async": async, "uppercase": uppercase, "lowercase": lowercase, "json": json -}; +}); /** * Map from {@link ChangeDetectorDefinition#id} to a factory method which takes a @@ -137,6 +145,7 @@ export class DynamicChangeDetection extends ChangeDetection { * @exportedAs angular2/change_detection */ @Injectable() +@CONST() export class JitChangeDetection extends ChangeDetection { constructor(public registry: PipeRegistry) { super(); } @@ -147,4 +156,4 @@ export class JitChangeDetection extends ChangeDetection { } } -export var defaultPipeRegistry: PipeRegistry = new PipeRegistry(defaultPipes); +export const defaultPipeRegistry: PipeRegistry = CONST_EXPR(new PipeRegistry(defaultPipes)); diff --git a/modules/angular2/src/change_detection/interfaces.ts b/modules/angular2/src/change_detection/interfaces.ts index 99e08d7fb2..d25a4880d5 100644 --- a/modules/angular2/src/change_detection/interfaces.ts +++ b/modules/angular2/src/change_detection/interfaces.ts @@ -1,4 +1,5 @@ import {List} from 'angular2/src/facade/collection'; +import {CONST} from 'angular2/src/facade/lang'; import {Locals} from './parser/locals'; import {BindingRecord} from './binding_record'; import {DirectiveRecord} from './directive_record'; @@ -29,6 +30,7 @@ import {DirectiveRecord} from './directive_record'; * ``` * @exportedAs angular2/change_detection */ +@CONST() export class ChangeDetection { createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector { return null; diff --git a/modules/angular2/src/change_detection/pipes/json_pipe.ts b/modules/angular2/src/change_detection/pipes/json_pipe.ts index 8d379b9246..e15c1b1237 100644 --- a/modules/angular2/src/change_detection/pipes/json_pipe.ts +++ b/modules/angular2/src/change_detection/pipes/json_pipe.ts @@ -1,4 +1,4 @@ -import {isBlank, isPresent, Json} from 'angular2/src/facade/lang'; +import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang'; import {Pipe, BasePipe, PipeFactory} from './pipe'; /** @@ -26,6 +26,7 @@ import {Pipe, BasePipe, PipeFactory} from './pipe'; * * @exportedAs angular2/pipes */ +@CONST() export class JsonPipe extends BasePipe { transform(value): string { return Json.stringify(value); } diff --git a/modules/angular2/src/change_detection/pipes/lowercase_pipe.ts b/modules/angular2/src/change_detection/pipes/lowercase_pipe.ts index 28a0fb72e0..6d41e5c220 100644 --- a/modules/angular2/src/change_detection/pipes/lowercase_pipe.ts +++ b/modules/angular2/src/change_detection/pipes/lowercase_pipe.ts @@ -1,4 +1,4 @@ -import {isString, StringWrapper} from 'angular2/src/facade/lang'; +import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang'; import {Pipe} from './pipe'; /** @@ -43,6 +43,7 @@ export class LowerCasePipe implements Pipe { /** * @exportedAs angular2/pipes */ +@CONST() export class LowerCaseFactory { supports(str): boolean { return isString(str); } diff --git a/modules/angular2/src/change_detection/pipes/pipe.ts b/modules/angular2/src/change_detection/pipes/pipe.ts index dd575c1c42..883665df99 100644 --- a/modules/angular2/src/change_detection/pipes/pipe.ts +++ b/modules/angular2/src/change_detection/pipes/pipe.ts @@ -70,6 +70,7 @@ export interface Pipe { * } * ``` */ +@CONST() export class BasePipe implements Pipe { supports(obj): boolean { return true; } onDestroy(): void {} diff --git a/modules/angular2/src/change_detection/pipes/pipe_registry.ts b/modules/angular2/src/change_detection/pipes/pipe_registry.ts index c278c0f851..ae9eeca173 100644 --- a/modules/angular2/src/change_detection/pipes/pipe_registry.ts +++ b/modules/angular2/src/change_detection/pipes/pipe_registry.ts @@ -5,6 +5,7 @@ import {Injectable} from 'angular2/src/di/decorators'; import {ChangeDetectorRef} from '../change_detector_ref'; @Injectable() +@CONST() export class PipeRegistry { constructor(public config) {} diff --git a/modules/angular2/src/change_detection/pipes/promise_pipe.ts b/modules/angular2/src/change_detection/pipes/promise_pipe.ts index 00ffaf10a5..3821484495 100644 --- a/modules/angular2/src/change_detection/pipes/promise_pipe.ts +++ b/modules/angular2/src/change_detection/pipes/promise_pipe.ts @@ -1,5 +1,5 @@ import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; -import {isBlank, isPresent, isPromise} from 'angular2/src/facade/lang'; +import {isBlank, isPresent, isPromise, CONST} from 'angular2/src/facade/lang'; import {Pipe, WrappedValue} from './pipe'; import {ChangeDetectorRef} from '../change_detector_ref'; @@ -80,6 +80,7 @@ export class PromisePipe implements Pipe { * * @exportedAs angular2/pipes */ +@CONST() export class PromisePipeFactory { supports(promise): boolean { return isPromise(promise); } diff --git a/modules/angular2/src/change_detection/pipes/uppercase_pipe.ts b/modules/angular2/src/change_detection/pipes/uppercase_pipe.ts index 8c9da28d70..78a9729184 100644 --- a/modules/angular2/src/change_detection/pipes/uppercase_pipe.ts +++ b/modules/angular2/src/change_detection/pipes/uppercase_pipe.ts @@ -1,4 +1,4 @@ -import {isString, StringWrapper} from 'angular2/src/facade/lang'; +import {isString, StringWrapper, CONST} from 'angular2/src/facade/lang'; import {Pipe} from './pipe'; /** @@ -43,6 +43,7 @@ export class UpperCasePipe implements Pipe { /** * @exportedAs angular2/pipes */ +@CONST() export class UpperCaseFactory { supports(str): boolean { return isString(str); } diff --git a/modules/angular2/src/core/application_tokens.ts b/modules/angular2/src/core/application_tokens.ts index d86cebaa56..441c5407bc 100644 --- a/modules/angular2/src/core/application_tokens.ts +++ b/modules/angular2/src/core/application_tokens.ts @@ -1,4 +1,5 @@ import {OpaqueToken} from 'angular2/di'; +import {CONST_EXPR} from 'angular2/src/facade/lang'; -export var appComponentRefToken: OpaqueToken = new OpaqueToken('ComponentRef'); -export var appComponentTypeToken: OpaqueToken = new OpaqueToken('RootComponent'); +export const appComponentRefToken: OpaqueToken = CONST_EXPR(new OpaqueToken('ComponentRef')); +export const appComponentTypeToken: OpaqueToken = CONST_EXPR(new OpaqueToken('RootComponent'));