From 1beadb86075d94197eb28c73c4811bce56421432 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Mon, 18 May 2015 11:57:20 -0700 Subject: [PATCH] =?UTF-8?q?refactor(render):=20ts=E2=80=99ify=20render=20a?= =?UTF-8?q?pi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/angular2/globals.ts | 7 + modules/angular2/src/core/compiler/view.js | 4 +- modules/angular2/src/core/zone/ng_zone.cjs | 17 - .../src/core/zone/{ng_zone.es6 => ng_zone.ts} | 77 +++-- modules/angular2/src/dom/browser_adapter.ts | 2 +- modules/angular2/src/dom/dom_adapter.ts | 4 +- .../angular2/src/render/{api.js => api.ts} | 159 +++++----- ...{compile_control.js => compile_control.ts} | 22 +- ...{compile_element.js => compile_element.ts} | 62 ++-- ...ompile_pipeline.js => compile_pipeline.ts} | 20 +- .../{compile_step.js => compile_step.ts} | 5 +- ...tep_factory.js => compile_step_factory.ts} | 4 +- .../dom/compiler/{compiler.js => compiler.ts} | 32 +- ...irective_parser.js => directive_parser.ts} | 76 ++--- ...g_parser.js => property_binding_parser.ts} | 58 ++-- .../dom/compiler/{selector.js => selector.ts} | 298 ++++++++++-------- ...{template_loader.js => template_loader.ts} | 10 +- ...parser.js => text_interpolation_parser.ts} | 13 +- .../{view_splitter.js => view_splitter.ts} | 37 +-- .../src/render/dom/{convert.js => convert.ts} | 24 +- .../dom/{dom_renderer.js => dom_renderer.ts} | 91 +++--- .../{event_manager.js => event_manager.ts} | 50 ++- .../{hammer_common.js => hammer_common.ts} | 4 +- ...hammer_gestures.es6 => hammer_gestures.ts} | 19 +- .../events/{key_events.js => key_events.ts} | 58 ++-- .../{content_tag.js => content_tag.ts} | 36 +-- ...=> emulated_scoped_shadow_dom_strategy.ts} | 25 +- ... emulated_unscoped_shadow_dom_strategy.ts} | 12 +- .../shadow_dom/{light_dom.js => light_dom.ts} | 52 ++- ...ategy.js => native_shadow_dom_strategy.ts} | 6 +- .../{shadow_css.js => shadow_css.ts} | 85 +++-- ...ile_step.js => shadow_dom_compile_step.ts} | 22 +- ...dom_strategy.js => shadow_dom_strategy.ts} | 16 +- .../{style_inliner.js => style_inliner.ts} | 57 ++-- ..._url_resolver.js => style_url_resolver.ts} | 6 +- .../dom/shadow_dom/{util.js => util.ts} | 0 .../src/render/dom/{util.js => util.ts} | 16 +- .../{element_binder.js => element_binder.ts} | 16 +- ..._factory.js => property_setter_factory.ts} | 40 ++- .../dom/view/{proto_view.js => proto_view.ts} | 23 +- ..._view_builder.js => proto_view_builder.ts} | 132 ++++---- .../src/render/dom/view/{view.js => view.ts} | 55 ++-- .../{view_container.js => view_container.ts} | 7 +- modules/angular2/src/services/title.js | 12 - modules/angular2/src/services/title.ts | 7 + .../{url_resolver.js => url_resolver.ts} | 20 +- .../angular2/src/services/{xhr.js => xhr.ts} | 4 +- .../services/{xhr_impl.es6 => xhr_impl.ts} | 6 +- modules/angular2/src/util/decorators.ts | 3 +- .../dom/compiler/compiler_common_tests.js | 3 +- .../dom/compiler/directive_parser_spec.js | 6 +- .../test/render/dom/compiler/pipeline_spec.js | 12 +- .../compiler/property_binding_parser_spec.js | 7 +- .../angular2/test/render/dom/dom_testbed.js | 7 +- .../dom/shadow_dom/style_inliner_spec.js | 39 ++- tools/broccoli/trees/node_tree.ts | 1 - 56 files changed, 938 insertions(+), 948 deletions(-) delete mode 100644 modules/angular2/src/core/zone/ng_zone.cjs rename modules/angular2/src/core/zone/{ng_zone.es6 => ng_zone.ts} (75%) rename modules/angular2/src/render/{api.js => api.ts} (61%) rename modules/angular2/src/render/dom/compiler/{compile_control.js => compile_control.ts} (76%) rename modules/angular2/src/render/dom/compiler/{compile_element.js => compile_element.ts} (69%) rename modules/angular2/src/render/dom/compiler/{compile_pipeline.js => compile_pipeline.ts} (78%) rename modules/angular2/src/render/dom/compiler/{compile_step.js => compile_step.ts} (57%) rename modules/angular2/src/render/dom/compiler/{compile_step_factory.js => compile_step_factory.ts} (96%) rename modules/angular2/src/render/dom/compiler/{compiler.js => compiler.ts} (70%) rename modules/angular2/src/render/dom/compiler/{directive_parser.js => directive_parser.ts} (74%) rename modules/angular2/src/render/dom/compiler/{property_binding_parser.js => property_binding_parser.ts} (62%) rename modules/angular2/src/render/dom/compiler/{selector.js => selector.ts} (51%) rename modules/angular2/src/render/dom/compiler/{template_loader.js => template_loader.ts} (83%) rename modules/angular2/src/render/dom/compiler/{text_interpolation_parser.js => text_interpolation_parser.ts} (76%) rename modules/angular2/src/render/dom/compiler/{view_splitter.js => view_splitter.ts} (81%) rename modules/angular2/src/render/dom/{convert.js => convert.ts} (62%) rename modules/angular2/src/render/dom/{dom_renderer.js => dom_renderer.ts} (76%) rename modules/angular2/src/render/dom/events/{event_manager.js => event_manager.ts} (68%) rename modules/angular2/src/render/dom/events/{hammer_common.js => hammer_common.ts} (96%) rename modules/angular2/src/render/dom/events/{hammer_gestures.es6 => hammer_gestures.ts} (61%) rename modules/angular2/src/render/dom/events/{key_events.js => key_events.ts} (65%) rename modules/angular2/src/render/dom/shadow_dom/{content_tag.js => content_tag.ts} (68%) rename modules/angular2/src/render/dom/shadow_dom/{emulated_scoped_shadow_dom_strategy.js => emulated_scoped_shadow_dom_strategy.ts} (77%) rename modules/angular2/src/render/dom/shadow_dom/{emulated_unscoped_shadow_dom_strategy.js => emulated_unscoped_shadow_dom_strategy.ts} (83%) rename modules/angular2/src/render/dom/shadow_dom/{light_dom.js => light_dom.ts} (74%) rename modules/angular2/src/render/dom/shadow_dom/{native_shadow_dom_strategy.js => native_shadow_dom_strategy.ts} (83%) rename modules/angular2/src/render/dom/shadow_dom/{shadow_css.js => shadow_css.ts} (87%) rename modules/angular2/src/render/dom/shadow_dom/{shadow_dom_compile_step.js => shadow_dom_compile_step.ts} (79%) rename modules/angular2/src/render/dom/shadow_dom/{shadow_dom_strategy.js => shadow_dom_strategy.ts} (58%) rename modules/angular2/src/render/dom/shadow_dom/{style_inliner.js => style_inliner.ts} (72%) rename modules/angular2/src/render/dom/shadow_dom/{style_url_resolver.js => style_url_resolver.ts} (89%) rename modules/angular2/src/render/dom/shadow_dom/{util.js => util.ts} (100%) rename modules/angular2/src/render/dom/{util.js => util.ts} (63%) rename modules/angular2/src/render/dom/view/{element_binder.js => element_binder.ts} (80%) rename modules/angular2/src/render/dom/view/{property_setter_factory.js => property_setter_factory.ts} (84%) rename modules/angular2/src/render/dom/view/{proto_view.js => proto_view.ts} (54%) rename modules/angular2/src/render/dom/view/{proto_view_builder.js => proto_view_builder.ts} (74%) rename modules/angular2/src/render/dom/view/{view.js => view.ts} (63%) rename modules/angular2/src/render/dom/view/{view_container.js => view_container.ts} (84%) delete mode 100644 modules/angular2/src/services/title.js create mode 100644 modules/angular2/src/services/title.ts rename modules/angular2/src/services/{url_resolver.js => url_resolver.ts} (82%) rename modules/angular2/src/services/{xhr.js => xhr.ts} (55%) rename modules/angular2/src/services/{xhr_impl.es6 => xhr_impl.ts} (80%) diff --git a/modules/angular2/globals.ts b/modules/angular2/globals.ts index 85af4a7159..781d3e03b1 100644 --- a/modules/angular2/globals.ts +++ b/modules/angular2/globals.ts @@ -2,12 +2,17 @@ * This file contains declarations of global symbols we reference in our code */ +/// +/// + declare var assert: any; declare var global: Window; type int = number; interface List extends Array {} +interface StringMap extends Object {} + interface Window { Object: typeof Object; Array: typeof Array; @@ -20,4 +25,6 @@ interface Window { assert: typeof assert; gc(): void; Reflect: any; + zone: Zone; + Hammer: HammerStatic; } diff --git a/modules/angular2/src/core/compiler/view.js b/modules/angular2/src/core/compiler/view.js index 8a26685adb..73b98984c9 100644 --- a/modules/angular2/src/core/compiler/view.js +++ b/modules/angular2/src/core/compiler/view.js @@ -6,6 +6,7 @@ import {ProtoElementInjector, ElementInjector, PreBuiltObjects, DirectiveBinding import {ElementBinder} from './element_binder'; import {IMPLEMENTS, int, isPresent, isBlank, BaseException} from 'angular2/src/facade/lang'; import * as renderApi from 'angular2/src/render/api'; +import {EventDispatcher} from 'angular2/src/render/api'; export class AppViewContainer { views: List; @@ -21,8 +22,7 @@ export class AppViewContainer { * */ @IMPLEMENTS(ChangeDispatcher) -// TODO(tbosch): this is not supported in dart2js (no '.' is allowed) -// @IMPLEMENTS(renderApi.EventDispatcher) +@IMPLEMENTS(EventDispatcher) export class AppView { render:renderApi.RenderViewRef; /// This list matches the _nodes list. It is sparse, since only Elements have ElementInjector diff --git a/modules/angular2/src/core/zone/ng_zone.cjs b/modules/angular2/src/core/zone/ng_zone.cjs deleted file mode 100644 index 12173d7986..0000000000 --- a/modules/angular2/src/core/zone/ng_zone.cjs +++ /dev/null @@ -1,17 +0,0 @@ -// TODO(vicb): implement this class properly -// The current stub implementation is only here to please cjs tests -export class NgZone { - constructor({enableLongStackTrace}) { - } - - initCallbacks({onTurnStart, onTurnDone, onScheduleMicrotask, onErrorHandler} = {}) { - } - - run(fn) { - return fn(); - } - - runOutsideAngular(fn) { - return fn(); - } -} diff --git a/modules/angular2/src/core/zone/ng_zone.es6 b/modules/angular2/src/core/zone/ng_zone.ts similarity index 75% rename from modules/angular2/src/core/zone/ng_zone.es6 rename to modules/angular2/src/core/zone/ng_zone.ts index 5cb1bac219..dfbd3131e4 100644 --- a/modules/angular2/src/core/zone/ng_zone.es6 +++ b/modules/angular2/src/core/zone/ng_zone.ts @@ -19,12 +19,12 @@ export class NgZone { // onTurnDone hook at the end of the current VM turn. _innerZone; - _onTurnStart:Function; - _onTurnDone:Function; - _onErrorHandler:Function; + _onTurnStart: () => void; + _onTurnDone: () => void; + _onErrorHandler: (error, stack) => void; // Number of microtasks pending from _innerZone (& descendants) - _pendingMicrotask: number; + _pendingMicrotasks: number; // Whether some code has been executed in the _innerZone (& descendants) in the current turn _hasExecutedCodeInInnerZone: boolean; // run() call depth in _mountZone. 0 at the end of a macrotask @@ -32,6 +32,10 @@ export class NgZone { // zone.run(() => {}); // nested call -> in-turn // }); _nestedRun: number; + + // TODO(vicb): implement this class properly for node.js environment + // This disabled flag is only here to please cjs tests + _disabled: boolean; /** * Associates with this @@ -50,19 +54,31 @@ export class NgZone { this._pendingMicrotasks = 0; this._hasExecutedCodeInInnerZone = false; this._nestedRun = 0; - - this._mountZone = global.zone; - this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace) + + if (global.zone) { + this._disabled = false; + this._mountZone = global.zone; + this._innerZone = this._createInnerZone(this._mountZone, enableLongStackTrace) + } else { + this._disabled = true; + this._mountZone = null; + } } /** * Initializes the zone hooks. * - * @param {Function} onTurnStart called before code executes in the inner zone for each VM turn - * @param {Function} onTurnDone called at the end of a VM turn if code has executed in the inner zone - * @param {Function} onErrorHandler called when an exception is thrown by a macro or micro task + * @param {() => void} onTurnStart called before code executes in the inner zone for each VM turn + * @param {() => void} onTurnDone called at the end of a VM turn if code has executed in the inner + * zone + * @param {(error, stack) => void} onErrorHandler called when an exception is thrown by a macro or + * micro task */ - initCallbacks({onTurnStart, onTurnDone, onErrorHandler} = {}) { + initCallbacks({onTurnStart, onTurnDone, onErrorHandler}: { + onTurnStart?: () => void, + onTurnDone?: () => void, + onErrorHandler?: (error, stack) => void + } = {}) { this._onTurnStart = normalizeBlank(onTurnStart); this._onTurnDone = normalizeBlank(onTurnDone); this._onErrorHandler = normalizeBlank(onErrorHandler); @@ -78,12 +94,17 @@ export class NgZone { * var zone: NgZone = [ref to the application zone]; * * zone.run(() => { - * // the change detection will run after this function and the microtasks it enqueues have executed. + * // the change detection will run after this function and the microtasks it enqueues have + * executed. * }); * ``` */ - run(fn) { - return this._innerZone.run(fn); + run(fn) { + if (this._disabled) { + return fn(); + } else { + return this._innerZone.run(fn); + } } /** @@ -102,8 +123,12 @@ export class NgZone { * }); * ``` */ - runOutsideAngular(fn) { - return this._mountZone.run(fn); + runOutsideAngular(fn) { + if (this._disabled) { + return fn(); + } else { + return this._mountZone.run(fn); + } } _createInnerZone(zone, enableLongStackTrace) { @@ -111,21 +136,15 @@ export class NgZone { var errorHandling; if (enableLongStackTrace) { - errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, { - onError: function (e) { - ngZone._onError(this, e) - } - }); + errorHandling = StringMapWrapper.merge(Zone.longStackTraceZone, + {onError: function(e) { ngZone._onError(this, e) }}); } else { errorHandling = { - onError: function (e) { - ngZone._onError(this, e) - } + onError: function(e) { ngZone._onError(this, e) } }; } - return zone - .fork(errorHandling) + return zone.fork(errorHandling) .fork({ '$run': function(parentRun) { return function() { @@ -140,8 +159,10 @@ export class NgZone { return parentRun.apply(this, arguments); } finally { ngZone._nestedRun--; - // If there are no more pending microtasks, we are at the end of a VM turn (or in onTurnStart) - // _nestedRun will be 0 at the end of a macrotasks (it could be > 0 when there are nested calls + // If there are no more pending microtasks, we are at the end of a VM turn (or in + // onTurnStart) + // _nestedRun will be 0 at the end of a macrotasks (it could be > 0 when there are + // nested calls // to run()). if (ngZone._pendingMicrotasks == 0 && ngZone._nestedRun == 0) { if (ngZone._onTurnDone && ngZone._hasExecutedCodeInInnerZone) { diff --git a/modules/angular2/src/dom/browser_adapter.ts b/modules/angular2/src/dom/browser_adapter.ts index 2e90385203..11da0887df 100644 --- a/modules/angular2/src/dom/browser_adapter.ts +++ b/modules/angular2/src/dom/browser_adapter.ts @@ -273,7 +273,7 @@ defaultDoc() { getBoundingClientRect(el) { return el.getBoundingClientRect(); } -getTitle() { +getTitle(): string { return document.title; } setTitle(newTitle: string) { diff --git a/modules/angular2/src/dom/dom_adapter.ts b/modules/angular2/src/dom/dom_adapter.ts index e39227e2c3..4e3ea3a0a9 100644 --- a/modules/angular2/src/dom/dom_adapter.ts +++ b/modules/angular2/src/dom/dom_adapter.ts @@ -81,7 +81,7 @@ export class DomAdapter { removeStyle(element, stylename: string) { throw _abstract(); } getStyle(element, stylename: string) { throw _abstract(); } tagName(element): string { throw _abstract(); } - attributeMap(element) { throw _abstract(); } + attributeMap(element): Map { throw _abstract(); } hasAttribute(element, attribute: string): boolean { throw _abstract(); } getAttribute(element, attribute: string): string { throw _abstract(); } setAttribute(element, name: string, value: string) { throw _abstract(); } @@ -90,7 +90,7 @@ export class DomAdapter { createHtmlDocument() { throw _abstract(); } defaultDoc(): any { throw _abstract(); } getBoundingClientRect(el) { throw _abstract(); } - getTitle() { throw _abstract(); } + getTitle(): string { throw _abstract(); } setTitle(newTitle: string) { throw _abstract(); } elementMatches(n, selector: string): boolean { throw _abstract(); } isTemplateElement(el: any): boolean { throw _abstract(); } diff --git a/modules/angular2/src/render/api.js b/modules/angular2/src/render/api.ts similarity index 61% rename from modules/angular2/src/render/api.js rename to modules/angular2/src/render/api.ts index b731ebdf30..302516f428 100644 --- a/modules/angular2/src/render/api.js +++ b/modules/angular2/src/render/api.ts @@ -20,21 +20,21 @@ import {ASTWithSource} from 'angular2/change_detection'; * its output will be stored in precompiled templates. */ export class EventBinding { - fullName: string; // name/target:name, e.g "click", "window:resize" + fullName: string; // name/target:name, e.g "click", "window:resize" source: ASTWithSource; - constructor(fullName :string, source: ASTWithSource) { + constructor(fullName: string, source: ASTWithSource) { this.fullName = fullName; this.source = source; } } export class ElementBinder { - index:number; - parentIndex:number; - distanceToParent:number; - directives:List; - nestedProtoView:ProtoViewDto; + index: number; + parentIndex: number; + distanceToParent: number; + directives: List; + nestedProtoView: ProtoViewDto; propertyBindings: Map; variableBindings: Map; // Note: this contains a preprocessed AST @@ -50,7 +50,11 @@ export class ElementBinder { propertyBindings, variableBindings, eventBindings, textBindings, readAttributes - }) { + }:{index?:number, parentIndex?:number, distanceToParent?:number, + directives?:List, nestedProtoView?:ProtoViewDto, + propertyBindings?:Map, variableBindings?:Map, + eventBindings?:List, textBindings?:List, + readAttributes?:Map}={}) { this.index = index; this.parentIndex = parentIndex; this.distanceToParent = distanceToParent; @@ -66,7 +70,7 @@ export class ElementBinder { export class DirectiveBinder { // Index into the array of directives in the View instance - directiveIndex:any; + directiveIndex: number; propertyBindings: Map; // Note: this contains a preprocessed AST // that replaced the values that should be extracted from the element @@ -75,6 +79,9 @@ export class DirectiveBinder { hostPropertyBindings: Map; constructor({ directiveIndex, propertyBindings, eventBindings, hostPropertyBindings + }:{ + directiveIndex?:number, propertyBindings?:Map, + eventBindings?:List, hostPropertyBindings?:Map }) { this.directiveIndex = directiveIndex; this.propertyBindings = propertyBindings; @@ -96,11 +103,16 @@ export class ProtoViewDto { static get EMBEDDED_VIEW_TYPE() { return 2; } render: RenderProtoViewRef; - elementBinders:List; + elementBinders: List; variableBindings: Map; type: number; - constructor({render, elementBinders, variableBindings, type}={}) { + constructor({ + render, elementBinders, variableBindings, type + }:{ + render?:RenderProtoViewRef, elementBinders?:List, + variableBindings?:Map, type?:number + }) { this.render = render; this.elementBinders = elementBinders; this.variableBindings = variableBindings; @@ -111,25 +123,31 @@ export class ProtoViewDto { export class DirectiveMetadata { static get DIRECTIVE_TYPE() { return 0; } static get COMPONENT_TYPE() { return 1; } - id:any; - selector:string; - compileChildren:boolean; - events:List; - hostListeners:Map; - hostProperties:Map; - hostAttributes:Map; - hostActions:Map; - properties:Map; - readAttributes:List; - type:number; - callOnDestroy:boolean; - callOnChange:boolean; - callOnAllChangesDone:boolean; + id: any; + selector: string; + compileChildren: boolean; + events: List; + hostListeners: Map; + hostProperties: Map; + hostAttributes: Map; + hostActions: Map; + properties: Map; + readAttributes: List; + type: number; + callOnDestroy: boolean; + callOnChange: boolean; + callOnAllChangesDone: boolean; changeDetection: string; - constructor({id, selector, compileChildren, events, hostListeners, hostProperties, + constructor({ + id, selector, compileChildren, events, hostListeners, hostProperties, hostAttributes, hostActions, properties, readAttributes, type, callOnDestroy, callOnChange, callOnAllChangesDone, changeDetection + }:{ + id?:string, selector?:string, compileChildren?:boolean, events?:List, hostListeners?:Map, hostProperties?:Map, + hostAttributes?:Map, hostActions?:Map, properties?:Map, readAttributes?:List, type?:number, + callOnDestroy?:boolean, callOnChange?:boolean, callOnAllChangesDone?:boolean, + changeDetection?:string }) { this.id = id; this.selector = selector; @@ -150,12 +168,10 @@ export class DirectiveMetadata { } // An opaque reference to a DomProtoView -export class RenderProtoViewRef { -} +export class RenderProtoViewRef {} // An opaque reference to a DomView -export class RenderViewRef { -} +export class RenderViewRef {} export class ViewDefinition { componentId: string; @@ -163,7 +179,11 @@ export class ViewDefinition { template: string; directives: List; - constructor({componentId, absUrl, template, directives}) { + constructor({ + componentId, absUrl, template, directives + }:{ + componentId?:string, absUrl?:string, template?:string, directives?:List + }) { this.componentId = componentId; this.absUrl = absUrl; this.template = template; @@ -175,123 +195,120 @@ export class RenderCompiler { /** * Creats a ProtoViewDto that contains a single nested component with the given componentId. */ - compileHost(componentId):Promise { return null; } + compileHost(directiveMetadata: DirectiveMetadata): Promise { return null; } /** * Compiles a single DomProtoView. Non recursive so that * we don't need to serialize all possible components over the wire, * but only the needed ones based on previous calls. */ - compile(template:ViewDefinition):Promise { return null; } + compile(template: ViewDefinition): Promise { return null; } } export class Renderer { /** * Creates a root host view that includes the given element. - * @param {RenderProtoViewRef} hostProtoViewRef a RenderProtoViewRef of type ProtoViewDto.HOST_VIEW_TYPE - * @param {any} hostElementSelector css selector for the host element (will be queried against the main document) + * @param {RenderProtoViewRef} hostProtoViewRef a RenderProtoViewRef of type + * ProtoViewDto.HOST_VIEW_TYPE + * @param {any} hostElementSelector css selector for the host element (will be queried against the + * main document) * @return {RenderViewRef} the created view */ - createRootHostView(hostProtoViewRef:RenderProtoViewRef, hostElementSelector:string):RenderViewRef { + createRootHostView(hostProtoViewRef: RenderProtoViewRef, + hostElementSelector: string): RenderViewRef { return null; } /** * Detaches a free host view's element from the DOM. */ - detachFreeHostView(parentHostViewRef:RenderViewRef, hostViewRef:RenderViewRef) { - } + detachFreeHostView(parentHostViewRef: RenderViewRef, hostViewRef: RenderViewRef) {} /** * Creates a regular view out of the given ProtoView */ - createView(protoViewRef:RenderProtoViewRef):RenderViewRef { - return null; - } + createView(protoViewRef: RenderProtoViewRef): RenderViewRef { return null; } /** * Destroys the given view after it has been dehydrated and detached */ - destroyView(viewRef:RenderViewRef) { - } + destroyView(viewRef: RenderViewRef) {} /** * Attaches a componentView into the given hostView at the given element */ - attachComponentView(hostViewRef:RenderViewRef, elementIndex:number, componentViewRef:RenderViewRef) { - } + attachComponentView(hostViewRef: RenderViewRef, elementIndex: number, + componentViewRef: RenderViewRef) {} /** * Detaches a componentView into the given hostView at the given element */ - detachComponentView(hostViewRef:RenderViewRef, boundElementIndex:number, componentViewRef:RenderViewRef) { - } + detachComponentView(hostViewRef: RenderViewRef, boundElementIndex: number, + componentViewRef: RenderViewRef) {} /** - * Attaches a view into a ViewContainer (in the given parentView at the given element) at the given index. + * Attaches a view into a ViewContainer (in the given parentView at the given element) at the + * given index. */ - attachViewInContainer(parentViewRef:RenderViewRef, boundElementIndex:number, atIndex:number, viewRef:RenderViewRef) { - } + attachViewInContainer(parentViewRef: RenderViewRef, boundElementIndex: number, atIndex: number, + viewRef: RenderViewRef) {} /** - * Detaches a view into a ViewContainer (in the given parentView at the given element) at the given index. + * Detaches a view into a ViewContainer (in the given parentView at the given element) at the + * given index. */ // TODO(tbosch): this should return a promise as it can be animated! - detachViewInContainer(parentViewRef:RenderViewRef, boundElementIndex:number, atIndex:number, viewRef:RenderViewRef) { - } + detachViewInContainer(parentViewRef: RenderViewRef, boundElementIndex: number, atIndex: number, + viewRef: RenderViewRef) {} /** - * Hydrates a view after it has been attached. Hydration/dehydration is used for reusing views inside of the view pool. + * Hydrates a view after it has been attached. Hydration/dehydration is used for reusing views + * inside of the view pool. */ - hydrateView(viewRef:RenderViewRef) { - } + hydrateView(viewRef: RenderViewRef) {} /** - * Dehydrates a view after it has been attached. Hydration/dehydration is used for reusing views inside of the view pool. + * Dehydrates a view after it has been attached. Hydration/dehydration is used for reusing views + * inside of the view pool. */ - dehydrateView(viewRef:RenderViewRef) { - } + dehydrateView(viewRef: RenderViewRef) {} /** * Sets a property on an element. * Note: This will fail if the property was not mentioned previously as a host property * in the ProtoView */ - setElementProperty(viewRef:RenderViewRef, elementIndex:number, propertyName:string, propertyValue:any):void { - } + setElementProperty(viewRef: RenderViewRef, elementIndex: number, propertyName: string, + propertyValue: any) {} /** * Calls an action. * Note: This will fail if the action was not mentioned previously as a host action * in the ProtoView */ - callAction(viewRef:RenderViewRef, elementIndex:number, actionExpression:string, actionArgs:any):void { - } + callAction(viewRef: RenderViewRef, elementIndex: number, actionExpression: string, + actionArgs: any) {} /** * Sets the value of a text node. */ - setText(viewRef:RenderViewRef, textNodeIndex:number, text:string):void { - } + setText(viewRef: RenderViewRef, textNodeIndex: number, text: string) {} /** * Sets the dispatcher for all events of the given view */ - setEventDispatcher(viewRef:RenderViewRef, dispatcher:any/*api.EventDispatcher*/):void { - } + setEventDispatcher(viewRef: RenderViewRef, dispatcher: EventDispatcher) {} } /** * A dispatcher for all events happening in a view. */ -export class EventDispatcher { +export interface EventDispatcher { /** * Called when an event was triggered for a on-* attribute on an element. * @param {Map} locals Locals to be used to evaluate the * event expressions */ - dispatchEvent( - elementIndex:number, eventName:string, locals:Map - ):void {} + dispatchEvent(elementIndex: number, eventName: string, locals: Map); } diff --git a/modules/angular2/src/render/dom/compiler/compile_control.js b/modules/angular2/src/render/dom/compiler/compile_control.ts similarity index 76% rename from modules/angular2/src/render/dom/compiler/compile_control.js rename to modules/angular2/src/render/dom/compiler/compile_control.ts index cff660bac0..220d3ae6dd 100644 --- a/modules/angular2/src/render/dom/compiler/compile_control.js +++ b/modules/angular2/src/render/dom/compiler/compile_control.ts @@ -8,9 +8,9 @@ import {CompileStep} from './compile_step'; * Right now it only allows to add a parent element. */ export class CompileControl { - _steps:List; - _currentStepIndex:number; - _parent:CompileElement; + _steps: List; + _currentStepIndex: number; + _parent: CompileElement; _results; _additionalChildren; _ignoreCurrentElement: boolean; @@ -24,16 +24,14 @@ export class CompileControl { } // only public so that it can be used by compile_pipeline - internalProcess(results, startStepIndex, parent:CompileElement, current:CompileElement) { + internalProcess(results, startStepIndex, parent: CompileElement, current: CompileElement) { this._results = results; var previousStepIndex = this._currentStepIndex; var previousParent = this._parent; this._ignoreCurrentElement = false; - for (var i = startStepIndex; - i < this._steps.length && !this._ignoreCurrentElement; - i++) { + for (var i = startStepIndex; i < this._steps.length && !this._ignoreCurrentElement; i++) { var step = this._steps[i]; this._parent = parent; this._currentStepIndex = i; @@ -53,12 +51,12 @@ export class CompileControl { return localAdditionalChildren; } - addParent(newElement:CompileElement) { - this.internalProcess(this._results, this._currentStepIndex+1, this._parent, newElement); + addParent(newElement: CompileElement) { + this.internalProcess(this._results, this._currentStepIndex + 1, this._parent, newElement); this._parent = newElement; } - addChild(element:CompileElement) { + addChild(element: CompileElement) { if (isBlank(this._additionalChildren)) { this._additionalChildren = ListWrapper.create(); } @@ -71,7 +69,5 @@ export class CompileControl { * When a step calls `ignoreCurrentElement`, no further steps are executed on the current * element and no `CompileElement` is added to the result list. */ - ignoreCurrentElement() { - this._ignoreCurrentElement = true; - } + ignoreCurrentElement() { this._ignoreCurrentElement = true; } } diff --git a/modules/angular2/src/render/dom/compiler/compile_element.js b/modules/angular2/src/render/dom/compiler/compile_element.ts similarity index 69% rename from modules/angular2/src/render/dom/compiler/compile_element.js rename to modules/angular2/src/render/dom/compiler/compile_element.ts index e7ebf3467b..9c41f8fd08 100644 --- a/modules/angular2/src/render/dom/compiler/compile_element.js +++ b/modules/angular2/src/render/dom/compiler/compile_element.ts @@ -1,6 +1,13 @@ import {List, Map, ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; import {DOM} from 'angular2/src/dom/dom_adapter'; -import {int, isBlank, isPresent, Type, StringJoiner, assertionsEnabled} from 'angular2/src/facade/lang'; +import { + int, + isBlank, + isPresent, + Type, + StringJoiner, + assertionsEnabled +} from 'angular2/src/facade/lang'; import {ProtoViewBuilder, ElementBinderBuilder} from '../view/proto_view_builder'; @@ -11,14 +18,15 @@ import {ProtoViewBuilder, ElementBinderBuilder} from '../view/proto_view_builder */ export class CompileElement { element; - _attrs:Map; - _classList:List; - isViewRoot:boolean; - inheritedProtoView:ProtoViewBuilder; - distanceToInheritedBinder:number; - inheritedElementBinder:ElementBinderBuilder; + _attrs: Map; + _classList: List; + isViewRoot: boolean; + inheritedProtoView: ProtoViewBuilder; + distanceToInheritedBinder: number; + inheritedElementBinder: ElementBinderBuilder; compileChildren: boolean; - elementDescription: string; // e.g. '
' : used to provide context in case of error + elementDescription: string; // e.g. '
' : used to provide context in case of + // error constructor(element, compilationUnit = '') { this.element = element; @@ -34,7 +42,7 @@ export class CompileElement { this.distanceToInheritedBinder = 0; this.compileChildren = true; // description is calculated here as compilation steps may change the element - var tplDesc = assertionsEnabled()? getElementDescription(element) : null; + var tplDesc = assertionsEnabled() ? getElementDescription(element) : null; if (compilationUnit !== '') { this.elementDescription = compilationUnit; if (isPresent(tplDesc)) this.elementDescription += ": " + tplDesc; @@ -50,7 +58,8 @@ export class CompileElement { bindElement() { if (!this.isBound()) { var parentBinder = this.inheritedElementBinder; - this.inheritedElementBinder = this.inheritedProtoView.bindElement(this.element, this.elementDescription); + this.inheritedElementBinder = + this.inheritedProtoView.bindElement(this.element, this.elementDescription); if (isPresent(parentBinder)) { this.inheritedElementBinder.setParent(parentBinder, this.distanceToInheritedBinder); } @@ -59,22 +68,18 @@ export class CompileElement { return this.inheritedElementBinder; } - refreshAttrs() { - this._attrs = null; - } + refreshAttrs() { this._attrs = null; } - attrs():Map { + attrs(): Map { if (isBlank(this._attrs)) { this._attrs = DOM.attributeMap(this.element); } return this._attrs; } - refreshClassList() { - this._classList = null; - } + refreshClassList() { this._classList = null; } - classList():List { + classList(): List { if (isBlank(this._classList)) { this._classList = ListWrapper.create(); var elClassList = DOM.classList(this.element); @@ -84,12 +89,11 @@ export class CompileElement { } return this._classList; } - } // return an HTML representation of an element start tag - without its content // this is used to give contextual information in case of errors -function getElementDescription(domElement):string { +function getElementDescription(domElement): string { var buf = new StringJoiner(); var atts = DOM.attributeMap(domElement); @@ -100,9 +104,9 @@ function getElementDescription(domElement):string { addDescriptionAttribute(buf, "id", MapWrapper.get(atts, "id")); addDescriptionAttribute(buf, "class", MapWrapper.get(atts, "class")); MapWrapper.forEach(atts, (attValue, attName) => { - if (attName !== "id" && attName !== "class") { - addDescriptionAttribute(buf, attName, attValue); - } + if (attName !== "id" && attName !== "class") { + addDescriptionAttribute(buf, attName, attValue); + } }); buf.add(">"); @@ -110,12 +114,12 @@ function getElementDescription(domElement):string { } -function addDescriptionAttribute(buffer:StringJoiner, attName:string, attValue) { +function addDescriptionAttribute(buffer: StringJoiner, attName: string, attValue) { if (isPresent(attValue)) { - if (attValue.length === 0) { - buffer.add(' ' + attName); - } else { - buffer.add(' ' + attName + '="' + attValue + '"'); - } + if (attValue.length === 0) { + buffer.add(' ' + attName); + } else { + buffer.add(' ' + attName + '="' + attValue + '"'); + } } } diff --git a/modules/angular2/src/render/dom/compiler/compile_pipeline.js b/modules/angular2/src/render/dom/compiler/compile_pipeline.ts similarity index 78% rename from modules/angular2/src/render/dom/compiler/compile_pipeline.js rename to modules/angular2/src/render/dom/compiler/compile_pipeline.ts index d8e4e15e19..36783edf20 100644 --- a/modules/angular2/src/render/dom/compiler/compile_pipeline.js +++ b/modules/angular2/src/render/dom/compiler/compile_pipeline.ts @@ -12,12 +12,11 @@ import {ProtoViewDto} from '../../api'; * all elements in a template. */ export class CompilePipeline { - _control:CompileControl; - constructor(steps:List) { - this._control = new CompileControl(steps); - } + _control: CompileControl; + constructor(steps: List) { this._control = new CompileControl(steps); } - process(rootElement, protoViewType:number = null, compilationCtxtDescription:string = ''):List { + process(rootElement, protoViewType: number = null, + compilationCtxtDescription: string = ''): List { if (isBlank(protoViewType)) { protoViewType = ProtoViewDto.COMPONENT_VIEW_TYPE; } @@ -25,13 +24,12 @@ export class CompilePipeline { var rootCompileElement = new CompileElement(rootElement, compilationCtxtDescription); rootCompileElement.inheritedProtoView = new ProtoViewBuilder(rootElement, protoViewType); rootCompileElement.isViewRoot = true; - this._process(results, null, rootCompileElement, - compilationCtxtDescription - ); + this._process(results, null, rootCompileElement, compilationCtxtDescription); return results; } - _process(results, parent:CompileElement, current:CompileElement, compilationCtxtDescription:string = '') { + _process(results, parent: CompileElement, current: CompileElement, + compilationCtxtDescription: string = '') { var additionalChildren = this._control.internalProcess(results, 0, parent, current); if (current.compileChildren) { @@ -44,7 +42,7 @@ export class CompilePipeline { var childCompileElement = new CompileElement(node, compilationCtxtDescription); childCompileElement.inheritedProtoView = current.inheritedProtoView; childCompileElement.inheritedElementBinder = current.inheritedElementBinder; - childCompileElement.distanceToInheritedBinder = current.distanceToInheritedBinder+1; + childCompileElement.distanceToInheritedBinder = current.distanceToInheritedBinder + 1; this._process(results, current, childCompileElement); } node = nextNode; @@ -52,7 +50,7 @@ export class CompilePipeline { } if (isPresent(additionalChildren)) { - for (var i=0; i):List { + createSteps(template: ViewDefinition, subTaskPromises: List>): List { return null; } } @@ -27,7 +27,7 @@ export class DefaultStepFactory extends CompileStepFactory { this._shadowDomStrategy = shadowDomStrategy; } - createSteps(template: ViewDefinition, subTaskPromises: List) { + createSteps(template: ViewDefinition, subTaskPromises: List>) { return [ new ViewSplitter(this._parser), new PropertyBindingParser(this._parser), diff --git a/modules/angular2/src/render/dom/compiler/compiler.js b/modules/angular2/src/render/dom/compiler/compiler.ts similarity index 70% rename from modules/angular2/src/render/dom/compiler/compiler.js rename to modules/angular2/src/render/dom/compiler/compiler.ts index ad9e2ad23a..2d4ab3b7c4 100644 --- a/modules/angular2/src/render/dom/compiler/compiler.js +++ b/modules/angular2/src/render/dom/compiler/compiler.ts @@ -1,10 +1,16 @@ -import {Injectable} from 'angular2/src/di/annotations_impl'; +import {Injectable} from 'angular2/di'; import {PromiseWrapper, Promise} from 'angular2/src/facade/async'; import {BaseException, isPresent} from 'angular2/src/facade/lang'; import {DOM} from 'angular2/src/dom/dom_adapter'; -import {ViewDefinition, ProtoViewDto, DirectiveMetadata, RenderCompiler, RenderProtoViewRef} from '../../api'; +import { + ViewDefinition, + ProtoViewDto, + DirectiveMetadata, + RenderCompiler, + RenderProtoViewRef +} from '../../api'; import {CompilePipeline} from './compile_pipeline'; import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; import {CompileStepFactory, DefaultStepFactory} from './compile_step_factory'; @@ -26,26 +32,27 @@ export class DomCompiler extends RenderCompiler { this._stepFactory = stepFactory; } - compile(template: ViewDefinition):Promise { + compile(template: ViewDefinition): Promise { var tplPromise = this._templateLoader.load(template); - return PromiseWrapper.then(tplPromise, - (el) => this._compileTemplate(template, el, ProtoViewDto.COMPONENT_VIEW_TYPE), - (_) => { throw new BaseException(`Failed to load the template "${template.componentId}"`); } - ); + return PromiseWrapper.then( + tplPromise, (el) => this._compileTemplate(template, el, ProtoViewDto.COMPONENT_VIEW_TYPE), + (_) => { + throw new BaseException(`Failed to load the template "${template.componentId}"`); + }); } - compileHost(directiveMetadata: DirectiveMetadata):Promise { + compileHost(directiveMetadata: DirectiveMetadata): Promise { var hostViewDef = new ViewDefinition({ componentId: directiveMetadata.id, - absUrl: null, - template: null, + absUrl: null, template: null, directives: [directiveMetadata] }); var element = DOM.createElement(directiveMetadata.selector); return this._compileTemplate(hostViewDef, element, ProtoViewDto.HOST_VIEW_TYPE); } - _compileTemplate(viewDef: ViewDefinition, tplElement, protoViewType:number):Promise { + _compileTemplate(viewDef: ViewDefinition, tplElement, + protoViewType: number): Promise { var subTaskPromises = []; var pipeline = new CompilePipeline(this._stepFactory.createSteps(viewDef, subTaskPromises)); var compileElements = pipeline.process(tplElement, protoViewType, viewDef.componentId); @@ -62,7 +69,8 @@ export class DomCompiler extends RenderCompiler { @Injectable() export class DefaultDomCompiler extends DomCompiler { - constructor(parser:Parser, shadowDomStrategy:ShadowDomStrategy, templateLoader: TemplateLoader) { + constructor(parser: Parser, shadowDomStrategy: ShadowDomStrategy, + templateLoader: TemplateLoader) { super(new DefaultStepFactory(parser, shadowDomStrategy), templateLoader); } } diff --git a/modules/angular2/src/render/dom/compiler/directive_parser.js b/modules/angular2/src/render/dom/compiler/directive_parser.ts similarity index 74% rename from modules/angular2/src/render/dom/compiler/directive_parser.js rename to modules/angular2/src/render/dom/compiler/directive_parser.ts index 3523f054a6..507a263852 100644 --- a/modules/angular2/src/render/dom/compiler/directive_parser.js +++ b/modules/angular2/src/render/dom/compiler/directive_parser.ts @@ -1,4 +1,11 @@ -import {isPresent, isBlank, BaseException, assertionsEnabled, RegExpWrapper, StringWrapper} from 'angular2/src/facade/lang'; +import { + isPresent, + isBlank, + BaseException, + assertionsEnabled, + RegExpWrapper, + StringWrapper +} from 'angular2/src/facade/lang'; import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {DOM} from 'angular2/src/dom/dom_adapter'; import {Parser} from 'angular2/change_detection'; @@ -16,17 +23,16 @@ import {dashCaseToCamelCase, camelCaseToDashCase, EVENT_TARGET_SEPARATOR} from ' * Parses the directives on a single element. Assumes ViewSplitter has already created *