From 15f1eb28a2c7c3af40aa8882c89e28014f2fa582 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Thu, 21 May 2015 16:42:19 +0200 Subject: [PATCH] fix(deps): Update clang-format to 1.0.14. --- modules/angular2/src/core/application.ts | 16 +- .../angular2/src/core/compiler/compiler.ts | 141 +++-- .../core/compiler/dynamic_component_loader.ts | 156 +++--- .../src/core/life_cycle/life_cycle.ts | 72 +-- modules/angular2/src/di/exceptions.ts | 8 +- modules/angular2/src/dom/browser_adapter.ts | 485 +++++++----------- .../src/render/dom/compiler/selector.ts | 171 +++--- .../src/render/dom/events/event_manager.ts | 6 +- .../src/render/dom/events/key_events.ts | 29 +- modules/angular2/src/test_lib/test_lib.ts | 40 +- modules/angular2/src/test_lib/utils.ts | 6 +- .../test/core/compiler/integration_spec.ts | 2 +- npm-shrinkwrap.clean.json | 4 +- npm-shrinkwrap.json | 12 +- package.json | 2 +- 15 files changed, 519 insertions(+), 631 deletions(-) diff --git a/modules/angular2/src/core/application.ts b/modules/angular2/src/core/application.ts index 822beeb0fe..9e13e6b339 100644 --- a/modules/angular2/src/core/application.ts +++ b/modules/angular2/src/core/application.ts @@ -89,7 +89,7 @@ function _injectorBindings(appComponentType): List> { bind(appComponentType).toFactory((ref) => ref.instance, [appComponentRefToken]), bind(LifeCycle) .toFactory((exceptionHandler) => new LifeCycle(exceptionHandler, null, assertionsEnabled()), - [ExceptionHandler]), + [ExceptionHandler]), bind(EventManager) .toFactory( (ngZone) => @@ -142,15 +142,15 @@ function _injectorBindings(appComponentType): List> { function _createNgZone(givenReporter: Function): NgZone { var defaultErrorReporter = (exception, stackTrace) => { var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n"); - DOM.logError(`${exception}\n\n${longStackTrace}`); - throw exception; -}; + DOM.logError(`${exception}\n\n${longStackTrace}`); + throw exception; + }; -var reporter = isPresent(givenReporter) ? givenReporter : defaultErrorReporter; + var reporter = isPresent(givenReporter) ? givenReporter : defaultErrorReporter; -var zone = new NgZone({enableLongStackTrace: assertionsEnabled()}); -zone.initCallbacks({onErrorHandler: reporter}); -return zone; + var zone = new NgZone({enableLongStackTrace: assertionsEnabled()}); + zone.initCallbacks({onErrorHandler: reporter}); + return zone; } /** diff --git a/modules/angular2/src/core/compiler/compiler.ts b/modules/angular2/src/core/compiler/compiler.ts index e671d5d67d..5b0bcc29d2 100644 --- a/modules/angular2/src/core/compiler/compiler.ts +++ b/modules/angular2/src/core/compiler/compiler.ts @@ -175,84 +175,83 @@ export class Compiler { var nestedPVPromises = []; ListWrapper.forEach(this._collectComponentElementBinders(protoViews), (elementBinder) => { var nestedComponent = elementBinder.componentDirective; - var elementBinderDone = (nestedPv: AppProtoView) => { - elementBinder.nestedProtoView = nestedPv; - }; + var elementBinderDone = + (nestedPv: AppProtoView) => { elementBinder.nestedProtoView = nestedPv; }; var nestedCall = this._compile(nestedComponent); if (PromiseWrapper.isPromise(nestedCall)) { - ListWrapper.push(nestedPVPromises, - (>nestedCall).then(elementBinderDone)); + ListWrapper.push(nestedPVPromises, + (>nestedCall).then(elementBinderDone)); } else if (isPresent(nestedCall)) { - elementBinderDone(nestedCall); - } - }); - - if (nestedPVPromises.length > 0) { - return PromiseWrapper.all(nestedPVPromises).then((_) => protoView); - } else { - return protoView; - } -} - -private _collectComponentElementBinders(protoViews: List): List { - var componentElementBinders = []; - ListWrapper.forEach(protoViews, (protoView) => { - ListWrapper.forEach(protoView.elementBinders, (elementBinder) => { - if (isPresent(elementBinder.componentDirective)) { - ListWrapper.push(componentElementBinders, elementBinder); + elementBinderDone(nestedCall); } }); - }); - 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 { - if (isBlank(template.directives)) return []; - - var directives = []; - this._flattenList(template.directives, directives); - - return directives; -} - -private _flattenList(tree: List, out: List>): void { - for (var i = 0; i < tree.length; i++) { - var item = resolveForwardRef(tree[i]); - if (ListWrapper.isList(item)) { - this._flattenList(item, out); + if (nestedPVPromises.length > 0) { + return PromiseWrapper.all(nestedPVPromises).then((_) => protoView); } else { - ListWrapper.push(out, item); + return protoView; + } + } + + private _collectComponentElementBinders(protoViews: List): List { + 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 { + if (isBlank(template.directives)) return []; + + var directives = []; + this._flattenList(template.directives, directives); + + return directives; + } + + private _flattenList(tree: List, out: List>): 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.`); - } -} -} diff --git a/modules/angular2/src/core/compiler/dynamic_component_loader.ts b/modules/angular2/src/core/compiler/dynamic_component_loader.ts index d87e334c28..25c798059f 100644 --- a/modules/angular2/src/core/compiler/dynamic_component_loader.ts +++ b/modules/angular2/src/core/compiler/dynamic_component_loader.ts @@ -38,81 +38,85 @@ export class DynamicComponentLoader { loadIntoExistingLocation(typeOrBinding, location: ElementRef, injector: Injector = null): Promise { var binding = this._getBinding(typeOrBinding); - return this._compiler.compile(binding.token).then(componentProtoViewRef => { - this._viewManager.createDynamicComponentView(location, componentProtoViewRef, binding, - injector); - var component = this._viewManager.getComponent(location); - 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. - * The loaded component receives injection normally as a hosted view. - */ -loadAsRoot(typeOrBinding, overrideSelector = null, - injector: Injector = null): Promise { - return this._compiler.compileInHost(this._getBinding(typeOrBinding)).then(hostProtoViewRef => { - var hostViewRef = - this._viewManager.createRootHostView(hostProtoViewRef, overrideSelector, injector); - var newLocation = new ElementRef(hostViewRef, 0); - var component = this._viewManager.getComponent(newLocation); - - 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. - * The loaded component receives injection normally as a hosted view. - */ -loadIntoNewLocation(typeOrBinding, parentComponentLocation: ElementRef, - injector: Injector = null): Promise { - return this._compiler.compileInHost(this._getBinding(typeOrBinding)).then(hostProtoViewRef => { - var hostViewRef = - this._viewManager.createFreeHostView(parentComponentLocation, hostProtoViewRef, injector); - var newLocation = new ElementRef(hostViewRef, 0); - var component = this._viewManager.getComponent(newLocation); - - var 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. - */ -loadNextToExistingLocation(typeOrBinding, location: ElementRef, - injector: Injector = null): Promise { - var binding = this._getBinding(typeOrBinding); - return this._compiler.compileInHost(binding).then(hostProtoViewRef => { - var viewContainer = this._viewManager.getViewContainer(location); - var hostViewRef = viewContainer.create(hostProtoViewRef, viewContainer.length, null, injector); - var newLocation = new ElementRef(hostViewRef, 0); - var component = this._viewManager.getComponent(newLocation); - - var dispose = () => { var index = viewContainer.indexOf(hostViewRef); - viewContainer.remove(index); - }; - return new ComponentRef(newLocation, component, dispose); -}); -} - -private _getBinding(typeOrBinding): Binding { - var binding; - if (typeOrBinding instanceof Binding) { - binding = typeOrBinding; - } else { - binding = bind(typeOrBinding).toClass(typeOrBinding); + return this._compiler.compile(binding.token) + .then(componentProtoViewRef => { + this._viewManager.createDynamicComponentView(location, componentProtoViewRef, binding, + injector); + var component = this._viewManager.getComponent(location); + 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. + * The loaded component receives injection normally as a hosted view. + */ + loadAsRoot(typeOrBinding, overrideSelector = null, + injector: Injector = null): Promise { + return this._compiler.compileInHost(this._getBinding(typeOrBinding)) + .then(hostProtoViewRef => { + var hostViewRef = + this._viewManager.createRootHostView(hostProtoViewRef, overrideSelector, injector); + var newLocation = new ElementRef(hostViewRef, 0); + var component = this._viewManager.getComponent(newLocation); + + 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. + * The loaded component receives injection normally as a hosted view. + */ + loadIntoNewLocation(typeOrBinding, parentComponentLocation: ElementRef, + injector: Injector = null): Promise { + return this._compiler.compileInHost(this._getBinding(typeOrBinding)) + .then(hostProtoViewRef => { + var hostViewRef = this._viewManager.createFreeHostView(parentComponentLocation, + hostProtoViewRef, injector); + var newLocation = new ElementRef(hostViewRef, 0); + var component = this._viewManager.getComponent(newLocation); + + var 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. + */ + loadNextToExistingLocation(typeOrBinding, location: ElementRef, + injector: Injector = null): Promise { + var binding = this._getBinding(typeOrBinding); + return this._compiler.compileInHost(binding).then(hostProtoViewRef => { + var viewContainer = this._viewManager.getViewContainer(location); + var hostViewRef = + viewContainer.create(hostProtoViewRef, viewContainer.length, null, injector); + var newLocation = new ElementRef(hostViewRef, 0); + var component = this._viewManager.getComponent(newLocation); + + var dispose = () => { + var index = viewContainer.indexOf(hostViewRef); + viewContainer.remove(index); + }; + return new ComponentRef(newLocation, component, dispose); + }); + } + + private _getBinding(typeOrBinding): Binding { + var binding; + if (typeOrBinding instanceof Binding) { + binding = typeOrBinding; + } else { + binding = bind(typeOrBinding).toClass(typeOrBinding); + } + return binding; } - return binding; -} } diff --git a/modules/angular2/src/core/life_cycle/life_cycle.ts b/modules/angular2/src/core/life_cycle/life_cycle.ts index 35d3568b86..f432bd3961 100644 --- a/modules/angular2/src/core/life_cycle/life_cycle.ts +++ b/modules/angular2/src/core/life_cycle/life_cycle.ts @@ -39,43 +39,45 @@ export class LifeCycle { constructor(exceptionHandler: ExceptionHandler, changeDetector: ChangeDetector = null, enforceNoNewChanges: boolean = false) { - this._errorHandler = (exception, stackTrace) => { exceptionHandler.call(exception, stackTrace); - throw exception; - }; - this._changeDetector = - 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; + this._errorHandler = (exception, stackTrace) => { + exceptionHandler.call(exception, stackTrace); + throw exception; + }; + this._changeDetector = + changeDetector; // may be null when instantiated from application bootstrap + this._enforceNoNewChanges = enforceNoNewChanges; } - zone.initCallbacks({onErrorHandler: this._errorHandler, onTurnDone: () => this.tick()}); -} + /** + * @private + */ + registerWith(zone: NgZone, changeDetector: ChangeDetector = null) { + if (isPresent(changeDetector)) { + this._changeDetector = changeDetector; + } -/** - * 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 - * changes are detected. If additional changes are picked up during this second cycle, bindings in - * the app have - * 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 - * detection must - * complete. - * - */ -tick() { - this._changeDetector.detectChanges(); - if (this._enforceNoNewChanges) { - this._changeDetector.checkNoChanges(); + 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 + * changes are detected. If additional changes are picked up during this second cycle, bindings + * in + * the app have + * 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 + * detection must + * complete. + * + */ + tick() { + this._changeDetector.detectChanges(); + if (this._enforceNoNewChanges) { + this._changeDetector.checkNoChanges(); + } } } -} diff --git a/modules/angular2/src/di/exceptions.ts b/modules/angular2/src/di/exceptions.ts index 22984f26e1..d6ed807651 100644 --- a/modules/angular2/src/di/exceptions.ts +++ b/modules/angular2/src/di/exceptions.ts @@ -61,7 +61,7 @@ export class AbstractBindingError extends BaseException { export class NoBindingError extends AbstractBindingError { // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(key) { - super(key, function (keys:List) { + super(key, function(keys: List) { var first = stringify(ListWrapper.first(keys).token); return `No provider for ${first}!${constructResolvingPath(keys)}`; }); @@ -95,7 +95,7 @@ export class NoBindingError extends AbstractBindingError { export class AsyncBindingError extends AbstractBindingError { // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(key) { - super(key, function (keys:List) { + super(key, function(keys: List) { var first = stringify(ListWrapper.first(keys).token); 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 { // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(key) { - super(key, function (keys:List) { + super(key, function(keys: List) { return `Cannot instantiate cyclic dependency!${constructResolvingPath(keys)}`; }); } @@ -142,7 +142,7 @@ export class InstantiationError extends AbstractBindingError { causeKey; // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(cause, key) { - super(key, function (keys:List) { + super(key, function(keys: List) { var first = stringify(ListWrapper.first(keys).token); return `Error during instantiation of ${first}!${constructResolvingPath(keys)}. ORIGINAL ERROR: ${cause}`; }); diff --git a/modules/angular2/src/dom/browser_adapter.ts b/modules/angular2/src/dom/browser_adapter.ts index ea7119f4f9..5254d51926 100644 --- a/modules/angular2/src/dom/browser_adapter.ts +++ b/modules/angular2/src/dom/browser_adapter.ts @@ -63,318 +63,197 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter { el.addEventListener(evt, listener, false); // Needed to follow Dart's subscription semantic, until fix of // https://code.google.com/p/dart/issues/detail?id=17406 - 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 (node).content; - } else { - return node; + return () => { el.removeEventListener(evt, listener, false); }; } -} -firstChild(el): Node { - return el.firstChild; -} -nextSibling(el): Node { - return el.nextSibling; -} -parentElement(el) { - return el.parentElement; -} -childNodes(el): List { - return el.childNodes; -} -childNodesAsList(el): List { - var childNodes = el.childNodes; - var res = ListWrapper.createFixedSize(childNodes.length); - for (var i = 0; i < childNodes.length; i++) { - res[i] = childNodes[i]; + dispatchEvent(el, evt) { el.dispatchEvent(evt); } + createMouseEvent(eventType: string): MouseEvent { + var evt: MouseEvent = document.createEvent('MouseEvent'); + evt.initEvent(eventType, true, true); + return evt; } - return res; -} -clearNodes(el) { - for (var i = 0; i < el.childNodes.length; i++) { - this.remove(el.childNodes[i]); + createEvent(eventType): Event { + var evt: Event = document.createEvent('Event'); + evt.initEvent(eventType, true, true); + return evt; } -} -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 = doc.createElement('SCRIPT'); - el.setAttribute(attrName, attrValue); - return el; -} -createStyleElement(css: string, doc = document): HTMLStyleElement { - var style = doc.createElement('style'); - this.appendChild(style, this.createTextNode(css)); - return style; -} -createShadowRoot(el: HTMLElement): DocumentFragment { - return (el).createShadowRoot(); -} -getShadowRoot(el: HTMLElement): DocumentFragment { - return (el).shadowRoot; -} -getHost(el: HTMLElement): HTMLElement { - return (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 { - return >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); + preventDefault(evt: Event) { + evt.preventDefault(); + evt.returnValue = false; } - 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 (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'; + 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 (node).content; + } else { + return node; } - 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]; + } + firstChild(el): Node { return el.firstChild; } + nextSibling(el): Node { return el.nextSibling; } + parentElement(el) { return el.parentElement; } + childNodes(el): List { return el.childNodes; } + childNodesAsList(el): List { + 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 = doc.createElement('SCRIPT'); + el.setAttribute(attrName, attrValue); + return el; + } + createStyleElement(css: string, doc = document): HTMLStyleElement { + var style = doc.createElement('style'); + this.appendChild(style, this.createTextNode(css)); + return style; + } + createShadowRoot(el: HTMLElement): DocumentFragment { return (el).createShadowRoot(); } + getShadowRoot(el: HTMLElement): DocumentFragment { return (el).shadowRoot; } + getHost(el: HTMLElement): HTMLElement { return (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 { + return >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 (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)) { - key = _keyMap[key]; + getGlobalEventTarget(target: string): EventTarget { + if (target == "window") { + return window; + } else if (target == "document") { + return document; + } else if (target == "body") { + return document.body; + } } - return key; -} -getGlobalEventTarget(target: string): EventTarget { - if (target == "window") { - 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; -} + 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 diff --git a/modules/angular2/src/render/dom/compiler/selector.ts b/modules/angular2/src/render/dom/compiler/selector.ts index d639d33745..7d7ab03b00 100644 --- a/modules/angular2/src/render/dom/compiler/selector.ts +++ b/modules/angular2/src/render/dom/compiler/selector.ts @@ -36,97 +36,96 @@ export class CssSelector { if (isPresent(cssSel.notSelector) && isBlank(cssSel.element) && ListWrapper.isEmpty(cssSel.classNames) && ListWrapper.isEmpty(cssSel.attrs)) { 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(); - current = current.notSelector; - } - if (isPresent(match[2])) { - current.setElement(match[2]); - } - if (isPresent(match[3])) { - current.addClassName(match[3]); - } - if (isPresent(match[4])) { - current.addAttribute(match[4], match[5]); - } - if (isPresent(match[6])) { - _addResult(results, cssSelector); - cssSelector = current = new CssSelector(); - } - } - _addResult(results, cssSelector); - return results; -} - -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; + 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(); + current = current.notSelector; + } + if (isPresent(match[2])) { + current.setElement(match[2]); + } + if (isPresent(match[3])) { + current.addClassName(match[3]); + } + if (isPresent(match[4])) { + current.addAttribute(match[4], match[5]); + } + if (isPresent(match[6])) { + _addResult(results, cssSelector); + cssSelector = current = new CssSelector(); } - 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; -} } /** diff --git a/modules/angular2/src/render/dom/events/event_manager.ts b/modules/angular2/src/render/dom/events/event_manager.ts index 4da3d79617..d762aa476c 100644 --- a/modules/angular2/src/render/dom/events/event_manager.ts +++ b/modules/angular2/src/render/dom/events/event_manager.ts @@ -96,7 +96,11 @@ export class DomEventsPlugin extends EventManagerPlugin { } 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) { diff --git a/modules/angular2/src/render/dom/events/key_events.ts b/modules/angular2/src/render/dom/events/key_events.ts index d95c4366f3..20707c90f2 100644 --- a/modules/angular2/src/render/dom/events/key_events.ts +++ b/modules/angular2/src/render/dom/events/key_events.ts @@ -89,20 +89,21 @@ export class KeyEventsPlugin extends EventManagerPlugin { } static eventCallback(element, shouldSupportBubble, fullKey, handler, zone) { - return (event) => { var correctElement = shouldSupportBubble || event.target === element; - if (correctElement && KeyEventsPlugin.getEventFullKey(event) === fullKey) { - zone.run(() => handler(event)); - } - }; -} + return (event) => { + var correctElement = shouldSupportBubble || event.target === element; + if (correctElement && KeyEventsPlugin.getEventFullKey(event) === fullKey) { + zone.run(() => handler(event)); + } + }; + } -static _normalizeKey(keyName: string): string { - // TODO: switch to a StringMap if the mapping grows too much - switch (keyName) { - case 'esc': - return 'escape'; - default: - return keyName; + static _normalizeKey(keyName: string): string { + // TODO: switch to a StringMap if the mapping grows too much + switch (keyName) { + case 'esc': + return 'escape'; + default: + return keyName; + } } } -} diff --git a/modules/angular2/src/test_lib/test_lib.ts b/modules/angular2/src/test_lib/test_lib.ts index 67e6b9b375..8b1d742cce 100644 --- a/modules/angular2/src/test_lib/test_lib.ts +++ b/modules/angular2/src/test_lib/test_lib.ts @@ -331,31 +331,33 @@ export class SpyObject { } function elementText(n) { - var hasNodes = (n) => { var children = DOM.childNodes(n); - return children && children.length > 0; -} + var hasNodes = (n) => + { + var children = DOM.childNodes(n); + return children && children.length > 0; + } -if (n instanceof Array) { - return n.map((nn) => elementText(nn)).join(""); -} + if (n instanceof Array) { + return n.map((nn) => elementText(nn)).join(""); + } -if (DOM.isCommentNode(n)) { - return ''; -} + if (DOM.isCommentNode(n)) { + return ''; + } -if (DOM.isElementNode(n) && DOM.tagName(n) == 'CONTENT') { - return elementText(Array.prototype.slice.apply(DOM.getDistributedNodes(n))); -} + if (DOM.isElementNode(n) && DOM.tagName(n) == 'CONTENT') { + return elementText(Array.prototype.slice.apply(DOM.getDistributedNodes(n))); + } -if (DOM.hasShadowRoot(n)) { - return elementText(DOM.childNodesAsList(DOM.getShadowRoot(n))); -} + if (DOM.hasShadowRoot(n)) { + return elementText(DOM.childNodesAsList(DOM.getShadowRoot(n))); + } -if (hasNodes(n)) { - return elementText(DOM.childNodesAsList(n)); -} + if (hasNodes(n)) { + return elementText(DOM.childNodesAsList(n)); + } -return DOM.getText(n); + return DOM.getText(n); } export function isInInnerZone(): boolean { diff --git a/modules/angular2/src/test_lib/utils.ts b/modules/angular2/src/test_lib/utils.ts index 588af3e211..f939c5fd6b 100644 --- a/modules/angular2/src/test_lib/utils.ts +++ b/modules/angular2/src/test_lib/utils.ts @@ -13,12 +13,10 @@ export class Log { fn(value) { return (a1 = null, a2 = null, a3 = null, a4 = null, a5 = null) => { ListWrapper.push(this._result, value); + } } -} -result(): string { - return ListWrapper.join(this._result, "; "); -} + result(): string { return ListWrapper.join(this._result, "; "); } } export function viewRootNodes(view): List { diff --git a/modules/angular2/test/core/compiler/integration_spec.ts b/modules/angular2/test/core/compiler/integration_spec.ts index 36ec547555..f2dfc01ac1 100644 --- a/modules/angular2/test/core/compiler/integration_spec.ts +++ b/modules/angular2/test/core/compiler/integration_spec.ts @@ -227,7 +227,7 @@ export function main() { return [bind(ChangeDetection) .toFactory(() => new DynamicChangeDetection( new PipeRegistry({"double": [new DoublePipeFactory()]})), - [])]; + [])]; }); it("should support pipes in bindings and bind config", diff --git a/npm-shrinkwrap.clean.json b/npm-shrinkwrap.clean.json index e4a3f9540a..b206194f57 100644 --- a/npm-shrinkwrap.clean.json +++ b/npm-shrinkwrap.clean.json @@ -3934,7 +3934,7 @@ } }, "gulp-clang-format": { - "version": "1.0.12", + "version": "1.0.13", "dependencies": { "gulp-util": { "version": "3.0.4", @@ -4112,7 +4112,7 @@ } }, "clang-format": { - "version": "1.0.12" + "version": "1.0.14" } } }, diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index d67968f54a..59cfc98328 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -6073,9 +6073,9 @@ } }, "gulp-clang-format": { - "version": "1.0.12", - "from": "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.12.tgz", + "version": "1.0.13", + "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.13.tgz", "dependencies": { "gulp-util": { "version": "3.0.4", @@ -6351,9 +6351,9 @@ } }, "clang-format": { - "version": "1.0.12", - "from": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.12.tgz", - "resolved": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.12.tgz" + "version": "1.0.14", + "from": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.14.tgz", + "resolved": "https://registry.npmjs.org/clang-format/-/clang-format-1.0.14.tgz" } } }, diff --git a/package.json b/package.json index 0f4bb20dd3..13c93925ff 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "gulp": "^3.8.8", "gulp-autoprefixer": "^2.1.0", "gulp-changed": "^1.0.0", - "gulp-clang-format": "^1.0.12", + "gulp-clang-format": "^1.0.13", "gulp-concat": "^2.5.2", "gulp-connect": "~1.0.5", "gulp-load-plugins": "^0.7.1",