From 83b27bac17ec2d1567a98f959334c6e7c6ff0dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=A1ko=20Hevery?= Date: Thu, 14 Dec 2017 15:03:46 -0800 Subject: [PATCH] style: fix formatting errors (#20855) PR Close #20855 --- packages/core/src/render3/component.ts | 3 +- packages/core/src/render3/di.ts | 35 ++++++++++++++-------- packages/core/src/render3/instructions.ts | 32 +++++++++++--------- packages/core/src/render3/interfaces.ts | 5 ++-- packages/core/src/render3/l_node.ts | 6 ++-- packages/core/src/render3/l_node_static.ts | 2 +- packages/core/src/render3/query.ts | 10 +++++-- packages/core/test/render3/render_util.ts | 3 +- 8 files changed, 59 insertions(+), 37 deletions(-) diff --git a/packages/core/src/render3/component.ts b/packages/core/src/render3/component.ts index 14c2f5d18e..b053e5eb99 100644 --- a/packages/core/src/render3/component.ts +++ b/packages/core/src/render3/component.ts @@ -7,12 +7,13 @@ */ import {ComponentRef, EmbeddedViewRef, Injector} from '../core'; + import {assertNotNull} from './assert'; import {NG_HOST_SYMBOL, createError, createViewState, directiveCreate, elementHost, enterView, leaveView} from './instructions'; import {LElement} from './l_node'; import {ComponentDef, ComponentType} from './public_interfaces'; import {RElement, Renderer3, RendererFactory3} from './renderer'; -import {stringify, notImplemented} from './util'; +import {notImplemented, stringify} from './util'; diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index f0d589e006..88b007eaaa 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -9,14 +9,17 @@ // We are temporarily importing the existing viewEngine from core so we can be sure we are // correctly implementing its interfaces for backwards compatibility. import * as viewEngine from '../core'; + import {BLOOM_SIZE, NG_ELEMENT_ID, getOrCreateNodeInjector} from './instructions'; import {LContainer, LNodeFlags, LNodeInjector} from './l_node'; import {ComponentTemplate, DirectiveDef} from './public_interfaces'; -import {stringify, notImplemented} from './util'; +import {notImplemented, stringify} from './util'; + /** Injection flags for DI. */ export const enum InjectFlags { - /** Dependency is not required. Null will be injected if there is no provider for the dependency. */ + /** Dependency is not required. Null will be injected if there is no provider for the dependency. + */ Optional = 1 << 0, /** When resolving a dependency, include the node that is requesting injection. */ CheckSelf = 1 << 1, @@ -86,7 +89,9 @@ export function inject(token: viewEngine.Type, flags?: InjectFlags): T { // If no injector is found, we *know* that there is no ancestor injector that contains the // token, so we abort. - if (!injector) { break; } + if (!injector) { + break; + } // At this point, we have an injector which *may* contain the token, so we step through the // directives associated with the injector's corresponding node to get the directive instance. @@ -160,8 +165,8 @@ function bloomHashBit(type: viewEngine.Type): number|null { * @param bloomBit The bit to check in each injector's bloom filter * @returns An injector that might have the directive */ -export function bloomFindPossibleInjector(startInjector: LNodeInjector, bloomBit: number): LNodeInjector| - null { +export function bloomFindPossibleInjector( + startInjector: LNodeInjector, bloomBit: number): LNodeInjector|null { // Create a mask that targets the specific bit associated with the directive we're looking for. // This will be a number between 0 and 31, corresponding to a bit position in a 32 bit integer. const mask = 1 << bloomBit; @@ -173,8 +178,8 @@ export function bloomFindPossibleInjector(startInjector: LNodeInjector, bloomBit // Our bloom filter size is 128 bits, which is four 32-bit bloom filter buckets: // bf0 = [0 - 31], bf1 = [32 - 63], bf2 = [64 - 95], bf3 = [96 - 127] // Get the bloom filter value from the appropriate bucket based on the directive's bloomBit. - let value: number = - bloomBit < 64 ? (bloomBit < 32 ? injector.bf0 : injector.bf1) : (bloomBit < 96 ? injector.bf2 : injector.bf3); + let value: number = bloomBit < 64 ? (bloomBit < 32 ? injector.bf0 : injector.bf1) : + (bloomBit < 96 ? injector.bf2 : injector.bf3); // If the bloom filter value has the bit corresponding to the directive's bloomBit flipped on, // this injector is a potential match. @@ -184,8 +189,8 @@ export function bloomFindPossibleInjector(startInjector: LNodeInjector, bloomBit // If the current injector does not have the directive, check the bloom filters for the ancestor // injectors (cbf0 - cbf3). These filters capture *all* ancestor injectors. - value = - bloomBit < 64 ? (bloomBit < 32 ? injector.cbf0 : injector.cbf1) : (bloomBit < 96 ? injector.cbf2 : injector.cbf3); + value = bloomBit < 64 ? (bloomBit < 32 ? injector.cbf0 : injector.cbf1) : + (bloomBit < 96 ? injector.cbf2 : injector.cbf3); // If the ancestor bloom filter value has the bit corresponding to the directive, traverse up to // find the specific injector. If the ancestor bloom filter does not have the bit, we can abort. @@ -264,8 +269,8 @@ class ViewContainerRef implements viewEngine.ViewContainerRef { get(index: number): viewEngine.ViewRef|null { throw notImplemented(); } length: number; createEmbeddedView( - templateRef: viewEngine.TemplateRef, context?: C|undefined, - index?: number|undefined): viewEngine.EmbeddedViewRef { + templateRef: viewEngine.TemplateRef, context?: C|undefined, + index?: number|undefined): viewEngine.EmbeddedViewRef { throw notImplemented(); } createComponent( @@ -274,8 +279,12 @@ class ViewContainerRef implements viewEngine.ViewContainerRef { ngModule?: viewEngine.NgModuleRef|undefined): viewEngine.ComponentRef { throw notImplemented(); } - insert(viewRef: viewEngine.ViewRef, index?: number|undefined): viewEngine.ViewRef { throw notImplemented(); } - move(viewRef: viewEngine.ViewRef, currentIndex: number): viewEngine.ViewRef { throw notImplemented(); } + insert(viewRef: viewEngine.ViewRef, index?: number|undefined): viewEngine.ViewRef { + throw notImplemented(); + } + move(viewRef: viewEngine.ViewRef, currentIndex: number): viewEngine.ViewRef { + throw notImplemented(); + } indexOf(viewRef: viewEngine.ViewRef): number { throw notImplemented(); } remove(index?: number|undefined): void { throw notImplemented(); } detach(index?: number|undefined): viewEngine.ViewRef|null { throw notImplemented(); } diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index 1299a20620..e2214cb41b 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -9,9 +9,11 @@ import './ng_dev_mode'; import {Type} from '../core'; + import {assertEqual, assertLessThan, assertNotEqual, assertNotNull} from './assert'; -import {CssSelector, ContainerState, ProjectionState, QueryState, ViewState} from './interfaces'; -import {LText, LView, LElement, LNode, LNodeFlags, LNodeInjector, LContainer, LProjection} from './l_node'; +import {ContainerState, CssSelector, ProjectionState, QueryState, ViewState} from './interfaces'; +import {LContainer, LElement, LNode, LNodeFlags, LNodeInjector, LProjection, LText, LView} from './l_node'; + import {NgStaticData, LNodeStatic, LContainerStatic, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './l_node_static'; import {assertNodeType} from './node_assert'; import {appendChild, insertChild, insertView, processProjectedNode, removeView} from './node_manipulation'; @@ -129,7 +131,8 @@ export function enterView(newViewState: ViewState, host: LElement | LView | null export const leaveView: (newViewState: ViewState) => void = enterView as any; -export function createViewState(viewId: number, renderer: Renderer3, ngStaticData: NgStaticData): ViewState { +export function createViewState( + viewId: number, renderer: Renderer3, ngStaticData: NgStaticData): ViewState { const newView = { parent: currentView, id: viewId, // -1 for component views @@ -336,7 +339,7 @@ export function elementCreate( } else { native = renderer.createElement(name); - let componentView: ViewState | null = null; + let componentView: ViewState|null = null; if (isHostElement) { const ngStaticData = getTemplateStatic((nameOrComponentDef as ComponentDef).template); componentView = addToViewTree(createViewState(-1, renderer, ngStaticData)); @@ -402,7 +405,8 @@ export function elementHost(elementOrSelector: RElement | string, def: Component throw createError('Host node is required:', elementOrSelector); } } - createLNode(0, LNodeFlags.Element, rNode, createViewState(-1, renderer, getTemplateStatic(def.template))); + createLNode( + 0, LNodeFlags.Element, rNode, createViewState(-1, renderer, getTemplateStatic(def.template))); } @@ -454,8 +458,7 @@ export function listenerCreate( function outputCreate(outputs: (number | string)[], listener: Function): void { for (let i = 0; i < outputs.length; i += 2) { ngDevMode && assertDataInRange(outputs[i] as number); - const subscription = - data[outputs[i] as number][outputs[i | 1]].subscribe(listener); + const subscription = data[outputs[i] as number][outputs[i | 1]].subscribe(listener); cleanup !.push(subscription.unsubscribe, subscription); } } @@ -570,7 +573,8 @@ function setInputsForProperty(inputs: (number | string)[], value: any): void { * * @param index Index where data should be stored in ngStaticData */ -function generatePropertyAliases(flags: number, data: LNodeStatic, isInputData = false): LNodeStatic { +function generatePropertyAliases( + flags: number, data: LNodeStatic, isInputData = false): LNodeStatic { const start = flags >> LNodeFlags.INDX_SHIFT; const size = (flags & LNodeFlags.SIZE_MASK) >> LNodeFlags.SIZE_SHIFT; @@ -582,7 +586,7 @@ function generatePropertyAliases(flags: number, data: LNodeStatic, isInputData = if (propertyAliasMap.hasOwnProperty(publicName)) { const internalName = propertyAliasMap[publicName]; const staticDirData: PropertyAliases = isInputData ? (data.inputs || (data.inputs = {})) : - (data.outputs || (data.outputs = {})); + (data.outputs || (data.outputs = {})); const hasProperty: boolean = staticDirData.hasOwnProperty(publicName); hasProperty ? staticDirData[publicName].push(i, internalName) : (staticDirData[publicName] = [i, internalName]); @@ -938,8 +942,8 @@ export function viewCreate(viewBlockId: number): boolean { const containerState = container.data; const views = containerState.views; - const existingView: LView|false = !creationMode && containerState.nextIndex < views.length && - views[containerState.nextIndex]; + const existingView: LView|false = + !creationMode && containerState.nextIndex < views.length && views[containerState.nextIndex]; let viewUpdateMode = existingView && viewBlockId === (existingView as LView).data.id; if (viewUpdateMode) { @@ -949,7 +953,8 @@ export function viewCreate(viewBlockId: number): boolean { enterView((existingView as LView).data, previousOrParentNode as LView); } else { // When we create a new View, we always reset the state of the instructions. - const newViewState = createViewState(viewBlockId, renderer, initViewStaticData(viewBlockId, container)); + const newViewState = + createViewState(viewBlockId, renderer, initViewStaticData(viewBlockId, container)); enterView(newViewState, createLNode(null, LNodeFlags.View, null, newViewState)); containerState.nextIndex++; } @@ -1571,7 +1576,7 @@ function valueInData(data: any[], index: number, value?: T): T { // We don't store any static data for local variables, so the first time // we see the template, we should store as null to avoid a sparse array if (index >= ngStaticData.length) { - ngStaticData[index] = null; + ngStaticData[index] = null; } data[index] = value; } @@ -1600,4 +1605,3 @@ function assertDataInRange(index: number, arr?: any[]) { if (arr == null) arr = data; assertLessThan(arr ? arr.length : 0, index, 'data.length'); } - diff --git a/packages/core/src/render3/interfaces.ts b/packages/core/src/render3/interfaces.ts index 32ae264b39..d085be48e9 100644 --- a/packages/core/src/render3/interfaces.ts +++ b/packages/core/src/render3/interfaces.ts @@ -7,10 +7,11 @@ */ import {QueryList, Type} from '../core'; + +import {LContainer, LElement, LNode, LText, LView} from './l_node'; +import {LNodeStatic} from './l_node_static'; import {ComponentTemplate, DirectiveDef} from './public_interfaces'; import {Renderer3} from './renderer'; -import {LNode, LView, LElement, LContainer, LText} from './l_node'; -import {LNodeStatic} from './l_node_static'; declare global { const ngDevMode: boolean; diff --git a/packages/core/src/render3/l_node.ts b/packages/core/src/render3/l_node.ts index ce53280ed7..2cf337ba94 100644 --- a/packages/core/src/render3/l_node.ts +++ b/packages/core/src/render3/l_node.ts @@ -7,9 +7,11 @@ */ import {ElementRef, Injector, TemplateRef, ViewContainerRef} from '../core'; -import {RComment, RElement, RText} from './renderer'; -import {ViewState, ContainerState, ProjectionState, QueryState} from './interfaces'; + +import {ContainerState, ProjectionState, QueryState, ViewState} from './interfaces'; import {LNodeStatic} from './l_node_static'; +import {RComment, RElement, RText} from './renderer'; + /** * LNodeFlags corresponds to the LNode.flags property. It contains information diff --git a/packages/core/src/render3/l_node_static.ts b/packages/core/src/render3/l_node_static.ts index 00c7bf6287..4d6b367ca2 100644 --- a/packages/core/src/render3/l_node_static.ts +++ b/packages/core/src/render3/l_node_static.ts @@ -9,7 +9,7 @@ import {DirectiveDef} from './public_interfaces'; /** The type of the global ngStaticData array. */ -export type NgStaticData = (LNodeStatic | DirectiveDef | null)[]; +export type NgStaticData = (LNodeStatic | DirectiveDef| null)[]; /** * LNode binding data (flywiehgt) for a particular node that is shared between all templates diff --git a/packages/core/src/render3/query.ts b/packages/core/src/render3/query.ts index fb7f58e8f9..6696be0d17 100644 --- a/packages/core/src/render3/query.ts +++ b/packages/core/src/render3/query.ts @@ -6,11 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ -import * as viewEngine from '../core'; +import {DirectiveDef} from '@angular/core/src/render3/public_interfaces'; import {Observable} from 'rxjs/Observable'; + +import * as viewEngine from '../core'; + import {assertNotNull} from './assert'; import {QueryState} from './interfaces'; -import {DirectiveDef} from '@angular/core/src/render3/public_interfaces'; import {LContainer, LNode, LNodeFlags, LView} from './l_node'; @@ -60,7 +62,9 @@ export class QueryState_ implements QueryState { constructor(deep?: QueryPredicate) { this.deep = deep == null ? null : deep; } - track(queryList: viewEngine.QueryList, predicate: viewEngine.Type|any[], descend?: boolean): void { + track( + queryList: viewEngine.QueryList, predicate: viewEngine.Type|any[], + descend?: boolean): void { // TODO(misko): This is not right. In case of inherited state, a calling track will incorrectly // mutate parent. if (descend) { diff --git a/packages/core/test/render3/render_util.ts b/packages/core/test/render3/render_util.ts index fdac5d9924..6d7f9ffbfa 100644 --- a/packages/core/test/render3/render_util.ts +++ b/packages/core/test/render3/render_util.ts @@ -37,7 +37,8 @@ export function resetDOM() { requestAnimationFrame.queue = []; containerEl = document.createElement('div'); containerEl.setAttribute('host', ''); - host = createLNode(null, LNodeFlags.Element, containerEl, createViewState(-1, activeRenderer, null !)); + host = createLNode( + null, LNodeFlags.Element, containerEl, createViewState(-1, activeRenderer, null !)); // TODO: assert that the global state is clean (e.g. ngData, previousOrParentNode, etc) }