Skip to content

Commit 4dc5ae5

Browse files
crisbetokirjs
authored andcommitted
refactor(core): remove unused instruction parameter
The `thisArg` in pure functions isn't used so we can drop it. We still need to keep it on the underlying implementation, because pipe instructions rely on it.
1 parent 090484c commit 4dc5ae5

2 files changed

Lines changed: 17 additions & 104 deletions

File tree

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

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ export function textInterpolate(
841841
): ir.UpdateOp {
842842
const interpolationArgs = collateInterpolationArgs(strings, expressions);
843843

844-
return callVariadicInstruction(TEXT_INTERPOLATE_CONFIG, [], interpolationArgs, [], sourceSpan);
844+
return callVariadicInstruction(TEXT_INTERPOLATE_CONFIG, [], interpolationArgs, sourceSpan);
845845
}
846846

847847
export function i18nExp(expr: o.Expression, sourceSpan: ParseSourceSpan | null): ir.UpdateOp {
@@ -930,13 +930,7 @@ export function pureFunction(
930930
fn: o.Expression,
931931
args: o.Expression[],
932932
): o.Expression {
933-
return callVariadicInstructionExpr(
934-
PURE_FUNCTION_CONFIG,
935-
[o.literal(varOffset), fn],
936-
args,
937-
[],
938-
null,
939-
);
933+
return callVariadicInstructionExpr(PURE_FUNCTION_CONFIG, [o.literal(varOffset), fn], args, null);
940934
}
941935

942936
export function attachSourceLocation(
@@ -980,13 +974,7 @@ function interpolationToExpression(
980974
interpolation.strings,
981975
interpolation.expressions,
982976
);
983-
return callVariadicInstructionExpr(
984-
VALUE_INTERPOLATE_CONFIG,
985-
[],
986-
interpolationArgs,
987-
[],
988-
sourceSpan,
989-
);
977+
return callVariadicInstructionExpr(VALUE_INTERPOLATE_CONFIG, [], interpolationArgs, sourceSpan);
990978
}
991979

992980
function call<OpT extends ir.CreateOp | ir.UpdateOp>(
@@ -1085,7 +1073,6 @@ function callVariadicInstructionExpr(
10851073
config: VariadicInstructionConfig,
10861074
baseArgs: o.Expression[],
10871075
interpolationArgs: o.Expression[],
1088-
extraArgs: o.Expression[],
10891076
sourceSpan: ParseSourceSpan | null,
10901077
): o.Expression {
10911078
// mapping need to be done before potentially dropping the last interpolation argument
@@ -1095,7 +1082,6 @@ function callVariadicInstructionExpr(
10951082
// And the runtime will take care of it.
10961083
const lastInterpolationArg = interpolationArgs.at(-1);
10971084
if (
1098-
extraArgs.length === 0 &&
10991085
interpolationArgs.length > 1 &&
11001086
lastInterpolationArg instanceof o.LiteralExpr &&
11011087
lastInterpolationArg.value === ''
@@ -1105,14 +1091,12 @@ function callVariadicInstructionExpr(
11051091

11061092
if (n < config.constant.length) {
11071093
// Constant calling pattern.
1108-
return o
1109-
.importExpr(config.constant[n])
1110-
.callFn([...baseArgs, ...interpolationArgs, ...extraArgs], sourceSpan);
1094+
return o.importExpr(config.constant[n]).callFn([...baseArgs, ...interpolationArgs], sourceSpan);
11111095
} else if (config.variable !== null) {
11121096
// Variable calling pattern.
11131097
return o
11141098
.importExpr(config.variable)
1115-
.callFn([...baseArgs, o.literalArr(interpolationArgs), ...extraArgs], sourceSpan);
1099+
.callFn([...baseArgs, o.literalArr(interpolationArgs)], sourceSpan);
11161100
} else {
11171101
throw new Error(`AssertionError: unable to call variadic function`);
11181102
}
@@ -1122,16 +1106,9 @@ function callVariadicInstruction(
11221106
config: VariadicInstructionConfig,
11231107
baseArgs: o.Expression[],
11241108
interpolationArgs: o.Expression[],
1125-
extraArgs: o.Expression[],
11261109
sourceSpan: ParseSourceSpan | null,
11271110
): ir.UpdateOp {
11281111
return ir.createStatementOp(
1129-
callVariadicInstructionExpr(
1130-
config,
1131-
baseArgs,
1132-
interpolationArgs,
1133-
extraArgs,
1134-
sourceSpan,
1135-
).toStmt(),
1112+
callVariadicInstructionExpr(config, baseArgs, interpolationArgs, sourceSpan).toStmt(),
11361113
);
11371114
}

packages/core/src/render3/pure_function.ts

Lines changed: 11 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@ import {NO_CHANGE} from './tokens';
4343
*
4444
* @param slotOffset the offset from binding root to the reserved slot
4545
* @param pureFn Function that returns a value
46-
* @param thisArg Optional calling context of pureFn
4746
* @returns value
4847
*
4948
* @codeGenApi
5049
*/
51-
export function ɵɵpureFunction0<T>(slotOffset: number, pureFn: () => T, thisArg?: any): T {
50+
export function ɵɵpureFunction0<T>(slotOffset: number, pureFn: () => T): T {
5251
const bindingIndex = getBindingRoot() + slotOffset;
5352
const lView = getLView();
5453
return lView[bindingIndex] === NO_CHANGE
55-
? updateBinding(lView, bindingIndex, thisArg ? pureFn.call(thisArg) : pureFn())
54+
? updateBinding(lView, bindingIndex, pureFn())
5655
: getBinding(lView, bindingIndex);
5756
}
5857

@@ -63,18 +62,12 @@ export function ɵɵpureFunction0<T>(slotOffset: number, pureFn: () => T, thisAr
6362
* @param slotOffset the offset from binding root to the reserved slot
6463
* @param pureFn Function that returns an updated value
6564
* @param exp Updated expression value
66-
* @param thisArg Optional calling context of pureFn
6765
* @returns Updated or cached value
6866
*
6967
* @codeGenApi
7068
*/
71-
export function ɵɵpureFunction1(
72-
slotOffset: number,
73-
pureFn: (v: any) => any,
74-
exp: any,
75-
thisArg?: any,
76-
): any {
77-
return pureFunction1Internal(getLView(), getBindingRoot(), slotOffset, pureFn, exp, thisArg);
69+
export function ɵɵpureFunction1(slotOffset: number, pureFn: (v: any) => any, exp: any): any {
70+
return pureFunction1Internal(getLView(), getBindingRoot(), slotOffset, pureFn, exp);
7871
}
7972

8073
/**
@@ -85,7 +78,6 @@ export function ɵɵpureFunction1(
8578
* @param pureFn
8679
* @param exp1
8780
* @param exp2
88-
* @param thisArg Optional calling context of pureFn
8981
* @returns Updated or cached value
9082
*
9183
* @codeGenApi
@@ -95,17 +87,8 @@ export function ɵɵpureFunction2(
9587
pureFn: (v1: any, v2: any) => any,
9688
exp1: any,
9789
exp2: any,
98-
thisArg?: any,
9990
): any {
100-
return pureFunction2Internal(
101-
getLView(),
102-
getBindingRoot(),
103-
slotOffset,
104-
pureFn,
105-
exp1,
106-
exp2,
107-
thisArg,
108-
);
91+
return pureFunction2Internal(getLView(), getBindingRoot(), slotOffset, pureFn, exp1, exp2);
10992
}
11093

11194
/**
@@ -117,7 +100,6 @@ export function ɵɵpureFunction2(
117100
* @param exp1
118101
* @param exp2
119102
* @param exp3
120-
* @param thisArg Optional calling context of pureFn
121103
* @returns Updated or cached value
122104
*
123105
* @codeGenApi
@@ -128,18 +110,8 @@ export function ɵɵpureFunction3(
128110
exp1: any,
129111
exp2: any,
130112
exp3: any,
131-
thisArg?: any,
132113
): any {
133-
return pureFunction3Internal(
134-
getLView(),
135-
getBindingRoot(),
136-
slotOffset,
137-
pureFn,
138-
exp1,
139-
exp2,
140-
exp3,
141-
thisArg,
142-
);
114+
return pureFunction3Internal(getLView(), getBindingRoot(), slotOffset, pureFn, exp1, exp2, exp3);
143115
}
144116

145117
/**
@@ -152,7 +124,6 @@ export function ɵɵpureFunction3(
152124
* @param exp2
153125
* @param exp3
154126
* @param exp4
155-
* @param thisArg Optional calling context of pureFn
156127
* @returns Updated or cached value
157128
*
158129
* @codeGenApi
@@ -175,7 +146,6 @@ export function ɵɵpureFunction4(
175146
exp2,
176147
exp3,
177148
exp4,
178-
thisArg,
179149
);
180150
}
181151

@@ -190,7 +160,6 @@ export function ɵɵpureFunction4(
190160
* @param exp3
191161
* @param exp4
192162
* @param exp5
193-
* @param thisArg Optional calling context of pureFn
194163
* @returns Updated or cached value
195164
*
196165
* @codeGenApi
@@ -203,19 +172,12 @@ export function ɵɵpureFunction5(
203172
exp3: any,
204173
exp4: any,
205174
exp5: any,
206-
thisArg?: any,
207175
): any {
208176
const bindingIndex = getBindingRoot() + slotOffset;
209177
const lView = getLView();
210178
const different = bindingUpdated4(lView, bindingIndex, exp1, exp2, exp3, exp4);
211179
return bindingUpdated(lView, bindingIndex + 4, exp5) || different
212-
? updateBinding(
213-
lView,
214-
bindingIndex + 5,
215-
thisArg
216-
? pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5)
217-
: pureFn(exp1, exp2, exp3, exp4, exp5),
218-
)
180+
? updateBinding(lView, bindingIndex + 5, pureFn(exp1, exp2, exp3, exp4, exp5))
219181
: getBinding(lView, bindingIndex + 5);
220182
}
221183

@@ -231,7 +193,6 @@ export function ɵɵpureFunction5(
231193
* @param exp4
232194
* @param exp5
233195
* @param exp6
234-
* @param thisArg Optional calling context of pureFn
235196
* @returns Updated or cached value
236197
*
237198
* @codeGenApi
@@ -245,19 +206,12 @@ export function ɵɵpureFunction6(
245206
exp4: any,
246207
exp5: any,
247208
exp6: any,
248-
thisArg?: any,
249209
): any {
250210
const bindingIndex = getBindingRoot() + slotOffset;
251211
const lView = getLView();
252212
const different = bindingUpdated4(lView, bindingIndex, exp1, exp2, exp3, exp4);
253213
return bindingUpdated2(lView, bindingIndex + 4, exp5, exp6) || different
254-
? updateBinding(
255-
lView,
256-
bindingIndex + 6,
257-
thisArg
258-
? pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5, exp6)
259-
: pureFn(exp1, exp2, exp3, exp4, exp5, exp6),
260-
)
214+
? updateBinding(lView, bindingIndex + 6, pureFn(exp1, exp2, exp3, exp4, exp5, exp6))
261215
: getBinding(lView, bindingIndex + 6);
262216
}
263217

@@ -274,7 +228,6 @@ export function ɵɵpureFunction6(
274228
* @param exp5
275229
* @param exp6
276230
* @param exp7
277-
* @param thisArg Optional calling context of pureFn
278231
* @returns Updated or cached value
279232
*
280233
* @codeGenApi
@@ -289,19 +242,12 @@ export function ɵɵpureFunction7(
289242
exp5: any,
290243
exp6: any,
291244
exp7: any,
292-
thisArg?: any,
293245
): any {
294246
const bindingIndex = getBindingRoot() + slotOffset;
295247
const lView = getLView();
296248
let different = bindingUpdated4(lView, bindingIndex, exp1, exp2, exp3, exp4);
297249
return bindingUpdated3(lView, bindingIndex + 4, exp5, exp6, exp7) || different
298-
? updateBinding(
299-
lView,
300-
bindingIndex + 7,
301-
thisArg
302-
? pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5, exp6, exp7)
303-
: pureFn(exp1, exp2, exp3, exp4, exp5, exp6, exp7),
304-
)
250+
? updateBinding(lView, bindingIndex + 7, pureFn(exp1, exp2, exp3, exp4, exp5, exp6, exp7))
305251
: getBinding(lView, bindingIndex + 7);
306252
}
307253

@@ -319,7 +265,6 @@ export function ɵɵpureFunction7(
319265
* @param exp6
320266
* @param exp7
321267
* @param exp8
322-
* @param thisArg Optional calling context of pureFn
323268
* @returns Updated or cached value
324269
*
325270
* @codeGenApi
@@ -335,19 +280,12 @@ export function ɵɵpureFunction8(
335280
exp6: any,
336281
exp7: any,
337282
exp8: any,
338-
thisArg?: any,
339283
): any {
340284
const bindingIndex = getBindingRoot() + slotOffset;
341285
const lView = getLView();
342286
const different = bindingUpdated4(lView, bindingIndex, exp1, exp2, exp3, exp4);
343287
return bindingUpdated4(lView, bindingIndex + 4, exp5, exp6, exp7, exp8) || different
344-
? updateBinding(
345-
lView,
346-
bindingIndex + 8,
347-
thisArg
348-
? pureFn.call(thisArg, exp1, exp2, exp3, exp4, exp5, exp6, exp7, exp8)
349-
: pureFn(exp1, exp2, exp3, exp4, exp5, exp6, exp7, exp8),
350-
)
288+
? updateBinding(lView, bindingIndex + 8, pureFn(exp1, exp2, exp3, exp4, exp5, exp6, exp7, exp8))
351289
: getBinding(lView, bindingIndex + 8);
352290
}
353291

@@ -361,7 +299,6 @@ export function ɵɵpureFunction8(
361299
* @param pureFn A pure function that takes binding values and builds an object or array
362300
* containing those values.
363301
* @param exps An array of binding values
364-
* @param thisArg Optional calling context of pureFn
365302
* @returns Updated or cached value
366303
*
367304
* @codeGenApi
@@ -370,9 +307,8 @@ export function ɵɵpureFunctionV(
370307
slotOffset: number,
371308
pureFn: (...v: any[]) => any,
372309
exps: any[],
373-
thisArg?: any,
374310
): any {
375-
return pureFunctionVInternal(getLView(), getBindingRoot(), slotOffset, pureFn, exps, thisArg);
311+
return pureFunctionVInternal(getLView(), getBindingRoot(), slotOffset, pureFn, exps);
376312
}
377313

378314
/**

0 commit comments

Comments
 (0)