fix(deps): Update clang-format to 1.0.14.

This commit is contained in:
Martin Probst 2015-05-21 16:42:19 +02:00 committed by Tobias Bosch
parent e50f537667
commit 15f1eb28a2
15 changed files with 519 additions and 631 deletions

View File

@ -89,7 +89,7 @@ function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
bind(appComponentType).toFactory((ref) => ref.instance, [appComponentRefToken]), bind(appComponentType).toFactory((ref) => ref.instance, [appComponentRefToken]),
bind(LifeCycle) bind(LifeCycle)
.toFactory((exceptionHandler) => new LifeCycle(exceptionHandler, null, assertionsEnabled()), .toFactory((exceptionHandler) => new LifeCycle(exceptionHandler, null, assertionsEnabled()),
[ExceptionHandler]), [ExceptionHandler]),
bind(EventManager) bind(EventManager)
.toFactory( .toFactory(
(ngZone) => (ngZone) =>
@ -142,15 +142,15 @@ function _injectorBindings(appComponentType): List<Type | Binding | List<any>> {
function _createNgZone(givenReporter: Function): NgZone { function _createNgZone(givenReporter: Function): NgZone {
var defaultErrorReporter = (exception, stackTrace) => { var defaultErrorReporter = (exception, stackTrace) => {
var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n"); var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n");
DOM.logError(`${exception}\n\n${longStackTrace}`); DOM.logError(`${exception}\n\n${longStackTrace}`);
throw exception; throw exception;
}; };
var reporter = isPresent(givenReporter) ? givenReporter : defaultErrorReporter; var reporter = isPresent(givenReporter) ? givenReporter : defaultErrorReporter;
var zone = new NgZone({enableLongStackTrace: assertionsEnabled()}); var zone = new NgZone({enableLongStackTrace: assertionsEnabled()});
zone.initCallbacks({onErrorHandler: reporter}); zone.initCallbacks({onErrorHandler: reporter});
return zone; return zone;
} }
/** /**

View File

@ -175,84 +175,83 @@ export class Compiler {
var nestedPVPromises = []; var nestedPVPromises = [];
ListWrapper.forEach(this._collectComponentElementBinders(protoViews), (elementBinder) => { ListWrapper.forEach(this._collectComponentElementBinders(protoViews), (elementBinder) => {
var nestedComponent = elementBinder.componentDirective; var nestedComponent = elementBinder.componentDirective;
var elementBinderDone = (nestedPv: AppProtoView) => { var elementBinderDone =
elementBinder.nestedProtoView = nestedPv; (nestedPv: AppProtoView) => { elementBinder.nestedProtoView = nestedPv; };
};
var nestedCall = this._compile(nestedComponent); var nestedCall = this._compile(nestedComponent);
if (PromiseWrapper.isPromise(nestedCall)) { if (PromiseWrapper.isPromise(nestedCall)) {
ListWrapper.push(nestedPVPromises, ListWrapper.push(nestedPVPromises,
(<Promise<AppProtoView>>nestedCall).then(elementBinderDone)); (<Promise<AppProtoView>>nestedCall).then(elementBinderDone));
} else if (isPresent(nestedCall)) { } else if (isPresent(nestedCall)) {
elementBinderDone(<AppProtoView>nestedCall); elementBinderDone(<AppProtoView>nestedCall);
}
});
if (nestedPVPromises.length > 0) {
return PromiseWrapper.all(nestedPVPromises).then((_) => protoView);
} else {
return protoView;
}
}
private _collectComponentElementBinders(protoViews: List<AppProtoView>): List<ElementBinder> {
var componentElementBinders = [];
ListWrapper.forEach(protoViews, (protoView) => {
ListWrapper.forEach(protoView.elementBinders, (elementBinder) => {
if (isPresent(elementBinder.componentDirective)) {
ListWrapper.push(componentElementBinders, elementBinder);
} }
}); });
});
return componentElementBinders;
}
private _buildRenderTemplate(component, view, directives): renderApi.ViewDefinition { if (nestedPVPromises.length > 0) {
var componentUrl = return PromiseWrapper.all(nestedPVPromises).then((_) => protoView);
this._urlResolver.resolve(this._appUrl, this._componentUrlMapper.getUrl(component));
var templateAbsUrl = null;
if (isPresent(view.templateUrl)) {
templateAbsUrl = this._urlResolver.resolve(componentUrl, view.templateUrl);
} else if (isPresent(view.template)) {
// Note: If we have an inline template, we also need to send
// the url for the component to the render so that it
// is able to resolve urls in stylesheets.
templateAbsUrl = componentUrl;
}
return new renderApi.ViewDefinition({
componentId: stringify(component),
absUrl: templateAbsUrl, template: view.template,
directives: ListWrapper.map(directives, directiveBinding => directiveBinding.metadata)
});
}
private _flattenDirectives(template: View): List<Type> {
if (isBlank(template.directives)) return [];
var directives = [];
this._flattenList(template.directives, directives);
return directives;
}
private _flattenList(tree: List<any>, out: List<Type | Binding | List<any>>): void {
for (var i = 0; i < tree.length; i++) {
var item = resolveForwardRef(tree[i]);
if (ListWrapper.isList(item)) {
this._flattenList(item, out);
} else { } else {
ListWrapper.push(out, item); return protoView;
}
}
private _collectComponentElementBinders(protoViews: List<AppProtoView>): List<ElementBinder> {
var componentElementBinders = [];
ListWrapper.forEach(protoViews, (protoView) => {
ListWrapper.forEach(protoView.elementBinders, (elementBinder) => {
if (isPresent(elementBinder.componentDirective)) {
ListWrapper.push(componentElementBinders, elementBinder);
}
});
});
return componentElementBinders;
}
private _buildRenderTemplate(component, view, directives): renderApi.ViewDefinition {
var componentUrl =
this._urlResolver.resolve(this._appUrl, this._componentUrlMapper.getUrl(component));
var templateAbsUrl = null;
if (isPresent(view.templateUrl)) {
templateAbsUrl = this._urlResolver.resolve(componentUrl, view.templateUrl);
} else if (isPresent(view.template)) {
// Note: If we have an inline template, we also need to send
// the url for the component to the render so that it
// is able to resolve urls in stylesheets.
templateAbsUrl = componentUrl;
}
return new renderApi.ViewDefinition({
componentId: stringify(component),
absUrl: templateAbsUrl, template: view.template,
directives: ListWrapper.map(directives, directiveBinding => directiveBinding.metadata)
});
}
private _flattenDirectives(template: View): List<Type> {
if (isBlank(template.directives)) return [];
var directives = [];
this._flattenList(template.directives, directives);
return directives;
}
private _flattenList(tree: List<any>, out: List<Type | Binding | List<any>>): void {
for (var i = 0; i < tree.length; i++) {
var item = resolveForwardRef(tree[i]);
if (ListWrapper.isList(item)) {
this._flattenList(item, out);
} else {
ListWrapper.push(out, item);
}
}
}
private static _isValidDirective(value: Type | Binding): boolean {
return isPresent(value) && (value instanceof Type || value instanceof Binding);
}
private static _assertTypeIsComponent(directiveBinding: DirectiveBinding): void {
if (directiveBinding.metadata.type !== renderApi.DirectiveMetadata.COMPONENT_TYPE) {
throw new BaseException(
`Could not load '${stringify(directiveBinding.key.token)}' because it is not a component.`);
} }
} }
} }
private static _isValidDirective(value: Type | Binding): boolean {
return isPresent(value) && (value instanceof Type || value instanceof Binding);
}
private static _assertTypeIsComponent(directiveBinding: DirectiveBinding): void {
if (directiveBinding.metadata.type !== renderApi.DirectiveMetadata.COMPONENT_TYPE) {
throw new BaseException(
`Could not load '${stringify(directiveBinding.key.token)}' because it is not a component.`);
}
}
}

View File

@ -38,81 +38,85 @@ export class DynamicComponentLoader {
loadIntoExistingLocation(typeOrBinding, location: ElementRef, loadIntoExistingLocation(typeOrBinding, location: ElementRef,
injector: Injector = null): Promise<ComponentRef> { injector: Injector = null): Promise<ComponentRef> {
var binding = this._getBinding(typeOrBinding); var binding = this._getBinding(typeOrBinding);
return this._compiler.compile(binding.token).then(componentProtoViewRef => { return this._compiler.compile(binding.token)
this._viewManager.createDynamicComponentView(location, componentProtoViewRef, binding, .then(componentProtoViewRef => {
injector); this._viewManager.createDynamicComponentView(location, componentProtoViewRef, binding,
var component = this._viewManager.getComponent(location); injector);
var dispose = () => { throw new BaseException("Not implemented");}; var component = this._viewManager.getComponent(location);
return new ComponentRef(location, component, dispose); var dispose = () => { throw new BaseException("Not implemented"); };
}); return new ComponentRef(location, component, dispose);
} });
}
/**
* Loads a root component that is placed at the first element that matches the /**
* component's selector. * Loads a root component that is placed at the first element that matches the
* The loaded component receives injection normally as a hosted view. * component's selector.
*/ * The loaded component receives injection normally as a hosted view.
loadAsRoot(typeOrBinding, overrideSelector = null, */
injector: Injector = null): Promise<ComponentRef> { loadAsRoot(typeOrBinding, overrideSelector = null,
return this._compiler.compileInHost(this._getBinding(typeOrBinding)).then(hostProtoViewRef => { injector: Injector = null): Promise<ComponentRef> {
var hostViewRef = return this._compiler.compileInHost(this._getBinding(typeOrBinding))
this._viewManager.createRootHostView(hostProtoViewRef, overrideSelector, injector); .then(hostProtoViewRef => {
var newLocation = new ElementRef(hostViewRef, 0); var hostViewRef =
var component = this._viewManager.getComponent(newLocation); this._viewManager.createRootHostView(hostProtoViewRef, overrideSelector, injector);
var newLocation = new ElementRef(hostViewRef, 0);
var dispose = () => { this._viewManager.destroyRootHostView(hostViewRef); var component = this._viewManager.getComponent(newLocation);
};
return new ComponentRef(newLocation, component, dispose); var dispose = () => { this._viewManager.destroyRootHostView(hostViewRef); };
}); return new ComponentRef(newLocation, component, dispose);
} });
}
/**
* Loads a component into a free host view that is not yet attached to /**
* a parent on the render side, although it is attached to a parent in the injector hierarchy. * Loads a component into a free host view that is not yet attached to
* The loaded component receives injection normally as a hosted view. * a parent on the render side, although it is attached to a parent in the injector hierarchy.
*/ * The loaded component receives injection normally as a hosted view.
loadIntoNewLocation(typeOrBinding, parentComponentLocation: ElementRef, */
injector: Injector = null): Promise<ComponentRef> { loadIntoNewLocation(typeOrBinding, parentComponentLocation: ElementRef,
return this._compiler.compileInHost(this._getBinding(typeOrBinding)).then(hostProtoViewRef => { injector: Injector = null): Promise<ComponentRef> {
var hostViewRef = return this._compiler.compileInHost(this._getBinding(typeOrBinding))
this._viewManager.createFreeHostView(parentComponentLocation, hostProtoViewRef, injector); .then(hostProtoViewRef => {
var newLocation = new ElementRef(hostViewRef, 0); var hostViewRef = this._viewManager.createFreeHostView(parentComponentLocation,
var component = this._viewManager.getComponent(newLocation); hostProtoViewRef, injector);
var newLocation = new ElementRef(hostViewRef, 0);
var dispose = () => { var component = this._viewManager.getComponent(newLocation);
this._viewManager.destroyFreeHostView(parentComponentLocation, hostViewRef);
}; var dispose = () => {
return new ComponentRef(newLocation, component, dispose); this._viewManager.destroyFreeHostView(parentComponentLocation, hostViewRef);
}); };
} return new ComponentRef(newLocation, component, dispose);
});
/** }
* Loads a component next to the provided ElementRef. The loaded component receives
* injection normally as a hosted view. /**
*/ * Loads a component next to the provided ElementRef. The loaded component receives
loadNextToExistingLocation(typeOrBinding, location: ElementRef, * injection normally as a hosted view.
injector: Injector = null): Promise<ComponentRef> { */
var binding = this._getBinding(typeOrBinding); loadNextToExistingLocation(typeOrBinding, location: ElementRef,
return this._compiler.compileInHost(binding).then(hostProtoViewRef => { injector: Injector = null): Promise<ComponentRef> {
var viewContainer = this._viewManager.getViewContainer(location); var binding = this._getBinding(typeOrBinding);
var hostViewRef = viewContainer.create(hostProtoViewRef, viewContainer.length, null, injector); return this._compiler.compileInHost(binding).then(hostProtoViewRef => {
var newLocation = new ElementRef(hostViewRef, 0); var viewContainer = this._viewManager.getViewContainer(location);
var component = this._viewManager.getComponent(newLocation); var hostViewRef =
viewContainer.create(hostProtoViewRef, viewContainer.length, null, injector);
var dispose = () => { var index = viewContainer.indexOf(hostViewRef); var newLocation = new ElementRef(hostViewRef, 0);
viewContainer.remove(index); var component = this._viewManager.getComponent(newLocation);
};
return new ComponentRef(newLocation, component, dispose); var dispose = () => {
}); var index = viewContainer.indexOf(hostViewRef);
} viewContainer.remove(index);
};
private _getBinding(typeOrBinding): Binding { return new ComponentRef(newLocation, component, dispose);
var binding; });
if (typeOrBinding instanceof Binding) { }
binding = typeOrBinding;
} else { private _getBinding(typeOrBinding): Binding {
binding = bind(typeOrBinding).toClass(typeOrBinding); var binding;
if (typeOrBinding instanceof Binding) {
binding = typeOrBinding;
} else {
binding = bind(typeOrBinding).toClass(typeOrBinding);
}
return binding;
} }
return binding;
}
} }

View File

@ -39,43 +39,45 @@ export class LifeCycle {
constructor(exceptionHandler: ExceptionHandler, changeDetector: ChangeDetector = null, constructor(exceptionHandler: ExceptionHandler, changeDetector: ChangeDetector = null,
enforceNoNewChanges: boolean = false) { enforceNoNewChanges: boolean = false) {
this._errorHandler = (exception, stackTrace) => { exceptionHandler.call(exception, stackTrace); this._errorHandler = (exception, stackTrace) => {
throw exception; exceptionHandler.call(exception, stackTrace);
}; throw exception;
this._changeDetector = };
changeDetector; // may be null when instantiated from application bootstrap this._changeDetector =
this._enforceNoNewChanges = enforceNoNewChanges; changeDetector; // may be null when instantiated from application bootstrap
} this._enforceNoNewChanges = enforceNoNewChanges;
/**
* @private
*/
registerWith(zone: NgZone, changeDetector: ChangeDetector = null) {
if (isPresent(changeDetector)) {
this._changeDetector = changeDetector;
} }
zone.initCallbacks({onErrorHandler: this._errorHandler, onTurnDone: () => this.tick()}); /**
} * @private
*/
registerWith(zone: NgZone, changeDetector: ChangeDetector = null) {
if (isPresent(changeDetector)) {
this._changeDetector = changeDetector;
}
/** zone.initCallbacks({onErrorHandler: this._errorHandler, onTurnDone: () => this.tick()});
* Invoke this method to explicitly process change detection and its side-effects. }
*
* In development mode, `tick()` also performs a second change detection cycle to ensure that no /**
* further * Invoke this method to explicitly process change detection and its side-effects.
* changes are detected. If additional changes are picked up during this second cycle, bindings in *
* the app have * In development mode, `tick()` also performs a second change detection cycle to ensure that no
* side-effects that cannot be resolved in a single change detection pass. In this case, Angular * further
* throws an error, * changes are detected. If additional changes are picked up during this second cycle, bindings
* since an Angular application can only have one change detection pass during which all change * in
* detection must * the app have
* complete. * side-effects that cannot be resolved in a single change detection pass. In this case, Angular
* * throws an error,
*/ * since an Angular application can only have one change detection pass during which all change
tick() { * detection must
this._changeDetector.detectChanges(); * complete.
if (this._enforceNoNewChanges) { *
this._changeDetector.checkNoChanges(); */
tick() {
this._changeDetector.detectChanges();
if (this._enforceNoNewChanges) {
this._changeDetector.checkNoChanges();
}
} }
} }
}

View File

@ -61,7 +61,7 @@ export class AbstractBindingError extends BaseException {
export class NoBindingError extends AbstractBindingError { export class NoBindingError extends AbstractBindingError {
// TODO(tbosch): Can't do key:Key as this results in a circular dependency! // TODO(tbosch): Can't do key:Key as this results in a circular dependency!
constructor(key) { constructor(key) {
super(key, function (keys:List<any>) { super(key, function(keys: List<any>) {
var first = stringify(ListWrapper.first(keys).token); var first = stringify(ListWrapper.first(keys).token);
return `No provider for ${first}!${constructResolvingPath(keys)}`; return `No provider for ${first}!${constructResolvingPath(keys)}`;
}); });
@ -95,7 +95,7 @@ export class NoBindingError extends AbstractBindingError {
export class AsyncBindingError extends AbstractBindingError { export class AsyncBindingError extends AbstractBindingError {
// TODO(tbosch): Can't do key:Key as this results in a circular dependency! // TODO(tbosch): Can't do key:Key as this results in a circular dependency!
constructor(key) { constructor(key) {
super(key, function (keys:List<any>) { super(key, function(keys: List<any>) {
var first = stringify(ListWrapper.first(keys).token); var first = stringify(ListWrapper.first(keys).token);
return `Cannot instantiate ${first} synchronously. It is provided as a promise!${constructResolvingPath(keys)}`; return `Cannot instantiate ${first} synchronously. It is provided as a promise!${constructResolvingPath(keys)}`;
}); });
@ -123,7 +123,7 @@ export class AsyncBindingError extends AbstractBindingError {
export class CyclicDependencyError extends AbstractBindingError { export class CyclicDependencyError extends AbstractBindingError {
// TODO(tbosch): Can't do key:Key as this results in a circular dependency! // TODO(tbosch): Can't do key:Key as this results in a circular dependency!
constructor(key) { constructor(key) {
super(key, function (keys:List<any>) { super(key, function(keys: List<any>) {
return `Cannot instantiate cyclic dependency!${constructResolvingPath(keys)}`; return `Cannot instantiate cyclic dependency!${constructResolvingPath(keys)}`;
}); });
} }
@ -142,7 +142,7 @@ export class InstantiationError extends AbstractBindingError {
causeKey; causeKey;
// TODO(tbosch): Can't do key:Key as this results in a circular dependency! // TODO(tbosch): Can't do key:Key as this results in a circular dependency!
constructor(cause, key) { constructor(cause, key) {
super(key, function (keys:List<any>) { super(key, function(keys: List<any>) {
var first = stringify(ListWrapper.first(keys).token); var first = stringify(ListWrapper.first(keys).token);
return `Error during instantiation of ${first}!${constructResolvingPath(keys)}. ORIGINAL ERROR: ${cause}`; return `Error during instantiation of ${first}!${constructResolvingPath(keys)}. ORIGINAL ERROR: ${cause}`;
}); });

View File

@ -63,318 +63,197 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
el.addEventListener(evt, listener, false); el.addEventListener(evt, listener, false);
// Needed to follow Dart's subscription semantic, until fix of // Needed to follow Dart's subscription semantic, until fix of
// https://code.google.com/p/dart/issues/detail?id=17406 // https://code.google.com/p/dart/issues/detail?id=17406
return () => { el.removeEventListener(evt, listener, false); return () => { el.removeEventListener(evt, listener, false); };
};
}
dispatchEvent(el, evt) {
el.dispatchEvent(evt);
}
createMouseEvent(eventType: string): MouseEvent {
var evt: MouseEvent = document.createEvent('MouseEvent');
evt.initEvent(eventType, true, true);
return evt;
}
createEvent(eventType): Event {
var evt: Event = document.createEvent('Event');
evt.initEvent(eventType, true, true);
return evt;
}
preventDefault(evt: Event) {
evt.preventDefault();
evt.returnValue = false;
}
getInnerHTML(el) {
return el.innerHTML;
}
getOuterHTML(el) {
return el.outerHTML;
}
nodeName(node: Node): string {
return node.nodeName;
}
nodeValue(node: Node): string {
return node.nodeValue;
}
type(node: HTMLInputElement): string {
return node.type;
}
content(node: Node): Node {
if (this.hasProperty(node, "content")) {
return (<any>node).content;
} else {
return node;
} }
} dispatchEvent(el, evt) { el.dispatchEvent(evt); }
firstChild(el): Node { createMouseEvent(eventType: string): MouseEvent {
return el.firstChild; var evt: MouseEvent = document.createEvent('MouseEvent');
} evt.initEvent(eventType, true, true);
nextSibling(el): Node { return evt;
return el.nextSibling;
}
parentElement(el) {
return el.parentElement;
}
childNodes(el): List<Node> {
return el.childNodes;
}
childNodesAsList(el): List<any> {
var childNodes = el.childNodes;
var res = ListWrapper.createFixedSize(childNodes.length);
for (var i = 0; i < childNodes.length; i++) {
res[i] = childNodes[i];
} }
return res; createEvent(eventType): Event {
} var evt: Event = document.createEvent('Event');
clearNodes(el) { evt.initEvent(eventType, true, true);
for (var i = 0; i < el.childNodes.length; i++) { return evt;
this.remove(el.childNodes[i]);
} }
} preventDefault(evt: Event) {
appendChild(el, node) { evt.preventDefault();
el.appendChild(node); evt.returnValue = false;
}
removeChild(el, node) {
el.removeChild(node);
}
replaceChild(el: Node, newChild, oldChild) {
el.replaceChild(newChild, oldChild);
}
remove(el) {
var parent = el.parentNode;
parent.removeChild(el);
return el;
}
insertBefore(el, node) {
el.parentNode.insertBefore(node, el);
}
insertAllBefore(el, nodes) {
ListWrapper.forEach(nodes, (n) => { el.parentNode.insertBefore(n, el); });
}
insertAfter(el, node) {
el.parentNode.insertBefore(node, el.nextSibling);
}
setInnerHTML(el, value) {
el.innerHTML = value;
}
getText(el) {
return el.textContent;
}
// TODO(vicb): removed Element type because it does not support StyleElement
setText(el, value: string) {
el.textContent = value;
}
getValue(el) {
return el.value;
}
setValue(el, value: string) {
el.value = value;
}
getChecked(el) {
return el.checked;
}
setChecked(el, value: boolean) {
el.checked = value;
}
createTemplate(html): HTMLElement {
var t = document.createElement('template');
t.innerHTML = html;
return t;
}
createElement(tagName, doc = document): HTMLElement {
return doc.createElement(tagName);
}
createTextNode(text: string, doc = document): Text {
return doc.createTextNode(text);
}
createScriptTag(attrName: string, attrValue: string, doc = document): HTMLScriptElement {
var el = <HTMLScriptElement>doc.createElement('SCRIPT');
el.setAttribute(attrName, attrValue);
return el;
}
createStyleElement(css: string, doc = document): HTMLStyleElement {
var style = <HTMLStyleElement>doc.createElement('style');
this.appendChild(style, this.createTextNode(css));
return style;
}
createShadowRoot(el: HTMLElement): DocumentFragment {
return (<any>el).createShadowRoot();
}
getShadowRoot(el: HTMLElement): DocumentFragment {
return (<any>el).shadowRoot;
}
getHost(el: HTMLElement): HTMLElement {
return (<any>el).host;
}
clone(node: Node) {
return node.cloneNode(true);
}
hasProperty(element, name: string) {
return name in element;
}
getElementsByClassName(element, name: string) {
return element.getElementsByClassName(name);
}
getElementsByTagName(element, name: string) {
return element.getElementsByTagName(name);
}
classList(element): List<any> {
return <List<any>>Array.prototype.slice.call(element.classList, 0);
}
addClass(element, classname: string) {
element.classList.add(classname);
}
removeClass(element, classname: string) {
element.classList.remove(classname);
}
hasClass(element, classname: string) {
return element.classList.contains(classname);
}
setStyle(element, stylename: string, stylevalue: string) {
element.style[stylename] = stylevalue;
}
removeStyle(element, stylename: string) {
element.style[stylename] = null;
}
getStyle(element, stylename: string) {
return element.style[stylename];
}
tagName(element): string {
return element.tagName;
}
attributeMap(element) {
var res = MapWrapper.create();
var elAttrs = element.attributes;
for (var i = 0; i < elAttrs.length; i++) {
var attrib = elAttrs[i];
MapWrapper.set(res, attrib.name, attrib.value);
} }
return res; getInnerHTML(el) { return el.innerHTML; }
} getOuterHTML(el) { return el.outerHTML; }
hasAttribute(element, attribute: string) { nodeName(node: Node): string { return node.nodeName; }
return element.hasAttribute(attribute); nodeValue(node: Node): string { return node.nodeValue; }
} type(node: HTMLInputElement): string { return node.type; }
getAttribute(element, attribute: string) { content(node: Node): Node {
return element.getAttribute(attribute); if (this.hasProperty(node, "content")) {
} return (<any>node).content;
setAttribute(element, name: string, value: string) { } else {
element.setAttribute(name, value); return node;
}
removeAttribute(element, attribute: string) {
return element.removeAttribute(attribute);
}
templateAwareRoot(el) {
return this.isTemplateElement(el) ? this.content(el) : el;
}
createHtmlDocument() {
return document.implementation.createHTMLDocument('fakeTitle');
}
defaultDoc() {
return document;
}
getBoundingClientRect(el) {
try {
return el.getBoundingClientRect();
} catch (e) {
return {top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0};
}
}
getTitle(): string {
return document.title;
}
setTitle(newTitle: string) {
document.title = newTitle || '';
}
elementMatches(n, selector: string): boolean {
return n instanceof HTMLElement && n.matches ? n.matches(selector) :
n.msMatchesSelector(selector);
}
isTemplateElement(el: any): boolean {
return el instanceof HTMLElement && el.nodeName == "TEMPLATE";
}
isTextNode(node: Node): boolean {
return node.nodeType === Node.TEXT_NODE;
}
isCommentNode(node: Node): boolean {
return node.nodeType === Node.COMMENT_NODE;
}
isElementNode(node: Node): boolean {
return node.nodeType === Node.ELEMENT_NODE;
}
hasShadowRoot(node): boolean {
return node instanceof HTMLElement && isPresent(node.shadowRoot);
}
isShadowRoot(node): boolean {
return node instanceof DocumentFragment;
}
importIntoDoc(node: Node) {
var toImport = node;
if (this.isTemplateElement(node)) {
toImport = this.content(node);
}
return document.importNode(toImport, true);
}
isPageRule(rule): boolean {
return rule.type === CSSRule.PAGE_RULE;
}
isStyleRule(rule): boolean {
return rule.type === CSSRule.STYLE_RULE;
}
isMediaRule(rule): boolean {
return rule.type === CSSRule.MEDIA_RULE;
}
isKeyframesRule(rule): boolean {
return rule.type === CSSRule.KEYFRAMES_RULE;
}
getHref(el: Element): string {
return (<any>el).href;
}
getEventKey(event): string {
var key = event.key;
if (isBlank(key)) {
key = event.keyIdentifier;
// keyIdentifier is defined in the old draft of DOM Level 3 Events implemented by Chrome and
// Safari
// cf
// http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-KeyboardEvents-Interfaces
if (isBlank(key)) {
return 'Unidentified';
} }
if (key.startsWith('U+')) { }
key = String.fromCharCode(parseInt(key.substring(2), 16)); firstChild(el): Node { return el.firstChild; }
if (event.location === DOM_KEY_LOCATION_NUMPAD && _chromeNumKeyPadMap.hasOwnProperty(key)) { nextSibling(el): Node { return el.nextSibling; }
// There is a bug in Chrome for numeric keypad keys: parentElement(el) { return el.parentElement; }
// https://code.google.com/p/chromium/issues/detail?id=155654 childNodes(el): List<Node> { return el.childNodes; }
// 1, 2, 3 ... are reported as A, B, C ... childNodesAsList(el): List<any> {
key = _chromeNumKeyPadMap[key]; var childNodes = el.childNodes;
var res = ListWrapper.createFixedSize(childNodes.length);
for (var i = 0; i < childNodes.length; i++) {
res[i] = childNodes[i];
}
return res;
}
clearNodes(el) {
for (var i = 0; i < el.childNodes.length; i++) {
this.remove(el.childNodes[i]);
}
}
appendChild(el, node) { el.appendChild(node); }
removeChild(el, node) { el.removeChild(node); }
replaceChild(el: Node, newChild, oldChild) { el.replaceChild(newChild, oldChild); }
remove(el) {
var parent = el.parentNode;
parent.removeChild(el);
return el;
}
insertBefore(el, node) { el.parentNode.insertBefore(node, el); }
insertAllBefore(el, nodes) {
ListWrapper.forEach(nodes, (n) => { el.parentNode.insertBefore(n, el); });
}
insertAfter(el, node) { el.parentNode.insertBefore(node, el.nextSibling); }
setInnerHTML(el, value) { el.innerHTML = value; }
getText(el) { return el.textContent; }
// TODO(vicb): removed Element type because it does not support StyleElement
setText(el, value: string) { el.textContent = value; }
getValue(el) { return el.value; }
setValue(el, value: string) { el.value = value; }
getChecked(el) { return el.checked; }
setChecked(el, value: boolean) { el.checked = value; }
createTemplate(html): HTMLElement {
var t = document.createElement('template');
t.innerHTML = html;
return t;
}
createElement(tagName, doc = document): HTMLElement { return doc.createElement(tagName); }
createTextNode(text: string, doc = document): Text { return doc.createTextNode(text); }
createScriptTag(attrName: string, attrValue: string, doc = document): HTMLScriptElement {
var el = <HTMLScriptElement>doc.createElement('SCRIPT');
el.setAttribute(attrName, attrValue);
return el;
}
createStyleElement(css: string, doc = document): HTMLStyleElement {
var style = <HTMLStyleElement>doc.createElement('style');
this.appendChild(style, this.createTextNode(css));
return style;
}
createShadowRoot(el: HTMLElement): DocumentFragment { return (<any>el).createShadowRoot(); }
getShadowRoot(el: HTMLElement): DocumentFragment { return (<any>el).shadowRoot; }
getHost(el: HTMLElement): HTMLElement { return (<any>el).host; }
clone(node: Node) { return node.cloneNode(true); }
hasProperty(element, name: string) { return name in element; }
getElementsByClassName(element, name: string) { return element.getElementsByClassName(name); }
getElementsByTagName(element, name: string) { return element.getElementsByTagName(name); }
classList(element): List<any> {
return <List<any>>Array.prototype.slice.call(element.classList, 0);
}
addClass(element, classname: string) { element.classList.add(classname); }
removeClass(element, classname: string) { element.classList.remove(classname); }
hasClass(element, classname: string) { return element.classList.contains(classname); }
setStyle(element, stylename: string, stylevalue: string) {
element.style[stylename] = stylevalue;
}
removeStyle(element, stylename: string) { element.style[stylename] = null; }
getStyle(element, stylename: string) { return element.style[stylename]; }
tagName(element): string { return element.tagName; }
attributeMap(element) {
var res = MapWrapper.create();
var elAttrs = element.attributes;
for (var i = 0; i < elAttrs.length; i++) {
var attrib = elAttrs[i];
MapWrapper.set(res, attrib.name, attrib.value);
}
return res;
}
hasAttribute(element, attribute: string) { return element.hasAttribute(attribute); }
getAttribute(element, attribute: string) { return element.getAttribute(attribute); }
setAttribute(element, name: string, value: string) { element.setAttribute(name, value); }
removeAttribute(element, attribute: string) { return element.removeAttribute(attribute); }
templateAwareRoot(el) { return this.isTemplateElement(el) ? this.content(el) : el; }
createHtmlDocument() { return document.implementation.createHTMLDocument('fakeTitle'); }
defaultDoc() { return document; }
getBoundingClientRect(el) {
try {
return el.getBoundingClientRect();
} catch (e) {
return {top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0};
}
}
getTitle(): string { return document.title; }
setTitle(newTitle: string) { document.title = newTitle || ''; }
elementMatches(n, selector: string): boolean {
return n instanceof HTMLElement && n.matches ? n.matches(selector) :
n.msMatchesSelector(selector);
}
isTemplateElement(el: any): boolean {
return el instanceof HTMLElement && el.nodeName == "TEMPLATE";
}
isTextNode(node: Node): boolean { return node.nodeType === Node.TEXT_NODE; }
isCommentNode(node: Node): boolean { return node.nodeType === Node.COMMENT_NODE; }
isElementNode(node: Node): boolean { return node.nodeType === Node.ELEMENT_NODE; }
hasShadowRoot(node): boolean { return node instanceof HTMLElement && isPresent(node.shadowRoot); }
isShadowRoot(node): boolean { return node instanceof DocumentFragment; }
importIntoDoc(node: Node) {
var toImport = node;
if (this.isTemplateElement(node)) {
toImport = this.content(node);
}
return document.importNode(toImport, true);
}
isPageRule(rule): boolean { return rule.type === CSSRule.PAGE_RULE; }
isStyleRule(rule): boolean { return rule.type === CSSRule.STYLE_RULE; }
isMediaRule(rule): boolean { return rule.type === CSSRule.MEDIA_RULE; }
isKeyframesRule(rule): boolean { return rule.type === CSSRule.KEYFRAMES_RULE; }
getHref(el: Element): string { return (<any>el).href; }
getEventKey(event): string {
var key = event.key;
if (isBlank(key)) {
key = event.keyIdentifier;
// keyIdentifier is defined in the old draft of DOM Level 3 Events implemented by Chrome and
// Safari
// cf
// http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-20071221/events.html#Events-KeyboardEvents-Interfaces
if (isBlank(key)) {
return 'Unidentified';
}
if (key.startsWith('U+')) {
key = String.fromCharCode(parseInt(key.substring(2), 16));
if (event.location === DOM_KEY_LOCATION_NUMPAD && _chromeNumKeyPadMap.hasOwnProperty(key)) {
// There is a bug in Chrome for numeric keypad keys:
// https://code.google.com/p/chromium/issues/detail?id=155654
// 1, 2, 3 ... are reported as A, B, C ...
key = _chromeNumKeyPadMap[key];
}
} }
} }
if (_keyMap.hasOwnProperty(key)) {
key = _keyMap[key];
}
return key;
} }
if (_keyMap.hasOwnProperty(key)) { getGlobalEventTarget(target: string): EventTarget {
key = _keyMap[key]; if (target == "window") {
return window;
} else if (target == "document") {
return document;
} else if (target == "body") {
return document.body;
}
} }
return key; getHistory() { return window.history; }
} getLocation() { return window.location; }
getGlobalEventTarget(target: string): EventTarget { getBaseHref() { return relativePath(document.baseURI); }
if (target == "window") { getUserAgent(): string { return window.navigator.userAgent; }
return window;
} else if (target == "document") {
return document;
} else if (target == "body") {
return document.body;
}
}
getHistory() {
return window.history;
}
getLocation() {
return window.location;
}
getBaseHref() {
return relativePath(document.baseURI);
}
getUserAgent(): string {
return window.navigator.userAgent;
}
} }
// based on urlUtils.js in AngularJS 1 // based on urlUtils.js in AngularJS 1

View File

@ -36,97 +36,96 @@ export class CssSelector {
if (isPresent(cssSel.notSelector) && isBlank(cssSel.element) && if (isPresent(cssSel.notSelector) && isBlank(cssSel.element) &&
ListWrapper.isEmpty(cssSel.classNames) && ListWrapper.isEmpty(cssSel.attrs)) { ListWrapper.isEmpty(cssSel.classNames) && ListWrapper.isEmpty(cssSel.attrs)) {
cssSel.element = "*"; cssSel.element = "*";
} ListWrapper.push(res, cssSel);
}
var cssSelector = new CssSelector();
var matcher = RegExpWrapper.matcher(_SELECTOR_REGEXP, selector);
var match;
var current = cssSelector;
while (isPresent(match = RegExpMatcherWrapper.next(matcher))) {
if (isPresent(match[1])) {
if (isPresent(cssSelector.notSelector)) {
throw new BaseException('Nesting :not is not allowed in a selector');
} }
current.notSelector = new CssSelector(); ListWrapper.push(res, cssSel);
current = current.notSelector; };
} var cssSelector = new CssSelector();
if (isPresent(match[2])) { var matcher = RegExpWrapper.matcher(_SELECTOR_REGEXP, selector);
current.setElement(match[2]); var match;
} var current = cssSelector;
if (isPresent(match[3])) { while (isPresent(match = RegExpMatcherWrapper.next(matcher))) {
current.addClassName(match[3]); if (isPresent(match[1])) {
} if (isPresent(cssSelector.notSelector)) {
if (isPresent(match[4])) { throw new BaseException('Nesting :not is not allowed in a selector');
current.addAttribute(match[4], match[5]); }
} current.notSelector = new CssSelector();
if (isPresent(match[6])) { current = current.notSelector;
_addResult(results, cssSelector); }
cssSelector = current = new CssSelector(); if (isPresent(match[2])) {
} current.setElement(match[2]);
} }
_addResult(results, cssSelector); if (isPresent(match[3])) {
return results; current.addClassName(match[3]);
} }
if (isPresent(match[4])) {
constructor() { current.addAttribute(match[4], match[5]);
this.element = null; }
this.classNames = ListWrapper.create(); if (isPresent(match[6])) {
this.attrs = ListWrapper.create(); _addResult(results, cssSelector);
this.notSelector = null; cssSelector = current = new CssSelector();
}
isElementSelector(): boolean {
return isPresent(this.element) && ListWrapper.isEmpty(this.classNames) &&
ListWrapper.isEmpty(this.attrs) && isBlank(this.notSelector);
}
setElement(element: string = null) {
if (isPresent(element)) {
element = element.toLowerCase();
}
this.element = element;
}
addAttribute(name: string, value: string = _EMPTY_ATTR_VALUE) {
ListWrapper.push(this.attrs, name.toLowerCase());
if (isPresent(value)) {
value = value.toLowerCase();
} else {
value = _EMPTY_ATTR_VALUE;
}
ListWrapper.push(this.attrs, value);
}
addClassName(name: string) {
ListWrapper.push(this.classNames, name.toLowerCase());
}
toString(): string {
var res = '';
if (isPresent(this.element)) {
res += this.element;
}
if (isPresent(this.classNames)) {
for (var i = 0; i < this.classNames.length; i++) {
res += '.' + this.classNames[i];
}
}
if (isPresent(this.attrs)) {
for (var i = 0; i < this.attrs.length;) {
var attrName = this.attrs[i++];
var attrValue = this.attrs[i++];
res += '[' + attrName;
if (attrValue.length > 0) {
res += '=' + attrValue;
} }
res += ']';
} }
_addResult(results, cssSelector);
return results;
} }
if (isPresent(this.notSelector)) {
res += ":not(" + this.notSelector.toString() + ")"; constructor() {
this.element = null;
this.classNames = ListWrapper.create();
this.attrs = ListWrapper.create();
this.notSelector = null;
}
isElementSelector(): boolean {
return isPresent(this.element) && ListWrapper.isEmpty(this.classNames) &&
ListWrapper.isEmpty(this.attrs) && isBlank(this.notSelector);
}
setElement(element: string = null) {
if (isPresent(element)) {
element = element.toLowerCase();
}
this.element = element;
}
addAttribute(name: string, value: string = _EMPTY_ATTR_VALUE) {
ListWrapper.push(this.attrs, name.toLowerCase());
if (isPresent(value)) {
value = value.toLowerCase();
} else {
value = _EMPTY_ATTR_VALUE;
}
ListWrapper.push(this.attrs, value);
}
addClassName(name: string) { ListWrapper.push(this.classNames, name.toLowerCase()); }
toString(): string {
var res = '';
if (isPresent(this.element)) {
res += this.element;
}
if (isPresent(this.classNames)) {
for (var i = 0; i < this.classNames.length; i++) {
res += '.' + this.classNames[i];
}
}
if (isPresent(this.attrs)) {
for (var i = 0; i < this.attrs.length;) {
var attrName = this.attrs[i++];
var attrValue = this.attrs[i++];
res += '[' + attrName;
if (attrValue.length > 0) {
res += '=' + attrValue;
}
res += ']';
}
}
if (isPresent(this.notSelector)) {
res += ":not(" + this.notSelector.toString() + ")";
}
return res;
} }
return res;
}
} }
/** /**

View File

@ -96,7 +96,11 @@ export class DomEventsPlugin extends EventManagerPlugin {
} }
static sameElementCallback(element, handler, zone) { static sameElementCallback(element, handler, zone) {
return (event) => { if (event.target === element) { zone.run(() => handler(event)); } }; return (event) => {
if (event.target === element) {
zone.run(() => handler(event));
}
};
} }
static bubbleCallback(element, handler, zone) { static bubbleCallback(element, handler, zone) {

View File

@ -89,20 +89,21 @@ export class KeyEventsPlugin extends EventManagerPlugin {
} }
static eventCallback(element, shouldSupportBubble, fullKey, handler, zone) { static eventCallback(element, shouldSupportBubble, fullKey, handler, zone) {
return (event) => { var correctElement = shouldSupportBubble || event.target === element; return (event) => {
if (correctElement && KeyEventsPlugin.getEventFullKey(event) === fullKey) { var correctElement = shouldSupportBubble || event.target === element;
zone.run(() => handler(event)); if (correctElement && KeyEventsPlugin.getEventFullKey(event) === fullKey) {
} zone.run(() => handler(event));
}; }
} };
}
static _normalizeKey(keyName: string): string { static _normalizeKey(keyName: string): string {
// TODO: switch to a StringMap if the mapping grows too much // TODO: switch to a StringMap if the mapping grows too much
switch (keyName) { switch (keyName) {
case 'esc': case 'esc':
return 'escape'; return 'escape';
default: default:
return keyName; return keyName;
}
} }
} }
}

View File

@ -331,31 +331,33 @@ export class SpyObject {
} }
function elementText(n) { function elementText(n) {
var hasNodes = (n) => { var children = DOM.childNodes(n); var hasNodes = (n) =>
return children && children.length > 0; {
} var children = DOM.childNodes(n);
return children && children.length > 0;
}
if (n instanceof Array) { if (n instanceof Array) {
return n.map((nn) => elementText(nn)).join(""); return n.map((nn) => elementText(nn)).join("");
} }
if (DOM.isCommentNode(n)) { if (DOM.isCommentNode(n)) {
return ''; return '';
} }
if (DOM.isElementNode(n) && DOM.tagName(n) == 'CONTENT') { if (DOM.isElementNode(n) && DOM.tagName(n) == 'CONTENT') {
return elementText(Array.prototype.slice.apply(DOM.getDistributedNodes(n))); return elementText(Array.prototype.slice.apply(DOM.getDistributedNodes(n)));
} }
if (DOM.hasShadowRoot(n)) { if (DOM.hasShadowRoot(n)) {
return elementText(DOM.childNodesAsList(DOM.getShadowRoot(n))); return elementText(DOM.childNodesAsList(DOM.getShadowRoot(n)));
} }
if (hasNodes(n)) { if (hasNodes(n)) {
return elementText(DOM.childNodesAsList(n)); return elementText(DOM.childNodesAsList(n));
} }
return DOM.getText(n); return DOM.getText(n);
} }
export function isInInnerZone(): boolean { export function isInInnerZone(): boolean {

View File

@ -13,12 +13,10 @@ export class Log {
fn(value) { fn(value) {
return (a1 = null, a2 = null, a3 = null, a4 = null, a5 = null) => { return (a1 = null, a2 = null, a3 = null, a4 = null, a5 = null) => {
ListWrapper.push(this._result, value); ListWrapper.push(this._result, value);
}
} }
}
result(): string { result(): string { return ListWrapper.join(this._result, "; "); }
return ListWrapper.join(this._result, "; ");
}
} }
export function viewRootNodes(view): List</*node*/ any> { export function viewRootNodes(view): List</*node*/ any> {

View File

@ -227,7 +227,7 @@ export function main() {
return [bind(ChangeDetection) return [bind(ChangeDetection)
.toFactory(() => new DynamicChangeDetection( .toFactory(() => new DynamicChangeDetection(
new PipeRegistry({"double": [new DoublePipeFactory()]})), new PipeRegistry({"double": [new DoublePipeFactory()]})),
[])]; [])];
}); });
it("should support pipes in bindings and bind config", it("should support pipes in bindings and bind config",

View File

@ -3934,7 +3934,7 @@
} }
}, },
"gulp-clang-format": { "gulp-clang-format": {
"version": "1.0.12", "version": "1.0.13",
"dependencies": { "dependencies": {
"gulp-util": { "gulp-util": {
"version": "3.0.4", "version": "3.0.4",
@ -4112,7 +4112,7 @@
} }
}, },
"clang-format": { "clang-format": {
"version": "1.0.12" "version": "1.0.14"
} }
} }
}, },

12
npm-shrinkwrap.json generated
View File

@ -6073,9 +6073,9 @@
} }
}, },
"gulp-clang-format": { "gulp-clang-format": {
"version": "1.0.12", "version": "1.0.13",
"from": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.12.tgz", "from": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.13.tgz",
"resolved": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.12.tgz", "resolved": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.13.tgz",
"dependencies": { "dependencies": {
"gulp-util": { "gulp-util": {
"version": "3.0.4", "version": "3.0.4",
@ -6351,9 +6351,9 @@
} }
}, },
"clang-format": { "clang-format": {
"version": "1.0.12", "version": "1.0.14",
"from": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.12.tgz", "from": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.14.tgz",
"resolved": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.12.tgz" "resolved": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.14.tgz"
} }
} }
}, },

View File

@ -64,7 +64,7 @@
"gulp": "^3.8.8", "gulp": "^3.8.8",
"gulp-autoprefixer": "^2.1.0", "gulp-autoprefixer": "^2.1.0",
"gulp-changed": "^1.0.0", "gulp-changed": "^1.0.0",
"gulp-clang-format": "^1.0.12", "gulp-clang-format": "^1.0.13",
"gulp-concat": "^2.5.2", "gulp-concat": "^2.5.2",
"gulp-connect": "~1.0.5", "gulp-connect": "~1.0.5",
"gulp-load-plugins": "^0.7.1", "gulp-load-plugins": "^0.7.1",