Skip to content

Commit 768a09d

Browse files
JeanMechekirjs
authored andcommitted
refactor(compiler): Remove the interpolation config (#64071)
After #63474, we don't need that anymore. PR Close #64071
1 parent 8a1e36b commit 768a09d

File tree

34 files changed

+74
-339
lines changed

34 files changed

+74
-339
lines changed

packages/compiler-cli/linker/src/file_linker/partial_linkers/partial_component_linker_1.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import {
1010
compileComponentFromMetadata,
1111
ConstantPool,
1212
DeclarationListEmitMode,
13-
DEFAULT_INTERPOLATION_CONFIG,
1413
DeferBlockDepsEmitMode,
1514
ForwardRefHandling,
16-
InterpolationConfig,
1715
makeBindingParser,
1816
outputAst as o,
1917
ParsedTemplate,
@@ -95,7 +93,6 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression>
9593
metaObj: AstObject<R3DeclareComponentMetadata, TExpression>,
9694
version: string,
9795
): R3ComponentMetadata<R3TemplateDependencyMetadata> {
98-
const interpolation = parseInterpolationConfig(metaObj);
9996
const templateSource = metaObj.getValue('template');
10097
const isInline = metaObj.has('isInline') ? metaObj.getBoolean('isInline') : false;
10198
const templateInfo = this.getTemplateInfo(templateSource, isInline);
@@ -109,7 +106,6 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression>
109106

110107
const template = parseTemplate(templateInfo.code, templateInfo.sourceUrl, {
111108
escapedString: templateInfo.isEscaped,
112-
interpolationConfig: interpolation,
113109
range: templateInfo.range,
114110
enableI18nLegacyMessageIdFormat: false,
115111
preserveWhitespaces: metaObj.has('preserveWhitespaces')
@@ -244,7 +240,6 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression>
244240
encapsulation: metaObj.has('encapsulation')
245241
? parseEncapsulation(metaObj.getValue('encapsulation'))
246242
: ViewEncapsulation.Emulated,
247-
interpolation,
248243
changeDetection: metaObj.has('changeDetection')
249244
? parseChangeDetectionStrategy(metaObj.getValue('changeDetection'))
250245
: ChangeDetectionStrategy.Default,
@@ -380,27 +375,6 @@ interface TemplateInfo {
380375
isEscaped: boolean;
381376
}
382377

383-
/**
384-
* Extract an `InterpolationConfig` from the component declaration.
385-
*/
386-
function parseInterpolationConfig<TExpression>(
387-
metaObj: AstObject<R3DeclareComponentMetadata, TExpression>,
388-
): InterpolationConfig {
389-
if (!metaObj.has('interpolation')) {
390-
return DEFAULT_INTERPOLATION_CONFIG;
391-
}
392-
393-
const interpolationExpr = metaObj.getValue('interpolation');
394-
const values = interpolationExpr.getArray().map((entry) => entry.getString());
395-
if (values.length !== 2) {
396-
throw new FatalLinkerError(
397-
interpolationExpr.expression,
398-
'Unsupported interpolation config, expected an array containing exactly two strings',
399-
);
400-
}
401-
return InterpolationConfig.fromArray(values as [string, string]);
402-
}
403-
404378
/**
405379
* Determines the `ViewEncapsulation` mode from the AST value's symbol name.
406380
*/

packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
CssSelector,
2121
DeclarationListEmitMode,
2222
DeclareComponentTemplateInfo,
23-
DEFAULT_INTERPOLATION_CONFIG,
2423
DeferBlockDepsEmitMode,
2524
DomElementSchemaRegistry,
2625
ExternalExpr,
@@ -955,7 +954,6 @@ export class ComponentDecoratorHandler
955954
template,
956955
encapsulation,
957956
changeDetection,
958-
interpolation: template.interpolationConfig ?? DEFAULT_INTERPOLATION_CONFIG,
959957
styles,
960958
externalStyles,
961959
// These will be replaced during the compilation step, after all `NgModule`s have been
@@ -1349,7 +1347,6 @@ export class ComponentDecoratorHandler
13491347
ctx.updateFromTemplate(
13501348
analysis.template.content,
13511349
analysis.template.declaration.resolvedTemplateUrl,
1352-
analysis.template.interpolationConfig ?? DEFAULT_INTERPOLATION_CONFIG,
13531350
);
13541351
}
13551352

@@ -2473,7 +2470,7 @@ export class ComponentDecoratorHandler
24732470

24742471
/** Creates a new binding parser. */
24752472
private getNewBindingParser() {
2476-
return makeBindingParser(undefined, this.enableSelectorless);
2473+
return makeBindingParser(this.enableSelectorless);
24772474
}
24782475
}
24792476

packages/compiler-cli/src/ngtsc/annotations/component/src/resources.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
*/
88

99
import {
10-
DEFAULT_INTERPOLATION_CONFIG,
11-
InterpolationConfig,
1210
LexerRange,
1311
ParsedTemplate,
1412
ParseSourceFile,
@@ -91,7 +89,6 @@ export interface ParsedTemplateWithSource extends ParsedComponentTemplate {
9189
*/
9290
interface CommonTemplateDeclaration {
9391
preserveWhitespaces: boolean;
94-
interpolationConfig: InterpolationConfig;
9592
templateUrl: string;
9693
resolvedTemplateUrl: string;
9794
}
@@ -284,15 +281,13 @@ export function createEmptyTemplate(
284281
declaration: templateUrl
285282
? {
286283
isInline: false,
287-
interpolationConfig: InterpolationConfig.fromArray(null),
288284
preserveWhitespaces: false,
289285
templateUrlExpression: templateUrl,
290286
templateUrl: 'missing.ng.html',
291287
resolvedTemplateUrl: '/missing.ng.html',
292288
}
293289
: {
294290
isInline: true,
295-
interpolationConfig: InterpolationConfig.fromArray(null),
296291
preserveWhitespaces: false,
297292
expression: template!,
298293
templateUrl: containingFile,
@@ -312,7 +307,6 @@ function parseExtractedTemplate(
312307
// We always normalize line endings if the template has been escaped (i.e. is inline).
313308
const i18nNormalizeLineEndingsInICUs = escapedString || options.i18nNormalizeLineEndingsInICUs;
314309
const commonParseOptions: ParseTemplateOptions = {
315-
interpolationConfig: template.interpolationConfig,
316310
range: sourceParseRange ?? undefined,
317311
enableI18nLegacyMessageIdFormat: options.enableI18nLegacyMessageIdFormat,
318312
i18nNormalizeLineEndingsInICUs,
@@ -379,7 +373,6 @@ export function parseTemplateDeclaration(
379373
preserveWhitespaces = value;
380374
}
381375

382-
let interpolationConfig = DEFAULT_INTERPOLATION_CONFIG;
383376
if (component.has('interpolation')) {
384377
const expr = component.get('interpolation')!;
385378
const value = evaluator.evaluate(expr);
@@ -394,7 +387,6 @@ export function parseTemplateDeclaration(
394387
'interpolation must be an array with 2 elements of string type',
395388
);
396389
}
397-
interpolationConfig = InterpolationConfig.fromArray(value as [string, string]);
398390
}
399391

400392
if (component.has('templateUrl')) {
@@ -411,7 +403,6 @@ export function parseTemplateDeclaration(
411403
const resourceUrl = resourceLoader.resolve(templateUrl, containingFile);
412404
return {
413405
isInline: false,
414-
interpolationConfig,
415406
preserveWhitespaces,
416407
templateUrl,
417408
templateUrlExpression: templateUrlExpr,
@@ -433,7 +424,6 @@ export function parseTemplateDeclaration(
433424
} else if (component.has('template')) {
434425
return {
435426
isInline: true,
436-
interpolationConfig,
437427
preserveWhitespaces,
438428
expression: component.get('template')!,
439429
templateUrl: containingFile,

packages/compiler-cli/src/ngtsc/xi18n/src/context.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {InterpolationConfig} from '@angular/compiler';
10-
119
/**
1210
* Captures template information intended for extraction of i18n messages from a template.
1311
*
@@ -23,5 +21,5 @@ export interface Xi18nContext {
2321
* the return type is declared as `void` for simplicity, since any parse errors would be reported
2422
* as diagnostics anyway.
2523
*/
26-
updateFromTemplate(html: string, url: string, interpolationConfig: InterpolationConfig): void;
24+
updateFromTemplate(html: string, url: string): void;
2725
}

packages/compiler/src/compiler_facade_interface.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ export interface R3ComponentMetadataFacade extends R3DirectiveMetadataFacade {
214214
styles: string[];
215215
encapsulation: ViewEncapsulation;
216216
viewProviders: Provider[] | null;
217-
interpolation?: [string, string];
218217
changeDetection?: ChangeDetectionStrategy;
219218
hasDirectiveDependencies: boolean;
220219
}
@@ -277,7 +276,6 @@ export interface R3DeclareComponentFacade extends R3DeclareDirectiveFacade {
277276
animations?: OpaqueValue;
278277
changeDetection?: ChangeDetectionStrategy;
279278
encapsulation?: ViewEncapsulation;
280-
interpolation?: [string, string];
281279
preserveWhitespaces?: boolean;
282280
}
283281

packages/compiler/src/expression_parser/parser.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import * as chars from '../chars';
10-
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/defaults';
1110
import {
1211
InterpolatedAttributeToken,
1312
InterpolatedTextToken,
@@ -103,10 +102,9 @@ export class Parser {
103102
input: string,
104103
parseSourceSpan: ParseSourceSpan,
105104
absoluteOffset: number,
106-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
107105
): ASTWithSource {
108106
const errors: ParseError[] = [];
109-
this._checkNoInterpolation(errors, input, parseSourceSpan, interpolationConfig);
107+
this._checkNoInterpolation(errors, input, parseSourceSpan);
110108
const {stripped: sourceToLex} = this._stripComments(input);
111109
const tokens = this._lexer.tokenize(sourceToLex);
112110
const ast = new _ParseAST(
@@ -127,16 +125,9 @@ export class Parser {
127125
input: string,
128126
parseSourceSpan: ParseSourceSpan,
129127
absoluteOffset: number,
130-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
131128
): ASTWithSource {
132129
const errors: ParseError[] = [];
133-
const ast = this._parseBindingAst(
134-
input,
135-
parseSourceSpan,
136-
absoluteOffset,
137-
interpolationConfig,
138-
errors,
139-
);
130+
const ast = this._parseBindingAst(input, parseSourceSpan, absoluteOffset, errors);
140131
return new ASTWithSource(ast, input, getLocation(parseSourceSpan), absoluteOffset, errors);
141132
}
142133

@@ -151,16 +142,9 @@ export class Parser {
151142
input: string,
152143
parseSourceSpan: ParseSourceSpan,
153144
absoluteOffset: number,
154-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
155145
): ASTWithSource {
156146
const errors: ParseError[] = [];
157-
const ast = this._parseBindingAst(
158-
input,
159-
parseSourceSpan,
160-
absoluteOffset,
161-
interpolationConfig,
162-
errors,
163-
);
147+
const ast = this._parseBindingAst(input, parseSourceSpan, absoluteOffset, errors);
164148
const simplExpressionErrors = this.checkSimpleExpression(ast);
165149

166150
if (simplExpressionErrors.length > 0) {
@@ -180,10 +164,9 @@ export class Parser {
180164
input: string,
181165
parseSourceSpan: ParseSourceSpan,
182166
absoluteOffset: number,
183-
interpolationConfig: InterpolationConfig,
184167
errors: ParseError[],
185168
): AST {
186-
this._checkNoInterpolation(errors, input, parseSourceSpan, interpolationConfig);
169+
this._checkNoInterpolation(errors, input, parseSourceSpan);
187170
const {stripped: sourceToLex} = this._stripComments(input);
188171
const tokens = this._lexer.tokenize(sourceToLex);
189172
return new _ParseAST(
@@ -254,15 +237,13 @@ export class Parser {
254237
parseSourceSpan: ParseSourceSpan,
255238
absoluteOffset: number,
256239
interpolatedTokens: InterpolatedAttributeToken[] | InterpolatedTextToken[] | null,
257-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
258240
): ASTWithSource | null {
259241
const errors: ParseError[] = [];
260242
const {strings, expressions, offsets} = this.splitInterpolation(
261243
input,
262244
parseSourceSpan,
263245
errors,
264246
interpolatedTokens,
265-
interpolationConfig,
266247
);
267248
if (expressions.length === 0) return null;
268249

@@ -377,7 +358,6 @@ export class Parser {
377358
parseSourceSpan: ParseSourceSpan,
378359
errors: ParseError[],
379360
interpolatedTokens: InterpolatedAttributeToken[] | InterpolatedTextToken[] | null,
380-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
381361
): SplitInterpolation {
382362
const strings: InterpolationPiece[] = [];
383363
const expressions: InterpolationPiece[] = [];
@@ -388,7 +368,8 @@ export class Parser {
388368
let i = 0;
389369
let atInterpolation = false;
390370
let extendLastString = false;
391-
let {start: interpStart, end: interpEnd} = interpolationConfig;
371+
const interpStart = '{{';
372+
const interpEnd = '}}';
392373
while (i < input.length) {
393374
if (!atInterpolation) {
394375
// parse until starting {{
@@ -493,18 +474,17 @@ export class Parser {
493474
errors: ParseError[],
494475
input: string,
495476
parseSourceSpan: ParseSourceSpan,
496-
{start, end}: InterpolationConfig,
497477
): void {
498478
let startIndex = -1;
499479
let endIndex = -1;
500480

501481
for (const charIndex of this._forEachUnquotedChar(input, 0)) {
502482
if (startIndex === -1) {
503-
if (input.startsWith(start)) {
483+
if (input.startsWith('{{')) {
504484
startIndex = charIndex;
505485
}
506486
} else {
507-
endIndex = this._getInterpolationEndIndex(input, end, charIndex);
487+
endIndex = this._getInterpolationEndIndex(input, '}}', charIndex);
508488
if (endIndex > -1) {
509489
break;
510490
}
@@ -514,7 +494,7 @@ export class Parser {
514494
if (startIndex > -1 && endIndex > -1) {
515495
errors.push(
516496
getParseError(
517-
`Got interpolation (${start}${end}) where expression was expected`,
497+
`Got interpolation ({{}}) where expression was expected`,
518498
input,
519499
`at column ${startIndex} in`,
520500
parseSourceSpan,

0 commit comments

Comments
 (0)