Skip to content

refacto(compiler): Error on comment only interpolations #62590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JeanMeche
Copy link
Member

This commit introduces a ParserError to prevent an error later in the pipepine

fixes #34084

@JeanMeche JeanMeche requested a review from crisbeto July 11, 2025 12:29
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Jul 11, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 11, 2025
@JeanMeche JeanMeche force-pushed the interpolation-comment-error branch from b7f0558 to 4c98083 Compare July 11, 2025 12:50
This commit introduces a ParserError to prevent an error later in the pipepine

fixes angular#34084
@JeanMeche JeanMeche force-pushed the interpolation-comment-error branch from 4c98083 to c2192d6 Compare July 11, 2025 13:21
const tokens = this._lexer.tokenize(sourceToLex);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked what the AST looks like, but couldn't we check that strings.length === 0 and expressions.length === 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the unit test I provided, both aren't empty: string actually contains 2empty string and expression contains ' // foobar '.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's weird, but it's probably because we should handle comments at the lexer level rather than in the parser.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although we should probably move the comment tokenization into the lexer at some point.

const tokens = this._lexer.tokenize(sourceToLex);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's weird, but it's probably because we should handle comments at the lexer level rather than in the parser.

const i = this._commentStart(input);
return i != null ? input.substring(0, i) : input;
return i != null
? {hasComments: true, stripped: input.substring(0, i)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe move hasComments to be second so the shape matches with the other variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: compiler Issues related to `ngc`, Angular's template compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vague error when a comment is inside interpolated expression
2 participants