Skip to content

Commit d714750

Browse files
committed
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
1 parent cfab5a5 commit d714750

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export type UnaryOperator = '+'|'-'|'!';
262262
* The binary operators supported by the `AstFactory`.
263263
*/
264264
export type BinaryOperator =
265-
'&&'|'>'|'>='|'&'|'/'|'=='|'==='|'<'|'<='|'-'|'%'|'*'|'!='|'!=='|'||'|'+'|'??';
265+
'&&'|'>'|'>='|'&'|'|'|'/'|'=='|'==='|'<'|'<='|'-'|'%'|'*'|'!='|'!=='|'||'|'+'|'??';
266266

267267
/**
268268
* The original location of the start or end of a node created by the `AstFactory`.

packages/compiler-cli/src/ngtsc/translator/src/translator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const BINARY_OPERATORS = new Map<o.BinaryOperator, BinaryOperator>([
2121
[o.BinaryOperator.Bigger, '>'],
2222
[o.BinaryOperator.BiggerEquals, '>='],
2323
[o.BinaryOperator.BitwiseAnd, '&'],
24+
[o.BinaryOperator.BitwiseOr, '|'],
2425
[o.BinaryOperator.Divide, '/'],
2526
[o.BinaryOperator.Equals, '=='],
2627
[o.BinaryOperator.Identical, '==='],

packages/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const BINARY_OPERATORS: Record<BinaryOperator, ts.BinaryOperator> = {
3636
'>': ts.SyntaxKind.GreaterThanToken,
3737
'>=': ts.SyntaxKind.GreaterThanEqualsToken,
3838
'&': ts.SyntaxKind.AmpersandToken,
39+
'|': ts.SyntaxKind.BarToken,
3940
'/': ts.SyntaxKind.SlashToken,
4041
'==': ts.SyntaxKind.EqualsEqualsToken,
4142
'===': ts.SyntaxKind.EqualsEqualsEqualsToken,

packages/compiler/src/output/abstract_emitter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
415415
case o.BinaryOperator.And:
416416
opStr = '&&';
417417
break;
418+
case o.BinaryOperator.BitwiseOr:
419+
opStr = '|';
420+
break;
418421
case o.BinaryOperator.BitwiseAnd:
419422
opStr = '&';
420423
break;

packages/compiler/src/output/output_ast.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export enum BinaryOperator {
125125
Modulo,
126126
And,
127127
Or,
128+
BitwiseOr,
128129
BitwiseAnd,
129130
Lower,
130131
LowerEquals,
@@ -239,6 +240,10 @@ export abstract class Expression {
239240
and(rhs: Expression, sourceSpan?: ParseSourceSpan|null): BinaryOperatorExpr {
240241
return new BinaryOperatorExpr(BinaryOperator.And, this, rhs, null, sourceSpan);
241242
}
243+
bitwiseOr(rhs: Expression, sourceSpan?: ParseSourceSpan|null, parens: boolean = true):
244+
BinaryOperatorExpr {
245+
return new BinaryOperatorExpr(BinaryOperator.BitwiseOr, this, rhs, null, sourceSpan, parens);
246+
}
242247
bitwiseAnd(rhs: Expression, sourceSpan?: ParseSourceSpan|null, parens: boolean = true):
243248
BinaryOperatorExpr {
244249
return new BinaryOperatorExpr(BinaryOperator.BitwiseAnd, this, rhs, null, sourceSpan, parens);

packages/compiler/src/render3/view/util.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ export function conditionallyCreateDirectiveBindingLiteral(
212212
// Build up input flags
213213
let flags: o.Expression|null = null;
214214
if (value.isSignal) {
215-
flags = bitwiseAndInputFlagsExpr(InputFlags.SignalBased, flags);
215+
flags = bitwiseOrInputFlagsExpr(InputFlags.SignalBased, flags);
216216
}
217217
if (hasDecoratorInputTransform) {
218-
flags = bitwiseAndInputFlagsExpr(InputFlags.HasDecoratorInputTransform, flags);
218+
flags = bitwiseOrInputFlagsExpr(InputFlags.HasDecoratorInputTransform, flags);
219219
}
220220

221221
// Inputs, compared to outputs, will track their declared name (for `ngOnChanges`), support
@@ -253,15 +253,11 @@ function getInputFlagExpr(flag: InputFlags): o.Expression {
253253
}
254254

255255
/** Combines a given input flag with an existing flag expression, if present. */
256-
function bitwiseAndInputFlagsExpr(flag: InputFlags, expr: o.Expression|null): o.Expression {
256+
function bitwiseOrInputFlagsExpr(flag: InputFlags, expr: o.Expression|null): o.Expression {
257257
if (expr === null) {
258258
return getInputFlagExpr(flag);
259259
}
260-
return new o.BinaryOperatorExpr(
261-
o.BinaryOperator.BitwiseAnd,
262-
expr,
263-
getInputFlagExpr(flag),
264-
);
260+
return getInputFlagExpr(flag).bitwiseOr(expr);
265261
}
266262

267263
/**

packages/compiler/src/template/pipeline/src/conversion.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const BINARY_OPERATORS = new Map([
1313
['&&', o.BinaryOperator.And],
1414
['>', o.BinaryOperator.Bigger],
1515
['>=', o.BinaryOperator.BiggerEquals],
16+
['|', o.BinaryOperator.BitwiseOr],
1617
['&', o.BinaryOperator.BitwiseAnd],
1718
['/', o.BinaryOperator.Divide],
1819
['==', o.BinaryOperator.Equals],

0 commit comments

Comments
 (0)