refactor(compiler): misc minor refactor / cleanup (#19189)
PR Close #19189
This commit is contained in:
parent
473a577e34
commit
34fdb91899
|
@ -81,7 +81,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
|
|||
new DirectiveResolver(staticReflector), 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 typeCheckCompiler = new TypeCheckCompiler(options, staticReflector);
|
||||
const compiler = new AotCompiler(
|
||||
config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver),
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
* 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';
|
||||
|
@ -18,8 +17,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';
|
||||
|
@ -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[],
|
||||
|
@ -684,7 +680,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;
|
||||
|
@ -701,8 +698,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;
|
||||
|
@ -720,7 +717,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) {
|
||||
|
@ -781,7 +778,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,
|
||||
|
@ -790,13 +793,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)
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ export const COMPILER_PROVIDERS = <StaticProvider[]>[
|
|||
[Optional, ERROR_COLLECTOR_TOKEN]]},
|
||||
DEFAULT_PACKAGE_URL_PROVIDER,
|
||||
{ provide: StyleCompiler, deps: [UrlResolver]},
|
||||
{ provide: ViewCompiler, deps: [CompilerConfig, CompileReflector, ElementSchemaRegistry]},
|
||||
{ provide: ViewCompiler, deps: [CompileReflector]},
|
||||
{ provide: NgModuleCompiler, deps: [CompileReflector] },
|
||||
{ provide: CompilerConfig, useValue: new CompilerConfig()},
|
||||
{ provide: Compiler, useClass: CompilerImpl, deps: [Injector, CompileMetadataResolver,
|
||||
|
|
|
@ -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();
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue