Skip to content

Expose TokenType - #53

Merged
fisker merged 5 commits into
prettier:devfrom
splincode:feat/angular-html-parser-interpolation-token-api
Sep 21, 2026
Merged

fisker merged 5 commits into
prettier:devfrom
splincode:feat/angular-html-parser-interpolation-token-api

Conversation

@splincode

Copy link
Copy Markdown

Description

Expose isInterpolationToken together with the InterpolationToken and InterpolatedTextToken types from the public package entry point.

This lets consumers identify interpolation tokens using parser-owned semantics instead of reimplementing the token structure, for example by checking parts.length and the {{ / }} markers.

TokenType is intentionally kept internal because it is currently a const enum; the public type guard provides the runtime discriminator without exposing that implementation detail.

This is useful for prettier/prettier#20117, where Prettier needs the parser-provided interpolation boundaries when an Angular expression contains }}.

Tests

Added a public API test that verifies the exported type guard and type narrowing against tokens returned by parse().

Comment thread packages/angular-html-parser/test/index_spec.ts Outdated
@fisker

fisker commented Sep 21, 2026

Copy link
Copy Markdown
Member

splincode#12

Comment on lines +96 to +100
export function isInterpolationToken(
token: InterpolatedTextToken,
): token is InterpolationToken {
return token.type === TokenType.INTERPOLATION;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's expose TokenType instead of a function for just InterpolationToken

@fisker fisker changed the title Expose interpolation token helpers Expose TokenType Sep 21, 2026
@fisker
fisker merged commit 1701b96 into prettier:dev Sep 21, 2026
7 checks passed
@fisker

fisker commented Sep 21, 2026

Copy link
Copy Markdown
Member

@splincode It's out of scope for this PR, but do you know if we can parse interpolations here? I saw there is a _consumeWithInterpolation

this._consumeWithInterpolation(
, but I didn't have time to look into it.

@fisker

fisker commented Sep 21, 2026

Copy link
Copy Markdown
Member

@splincode

Copy link
Copy Markdown
Author

Yes. I checked it, and _consumeWithInterpolation already tokenizes the text into TEXT and INTERPOLATION tokens. _TreeBuilder._consumeText merges them back into a Text node, but preserves the original tokens in Text.tokens.

So I think we don't need another interpolation parser here. With TokenType now exposed in v10.13.0, Prettier can use token.type === TokenType.INTERPOLATION directly and rely on the interpolation boundaries produced by the lexer.

I'll update prettier/prettier#20117 to use that instead of detecting interpolation tokens from parts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants