Skip to content

Commit

Permalink
refactor(compiler): misc minor refactor / cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Sep 13, 2017
1 parent e140597 commit c49afdb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 95 deletions.
2 changes: 1 addition & 1 deletion packages/compiler/src/aot/compiler_factory.ts
Expand Up @@ -80,7 +80,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
new PipeResolver(staticReflector), summaryResolver, elementSchemaRegistry, normalizer,
console, symbolCache, staticReflector);
// TODO(vicb): do not pass options.i18nFormat here
const viewCompiler = new ViewCompiler(config, staticReflector, elementSchemaRegistry);
const viewCompiler = new ViewCompiler(staticReflector);
const compiler = new AotCompiler(
config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver),
viewCompiler, new NgModuleCompiler(staticReflector), new TypeScriptEmitter(), summaryResolver,
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler/src/identifiers.ts
Expand Up @@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
import {CompileTokenMetadata} from './compile_metadata';
import {CompileReflector} from './compile_reflector';
import {Attribute, Component, Directive, HostBinding, HostListener, Inject, Input, NgModule, Output, Pipe, Query} from './core';
import * as o from './output/output_ast';

const CORE = '@angular/core';
Expand Down
35 changes: 19 additions & 16 deletions packages/compiler/src/view_compiler/view_compiler.ts
Expand Up @@ -6,20 +6,18 @@
* found in the LICENSE file at https://angular.io/license
*/

import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompilePipeSummary, CompileProviderMetadata, CompileTokenMetadata, CompileTypeMetadata, rendererTypeName, tokenReference, viewClassName} from '../compile_metadata';
import {CompileDirectiveMetadata, CompilePipeSummary, rendererTypeName, tokenReference, viewClassName} from '../compile_metadata';
import {CompileReflector} from '../compile_reflector';
import {BuiltinConverter, EventHandlerVars, LocalResolver, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins} from '../compiler_util/expression_converter';
import {CompilerConfig} from '../config';
import {ArgumentType, BindingFlags, ChangeDetectionStrategy, DepFlags, NodeFlags, QueryBindingType, QueryValueType, ViewFlags} from '../core';
import {ArgumentType, BindingFlags, ChangeDetectionStrategy, NodeFlags, QueryBindingType, QueryValueType, ViewFlags} from '../core';
import {AST, ASTWithSource, Interpolation} from '../expression_parser/ast';
import {Identifiers} from '../identifiers';
import {LifecycleHooks} from '../lifecycle_reflector';
import {isNgContainer} from '../ml_parser/tags';
import * as o from '../output/output_ast';
import {convertValueToOutputAst} from '../output/value_util';
import {ParseSourceSpan} from '../parse_util';
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, PropertyBindingType, ProviderAst, ProviderAstType, QueryMatch, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast';
import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, PropertyBindingType, ProviderAst, QueryMatch, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast';
import {OutputContext} from '../util';

import {componentFactoryResolverProviderDef, depDef, lifecycleHookToNodeFlag, providerDef} from './provider_compiler';
Expand All @@ -33,9 +31,7 @@ export class ViewCompileResult {
}

export class ViewCompiler {
constructor(
private _config: CompilerConfig, private _reflector: CompileReflector,
private _schemaRegistry: ElementSchemaRegistry) {}
constructor(private _reflector: CompileReflector) {}

compileComponent(
outputCtx: OutputContext, component: CompileDirectiveMetadata, template: TemplateAst[],
Expand Down Expand Up @@ -685,7 +681,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
return null;
}

createLiteralArrayConverter(sourceSpan: ParseSourceSpan, argCount: number): BuiltinConverter {
private _createLiteralArrayConverter(sourceSpan: ParseSourceSpan, argCount: number):
BuiltinConverter {
if (argCount === 0) {
const valueExpr = o.importExpr(Identifiers.EMPTY_ARRAY);
return () => valueExpr;
Expand All @@ -702,8 +699,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
return (args: o.Expression[]) => callCheckStmt(nodeIndex, args);
}

createLiteralMapConverter(sourceSpan: ParseSourceSpan, keys: {key: string, quoted: boolean}[]):
BuiltinConverter {
private _createLiteralMapConverter(
sourceSpan: ParseSourceSpan, keys: {key: string, quoted: boolean}[]): BuiltinConverter {
if (keys.length === 0) {
const valueExpr = o.importExpr(Identifiers.EMPTY_MAP);
return () => valueExpr;
Expand All @@ -721,7 +718,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
return (args: o.Expression[]) => callCheckStmt(nodeIndex, args);
}

createPipeConverter(expression: UpdateExpression, name: string, argCount: number):
private _createPipeConverter(expression: UpdateExpression, name: string, argCount: number):
BuiltinConverter {
const pipe = this.usedPipes.find((pipeSummary) => pipeSummary.name === name) !;
if (pipe.pure) {
Expand Down Expand Up @@ -782,7 +779,13 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
return nodeIndex;
}

// Attention: This might create new nodeDefs (for pipes and literal arrays and literal maps)!
/**
* For the AST in `UpdateExpression.value`:
* - create nodes for pipes, literal arrays and, literal maps,
* - update the AST to replace pipes, literal arrays and, literal maps with calls to check fn.
*
* WARNING: This might create new nodeDefs (for pipes and literal arrays and literal maps)!
*/
private _preprocessUpdateExpression(expression: UpdateExpression): UpdateExpression {
return {
nodeIndex: expression.nodeIndex,
Expand All @@ -791,13 +794,13 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
context: expression.context,
value: convertPropertyBindingBuiltins(
{
createLiteralArrayConverter: (argCount: number) => this.createLiteralArrayConverter(
createLiteralArrayConverter: (argCount: number) => this._createLiteralArrayConverter(
expression.sourceSpan, argCount),
createLiteralMapConverter:
(keys: {key: string, quoted: boolean}[]) =>
this.createLiteralMapConverter(expression.sourceSpan, keys),
this._createLiteralMapConverter(expression.sourceSpan, keys),
createPipeConverter: (name: string, argCount: number) =>
this.createPipeConverter(expression, name, argCount)
this._createPipeConverter(expression, name, argCount)
},
expression.value)
};
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/view/text.ts
Expand Up @@ -7,21 +7,21 @@
*/

import {BindingDef, BindingFlags, NodeDef, NodeFlags, TextData, ViewData, asTextData} from './types';
import {calcBindingFlags, checkAndUpdateBinding, getParentRenderElement} from './util';
import {checkAndUpdateBinding, getParentRenderElement} from './util';

export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
const bindings: BindingDef[] = new Array(constants.length - 1);
for (let i = 1; i < constants.length; i++) {
export function textDef(ngContentIndex: number, staticText: string[]): NodeDef {
const bindings: BindingDef[] = new Array(staticText.length - 1);
for (let i = 1; i < staticText.length; i++) {
bindings[i - 1] = {
flags: BindingFlags.TypeProperty,
name: null,
ns: null,
nonMinifiedName: null,
securityContext: null,
suffix: constants[i]
suffix: staticText[i],
};
}
const flags = NodeFlags.TypeText;

return {
// will bet set by the view definition
index: -1,
Expand All @@ -30,21 +30,21 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
bindingIndex: -1,
outputIndex: -1,
// regular values
flags,
flags: NodeFlags.TypeText,
childFlags: 0,
directChildFlags: 0,
childMatchedQueries: 0,
matchedQueries: {},
matchedQueryIds: 0,
references: {}, ngContentIndex,
childCount: 0, bindings,
bindingFlags: calcBindingFlags(bindings),
bindingFlags: BindingFlags.TypeProperty,
outputs: [],
element: null,
provider: null,
text: {prefix: constants[0]},
text: {prefix: staticText[0]},
query: null,
ngContent: null
ngContent: null,
};
}

Expand Down
80 changes: 14 additions & 66 deletions packages/platform-browser-dynamic/src/compiler_reflector.ts
Expand Up @@ -7,7 +7,7 @@
*/

import {CompileReflector, ExternalReference, Identifiers, getUrlScheme, syntaxError} from '@angular/compiler';
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Inject, InjectionToken, Injector, LOCALE_ID, NgModuleFactory, NgModuleRef, Optional, PACKAGE_ROOT_URL, PlatformRef, QueryList, Renderer, SecurityContext, StaticProvider, TRANSLATIONS, TRANSLATIONS_FORMAT, TemplateRef, Type, ViewContainerRef, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore, ɵCodegenComponentFactoryResolver, ɵConsole as Console, ɵEMPTY_ARRAY, ɵEMPTY_MAP, ɵReflectionCapabilities as ReflectionCapabilities, ɵand, ɵccf, ɵcmf, ɵcrt, ɵdid, ɵeld, ɵinlineInterpolate, ɵinterpolate, ɵmod, ɵmpd, ɵncd, ɵnov, ɵpad, ɵpid, ɵpod, ɵppd, ɵprd, ɵqud, ɵregisterModuleFactory, ɵstringify as stringify, ɵted, ɵunv, ɵvid} from '@angular/core';
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, NgModuleRef, QueryList, Renderer, SecurityContext, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation, ɵCodegenComponentFactoryResolver, ɵEMPTY_ARRAY, ɵEMPTY_MAP, ɵReflectionCapabilities as ReflectionCapabilities, ɵand, ɵccf, ɵcmf, ɵcrt, ɵdid, ɵeld, ɵinlineInterpolate, ɵinterpolate, ɵmod, ɵmpd, ɵncd, ɵnov, ɵpad, ɵpid, ɵpod, ɵppd, ɵprd, ɵqud, ɵregisterModuleFactory, ɵstringify as stringify, ɵted, ɵunv, ɵvid} from '@angular/core';

export const MODULE_SUFFIX = '';
const builtinExternalReferences = createBuiltinExternalReferencesMap();
Expand Down Expand Up @@ -50,81 +50,29 @@ export class JitReflector implements CompileReflector {

function createBuiltinExternalReferencesMap() {
const map = new Map<ExternalReference, any>();
map.set(
Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS,


ANALYZE_FOR_ENTRY_COMPONENTS);
map.set(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS, ANALYZE_FOR_ENTRY_COMPONENTS);
map.set(Identifiers.ElementRef, ElementRef);
map.set(Identifiers.NgModuleRef, NgModuleRef);
map.set(Identifiers.ViewContainerRef, ViewContainerRef);
map.set(
Identifiers.ChangeDetectorRef,


ChangeDetectorRef);
map.set(Identifiers.ChangeDetectorRef, ChangeDetectorRef);
map.set(Identifiers.QueryList, QueryList);
map.set(Identifiers.TemplateRef, TemplateRef);
map.set(
Identifiers.CodegenComponentFactoryResolver,


ɵCodegenComponentFactoryResolver);
map.set(
Identifiers.ComponentFactoryResolver,


ComponentFactoryResolver);
map.set(Identifiers.CodegenComponentFactoryResolver, ɵCodegenComponentFactoryResolver);
map.set(Identifiers.ComponentFactoryResolver, ComponentFactoryResolver);
map.set(Identifiers.ComponentFactory, ComponentFactory);
map.set(Identifiers.ComponentRef, ComponentRef);
map.set(Identifiers.NgModuleFactory, NgModuleFactory);
map.set(
Identifiers.createModuleFactory,


ɵcmf, );
map.set(
Identifiers.moduleDef,


ɵmod, );
map.set(
Identifiers.moduleProviderDef,


ɵmpd, );
map.set(
Identifiers.RegisterModuleFactoryFn,


ɵregisterModuleFactory, );
map.set(Identifiers.createModuleFactory, ɵcmf);
map.set(Identifiers.moduleDef, ɵmod);
map.set(Identifiers.moduleProviderDef, ɵmpd);
map.set(Identifiers.RegisterModuleFactoryFn, ɵregisterModuleFactory);
map.set(Identifiers.Injector, Injector);
map.set(
Identifiers.ViewEncapsulation,


ViewEncapsulation);
map.set(
Identifiers.ChangeDetectionStrategy,


ChangeDetectionStrategy);
map.set(
Identifiers.SecurityContext,


SecurityContext, );
map.set(Identifiers.ViewEncapsulation, ViewEncapsulation);
map.set(Identifiers.ChangeDetectionStrategy, ChangeDetectionStrategy);
map.set(Identifiers.SecurityContext, SecurityContext);
map.set(Identifiers.LOCALE_ID, LOCALE_ID);
map.set(
Identifiers.TRANSLATIONS_FORMAT,


TRANSLATIONS_FORMAT);
map.set(
Identifiers.inlineInterpolate,


ɵinlineInterpolate);
map.set(Identifiers.TRANSLATIONS_FORMAT, TRANSLATIONS_FORMAT);
map.set(Identifiers.inlineInterpolate, ɵinlineInterpolate);
map.set(Identifiers.interpolate, ɵinterpolate);
map.set(Identifiers.EMPTY_ARRAY, ɵEMPTY_ARRAY);
map.set(Identifiers.EMPTY_MAP, ɵEMPTY_MAP);
Expand Down

0 comments on commit c49afdb

Please sign in to comment.