From e61d82b9be973a2f8f0afcdce9399aa2557323a9 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 20 May 2015 09:48:15 -0700 Subject: [PATCH] =?UTF-8?q?refactor(core):=20ts=E2=80=99ify=20core?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/angular2/core.js | 1 - modules/angular2/globals.d.ts | 1 + .../src/change_detection/change_detection.ts | 8 +- .../{annotations.es6 => annotations.ts} | 4 +- .../{decorators.es6 => decorators.ts} | 5 +- .../src/core/annotations/{di.es6 => di.ts} | 0 .../angular2/src/core/annotations/view.es6 | 3 - modules/angular2/src/core/annotations/view.ts | 3 + .../{visibility.es6 => visibility.ts} | 2 +- .../{annotations.js => annotations.ts} | 310 +++--- .../core/annotations_impl/{di.js => di.ts} | 25 +- .../annotations_impl/{view.js => view.ts} | 29 +- .../{visibility.js => visibility.ts} | 51 +- modules/angular2/src/core/application.js | 307 ------ modules/angular2/src/core/application.ts | 348 +++++++ .../angular2/src/core/application_tokens.js | 4 - .../angular2/src/core/application_tokens.ts | 4 + ...base_query_list.es6 => base_query_list.ts} | 12 +- .../angular2/src/core/compiler/compiler.js | 258 ----- .../angular2/src/core/compiler/compiler.ts | 258 +++++ ..._url_mapper.js => component_url_mapper.ts} | 8 +- ...tive_resolver.js => directive_resolver.ts} | 8 +- .../core/compiler/dynamic_component_loader.js | 132 --- .../core/compiler/dynamic_component_loader.ts | 118 +++ .../{element_binder.js => element_binder.ts} | 20 +- ...lement_injector.js => element_injector.ts} | 955 ++++++++++-------- .../{element_ref.js => element_ref.ts} | 8 +- .../angular2/src/core/compiler/interfaces.js | 8 - ..._view_factory.js => proto_view_factory.ts} | 241 ++--- .../compiler/{query_list.js => query_list.ts} | 41 +- ...plate_resolver.js => template_resolver.ts} | 8 +- .../src/core/compiler/{view.js => view.ts} | 98 +- .../src/core/compiler/view_container_ref.js | 71 -- .../src/core/compiler/view_container_ref.ts | 61 ++ .../{view_manager.js => view_manager.ts} | 95 +- ...manager_utils.js => view_manager_utils.ts} | 80 +- .../compiler/{view_pool.js => view_pool.ts} | 11 +- .../compiler/{view_ref.js => view_ref.ts} | 24 +- ...eption_handler.js => exception_handler.ts} | 8 +- .../src/core/life_cycle/life_cycle.js | 76 -- .../src/core/life_cycle/life_cycle.ts | 81 ++ ...get_testability.es6 => get_testability.ts} | 10 +- .../{testability.js => testability.ts} | 16 +- modules/angular2/src/core/zone/ng_zone.ts | 6 +- modules/angular2/src/di/injector.ts | 16 +- modules/angular2/src/dom/dom_adapter.ts | 2 +- modules/angular2/src/facade/collection.ts | 44 +- modules/angular2/src/facade/lang.ts | 2 +- .../render/dom/compiler/directive_parser.ts | 16 +- .../src/render/dom/compiler/selector.ts | 58 +- .../src/render/dom/events/key_events.ts | 2 +- .../emulated_scoped_shadow_dom_strategy.ts | 13 +- .../render/dom/shadow_dom/style_inliner.ts | 26 +- .../src/services/{ruler.js => ruler.ts} | 14 +- .../dom/shadow_dom/style_inliner_spec.js | 38 +- modules/angular2/traceur-runtime.d.ts | 2 + 56 files changed, 2128 insertions(+), 1922 deletions(-) rename modules/angular2/src/core/annotations/{annotations.es6 => annotations.ts} (86%) rename modules/angular2/src/core/annotations/{decorators.es6 => decorators.ts} (90%) rename modules/angular2/src/core/annotations/{di.es6 => di.ts} (100%) delete mode 100644 modules/angular2/src/core/annotations/view.es6 create mode 100644 modules/angular2/src/core/annotations/view.ts rename modules/angular2/src/core/annotations/{visibility.es6 => visibility.ts} (62%) rename modules/angular2/src/core/annotations_impl/{annotations.js => annotations.ts} (81%) rename modules/angular2/src/core/annotations_impl/{di.js => di.ts} (62%) rename modules/angular2/src/core/annotations_impl/{view.js => view.ts} (84%) rename modules/angular2/src/core/annotations_impl/{visibility.js => visibility.ts} (84%) delete mode 100644 modules/angular2/src/core/application.js create mode 100644 modules/angular2/src/core/application.ts delete mode 100644 modules/angular2/src/core/application_tokens.js create mode 100644 modules/angular2/src/core/application_tokens.ts rename modules/angular2/src/core/compiler/{base_query_list.es6 => base_query_list.ts} (81%) delete mode 100644 modules/angular2/src/core/compiler/compiler.js create mode 100644 modules/angular2/src/core/compiler/compiler.ts rename modules/angular2/src/core/compiler/{component_url_mapper.js => component_url_mapper.ts} (84%) rename modules/angular2/src/core/compiler/{directive_resolver.js => directive_resolver.ts} (75%) delete mode 100644 modules/angular2/src/core/compiler/dynamic_component_loader.js create mode 100644 modules/angular2/src/core/compiler/dynamic_component_loader.ts rename modules/angular2/src/core/compiler/{element_binder.js => element_binder.ts} (63%) rename modules/angular2/src/core/compiler/{element_injector.js => element_injector.ts} (54%) rename modules/angular2/src/core/compiler/{element_ref.js => element_ref.ts} (88%) delete mode 100644 modules/angular2/src/core/compiler/interfaces.js rename modules/angular2/src/core/compiler/{proto_view_factory.js => proto_view_factory.ts} (57%) rename modules/angular2/src/core/compiler/{query_list.js => query_list.ts} (73%) rename modules/angular2/src/core/compiler/{template_resolver.js => template_resolver.ts} (86%) rename modules/angular2/src/core/compiler/{view.js => view.ts} (73%) delete mode 100644 modules/angular2/src/core/compiler/view_container_ref.js create mode 100644 modules/angular2/src/core/compiler/view_container_ref.ts rename modules/angular2/src/core/compiler/{view_manager.js => view_manager.ts} (75%) rename modules/angular2/src/core/compiler/{view_manager_utils.js => view_manager_utils.ts} (74%) rename modules/angular2/src/core/compiler/{view_pool.js => view_pool.ts} (80%) rename modules/angular2/src/core/compiler/{view_ref.js => view_ref.ts} (50%) rename modules/angular2/src/core/{exception_handler.js => exception_handler.ts} (82%) delete mode 100644 modules/angular2/src/core/life_cycle/life_cycle.js create mode 100644 modules/angular2/src/core/life_cycle/life_cycle.ts rename modules/angular2/src/core/testability/{get_testability.es6 => get_testability.ts} (78%) rename modules/angular2/src/core/testability/{testability.js => testability.ts} (86%) rename modules/angular2/src/services/{ruler.js => ruler.ts} (55%) diff --git a/modules/angular2/core.js b/modules/angular2/core.js index 6e164a4d13..518edd0518 100644 --- a/modules/angular2/core.js +++ b/modules/angular2/core.js @@ -5,7 +5,6 @@ * Define angular core API here. */ export * from './src/core/annotations/visibility'; -export * from './src/core/compiler/interfaces'; export * from './src/core/annotations/view'; export * from './src/core/application'; export * from './src/core/application_tokens'; diff --git a/modules/angular2/globals.d.ts b/modules/angular2/globals.d.ts index 56e1ed6751..f544935e04 100644 --- a/modules/angular2/globals.d.ts +++ b/modules/angular2/globals.d.ts @@ -27,4 +27,5 @@ interface Window { Reflect: any; zone: Zone; Hammer: HammerStatic; + getAngularTestability: Function; } diff --git a/modules/angular2/src/change_detection/change_detection.ts b/modules/angular2/src/change_detection/change_detection.ts index fa5662617d..3cc06083a9 100644 --- a/modules/angular2/src/change_detection/change_detection.ts +++ b/modules/angular2/src/change_detection/change_detection.ts @@ -77,19 +77,19 @@ export var preGeneratedProtoDetectors = {}; */ export class PreGeneratedChangeDetection extends ChangeDetection { _dynamicChangeDetection: ChangeDetection; - _protoChangeDetectors: any; + _protoChangeDetectorFactories: StringMap; constructor(private registry: PipeRegistry, protoChangeDetectors?) { super(); this._dynamicChangeDetection = new DynamicChangeDetection(registry); - this._protoChangeDetectors = + this._protoChangeDetectorFactories = isPresent(protoChangeDetectors) ? protoChangeDetectors : preGeneratedProtoDetectors; } createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector { var id = definition.id; - if (StringMapWrapper.contains(this._protoChangeDetectors, id)) { - return StringMapWrapper.get(this._protoChangeDetectors, id)(this.registry); + if (StringMapWrapper.contains(this._protoChangeDetectorFactories, id)) { + return StringMapWrapper.get(this._protoChangeDetectorFactories, id)(this.registry); } return this._dynamicChangeDetection.createProtoChangeDetector(definition); } diff --git a/modules/angular2/src/core/annotations/annotations.es6 b/modules/angular2/src/core/annotations/annotations.ts similarity index 86% rename from modules/angular2/src/core/annotations/annotations.es6 rename to modules/angular2/src/core/annotations/annotations.ts index 1cef71cfb3..e9dde7d412 100644 --- a/modules/angular2/src/core/annotations/annotations.es6 +++ b/modules/angular2/src/core/annotations/annotations.ts @@ -6,5 +6,7 @@ export { Component as ComponentAnnotation, Directive as DirectiveAnnotation, - onDestroy, onChange, onAllChangesDone + onDestroy, + onChange, + onAllChangesDone } from '../annotations_impl/annotations'; diff --git a/modules/angular2/src/core/annotations/decorators.es6 b/modules/angular2/src/core/annotations/decorators.ts similarity index 90% rename from modules/angular2/src/core/annotations/decorators.es6 rename to modules/angular2/src/core/annotations/decorators.ts index 48fed20015..f5e80b89e5 100644 --- a/modules/angular2/src/core/annotations/decorators.es6 +++ b/modules/angular2/src/core/annotations/decorators.ts @@ -1,7 +1,4 @@ -import { - ComponentAnnotation, - DirectiveAnnotation -} from './annotations'; +import {ComponentAnnotation, DirectiveAnnotation} from './annotations'; import {ViewAnnotation} from './view'; import {AncestorAnnotation, ParentAnnotation} from './visibility'; import {AttributeAnnotation, QueryAnnotation} from './di'; diff --git a/modules/angular2/src/core/annotations/di.es6 b/modules/angular2/src/core/annotations/di.ts similarity index 100% rename from modules/angular2/src/core/annotations/di.es6 rename to modules/angular2/src/core/annotations/di.ts diff --git a/modules/angular2/src/core/annotations/view.es6 b/modules/angular2/src/core/annotations/view.es6 deleted file mode 100644 index 504e1866b4..0000000000 --- a/modules/angular2/src/core/annotations/view.es6 +++ /dev/null @@ -1,3 +0,0 @@ -export { - View as ViewAnnotation, - } from '../annotations_impl/view'; diff --git a/modules/angular2/src/core/annotations/view.ts b/modules/angular2/src/core/annotations/view.ts new file mode 100644 index 0000000000..8aee85b989 --- /dev/null +++ b/modules/angular2/src/core/annotations/view.ts @@ -0,0 +1,3 @@ +export { + View as ViewAnnotation, +} from '../annotations_impl/view'; diff --git a/modules/angular2/src/core/annotations/visibility.es6 b/modules/angular2/src/core/annotations/visibility.ts similarity index 62% rename from modules/angular2/src/core/annotations/visibility.es6 rename to modules/angular2/src/core/annotations/visibility.ts index 6b768671d0..53acffc1fb 100644 --- a/modules/angular2/src/core/annotations/visibility.es6 +++ b/modules/angular2/src/core/annotations/visibility.ts @@ -1,4 +1,4 @@ export { Ancestor as AncestorAnnotation, Parent as ParentAnnotation, - } from '../annotations_impl/visibility'; +} from '../annotations_impl/visibility'; diff --git a/modules/angular2/src/core/annotations_impl/annotations.js b/modules/angular2/src/core/annotations_impl/annotations.ts similarity index 81% rename from modules/angular2/src/core/annotations_impl/annotations.js rename to modules/angular2/src/core/annotations_impl/annotations.ts index 3890bf64dc..32b9b4768a 100644 --- a/modules/angular2/src/core/annotations_impl/annotations.js +++ b/modules/angular2/src/core/annotations_impl/annotations.ts @@ -1,4 +1,4 @@ -import {CONST, normalizeBlank, isPresent} from 'angular2/src/facade/lang'; +import {CONST, normalizeBlank, isPresent, CONST_EXPR} from 'angular2/src/facade/lang'; import {ListWrapper, List} from 'angular2/src/facade/collection'; import {Injectable} from 'angular2/src/di/annotations_impl'; import {DEFAULT} from 'angular2/change_detection'; @@ -10,29 +10,38 @@ import {DEFAULT} from 'angular2/change_detection'; * * {@link Directive}s with an embedded view are called {@link Component}s. * - * A directive consists of a single directive annotation and a controller class. When the directive's `selector` matches + * A directive consists of a single directive annotation and a controller class. When the + * directive's `selector` matches * elements in the DOM, the following steps occur: * - * 1. For each directive, the `ElementInjector` attempts to resolve the directive's constructor arguments. - * 2. Angular instantiates directives for each matched element using `ElementInjector` in a depth-first order, + * 1. For each directive, the `ElementInjector` attempts to resolve the directive's constructor + * arguments. + * 2. Angular instantiates directives for each matched element using `ElementInjector` in a + * depth-first order, * as declared in the HTML. * * ## Understanding How Injection Works * * There are three stages of injection resolution. * - *Pre-existing Injectors*: - * - The terminal {@link Injector} cannot resolve dependencies. It either throws an error or, if the dependency was + * - The terminal {@link Injector} cannot resolve dependencies. It either throws an error or, if + * the dependency was * specified as `@Optional`, returns `null`. - * - The platform injector resolves browser singleton resources, such as: cookies, title, location, and others. - * - *Component Injectors*: Each component instance has its own {@link Injector}, and they follow the same parent-child hierarchy + * - The platform injector resolves browser singleton resources, such as: cookies, title, + * location, and others. + * - *Component Injectors*: Each component instance has its own {@link Injector}, and they follow + * the same parent-child hierarchy * as the component instances in the DOM. - * - *Element Injectors*: Each component instance has a Shadow DOM. Within the Shadow DOM each element has an `ElementInjector` + * - *Element Injectors*: Each component instance has a Shadow DOM. Within the Shadow DOM each + * element has an `ElementInjector` * which follow the same parent-child hierarchy as the DOM elements themselves. * - * When a template is instantiated, it also must instantiate the corresponding directives in a depth-first order. The + * When a template is instantiated, it also must instantiate the corresponding directives in a + * depth-first order. The * current `ElementInjector` resolves the constructor dependencies for each directive. * - * Angular then resolves dependencies as follows, according to the order in which they appear in the {@link View}: + * Angular then resolves dependencies as follows, according to the order in which they appear in the + * {@link View}: * * 1. Dependencies on the current element * 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM boundary @@ -40,26 +49,34 @@ import {DEFAULT} from 'angular2/change_detection'; * 4. Dependencies on pre-existing injectors * * - * The `ElementInjector` can inject other directives, element-specific special objects, or it can delegate to the parent + * The `ElementInjector` can inject other directives, element-specific special objects, or it can + * delegate to the parent * injector. * * To inject other directives, declare the constructor parameter as: * - `directive:DirectiveType`: a directive on the current element only - * - `@Ancestor() directive:DirectiveType`: any directive that matches the type between the current element and the - * Shadow DOM root. Current element is not included in the resolution, therefore even if it could resolve it, it will + * - `@Ancestor() directive:DirectiveType`: any directive that matches the type between the current + * element and the + * Shadow DOM root. Current element is not included in the resolution, therefore even if it could + * resolve it, it will * be ignored. - * - `@Parent() directive:DirectiveType`: any directive that matches the type on a direct parent element only. - * - `@Query(DirectiveType) query:QueryList`: A live collection of direct child directives. - * - `@QueryDescendants(DirectiveType) query:QueryList`: A live collection of any child directives. + * - `@Parent() directive:DirectiveType`: any directive that matches the type on a direct parent + * element only. + * - `@Query(DirectiveType) query:QueryList`: A live collection of direct child + * directives. + * - `@QueryDescendants(DirectiveType) query:QueryList`: A live collection of any + * child directives. * * To inject element-specific special objects, declare the constructor parameter as: * - `element: ElementRef` to obtain a reference to logical element in the view. - * - `viewContainer: ViewContainerRef` to control child template instantiation, for {@link Directive} directives only + * - `viewContainer: ViewContainerRef` to control child template instantiation, for {@link + * Directive} directives only * - `bindingPropagation: BindingPropagation` to control change detection in a more granular way. * * ## Example * - * The following example demonstrates how dependency injection resolves constructor arguments in practice. + * The following example demonstrates how dependency injection resolves constructor arguments in + * practice. * * * Assume this HTML template: @@ -100,7 +117,8 @@ import {DEFAULT} from 'angular2/change_detection'; * * ### No injection * - * Here the constructor is declared with no arguments, therefore nothing is injected into `MyDirective`. + * Here the constructor is declared with no arguments, therefore nothing is injected into + * `MyDirective`. * * ``` * @Directive({ selector: '[my-directive]' }) @@ -115,9 +133,11 @@ import {DEFAULT} from 'angular2/change_detection'; * * ### Component-level injection * - * Directives can inject any injectable instance from the closest component injector or any of its parents. + * Directives can inject any injectable instance from the closest component injector or any of its + * parents. * - * Here, the constructor declares a parameter, `someService`, and injects the `SomeService` type from the parent + * Here, the constructor declares a parameter, `someService`, and injects the `SomeService` type + * from the parent * component's injector. * ``` * @Directive({ selector: '[my-directive]' }) @@ -142,13 +162,16 @@ import {DEFAULT} from 'angular2/change_detection'; * } * } * ``` - * This directive would be instantiated with `Dependency` declared at the same element, in this case `dependency="3"`. + * This directive would be instantiated with `Dependency` declared at the same element, in this case + * `dependency="3"`. * * * ### Injecting a directive from a direct parent element * - * Directives can inject other directives declared on a direct parent element. By definition, a directive with a - * `@Parent` annotation does not attempt to resolve dependencies for the current element, even if this would satisfy + * Directives can inject other directives declared on a direct parent element. By definition, a + * directive with a + * `@Parent` annotation does not attempt to resolve dependencies for the current element, even if + * this would satisfy * the dependency. * * ``` @@ -159,13 +182,16 @@ import {DEFAULT} from 'angular2/change_detection'; * } * } * ``` - * This directive would be instantiated with `Dependency` declared at the parent element, in this case `dependency="2"`. + * This directive would be instantiated with `Dependency` declared at the parent element, in this + * case `dependency="2"`. * * * ### Injecting a directive from any ancestor elements * - * Directives can inject other directives declared on any ancestor element (in the current Shadow DOM), i.e. on the - * parent element and its parents. By definition, a directive with an `@Ancestor` annotation does not attempt to + * Directives can inject other directives declared on any ancestor element (in the current Shadow + * DOM), i.e. on the + * parent element and its parents. By definition, a directive with an `@Ancestor` annotation does + * not attempt to * resolve dependencies for the current element, even if this would satisfy the dependency. * * ``` @@ -178,16 +204,19 @@ import {DEFAULT} from 'angular2/change_detection'; * ``` * * Unlike the `@Parent` which only checks the parent, `@Ancestor` checks the parent, as well as its - * parents recursively. If `dependency="2"` didn't exist on the direct parent, this injection would have returned + * parents recursively. If `dependency="2"` didn't exist on the direct parent, this injection would + * have returned * `dependency="1"`. * * * ### Injecting a live collection of direct child directives * * - * A directive can also query for other child directives. Since parent directives are instantiated before child + * A directive can also query for other child directives. Since parent directives are instantiated + * before child * directives, a directive can't simply inject the list of child directives. Instead, the directive - * injects a {@link QueryList}, which updates its contents as children are added, removed, or moved by a directive + * injects a {@link QueryList}, which updates its contents as children are added, removed, or moved + * by a directive * that uses a {@link ViewContainerRef} such as a `for`, an `if`, or a `switch`. * * ``` @@ -198,7 +227,8 @@ import {DEFAULT} from 'angular2/change_detection'; * } * ``` * - * This directive would be instantiated with a {@link QueryList} which contains `Dependency` 4 and 6. Here, `Dependency` + * This directive would be instantiated with a {@link QueryList} which contains `Dependency` 4 and + * 6. Here, `Dependency` * 5 would not be included, because it is not a direct child. * * ### Injecting a live collection of descendant directives @@ -219,9 +249,12 @@ import {DEFAULT} from 'angular2/change_detection'; * * ### Optional injection * - * The normal behavior of directives is to return an error when a specified dependency cannot be resolved. If you - * would like to inject `null` on unresolved dependency instead, you can annotate that dependency with `@Optional()`. - * This explicitly permits the author of a template to treat some of the surrounding directives as optional. + * The normal behavior of directives is to return an error when a specified dependency cannot be + * resolved. If you + * would like to inject `null` on unresolved dependency instead, you can annotate that dependency + * with `@Optional()`. + * This explicitly permits the author of a template to treat some of the surrounding directives as + * optional. * * ``` * @Directive({ selector: '[my-directive]' }) @@ -231,7 +264,8 @@ import {DEFAULT} from 'angular2/change_detection'; * } * ``` * - * This directive would be instantiated with a `Dependency` directive found on the current element. If none can be + * This directive would be instantiated with a `Dependency` directive found on the current element. + * If none can be * found, the injector supplies `null` instead of throwing an error. * * ## Example @@ -269,24 +303,31 @@ import {DEFAULT} from 'angular2/change_detection'; * } * } * ``` - * In our HTML template, we can then add this behavior to a `
` or any other element with the `tooltip` selector, + * In our HTML template, we can then add this behavior to a `
` or any other element with the + * `tooltip` selector, * like so: * * ``` *
* ``` * - * Directives can also control the instantiation, destruction, and positioning of inline template elements: + * Directives can also control the instantiation, destruction, and positioning of inline template + * elements: * - * A directive uses a {@link ViewContainerRef} to instantiate, insert, move, and destroy views at runtime. - * The {@link ViewContainerRef} is created as a result of `