mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(core): properly emit input flags using bitwise or (#53808)
As part of testing we did accidentally use `bitwiseAnd` for the input flags, given we started without an extra flag for `HasTransform`. This commit teaches the compiler to support emitting bitwise OR and uses it when combining input flags, fully re-enabling transforms for signal components after the new flag mechanism was introduced in previous commits. PR Close #53808
This commit is contained in:
@@ -262,7 +262,7 @@ export type UnaryOperator = '+'|'-'|'!';
|
||||
* The binary operators supported by the `AstFactory`.
|
||||
*/
|
||||
export type BinaryOperator =
|
||||
'&&'|'>'|'>='|'&'|'/'|'=='|'==='|'<'|'<='|'-'|'%'|'*'|'!='|'!=='|'||'|'+'|'??';
|
||||
'&&'|'>'|'>='|'&'|'|'|'/'|'=='|'==='|'<'|'<='|'-'|'%'|'*'|'!='|'!=='|'||'|'+'|'??';
|
||||
|
||||
/**
|
||||
* The original location of the start or end of a node created by the `AstFactory`.
|
||||
|
||||
@@ -21,6 +21,7 @@ const BINARY_OPERATORS = new Map<o.BinaryOperator, BinaryOperator>([
|
||||
[o.BinaryOperator.Bigger, '>'],
|
||||
[o.BinaryOperator.BiggerEquals, '>='],
|
||||
[o.BinaryOperator.BitwiseAnd, '&'],
|
||||
[o.BinaryOperator.BitwiseOr, '|'],
|
||||
[o.BinaryOperator.Divide, '/'],
|
||||
[o.BinaryOperator.Equals, '=='],
|
||||
[o.BinaryOperator.Identical, '==='],
|
||||
|
||||
@@ -36,6 +36,7 @@ const BINARY_OPERATORS: Record<BinaryOperator, ts.BinaryOperator> = {
|
||||
'>': ts.SyntaxKind.GreaterThanToken,
|
||||
'>=': ts.SyntaxKind.GreaterThanEqualsToken,
|
||||
'&': ts.SyntaxKind.AmpersandToken,
|
||||
'|': ts.SyntaxKind.BarToken,
|
||||
'/': ts.SyntaxKind.SlashToken,
|
||||
'==': ts.SyntaxKind.EqualsEqualsToken,
|
||||
'===': ts.SyntaxKind.EqualsEqualsEqualsToken,
|
||||
|
||||
@@ -415,6 +415,9 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
|
||||
case o.BinaryOperator.And:
|
||||
opStr = '&&';
|
||||
break;
|
||||
case o.BinaryOperator.BitwiseOr:
|
||||
opStr = '|';
|
||||
break;
|
||||
case o.BinaryOperator.BitwiseAnd:
|
||||
opStr = '&';
|
||||
break;
|
||||
|
||||
@@ -125,6 +125,7 @@ export enum BinaryOperator {
|
||||
Modulo,
|
||||
And,
|
||||
Or,
|
||||
BitwiseOr,
|
||||
BitwiseAnd,
|
||||
Lower,
|
||||
LowerEquals,
|
||||
@@ -239,6 +240,10 @@ export abstract class Expression {
|
||||
and(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
|
||||
return new BinaryOperatorExpr(BinaryOperator.And, this, rhs, null, sourceSpan);
|
||||
}
|
||||
bitwiseOr(rhs: Expression, sourceSpan?: ParseSourceSpan|null, parens: boolean = true):
|
||||
BinaryOperatorExpr {
|
||||
return new BinaryOperatorExpr(BinaryOperator.BitwiseOr, this, rhs, null, sourceSpan, parens);
|
||||
}
|
||||
bitwiseAnd(rhs: Expression, sourceSpan?: ParseSourceSpan|null, parens: boolean = true):
|
||||
BinaryOperatorExpr {
|
||||
return new BinaryOperatorExpr(BinaryOperator.BitwiseAnd, this, rhs, null, sourceSpan, parens);
|
||||
|
||||
@@ -212,10 +212,10 @@ export function conditionallyCreateDirectiveBindingLiteral(
|
||||
// Build up input flags
|
||||
let flags: o.Expression|null = null;
|
||||
if (value.isSignal) {
|
||||
flags = bitwiseAndInputFlagsExpr(InputFlags.SignalBased, flags);
|
||||
flags = bitwiseOrInputFlagsExpr(InputFlags.SignalBased, flags);
|
||||
}
|
||||
if (hasDecoratorInputTransform) {
|
||||
flags = bitwiseAndInputFlagsExpr(InputFlags.HasDecoratorInputTransform, flags);
|
||||
flags = bitwiseOrInputFlagsExpr(InputFlags.HasDecoratorInputTransform, flags);
|
||||
}
|
||||
|
||||
// Inputs, compared to outputs, will track their declared name (for `ngOnChanges`), support
|
||||
@@ -253,15 +253,11 @@ function getInputFlagExpr(flag: InputFlags): o.Expression {
|
||||
}
|
||||
|
||||
/** Combines a given input flag with an existing flag expression, if present. */
|
||||
function bitwiseAndInputFlagsExpr(flag: InputFlags, expr: o.Expression|null): o.Expression {
|
||||
function bitwiseOrInputFlagsExpr(flag: InputFlags, expr: o.Expression|null): o.Expression {
|
||||
if (expr === null) {
|
||||
return getInputFlagExpr(flag);
|
||||
}
|
||||
return new o.BinaryOperatorExpr(
|
||||
o.BinaryOperator.BitwiseAnd,
|
||||
expr,
|
||||
getInputFlagExpr(flag),
|
||||
);
|
||||
return getInputFlagExpr(flag).bitwiseOr(expr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,7 @@ export const BINARY_OPERATORS = new Map([
|
||||
['&&', o.BinaryOperator.And],
|
||||
['>', o.BinaryOperator.Bigger],
|
||||
['>=', o.BinaryOperator.BiggerEquals],
|
||||
['|', o.BinaryOperator.BitwiseOr],
|
||||
['&', o.BinaryOperator.BitwiseAnd],
|
||||
['/', o.BinaryOperator.Divide],
|
||||
['==', o.BinaryOperator.Equals],
|
||||
|
||||
Reference in New Issue
Block a user