refactor(compiler): misc minor refactor / cleanup (#19189)

PR Close #19189
This commit is contained in:
Victor Berchet 2017-08-16 16:29:39 -07:00 committed by Alex Rickabaugh
parent 6c66031c4a
commit f0774254de
4 changed files with 31 additions and 28 deletions

View File

@ -67,7 +67,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,

View File

@ -8,7 +8,7 @@
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, ɵand, ɵccf, ɵcmf, ɵcrt, ɵdid, ɵeld, ɵinlineInterpolate, ɵinterpolate, ɵmod, ɵmpd, ɵncd, ɵnov, ɵpad, ɵpid, ɵpod, ɵppd, ɵprd, ɵqud, ɵregisterModuleFactory, ɵted, ɵunv, ɵvid} from '@angular/core';
import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
import {CompileTokenMetadata} from './compile_metadata';
import {CompileReflector} from './compile_reflector';
import * as o from './output/output_ast';

View File

@ -6,12 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ChangeDetectionStrategy, ɵArgumentType as ArgumentType, ɵBindingFlags as BindingFlags, ɵDepFlags as DepFlags, ɵ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, ɵNodeFlags as NodeFlags, ɵQueryBindingType as QueryBindingType, ɵQueryValueType as QueryValueType, ɵViewFlags as ViewFlags, ɵelementEventFullName as elementEventFullName} from '@angular/core';
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 {AST, ASTWithSource, Interpolation} from '../expression_parser/ast';
import {Identifiers} from '../identifiers';
import {CompilerInjectable} from '../injectable';
@ -20,8 +19,7 @@ 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';
@ -37,9 +35,7 @@ export class ViewCompileResult {
@CompilerInjectable()
export class ViewCompiler {
constructor(
private _config: CompilerConfig, private _reflector: CompileReflector,
private _schemaRegistry: ElementSchemaRegistry) {}
constructor(private _reflector: CompileReflector) {}
compileComponent(
outputCtx: OutputContext, component: CompileDirectiveMetadata, template: TemplateAst[],
@ -689,7 +685,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;
@ -706,8 +703,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;
@ -725,7 +722,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) {
@ -786,7 +783,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,
@ -795,13 +798,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)
};

View File

@ -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,
@ -30,7 +30,7 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
bindingIndex: -1,
outputIndex: -1,
// regular values
flags,
flags: NodeFlags.TypeText,
childFlags: 0,
directChildFlags: 0,
childMatchedQueries: 0,
@ -38,13 +38,13 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
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,
};
}