refactor(compiler): misc updates (#12773)
This commit is contained in:
parent
634b3bb88b
commit
2ced2a8a5a
|
@ -13,19 +13,14 @@ import {ConvertPropertyBindingResult, convertPropertyBinding} from '../compiler_
|
||||||
import {createEnumExpression} from '../compiler_util/identifier_util';
|
import {createEnumExpression} from '../compiler_util/identifier_util';
|
||||||
import {triggerAnimation, writeToRenderer} from '../compiler_util/render_util';
|
import {triggerAnimation, writeToRenderer} from '../compiler_util/render_util';
|
||||||
import {DirectiveWrapperExpressions} from '../directive_wrapper_compiler';
|
import {DirectiveWrapperExpressions} from '../directive_wrapper_compiler';
|
||||||
import * as cdAst from '../expression_parser/ast';
|
|
||||||
import {isPresent} from '../facade/lang';
|
|
||||||
import {Identifiers, resolveIdentifier} from '../identifiers';
|
import {Identifiers, resolveIdentifier} from '../identifiers';
|
||||||
import * as o from '../output/output_ast';
|
import * as o from '../output/output_ast';
|
||||||
import {EMPTY_STATE as EMPTY_ANIMATION_STATE, LifecycleHooks, isDefaultChangeDetectionStrategy} from '../private_import_core';
|
import {isDefaultChangeDetectionStrategy} from '../private_import_core';
|
||||||
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
|
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
|
||||||
import {BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, PropertyBindingType} from '../template_parser/template_ast';
|
import {BoundElementPropertyAst, BoundTextAst, DirectiveAst, PropertyBindingType} from '../template_parser/template_ast';
|
||||||
import {camelCaseToDashCase} from '../util';
|
|
||||||
|
|
||||||
import {CompileElement, CompileNode} from './compile_element';
|
import {CompileElement, CompileNode} from './compile_element';
|
||||||
import {CompileMethod} from './compile_method';
|
|
||||||
import {CompileView} from './compile_view';
|
import {CompileView} from './compile_view';
|
||||||
import {DetectChangesVars, ViewProperties} from './constants';
|
import {DetectChangesVars} from './constants';
|
||||||
import {getHandleEventMethodName} from './util';
|
import {getHandleEventMethodName} from './util';
|
||||||
|
|
||||||
export function bindRenderText(
|
export function bindRenderText(
|
||||||
|
@ -47,8 +42,9 @@ export function bindRenderText(
|
||||||
|
|
||||||
export function bindRenderInputs(
|
export function bindRenderInputs(
|
||||||
boundProps: BoundElementPropertyAst[], hasEvents: boolean, compileElement: CompileElement) {
|
boundProps: BoundElementPropertyAst[], hasEvents: boolean, compileElement: CompileElement) {
|
||||||
var view = compileElement.view;
|
const view = compileElement.view;
|
||||||
var renderNode = compileElement.renderNode;
|
const renderNode = compileElement.renderNode;
|
||||||
|
|
||||||
boundProps.forEach((boundProp) => {
|
boundProps.forEach((boundProp) => {
|
||||||
const bindingField = createCheckBindingField(view);
|
const bindingField = createCheckBindingField(view);
|
||||||
view.detectChangesRenderPropertiesMethod.resetDebugInfo(compileElement.nodeIndex, boundProp);
|
view.detectChangesRenderPropertiesMethod.resetDebugInfo(compileElement.nodeIndex, boundProp);
|
||||||
|
@ -57,8 +53,8 @@ export function bindRenderInputs(
|
||||||
if (!evalResult) {
|
if (!evalResult) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var checkBindingStmts: o.Statement[] = [];
|
const checkBindingStmts: o.Statement[] = [];
|
||||||
var compileMethod = view.detectChangesRenderPropertiesMethod;
|
let compileMethod = view.detectChangesRenderPropertiesMethod;
|
||||||
switch (boundProp.type) {
|
switch (boundProp.type) {
|
||||||
case PropertyBindingType.Property:
|
case PropertyBindingType.Property:
|
||||||
case PropertyBindingType.Attribute:
|
case PropertyBindingType.Attribute:
|
||||||
|
@ -117,8 +113,8 @@ export function bindDirectiveHostProps(
|
||||||
export function bindDirectiveInputs(
|
export function bindDirectiveInputs(
|
||||||
directiveAst: DirectiveAst, directiveWrapperInstance: o.Expression, dirIndex: number,
|
directiveAst: DirectiveAst, directiveWrapperInstance: o.Expression, dirIndex: number,
|
||||||
compileElement: CompileElement) {
|
compileElement: CompileElement) {
|
||||||
var view = compileElement.view;
|
const view = compileElement.view;
|
||||||
var detectChangesInInputsMethod = view.detectChangesInInputsMethod;
|
const detectChangesInInputsMethod = view.detectChangesInInputsMethod;
|
||||||
detectChangesInInputsMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
|
detectChangesInInputsMethod.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
|
||||||
|
|
||||||
directiveAst.inputs.forEach((input, inputIdx) => {
|
directiveAst.inputs.forEach((input, inputIdx) => {
|
||||||
|
@ -141,7 +137,7 @@ export function bindDirectiveInputs(
|
||||||
])
|
])
|
||||||
.toStmt());
|
.toStmt());
|
||||||
});
|
});
|
||||||
var isOnPushComp = directiveAst.directive.isComponent &&
|
const isOnPushComp = directiveAst.directive.isComponent &&
|
||||||
!isDefaultChangeDetectionStrategy(directiveAst.directive.changeDetection);
|
!isDefaultChangeDetectionStrategy(directiveAst.directive.changeDetection);
|
||||||
let directiveDetectChangesExpr = DirectiveWrapperExpressions.ngDoCheck(
|
let directiveDetectChangesExpr = DirectiveWrapperExpressions.ngDoCheck(
|
||||||
directiveWrapperInstance, o.THIS_EXPR, compileElement.renderNode,
|
directiveWrapperInstance, o.THIS_EXPR, compileElement.renderNode,
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {bindDirectiveHostProps, bindDirectiveInputs, bindRenderInputs, bindRende
|
||||||
|
|
||||||
export function bindView(
|
export function bindView(
|
||||||
view: CompileView, parsedTemplate: TemplateAst[], schemaRegistry: ElementSchemaRegistry): void {
|
view: CompileView, parsedTemplate: TemplateAst[], schemaRegistry: ElementSchemaRegistry): void {
|
||||||
var visitor = new ViewBinderVisitor(view, schemaRegistry);
|
const visitor = new ViewBinderVisitor(view, schemaRegistry);
|
||||||
templateVisitAll(visitor, parsedTemplate);
|
templateVisitAll(visitor, parsedTemplate);
|
||||||
view.pipes.forEach(
|
view.pipes.forEach(
|
||||||
(pipe) => { bindPipeDestroyLifecycleCallbacks(pipe.meta, pipe.instance, pipe.view); });
|
(pipe) => { bindPipeDestroyLifecycleCallbacks(pipe.meta, pipe.instance, pipe.view); });
|
||||||
|
@ -29,7 +29,7 @@ class ViewBinderVisitor implements TemplateAstVisitor {
|
||||||
constructor(public view: CompileView, private _schemaRegistry: ElementSchemaRegistry) {}
|
constructor(public view: CompileView, private _schemaRegistry: ElementSchemaRegistry) {}
|
||||||
|
|
||||||
visitBoundText(ast: BoundTextAst, parent: CompileElement): any {
|
visitBoundText(ast: BoundTextAst, parent: CompileElement): any {
|
||||||
var node = this.view.nodes[this._nodeIndex++];
|
const node = this.view.nodes[this._nodeIndex++];
|
||||||
bindRenderText(ast, node, this.view);
|
bindRenderText(ast, node, this.view);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,11 @@ class ViewBinderVisitor implements TemplateAstVisitor {
|
||||||
visitNgContent(ast: NgContentAst, parent: CompileElement): any { return null; }
|
visitNgContent(ast: NgContentAst, parent: CompileElement): any { return null; }
|
||||||
|
|
||||||
visitElement(ast: ElementAst, parent: CompileElement): any {
|
visitElement(ast: ElementAst, parent: CompileElement): any {
|
||||||
var compileElement = <CompileElement>this.view.nodes[this._nodeIndex++];
|
const compileElement = <CompileElement>this.view.nodes[this._nodeIndex++];
|
||||||
const hasEvents = bindOutputs(ast.outputs, ast.directives, compileElement, true);
|
const hasEvents = bindOutputs(ast.outputs, ast.directives, compileElement, true);
|
||||||
bindRenderInputs(ast.inputs, hasEvents, compileElement);
|
bindRenderInputs(ast.inputs, hasEvents, compileElement);
|
||||||
ast.directives.forEach((directiveAst, dirIndex) => {
|
ast.directives.forEach((directiveAst, dirIndex) => {
|
||||||
var directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference);
|
const directiveWrapperInstance =
|
||||||
var directiveWrapperInstance =
|
|
||||||
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
||||||
bindDirectiveInputs(directiveAst, directiveWrapperInstance, dirIndex, compileElement);
|
bindDirectiveInputs(directiveAst, directiveWrapperInstance, dirIndex, compileElement);
|
||||||
bindDirectiveHostProps(
|
bindDirectiveHostProps(
|
||||||
|
@ -56,8 +55,8 @@ class ViewBinderVisitor implements TemplateAstVisitor {
|
||||||
// afterContent and afterView lifecycles need to be called bottom up
|
// afterContent and afterView lifecycles need to be called bottom up
|
||||||
// so that children are notified before parents
|
// so that children are notified before parents
|
||||||
ast.directives.forEach((directiveAst) => {
|
ast.directives.forEach((directiveAst) => {
|
||||||
var directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference);
|
const directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference);
|
||||||
var directiveWrapperInstance =
|
const directiveWrapperInstance =
|
||||||
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
||||||
bindDirectiveAfterContentLifecycleCallbacks(
|
bindDirectiveAfterContentLifecycleCallbacks(
|
||||||
directiveAst.directive, directiveInstance, compileElement);
|
directiveAst.directive, directiveInstance, compileElement);
|
||||||
|
@ -67,18 +66,18 @@ class ViewBinderVisitor implements TemplateAstVisitor {
|
||||||
directiveAst, directiveWrapperInstance, compileElement);
|
directiveAst, directiveWrapperInstance, compileElement);
|
||||||
});
|
});
|
||||||
ast.providers.forEach((providerAst) => {
|
ast.providers.forEach((providerAst) => {
|
||||||
var providerInstance = compileElement.instances.get(providerAst.token.reference);
|
const providerInstance = compileElement.instances.get(providerAst.token.reference);
|
||||||
bindInjectableDestroyLifecycleCallbacks(providerAst, providerInstance, compileElement);
|
bindInjectableDestroyLifecycleCallbacks(providerAst, providerInstance, compileElement);
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, parent: CompileElement): any {
|
visitEmbeddedTemplate(ast: EmbeddedTemplateAst, parent: CompileElement): any {
|
||||||
var compileElement = <CompileElement>this.view.nodes[this._nodeIndex++];
|
const compileElement = <CompileElement>this.view.nodes[this._nodeIndex++];
|
||||||
bindOutputs(ast.outputs, ast.directives, compileElement, false);
|
bindOutputs(ast.outputs, ast.directives, compileElement, false);
|
||||||
ast.directives.forEach((directiveAst, dirIndex) => {
|
ast.directives.forEach((directiveAst, dirIndex) => {
|
||||||
var directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference);
|
const directiveInstance = compileElement.instances.get(directiveAst.directive.type.reference);
|
||||||
var directiveWrapperInstance =
|
const directiveWrapperInstance =
|
||||||
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
compileElement.directiveWrapperInstance.get(directiveAst.directive.type.reference);
|
||||||
bindDirectiveInputs(directiveAst, directiveWrapperInstance, dirIndex, compileElement);
|
bindDirectiveInputs(directiveAst, directiveWrapperInstance, dirIndex, compileElement);
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ class ViewBinderVisitor implements TemplateAstVisitor {
|
||||||
directiveAst, directiveWrapperInstance, compileElement);
|
directiveAst, directiveWrapperInstance, compileElement);
|
||||||
});
|
});
|
||||||
ast.providers.forEach((providerAst) => {
|
ast.providers.forEach((providerAst) => {
|
||||||
var providerInstance = compileElement.instances.get(providerAst.token.reference);
|
const providerInstance = compileElement.instances.get(providerAst.token.reference);
|
||||||
bindInjectableDestroyLifecycleCallbacks(providerAst, providerInstance, compileElement);
|
bindInjectableDestroyLifecycleCallbacks(providerAst, providerInstance, compileElement);
|
||||||
});
|
});
|
||||||
bindView(compileElement.embeddedView, ast.children, this._schemaRegistry);
|
bindView(compileElement.embeddedView, ast.children, this._schemaRegistry);
|
||||||
|
|
Loading…
Reference in New Issue