From bac265fdc262844b2e9ea2b6240908f13febde0d Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 21 Mar 2017 13:36:42 -0700 Subject: [PATCH] refactor(core): misc cleanup (#15366) PR Close #15366 --- packages/compiler/src/identifiers.ts | 3 +-- .../compiler/src/view_compiler/view_compiler.ts | 6 +++--- packages/core/src/view/element.ts | 9 ++++----- packages/core/src/view/ng_content.ts | 2 +- packages/core/src/view/provider.ts | 7 +++---- packages/core/src/view/pure_expression.ts | 4 ++-- packages/core/src/view/query.ts | 6 ++---- packages/core/src/view/refs.ts | 4 ++-- packages/core/src/view/services.ts | 8 ++++---- packages/core/src/view/text.ts | 4 +--- packages/core/src/view/types.ts | 4 ---- packages/core/src/view/util.ts | 11 +++-------- packages/core/src/view/view.ts | 14 ++++++-------- packages/core/src/view/view_attach.ts | 4 ++-- 14 files changed, 34 insertions(+), 52 deletions(-) diff --git a/packages/compiler/src/identifiers.ts b/packages/compiler/src/identifiers.ts index 7ae97d0623..bf8aa20ca0 100644 --- a/packages/compiler/src/identifiers.ts +++ b/packages/compiler/src/identifiers.ts @@ -6,12 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, NgModuleRef, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation, ɵChangeDetectorStatus, ɵCodegenComponentFactoryResolver, ɵEMPTY_ARRAY, ɵEMPTY_MAP, ɵNgModuleInjector, ɵValueUnwrapper, ɵand, ɵccf, ɵcrt, ɵdevModeEqual, ɵdid, ɵeld, ɵinlineInterpolate, ɵinterpolate, ɵncd, ɵnov, ɵpad, ɵpid, ɵpod, ɵppd, ɵprd, ɵqud, ɵreflector, ɵregisterModuleFactory, ɵted, ɵunv, ɵvid} from '@angular/core'; +import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, NgModuleRef, QueryList, Renderer, SecurityContext, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation, ɵCodegenComponentFactoryResolver, ɵEMPTY_ARRAY, ɵEMPTY_MAP, ɵNgModuleInjector, ɵand, ɵccf, ɵcrt, ɵdid, ɵeld, ɵinlineInterpolate, ɵinterpolate, ɵncd, ɵnov, ɵpad, ɵpid, ɵpod, ɵppd, ɵprd, ɵqud, ɵreflector, ɵregisterModuleFactory, ɵted, ɵunv, ɵvid} from '@angular/core'; import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata'; const CORE = assetUrl('core'); -const VIEW_UTILS_MODULE_URL = assetUrl('core', 'linker/view_utils'); export interface IdentifierSpec { name: string; diff --git a/packages/compiler/src/view_compiler/view_compiler.ts b/packages/compiler/src/view_compiler/view_compiler.ts index 2d09942982..ad7b77e3ec 100644 --- a/packages/compiler/src/view_compiler/view_compiler.ts +++ b/packages/compiler/src/view_compiler/view_compiler.ts @@ -6,10 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -import {ChangeDetectionStrategy, ViewEncapsulation, ɵArgumentType as ArgumentType, ɵBindingFlags as BindingFlags, ɵDepFlags as DepFlags, ɵLifecycleHooks as LifecycleHooks, ɵNodeFlags as NodeFlags, ɵQueryBindingType as QueryBindingType, ɵQueryValueType as QueryValueType, ɵViewFlags as ViewFlags, ɵelementEventFullName as elementEventFullName} from '@angular/core'; +import {ChangeDetectionStrategy, ɵArgumentType as ArgumentType, ɵBindingFlags as BindingFlags, ɵDepFlags as DepFlags, ɵLifecycleHooks as LifecycleHooks, ɵNodeFlags as NodeFlags, ɵQueryBindingType as QueryBindingType, ɵQueryValueType as QueryValueType, ɵViewFlags as ViewFlags, ɵelementEventFullName as elementEventFullName} from '@angular/core'; -import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeSummary, CompileProviderMetadata, CompileTokenMetadata, CompileTypeMetadata, identifierModuleUrl, identifierName, rendererTypeName, tokenReference, viewClassName} from '../compile_metadata'; -import {BuiltinConverter, BuiltinConverterFactory, EventHandlerVars, LocalResolver, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins} from '../compiler_util/expression_converter'; +import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompilePipeSummary, CompileProviderMetadata, CompileTokenMetadata, CompileTypeMetadata, rendererTypeName, tokenReference, viewClassName} from '../compile_metadata'; +import {BuiltinConverter, EventHandlerVars, LocalResolver, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins} from '../compiler_util/expression_converter'; import {CompilerConfig} from '../config'; import {AST, ASTWithSource, Interpolation} from '../expression_parser/ast'; import {Identifiers, createIdentifier, createIdentifierToken, resolveIdentifier} from '../identifiers'; diff --git a/packages/core/src/view/element.ts b/packages/core/src/view/element.ts index 848fa1bb5c..f30cd74e68 100644 --- a/packages/core/src/view/element.ts +++ b/packages/core/src/view/element.ts @@ -6,12 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {ViewEncapsulation} from '../metadata/view'; -import {Renderer2, RendererType2} from '../render/api'; +import {RendererType2} from '../render/api'; import {SecurityContext} from '../security'; -import {BindingDef, BindingFlags, DebugContext, DisposableFn, ElementData, ElementHandleEventFn, NodeData, NodeDef, NodeFlags, OutputDef, OutputType, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, asElementData, asProviderData} from './types'; -import {NOOP, calcBindingFlags, checkAndUpdateBinding, dispatchEvent, elementEventFullName, filterQueryId, getParentRenderElement, resolveRendererType2, resolveViewDefinition, splitMatchedQueriesDsl, splitNamespace} from './util'; +import {BindingDef, BindingFlags, ElementData, ElementHandleEventFn, NodeDef, NodeFlags, OutputDef, OutputType, QueryValueType, ViewData, ViewDefinitionFactory, asElementData} from './types'; +import {NOOP, calcBindingFlags, checkAndUpdateBinding, dispatchEvent, elementEventFullName, getParentRenderElement, resolveRendererType2, resolveViewDefinition, splitMatchedQueriesDsl, splitNamespace} from './util'; export function anchorDef( flags: NodeFlags, matchedQueriesDsl: [string | number, QueryValueType][], @@ -76,7 +75,7 @@ export function elementDef( const bindingDefs: BindingDef[] = new Array(bindings.length); for (let i = 0; i < bindings.length; i++) { const [bindingFlags, namespaceAndName, suffixOrSecurityContext] = bindings[i]; - let bindingDef: BindingDef; + const [ns, name] = splitNamespace(namespaceAndName); let securityContext: SecurityContext; let suffix: string; diff --git a/packages/core/src/view/ng_content.ts b/packages/core/src/view/ng_content.ts index c7e0c0226c..18bff51790 100644 --- a/packages/core/src/view/ng_content.ts +++ b/packages/core/src/view/ng_content.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {NodeDef, NodeFlags, ViewData, asElementData} from './types'; +import {NodeDef, NodeFlags, ViewData} from './types'; import {RenderNodeAction, getParentRenderElement, visitProjectedRenderNodes} from './util'; export function ngContentDef(ngContentIndex: number, index: number): NodeDef { diff --git a/packages/core/src/view/provider.ts b/packages/core/src/view/provider.ts index 1bc402a789..5439edec2e 100644 --- a/packages/core/src/view/provider.ts +++ b/packages/core/src/view/provider.ts @@ -11,12 +11,11 @@ import {Injector} from '../di'; import {ElementRef} from '../linker/element_ref'; import {TemplateRef} from '../linker/template_ref'; import {ViewContainerRef} from '../linker/view_container_ref'; -import {ViewEncapsulation} from '../metadata/view'; -import {Renderer as RendererV1, Renderer2, RendererFactory2, RendererType2} from '../render/api'; +import {Renderer as RendererV1, Renderer2} from '../render/api'; import {createChangeDetectorRef, createInjector, createRendererV1} from './refs'; -import {BindingDef, BindingFlags, DepDef, DepFlags, DisposableFn, NodeData, NodeDef, NodeFlags, OutputDef, OutputType, ProviderData, QueryBindingType, QueryDef, QueryValueType, RootData, Services, ViewData, ViewDefinition, ViewFlags, ViewState, asElementData, asProviderData} from './types'; -import {calcBindingFlags, checkBinding, dispatchEvent, filterQueryId, isComponentView, splitMatchedQueriesDsl, tokenKey, viewParentEl} from './util'; +import {BindingDef, BindingFlags, DepDef, DepFlags, NodeDef, NodeFlags, OutputDef, OutputType, ProviderData, QueryValueType, Services, ViewData, ViewFlags, ViewState, asElementData, asProviderData} from './types'; +import {calcBindingFlags, checkBinding, dispatchEvent, isComponentView, splitMatchedQueriesDsl, tokenKey, viewParentEl} from './util'; const RendererV1TokenKey = tokenKey(RendererV1); const Renderer2TokenKey = tokenKey(Renderer2); diff --git a/packages/core/src/view/pure_expression.ts b/packages/core/src/view/pure_expression.ts index a3e153cba3..bb3ff7a75c 100644 --- a/packages/core/src/view/pure_expression.ts +++ b/packages/core/src/view/pure_expression.ts @@ -6,8 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {BindingDef, BindingFlags, DepDef, DepFlags, NodeData, NodeDef, NodeFlags, ProviderData, PureExpressionData, Services, ViewData, asPureExpressionData} from './types'; -import {calcBindingFlags, checkAndUpdateBinding, tokenKey} from './util'; +import {BindingDef, BindingFlags, NodeDef, NodeFlags, PureExpressionData, ViewData, asPureExpressionData} from './types'; +import {calcBindingFlags, checkAndUpdateBinding} from './util'; export function purePipeDef(argCount: number): NodeDef { // argCount + 1 to include the pipe as first arg diff --git a/packages/core/src/view/query.ts b/packages/core/src/view/query.ts index 63deb0c7b9..015c052fe5 100644 --- a/packages/core/src/view/query.ts +++ b/packages/core/src/view/query.ts @@ -8,11 +8,9 @@ import {ElementRef} from '../linker/element_ref'; import {QueryList} from '../linker/query_list'; -import {TemplateRef} from '../linker/template_ref'; -import {ViewContainerRef} from '../linker/view_container_ref'; -import {NodeDef, NodeFlags, QueryBindingDef, QueryBindingType, QueryDef, QueryValueType, Services, ViewData, asElementData, asProviderData, asQueryList} from './types'; -import {declaredViewContainer, filterQueryId, isEmbeddedView, viewParentEl} from './util'; +import {NodeDef, NodeFlags, QueryBindingDef, QueryBindingType, QueryDef, QueryValueType, ViewData, asElementData, asProviderData, asQueryList} from './types'; +import {declaredViewContainer, filterQueryId, isEmbeddedView} from './util'; export function queryDef( flags: NodeFlags, id: number, bindings: {[propName: string]: QueryBindingType}): NodeDef { diff --git a/packages/core/src/view/refs.ts b/packages/core/src/view/refs.ts index f3b8d5cb82..2a7fea465a 100644 --- a/packages/core/src/view/refs.ts +++ b/packages/core/src/view/refs.ts @@ -20,8 +20,8 @@ import {Renderer as RendererV1, Renderer2} from '../render/api'; import {Type} from '../type'; import {VERSION} from '../version'; -import {ArgumentType, BindingFlags, DebugContext, DepFlags, ElementData, NodeCheckFn, NodeData, NodeDef, NodeFlags, RootData, Services, TemplateData, ViewContainerData, ViewData, ViewDefinition, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asTextData} from './types'; -import {isComponentView, markParentViewsForCheck, renderNode, resolveViewDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util'; +import {DepFlags, ElementData, NodeDef, NodeFlags, Services, TemplateData, ViewContainerData, ViewData, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asTextData} from './types'; +import {markParentViewsForCheck, resolveViewDefinition, rootRenderNodes, splitNamespace, tokenKey, viewParentEl} from './util'; import {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachView} from './view_attach'; const EMPTY_CONTEXT = new Object(); diff --git a/packages/core/src/view/services.ts b/packages/core/src/view/services.ts index 756c17d460..2e191587fc 100644 --- a/packages/core/src/view/services.ts +++ b/packages/core/src/view/services.ts @@ -11,14 +11,14 @@ import {DebugElement, DebugNode, EventListener, getDebugNode, indexDebugNode, re import {Injector} from '../di'; import {NgModuleRef} from '../linker/ng_module_factory'; import {Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2} from '../render/api'; -import {Sanitizer, SecurityContext} from '../security'; +import {Sanitizer} from '../security'; import {isViewDebugError, viewDestroyedError, viewWrappedDebugError} from './errors'; import {resolveDep} from './provider'; import {dirtyParentQueries, getQueryValue} from './query'; import {createInjector} from './refs'; -import {ArgumentType, BindingFlags, CheckType, DebugContext, DepFlags, ElementData, NodeCheckFn, NodeData, NodeDef, NodeFlags, NodeLogger, RootData, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewState, asElementData, asProviderData, asPureExpressionData} from './types'; -import {NOOP, checkBinding, isComponentView, renderNode, viewParentEl} from './util'; +import {ArgumentType, BindingFlags, CheckType, DebugContext, ElementData, NodeDef, NodeFlags, NodeLogger, RootData, Services, ViewData, ViewDefinition, ViewState, asElementData, asPureExpressionData} from './types'; +import {NOOP, isComponentView, renderNode, viewParentEl} from './util'; import {checkAndUpdateNode, checkAndUpdateView, checkNoChangesNode, checkNoChangesView, createEmbeddedView, createRootView, destroyView} from './view'; @@ -193,7 +193,7 @@ function debugUpdateDirectives(view: ViewData, checkType: CheckType) { return (nodeDef.flags & NodeFlags.CatPureExpression) ? asPureExpressionData(view, nodeDef.index).value : undefined; - }; + } } function debugUpdateRenderer(view: ViewData, checkType: CheckType) { diff --git a/packages/core/src/view/text.ts b/packages/core/src/view/text.ts index e5b2e22764..862d21af3d 100644 --- a/packages/core/src/view/text.ts +++ b/packages/core/src/view/text.ts @@ -6,9 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {looseIdentical} from '../util'; - -import {BindingDef, BindingFlags, DebugContext, NodeData, NodeDef, NodeFlags, RootData, Services, TextData, ViewData, ViewFlags, asElementData, asTextData} from './types'; +import {BindingDef, BindingFlags, NodeDef, NodeFlags, TextData, ViewData, asTextData} from './types'; import {calcBindingFlags, checkAndUpdateBinding, getParentRenderElement} from './util'; export function textDef(ngContentIndex: number, constants: string[]): NodeDef { diff --git a/packages/core/src/view/types.ts b/packages/core/src/view/types.ts index 41810ff186..73d5d7b98b 100644 --- a/packages/core/src/view/types.ts +++ b/packages/core/src/view/types.ts @@ -6,15 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ -import {PipeTransform} from '../change_detection/change_detection'; import {Injector} from '../di'; -import {ComponentRef} from '../linker/component_factory'; import {NgModuleRef} from '../linker/ng_module_factory'; import {QueryList} from '../linker/query_list'; import {TemplateRef} from '../linker/template_ref'; import {ViewContainerRef} from '../linker/view_container_ref'; -import {ViewRef} from '../linker/view_ref'; -import {ViewEncapsulation} from '../metadata/view'; import {Renderer2, RendererFactory2, RendererType2} from '../render/api'; import {Sanitizer, SecurityContext} from '../security'; diff --git a/packages/core/src/view/util.ts b/packages/core/src/view/util.ts index 559d38c7ab..d00eb244dc 100644 --- a/packages/core/src/view/util.ts +++ b/packages/core/src/view/util.ts @@ -7,17 +7,12 @@ */ import {WrappedValue, devModeEqual} from '../change_detection/change_detection'; -import {SimpleChange} from '../change_detection/change_detection_util'; -import {Injector} from '../di'; -import {TemplateRef} from '../linker/template_ref'; -import {ViewContainerRef} from '../linker/view_container_ref'; -import {ViewRef} from '../linker/view_ref'; import {ViewEncapsulation} from '../metadata/view'; -import {Renderer, RendererType2} from '../render/api'; +import {RendererType2} from '../render/api'; import {looseIdentical, stringify} from '../util'; -import {expressionChangedAfterItHasBeenCheckedError, isViewDebugError, viewDestroyedError, viewWrappedDebugError} from './errors'; -import {BindingDef, BindingFlags, DebugContext, ElementData, NodeData, NodeDef, NodeFlags, NodeLogger, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewState, asElementData, asProviderData, asTextData} from './types'; +import {expressionChangedAfterItHasBeenCheckedError} from './errors'; +import {BindingDef, BindingFlags, ElementData, NodeDef, NodeFlags, QueryValueType, Services, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewState, asElementData, asTextData} from './types'; export const NOOP: any = () => {}; diff --git a/packages/core/src/view/view.ts b/packages/core/src/view/view.ts index 9681446f36..f79b1e9ce4 100644 --- a/packages/core/src/view/view.ts +++ b/packages/core/src/view/view.ts @@ -6,25 +6,23 @@ * found in the LICENSE file at https://angular.io/license */ -import {ViewEncapsulation} from '../metadata/view'; -import {Renderer2, RendererType2} from '../render/api'; +import {Renderer2} from '../render/api'; import {checkAndUpdateElementDynamic, checkAndUpdateElementInline, createElement, listenToElementOutputs} from './element'; import {expressionChangedAfterItHasBeenCheckedError} from './errors'; import {appendNgContent} from './ng_content'; import {callLifecycleHooksChildrenFirst, checkAndUpdateDirectiveDynamic, checkAndUpdateDirectiveInline, createDirectiveInstance, createPipeInstance, createProviderInstance} from './provider'; import {checkAndUpdatePureExpressionDynamic, checkAndUpdatePureExpressionInline, createPureExpression} from './pure_expression'; -import {checkAndUpdateQuery, createQuery, queryDef} from './query'; +import {checkAndUpdateQuery, createQuery} from './query'; import {createTemplateData, createViewContainerData} from './refs'; import {checkAndUpdateTextDynamic, checkAndUpdateTextInline, createText} from './text'; -import {ArgumentType, CheckType, ElementData, ElementDef, NodeData, NodeDef, NodeFlags, ProviderData, ProviderDef, RootData, Services, TextDef, ViewData, ViewDefinition, ViewDefinitionFactory, ViewFlags, ViewHandleEventFn, ViewState, ViewUpdateFn, asElementData, asProviderData, asPureExpressionData, asQueryList, asTextData} from './types'; -import {NOOP, checkBindingNoChanges, isComponentView, resolveViewDefinition, viewParentEl} from './util'; +import {ArgumentType, CheckType, ElementData, NodeData, NodeDef, NodeFlags, ProviderData, RootData, Services, ViewData, ViewDefinition, ViewFlags, ViewHandleEventFn, ViewState, ViewUpdateFn, asElementData, asQueryList, asTextData} from './types'; +import {NOOP, checkBindingNoChanges, isComponentView, resolveViewDefinition} from './util'; export function viewDef( flags: ViewFlags, nodes: NodeDef[], updateDirectives?: ViewUpdateFn, updateRenderer?: ViewUpdateFn): ViewDefinition { // clone nodes and set auto calculated values - const reverseChildNodes: NodeDef[] = new Array(nodes.length); let viewBindingCount = 0; let viewDisposableCount = 0; let viewNodeFlags = 0; @@ -95,7 +93,7 @@ export function viewDef( if (node.flags & NodeFlags.CatProvider) { if (!currentElementHasPublicProviders) { currentElementHasPublicProviders = true; - // Use protoypical inheritance to not get O(n^2) complexity... + // Use prototypical inheritance to not get O(n^2) complexity... currentParent.element.publicProviders = Object.create(currentParent.element.publicProviders); currentParent.element.allProviders = currentParent.element.publicProviders; @@ -107,7 +105,7 @@ export function viewDef( } else { if (!currentElementHasPrivateProviders) { currentElementHasPrivateProviders = true; - // Use protoypical inheritance to not get O(n^2) complexity... + // Use protoyypical inheritance to not get O(n^2) complexity... currentParent.element.allProviders = Object.create(currentParent.element.publicProviders); } currentParent.element.allProviders[node.provider.tokenKey] = node; diff --git a/packages/core/src/view/view_attach.ts b/packages/core/src/view/view_attach.ts index 82be6dd500..6181b277eb 100644 --- a/packages/core/src/view/view_attach.ts +++ b/packages/core/src/view/view_attach.ts @@ -6,8 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {ElementData, NodeData, NodeDef, NodeFlags, Services, ViewData, asElementData, asProviderData, asTextData} from './types'; -import {RenderNodeAction, declaredViewContainer, isComponentView, renderNode, rootRenderNodes, visitProjectedRenderNodes, visitRootRenderNodes} from './util'; +import {ElementData, Services, ViewData} from './types'; +import {RenderNodeAction, declaredViewContainer, renderNode, visitRootRenderNodes} from './util'; export function attachEmbeddedView( parentView: ViewData, elementData: ElementData, viewIndex: number, view: ViewData) {