Skip to content

Commit 9dbcff8

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 8cf95ce commit 9dbcff8

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,
@@ -951,7 +950,6 @@ export class ComponentDecoratorHandler
951950
template,
952951
encapsulation,
953952
changeDetection,
954-
interpolation: template.interpolationConfig ?? DEFAULT_INTERPOLATION_CONFIG,
955953
styles,
956954
externalStyles,
957955
// These will be replaced during the compilation step, after all `NgModule`s have been
@@ -1345,7 +1343,6 @@ export class ComponentDecoratorHandler
13451343
ctx.updateFromTemplate(
13461344
analysis.template.content,
13471345
analysis.template.declaration.resolvedTemplateUrl,
1348-
analysis.template.interpolationConfig ?? DEFAULT_INTERPOLATION_CONFIG,
13491346
);
13501347
}
13511348

@@ -2469,7 +2466,7 @@ export class ComponentDecoratorHandler
24692466

24702467
/** Creates a new binding parser. */
24712468
private getNewBindingParser() {
2472-
return makeBindingParser(undefined, this.enableSelectorless);
2469+
return makeBindingParser(this.enableSelectorless);
24732470
}
24742471
}
24752472

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,
@@ -102,10 +101,9 @@ export class Parser {
102101
input: string,
103102
parseSourceSpan: ParseSourceSpan,
104103
absoluteOffset: number,
105-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
106104
): ASTWithSource {
107105
const errors: ParseError[] = [];
108-
this._checkNoInterpolation(errors, input, parseSourceSpan, interpolationConfig);
106+
this._checkNoInterpolation(errors, input, parseSourceSpan);
109107
const {stripped: sourceToLex} = this._stripComments(input);
110108
const tokens = this._lexer.tokenize(sourceToLex);
111109
const ast = new _ParseAST(
@@ -126,16 +124,9 @@ export class Parser {
126124
input: string,
127125
parseSourceSpan: ParseSourceSpan,
128126
absoluteOffset: number,
129-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
130127
): ASTWithSource {
131128
const errors: ParseError[] = [];
132-
const ast = this._parseBindingAst(
133-
input,
134-
parseSourceSpan,
135-
absoluteOffset,
136-
interpolationConfig,
137-
errors,
138-
);
129+
const ast = this._parseBindingAst(input, parseSourceSpan, absoluteOffset, errors);
139130
return new ASTWithSource(ast, input, getLocation(parseSourceSpan), absoluteOffset, errors);
140131
}
141132

@@ -150,16 +141,9 @@ export class Parser {
150141
input: string,
151142
parseSourceSpan: ParseSourceSpan,
152143
absoluteOffset: number,
153-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
154144
): ASTWithSource {
155145
const errors: ParseError[] = [];
156-
const ast = this._parseBindingAst(
157-
input,
158-
parseSourceSpan,
159-
absoluteOffset,
160-
interpolationConfig,
161-
errors,
162-
);
146+
const ast = this._parseBindingAst(input, parseSourceSpan, absoluteOffset, errors);
163147
const simplExpressionErrors = this.checkSimpleExpression(ast);
164148

165149
if (simplExpressionErrors.length > 0) {
@@ -179,10 +163,9 @@ export class Parser {
179163
input: string,
180164
parseSourceSpan: ParseSourceSpan,
181165
absoluteOffset: number,
182-
interpolationConfig: InterpolationConfig,
183166
errors: ParseError[],
184167
): AST {
185-
this._checkNoInterpolation(errors, input, parseSourceSpan, interpolationConfig);
168+
this._checkNoInterpolation(errors, input, parseSourceSpan);
186169
const {stripped: sourceToLex} = this._stripComments(input);
187170
const tokens = this._lexer.tokenize(sourceToLex);
188171
return new _ParseAST(
@@ -253,15 +236,13 @@ export class Parser {
253236
parseSourceSpan: ParseSourceSpan,
254237
absoluteOffset: number,
255238
interpolatedTokens: InterpolatedAttributeToken[] | InterpolatedTextToken[] | null,
256-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
257239
): ASTWithSource | null {
258240
const errors: ParseError[] = [];
259241
const {strings, expressions, offsets} = this.splitInterpolation(
260242
input,
261243
parseSourceSpan,
262244
errors,
263245
interpolatedTokens,
264-
interpolationConfig,
265246
);
266247
if (expressions.length === 0) return null;
267248

@@ -376,7 +357,6 @@ export class Parser {
376357
parseSourceSpan: ParseSourceSpan,
377358
errors: ParseError[],
378359
interpolatedTokens: InterpolatedAttributeToken[] | InterpolatedTextToken[] | null,
379-
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
380360
): SplitInterpolation {
381361
const strings: InterpolationPiece[] = [];
382362
const expressions: InterpolationPiece[] = [];
@@ -387,7 +367,8 @@ export class Parser {
387367
let i = 0;
388368
let atInterpolation = false;
389369
let extendLastString = false;
390-
let {start: interpStart, end: interpEnd} = interpolationConfig;
370+
const interpStart = '{{';
371+
const interpEnd = '}}';
391372
while (i < input.length) {
392373
if (!atInterpolation) {
393374
// parse until starting {{
@@ -492,18 +473,17 @@ export class Parser {
492473
errors: ParseError[],
493474
input: string,
494475
parseSourceSpan: ParseSourceSpan,
495-
{start, end}: InterpolationConfig,
496476
): void {
497477
let startIndex = -1;
498478
let endIndex = -1;
499479

500480
for (const charIndex of this._forEachUnquotedChar(input, 0)) {
501481
if (startIndex === -1) {
502-
if (input.startsWith(start)) {
482+
if (input.startsWith('{{')) {
503483
startIndex = charIndex;
504484
}
505485
} else {
506-
endIndex = this._getInterpolationEndIndex(input, end, charIndex);
486+
endIndex = this._getInterpolationEndIndex(input, '}}', charIndex);
507487
if (endIndex > -1) {
508488
break;
509489
}
@@ -513,7 +493,7 @@ export class Parser {
513493
if (startIndex > -1 && endIndex > -1) {
514494
errors.push(
515495
getParseError(
516-
`Got interpolation (${start}${end}) where expression was expected`,
496+
`Got interpolation ({{}}) where expression was expected`,
517497
input,
518498
`at column ${startIndex} in`,
519499
parseSourceSpan,

0 commit comments

Comments
 (0)