mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(compiler): remove BindingForm enum (#44411)
The Ivy compiler only uses `BindingForm.Expression`, so all other variants are removed. PR Close #44411
This commit is contained in:
@@ -100,20 +100,6 @@ export class ConvertPropertyBindingResult {
|
||||
constructor(public stmts: o.Statement[], public currValExpr: o.Expression) {}
|
||||
}
|
||||
|
||||
export enum BindingForm {
|
||||
// The general form of binding expression, supports all expressions.
|
||||
General,
|
||||
|
||||
// Try to generate a simple binding (no temporaries or statements)
|
||||
// otherwise generate a general binding
|
||||
TrySimple,
|
||||
|
||||
// Inlines assignment of temporaries into the generated expression. The result may still
|
||||
// have statements attached for declarations of temporary variables.
|
||||
// This is the only relevant form for Ivy, the other forms are only used in ViewEngine.
|
||||
Expression,
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given expression AST into an executable output AST, assuming the expression
|
||||
* is used in property binding. The expression has to be preprocessed via
|
||||
@@ -121,7 +107,7 @@ export enum BindingForm {
|
||||
*/
|
||||
export function convertPropertyBinding(
|
||||
localResolver: LocalResolver|null, implicitReceiver: o.Expression,
|
||||
expressionWithoutBuiltins: cdAst.AST, bindingId: string, form: BindingForm,
|
||||
expressionWithoutBuiltins: cdAst.AST, bindingId: string,
|
||||
interpolationFunction?: InterpolationFunction): ConvertPropertyBindingResult {
|
||||
if (!localResolver) {
|
||||
localResolver = new DefaultLocalResolver();
|
||||
@@ -135,15 +121,7 @@ export function convertPropertyBinding(
|
||||
localResolver.notifyImplicitReceiverUse();
|
||||
}
|
||||
|
||||
if (visitor.temporaryCount === 0 && form == BindingForm.TrySimple) {
|
||||
return new ConvertPropertyBindingResult([], outputExpr);
|
||||
} else if (form === BindingForm.Expression) {
|
||||
return new ConvertPropertyBindingResult(stmts, outputExpr);
|
||||
}
|
||||
|
||||
const currValExpr = createCurrValueExpr(bindingId);
|
||||
stmts.push(currValExpr.set(outputExpr).toDeclStmt(o.DYNAMIC_TYPE, [o.StmtModifier.Final]));
|
||||
return new ConvertPropertyBindingResult(stmts, currValExpr);
|
||||
return new ConvertPropertyBindingResult(stmts, outputExpr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -906,10 +884,6 @@ class DefaultLocalResolver implements LocalResolver {
|
||||
}
|
||||
}
|
||||
|
||||
function createCurrValueExpr(bindingId: string): o.ReadVarExpr {
|
||||
return o.variable(`currVal_${bindingId}`); // fix syntax highlighting: `
|
||||
}
|
||||
|
||||
export class BuiltinFunctionCall extends cdAst.Call {
|
||||
constructor(
|
||||
span: cdAst.ParseSpan, sourceSpan: cdAst.AbsoluteSourceSpan, args: cdAst.AST[],
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {BindingForm, convertPropertyBinding} from '../../compiler_util/expression_converter';
|
||||
import {convertPropertyBinding} from '../../compiler_util/expression_converter';
|
||||
import {ConstantPool} from '../../constant_pool';
|
||||
import * as core from '../../core';
|
||||
import {AST, ParsedEvent, ParsedEventType, ParsedProperty} from '../../expression_parser/ast';
|
||||
@@ -646,7 +646,7 @@ function createHostBindingsFunction(
|
||||
|
||||
function bindingFn(implicit: any, value: AST) {
|
||||
return convertPropertyBinding(
|
||||
null, implicit, value, 'b', BindingForm.Expression, () => error('Unexpected interpolation'));
|
||||
null, implicit, value, 'b', () => error('Unexpected interpolation'));
|
||||
}
|
||||
|
||||
function convertStylingCall(
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {BindingForm, BuiltinFunctionCall, convertActionBinding, convertPropertyBinding, convertUpdateArguments, LocalResolver} from '../../compiler_util/expression_converter';
|
||||
import {BuiltinFunctionCall, convertActionBinding, convertPropertyBinding, convertUpdateArguments, LocalResolver} from '../../compiler_util/expression_converter';
|
||||
import {ConstantPool} from '../../constant_pool';
|
||||
import * as core from '../../core';
|
||||
import {AST, AstMemoryEfficientTransformer, BindingPipe, BindingType, Call, ImplicitReceiver, Interpolation, LiteralArray, LiteralMap, LiteralPrimitive, ParsedEventType, PropertyRead} from '../../expression_parser/ast';
|
||||
@@ -1261,7 +1261,7 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
|
||||
|
||||
private convertPropertyBinding(value: AST): o.Expression {
|
||||
const convertedPropertyBinding = convertPropertyBinding(
|
||||
this, this.getImplicitReceiverExpr(), value, this.bindingContext(), BindingForm.Expression,
|
||||
this, this.getImplicitReceiverExpr(), value, this.bindingContext(),
|
||||
() => error('Unexpected interpolation'));
|
||||
const valExpr = convertedPropertyBinding.currValExpr;
|
||||
this._tempVariables.push(...convertedPropertyBinding.stmts);
|
||||
|
||||
Reference in New Issue
Block a user