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