fix(core): workaround for circular dependencies in nodejs

Closes #716
This commit is contained in:
Marc Laval 2015-02-19 18:14:29 +01:00 committed by Misko Hevery
parent d0ca07afaa
commit 85211f0a6b
3 changed files with 24 additions and 18 deletions

View File

@ -1,25 +1,25 @@
import {View, ProtoView} from './view'; import * as viewModule from './view';
import {DOM, Node, Element} from 'angular2/src/facade/dom'; import {DOM, Node, Element} from 'angular2/src/facade/dom';
import {ListWrapper, MapWrapper, List} from 'angular2/src/facade/collection'; import {ListWrapper, MapWrapper, List} from 'angular2/src/facade/collection';
import {BaseException} from 'angular2/src/facade/lang'; import {BaseException} from 'angular2/src/facade/lang';
import {Injector} from 'angular2/di'; import {Injector} from 'angular2/di';
import {ElementInjector} from 'angular2/src/core/compiler/element_injector'; import * as eiModule from 'angular2/src/core/compiler/element_injector';
import {isPresent, isBlank} from 'angular2/src/facade/lang'; import {isPresent, isBlank} from 'angular2/src/facade/lang';
import {EventManager} from 'angular2/src/core/events/event_manager'; import {EventManager} from 'angular2/src/core/events/event_manager';
export class ViewContainer { export class ViewContainer {
parentView: View; parentView: viewModule.View;
templateElement: Element; templateElement: Element;
defaultProtoView: ProtoView; defaultProtoView: viewModule.ProtoView;
_views: List<View>; _views: List<viewModule.View>;
_lightDom: any; _lightDom: any;
_eventManager: EventManager; _eventManager: EventManager;
elementInjector: ElementInjector; elementInjector: eiModule.ElementInjector;
appInjector: Injector; appInjector: Injector;
hostElementInjector: ElementInjector; hostElementInjector: eiModule.ElementInjector;
constructor(parentView: View, templateElement: Element, defaultProtoView: ProtoView, constructor(parentView: viewModule.View, templateElement: Element, defaultProtoView: viewModule.ProtoView,
elementInjector: ElementInjector, eventManager: EventManager, lightDom = null) { elementInjector: eiModule.ElementInjector, eventManager: EventManager, lightDom = null) {
this.parentView = parentView; this.parentView = parentView;
this.templateElement = templateElement; this.templateElement = templateElement;
this.defaultProtoView = defaultProtoView; this.defaultProtoView = defaultProtoView;
@ -33,7 +33,7 @@ export class ViewContainer {
this._eventManager = eventManager; this._eventManager = eventManager;
} }
hydrate(appInjector: Injector, hostElementInjector: ElementInjector) { hydrate(appInjector: Injector, hostElementInjector: eiModule.ElementInjector) {
this.appInjector = appInjector; this.appInjector = appInjector;
this.hostElementInjector = hostElementInjector; this.hostElementInjector = hostElementInjector;
} }
@ -50,7 +50,7 @@ export class ViewContainer {
} }
} }
get(index: number): View { get(index: number): viewModule.View {
return this._views[index]; return this._views[index];
} }
@ -69,7 +69,7 @@ export class ViewContainer {
// TODO(rado): profile and decide whether bounds checks should be added // TODO(rado): profile and decide whether bounds checks should be added
// to the methods below. // to the methods below.
create(atIndex=-1): View { create(atIndex=-1): viewModule.View {
if (!this.hydrated()) throw new BaseException( if (!this.hydrated()) throw new BaseException(
'Cannot create views on a dehydrated ViewContainer'); 'Cannot create views on a dehydrated ViewContainer');
// TODO(rado): replace with viewFactory. // TODO(rado): replace with viewFactory.
@ -78,7 +78,7 @@ export class ViewContainer {
return this.insert(newView, atIndex); return this.insert(newView, atIndex);
} }
insert(view, atIndex=-1): View { insert(view, atIndex=-1): viewModule.View {
if (atIndex == -1) atIndex = this._views.length; if (atIndex == -1) atIndex = this._views.length;
ListWrapper.insert(this._views, atIndex, view); ListWrapper.insert(this._views, atIndex, view);
if (isBlank(this._lightDom)) { if (isBlank(this._lightDom)) {
@ -104,7 +104,7 @@ export class ViewContainer {
* The method can be used together with insert to implement a view move, i.e. * The method can be used together with insert to implement a view move, i.e.
* moving the dom nodes while the directives in the view stay intact. * moving the dom nodes while the directives in the view stay intact.
*/ */
detach(atIndex=-1): View { detach(atIndex=-1): viewModule.View {
if (atIndex == -1) atIndex = this._views.length - 1; if (atIndex == -1) atIndex = this._views.length - 1;
var detachedView = this.get(atIndex); var detachedView = this.get(atIndex);
ListWrapper.removeAt(this._views, atIndex); ListWrapper.removeAt(this._views, atIndex);

View File

@ -1,19 +1,19 @@
import {ListWrapper, MapWrapper, StringMapWrapper, List} from 'angular2/src/facade/collection'; import {ListWrapper, MapWrapper, StringMapWrapper, List} from 'angular2/src/facade/collection';
import {View} from './view'; import * as viewModule from './view';
export class ViewPool { export class ViewPool {
_views: List<View>; _views: List<viewModule.View>;
_capacity: number; _capacity: number;
constructor(capacity: number) { constructor(capacity: number) {
this._views = []; this._views = [];
this._capacity = capacity; this._capacity = capacity;
} }
pop(): View { pop(): viewModule.View {
return ListWrapper.isEmpty(this._views) ? null : ListWrapper.removeLast(this._views); return ListWrapper.isEmpty(this._views) ? null : ListWrapper.removeLast(this._views);
} }
push(view: View) { push(view: viewModule.View) {
if (this._views.length < this._capacity) { if (this._views.length < this._capacity) {
ListWrapper.push(this._views, view); ListWrapper.push(this._views, view);
} }

View File

@ -16,6 +16,7 @@ import {
OPEN_PAREN, OPEN_PAREN,
OBJECT_PATTERN, OBJECT_PATTERN,
OPEN_SQUARE, OPEN_SQUARE,
PERIOD,
SEMI_COLON, SEMI_COLON,
STAR, STAR,
STATIC, STATIC,
@ -273,6 +274,11 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
args = []; args = [];
} }
if (typeNameNode.moduleName && typeNameNode.moduleName.name && typeNameNode.moduleName.name.value) {
this.write_(typeNameNode.moduleName.name.value);
this.write_(PERIOD);
}
// TODO(vojta): Figure out why `typeNameNode` has different structure when used with a variable. // TODO(vojta): Figure out why `typeNameNode` has different structure when used with a variable.
// This should probably be fixed in Traceur. // This should probably be fixed in Traceur.
var typeName = typeNameNode.typeToken && typeNameNode.typeToken.value || (typeNameNode.name && typeNameNode.name.value) || null; var typeName = typeNameNode.typeToken && typeNameNode.typeToken.value || (typeNameNode.name && typeNameNode.name.value) || null;