refactor(compiler): misc minor refactor / cleanup (#19189)
PR Close #19189
This commit is contained in:
parent
6c66031c4a
commit
f0774254de
@ -67,7 +67,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
|
|||||||
new PipeResolver(staticReflector), summaryResolver, elementSchemaRegistry, normalizer,
|
new PipeResolver(staticReflector), summaryResolver, elementSchemaRegistry, normalizer,
|
||||||
console, symbolCache, staticReflector);
|
console, symbolCache, staticReflector);
|
||||||
// TODO(vicb): do not pass options.i18nFormat here
|
// TODO(vicb): do not pass options.i18nFormat here
|
||||||
const viewCompiler = new ViewCompiler(config, staticReflector, elementSchemaRegistry);
|
const viewCompiler = new ViewCompiler(staticReflector);
|
||||||
const compiler = new AotCompiler(
|
const compiler = new AotCompiler(
|
||||||
config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver),
|
config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver),
|
||||||
viewCompiler, new NgModuleCompiler(staticReflector), new TypeScriptEmitter(), summaryResolver,
|
viewCompiler, new NgModuleCompiler(staticReflector), new TypeScriptEmitter(), summaryResolver,
|
||||||
|
@ -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 {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 {CompileReflector} from './compile_reflector';
|
||||||
import * as o from './output/output_ast';
|
import * as o from './output/output_ast';
|
||||||
|
|
||||||
|
@ -6,12 +6,11 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {CompileReflector} from '../compile_reflector';
|
||||||
import {BuiltinConverter, EventHandlerVars, LocalResolver, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins} from '../compiler_util/expression_converter';
|
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 {AST, ASTWithSource, Interpolation} from '../expression_parser/ast';
|
||||||
import {Identifiers} from '../identifiers';
|
import {Identifiers} from '../identifiers';
|
||||||
import {CompilerInjectable} from '../injectable';
|
import {CompilerInjectable} from '../injectable';
|
||||||
@ -20,8 +19,7 @@ import {isNgContainer} from '../ml_parser/tags';
|
|||||||
import * as o from '../output/output_ast';
|
import * as o from '../output/output_ast';
|
||||||
import {convertValueToOutputAst} from '../output/value_util';
|
import {convertValueToOutputAst} from '../output/value_util';
|
||||||
import {ParseSourceSpan} from '../parse_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, QueryMatch, ReferenceAst, TemplateAst, TemplateAstVisitor, TextAst, VariableAst, templateVisitAll} from '../template_parser/template_ast';
|
||||||
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 {OutputContext} from '../util';
|
import {OutputContext} from '../util';
|
||||||
|
|
||||||
import {componentFactoryResolverProviderDef, depDef, lifecycleHookToNodeFlag, providerDef} from './provider_compiler';
|
import {componentFactoryResolverProviderDef, depDef, lifecycleHookToNodeFlag, providerDef} from './provider_compiler';
|
||||||
@ -37,9 +35,7 @@ export class ViewCompileResult {
|
|||||||
|
|
||||||
@CompilerInjectable()
|
@CompilerInjectable()
|
||||||
export class ViewCompiler {
|
export class ViewCompiler {
|
||||||
constructor(
|
constructor(private _reflector: CompileReflector) {}
|
||||||
private _config: CompilerConfig, private _reflector: CompileReflector,
|
|
||||||
private _schemaRegistry: ElementSchemaRegistry) {}
|
|
||||||
|
|
||||||
compileComponent(
|
compileComponent(
|
||||||
outputCtx: OutputContext, component: CompileDirectiveMetadata, template: TemplateAst[],
|
outputCtx: OutputContext, component: CompileDirectiveMetadata, template: TemplateAst[],
|
||||||
@ -689,7 +685,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
createLiteralArrayConverter(sourceSpan: ParseSourceSpan, argCount: number): BuiltinConverter {
|
private _createLiteralArrayConverter(sourceSpan: ParseSourceSpan, argCount: number):
|
||||||
|
BuiltinConverter {
|
||||||
if (argCount === 0) {
|
if (argCount === 0) {
|
||||||
const valueExpr = o.importExpr(Identifiers.EMPTY_ARRAY);
|
const valueExpr = o.importExpr(Identifiers.EMPTY_ARRAY);
|
||||||
return () => valueExpr;
|
return () => valueExpr;
|
||||||
@ -706,8 +703,8 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
|
|||||||
return (args: o.Expression[]) => callCheckStmt(nodeIndex, args);
|
return (args: o.Expression[]) => callCheckStmt(nodeIndex, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
createLiteralMapConverter(sourceSpan: ParseSourceSpan, keys: {key: string, quoted: boolean}[]):
|
private _createLiteralMapConverter(
|
||||||
BuiltinConverter {
|
sourceSpan: ParseSourceSpan, keys: {key: string, quoted: boolean}[]): BuiltinConverter {
|
||||||
if (keys.length === 0) {
|
if (keys.length === 0) {
|
||||||
const valueExpr = o.importExpr(Identifiers.EMPTY_MAP);
|
const valueExpr = o.importExpr(Identifiers.EMPTY_MAP);
|
||||||
return () => valueExpr;
|
return () => valueExpr;
|
||||||
@ -725,7 +722,7 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
|
|||||||
return (args: o.Expression[]) => callCheckStmt(nodeIndex, args);
|
return (args: o.Expression[]) => callCheckStmt(nodeIndex, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
createPipeConverter(expression: UpdateExpression, name: string, argCount: number):
|
private _createPipeConverter(expression: UpdateExpression, name: string, argCount: number):
|
||||||
BuiltinConverter {
|
BuiltinConverter {
|
||||||
const pipe = this.usedPipes.find((pipeSummary) => pipeSummary.name === name) !;
|
const pipe = this.usedPipes.find((pipeSummary) => pipeSummary.name === name) !;
|
||||||
if (pipe.pure) {
|
if (pipe.pure) {
|
||||||
@ -786,7 +783,13 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
|
|||||||
return nodeIndex;
|
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 {
|
private _preprocessUpdateExpression(expression: UpdateExpression): UpdateExpression {
|
||||||
return {
|
return {
|
||||||
nodeIndex: expression.nodeIndex,
|
nodeIndex: expression.nodeIndex,
|
||||||
@ -795,13 +798,13 @@ class ViewBuilder implements TemplateAstVisitor, LocalResolver {
|
|||||||
context: expression.context,
|
context: expression.context,
|
||||||
value: convertPropertyBindingBuiltins(
|
value: convertPropertyBindingBuiltins(
|
||||||
{
|
{
|
||||||
createLiteralArrayConverter: (argCount: number) => this.createLiteralArrayConverter(
|
createLiteralArrayConverter: (argCount: number) => this._createLiteralArrayConverter(
|
||||||
expression.sourceSpan, argCount),
|
expression.sourceSpan, argCount),
|
||||||
createLiteralMapConverter:
|
createLiteralMapConverter:
|
||||||
(keys: {key: string, quoted: boolean}[]) =>
|
(keys: {key: string, quoted: boolean}[]) =>
|
||||||
this.createLiteralMapConverter(expression.sourceSpan, keys),
|
this._createLiteralMapConverter(expression.sourceSpan, keys),
|
||||||
createPipeConverter: (name: string, argCount: number) =>
|
createPipeConverter: (name: string, argCount: number) =>
|
||||||
this.createPipeConverter(expression, name, argCount)
|
this._createPipeConverter(expression, name, argCount)
|
||||||
},
|
},
|
||||||
expression.value)
|
expression.value)
|
||||||
};
|
};
|
||||||
|
@ -7,21 +7,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {BindingDef, BindingFlags, NodeDef, NodeFlags, TextData, ViewData, asTextData} from './types';
|
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 {
|
export function textDef(ngContentIndex: number, staticText: string[]): NodeDef {
|
||||||
const bindings: BindingDef[] = new Array(constants.length - 1);
|
const bindings: BindingDef[] = new Array(staticText.length - 1);
|
||||||
for (let i = 1; i < constants.length; i++) {
|
for (let i = 1; i < staticText.length; i++) {
|
||||||
bindings[i - 1] = {
|
bindings[i - 1] = {
|
||||||
flags: BindingFlags.TypeProperty,
|
flags: BindingFlags.TypeProperty,
|
||||||
name: null,
|
name: null,
|
||||||
ns: null,
|
ns: null,
|
||||||
nonMinifiedName: null,
|
nonMinifiedName: null,
|
||||||
securityContext: null,
|
securityContext: null,
|
||||||
suffix: constants[i]
|
suffix: staticText[i],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const flags = NodeFlags.TypeText;
|
|
||||||
return {
|
return {
|
||||||
// will bet set by the view definition
|
// will bet set by the view definition
|
||||||
index: -1,
|
index: -1,
|
||||||
@ -30,7 +30,7 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
|
|||||||
bindingIndex: -1,
|
bindingIndex: -1,
|
||||||
outputIndex: -1,
|
outputIndex: -1,
|
||||||
// regular values
|
// regular values
|
||||||
flags,
|
flags: NodeFlags.TypeText,
|
||||||
childFlags: 0,
|
childFlags: 0,
|
||||||
directChildFlags: 0,
|
directChildFlags: 0,
|
||||||
childMatchedQueries: 0,
|
childMatchedQueries: 0,
|
||||||
@ -38,13 +38,13 @@ export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
|
|||||||
matchedQueryIds: 0,
|
matchedQueryIds: 0,
|
||||||
references: {}, ngContentIndex,
|
references: {}, ngContentIndex,
|
||||||
childCount: 0, bindings,
|
childCount: 0, bindings,
|
||||||
bindingFlags: calcBindingFlags(bindings),
|
bindingFlags: BindingFlags.TypeProperty,
|
||||||
outputs: [],
|
outputs: [],
|
||||||
element: null,
|
element: null,
|
||||||
provider: null,
|
provider: null,
|
||||||
text: {prefix: constants[0]},
|
text: {prefix: staticText[0]},
|
||||||
query: null,
|
query: null,
|
||||||
ngContent: null
|
ngContent: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user