From ea378a12d65ff2e33be86775a746d783012784cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Sun, 20 Sep 2026 17:05:06 +0300 Subject: [PATCH 1/5] Expose interpolation token helpers --- packages/angular-html-parser/src/index.ts | 15 +++++++++++ .../angular-html-parser/test/index_spec.ts | 25 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/angular-html-parser/src/index.ts b/packages/angular-html-parser/src/index.ts index d3eff0bd2705..1a68e5915ac0 100644 --- a/packages/angular-html-parser/src/index.ts +++ b/packages/angular-html-parser/src/index.ts @@ -2,6 +2,11 @@ import { HtmlParser } from "../../compiler/src/ml_parser/html_parser.ts"; import { XmlParser } from "../../compiler/src/ml_parser/xml_parser.ts"; import type { TagContentType } from "../../compiler/src/ml_parser/tags.ts"; import { ParseTreeResult as HtmlParseTreeResult } from "../../compiler/src/ml_parser/parser.ts"; +import { TokenType } from "../../compiler/src/ml_parser/tokens.ts"; +import type { + InterpolatedTextToken, + InterpolationToken, +} from "../../compiler/src/ml_parser/tokens.ts"; export interface HtmlParseOptions { /** @@ -88,6 +93,12 @@ export function parseHtml( ); } +export function isInterpolationToken( + token: InterpolatedTextToken, +): token is InterpolationToken { + return token.type === TokenType.INTERPOLATION; +} + let xmlParser: XmlParser; export function parseXml(input: string) { xmlParser ??= new XmlParser(); @@ -111,6 +122,10 @@ export { SUPPORTED_BLOCKS as SUPPORTED_ANGULAR_BLOCKS } from "../../compiler/src // Types export type { ParseTreeResult } from "../../compiler/src/ml_parser/parser.ts"; +export type { + InterpolatedTextToken, + InterpolationToken, +} from "../../compiler/src/ml_parser/tokens.ts"; export type * as Ast from "../../compiler/src/ml_parser/ast.ts"; // Remove these alias in next major release diff --git a/packages/angular-html-parser/test/index_spec.ts b/packages/angular-html-parser/test/index_spec.ts index dff895cc624f..74ac66a0d722 100644 --- a/packages/angular-html-parser/test/index_spec.ts +++ b/packages/angular-html-parser/test/index_spec.ts @@ -1,5 +1,11 @@ import { describe, it, expect } from "vitest"; -import { parse, TagContentType } from "../src/index.ts"; +import { + isInterpolationToken, + parse, + TagContentType, + type InterpolatedTextToken, + type InterpolationToken, +} from "../src/index.ts"; import { humanizeDom } from "../../compiler/test/ml_parser/ast_spec_utils.ts"; import * as ast from "../../compiler/src/ml_parser/ast.ts"; @@ -64,6 +70,23 @@ describe("options", () => { }); }); +describe("public token API", () => { + it("should expose interpolation token helpers", () => { + const [node] = parse('{{ "}}" }}').rootNodes; + expect(node).toBeInstanceOf(ast.Text); + + if (!(node instanceof ast.Text)) { + return; + } + + const tokens: InterpolatedTextToken[] = node.tokens; + const token: InterpolationToken | undefined = + tokens.find(isInterpolationToken); + + expect(token?.parts).toEqual(["{{", ' "}}" ', "}}"]); + }); +}); + describe("AST format", () => { it("should have `type` property", () => { const input = ` txt`; From 92fd40bb3a227f0ac0fbdd20caa8b8c028705fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Mon, 21 Sep 2026 16:30:43 +0300 Subject: [PATCH 2/5] test: simplify interpolation token API test --- packages/angular-html-parser/test/index_spec.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/angular-html-parser/test/index_spec.ts b/packages/angular-html-parser/test/index_spec.ts index 74ac66a0d722..7b9f7807719d 100644 --- a/packages/angular-html-parser/test/index_spec.ts +++ b/packages/angular-html-parser/test/index_spec.ts @@ -75,10 +75,6 @@ describe("public token API", () => { const [node] = parse('{{ "}}" }}').rootNodes; expect(node).toBeInstanceOf(ast.Text); - if (!(node instanceof ast.Text)) { - return; - } - const tokens: InterpolatedTextToken[] = node.tokens; const token: InterpolationToken | undefined = tokens.find(isInterpolationToken); From ae53dd8b41a4c2983d4fecf2598308eb5719fe1e Mon Sep 17 00:00:00 2001 From: fisker Date: Mon, 21 Sep 2026 21:30:32 +0800 Subject: [PATCH 3/5] Rewrite test --- .../angular-html-parser/test/index_spec.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/angular-html-parser/test/index_spec.ts b/packages/angular-html-parser/test/index_spec.ts index 7b9f7807719d..2e8042931d9a 100644 --- a/packages/angular-html-parser/test/index_spec.ts +++ b/packages/angular-html-parser/test/index_spec.ts @@ -70,19 +70,6 @@ describe("options", () => { }); }); -describe("public token API", () => { - it("should expose interpolation token helpers", () => { - const [node] = parse('{{ "}}" }}').rootNodes; - expect(node).toBeInstanceOf(ast.Text); - - const tokens: InterpolatedTextToken[] = node.tokens; - const token: InterpolationToken | undefined = - tokens.find(isInterpolationToken); - - expect(token?.parts).toEqual(["{{", ' "}}" ', "}}"]); - }); -}); - describe("AST format", () => { it("should have `type` property", () => { const input = ` txt`; @@ -305,3 +292,14 @@ it("Edge cases", () => { [ast.Element, ":html:style", 0], ]); }); + +describe("public token API", () => { + it("should expose interpolation token helpers", () => { + const node = parse('{{ "}}" }}').rootNodes[0] as ast.Text; + expect(node).toBeInstanceOf(ast.Text); + + const tokens = node.tokens; + const token = tokens.find(isInterpolationToken)!; + expect(token.parts).toEqual(["{{", ' "}}" ', "}}"]); + }); +}); From 03dccec8cdff86892817f29b82080060bd1f20b3 Mon Sep 17 00:00:00 2001 From: fisker Date: Mon, 21 Sep 2026 21:34:44 +0800 Subject: [PATCH 4/5] Expose all Tokens --- packages/angular-html-parser/src/index.ts | 5 +---- packages/angular-html-parser/test/index_spec.ts | 8 +------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/angular-html-parser/src/index.ts b/packages/angular-html-parser/src/index.ts index 1a68e5915ac0..c14421acbecd 100644 --- a/packages/angular-html-parser/src/index.ts +++ b/packages/angular-html-parser/src/index.ts @@ -122,10 +122,7 @@ export { SUPPORTED_BLOCKS as SUPPORTED_ANGULAR_BLOCKS } from "../../compiler/src // Types export type { ParseTreeResult } from "../../compiler/src/ml_parser/parser.ts"; -export type { - InterpolatedTextToken, - InterpolationToken, -} from "../../compiler/src/ml_parser/tokens.ts"; +export type * as Tokens from "../../compiler/src/ml_parser/tokens.ts"; export type * as Ast from "../../compiler/src/ml_parser/ast.ts"; // Remove these alias in next major release diff --git a/packages/angular-html-parser/test/index_spec.ts b/packages/angular-html-parser/test/index_spec.ts index 2e8042931d9a..296a5443ffc8 100644 --- a/packages/angular-html-parser/test/index_spec.ts +++ b/packages/angular-html-parser/test/index_spec.ts @@ -1,11 +1,5 @@ import { describe, it, expect } from "vitest"; -import { - isInterpolationToken, - parse, - TagContentType, - type InterpolatedTextToken, - type InterpolationToken, -} from "../src/index.ts"; +import { isInterpolationToken, parse, TagContentType } from "../src/index.ts"; import { humanizeDom } from "../../compiler/test/ml_parser/ast_spec_utils.ts"; import * as ast from "../../compiler/src/ml_parser/ast.ts"; From 97442a1e974f98dd45834748ec47181b1a602967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Mon, 21 Sep 2026 17:46:16 +0300 Subject: [PATCH 5/5] Expose TokenType --- packages/angular-html-parser/src/index.ts | 12 +----------- packages/angular-html-parser/test/index_spec.ts | 9 +++++---- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/angular-html-parser/src/index.ts b/packages/angular-html-parser/src/index.ts index c14421acbecd..d3e2c91cd264 100644 --- a/packages/angular-html-parser/src/index.ts +++ b/packages/angular-html-parser/src/index.ts @@ -2,11 +2,6 @@ import { HtmlParser } from "../../compiler/src/ml_parser/html_parser.ts"; import { XmlParser } from "../../compiler/src/ml_parser/xml_parser.ts"; import type { TagContentType } from "../../compiler/src/ml_parser/tags.ts"; import { ParseTreeResult as HtmlParseTreeResult } from "../../compiler/src/ml_parser/parser.ts"; -import { TokenType } from "../../compiler/src/ml_parser/tokens.ts"; -import type { - InterpolatedTextToken, - InterpolationToken, -} from "../../compiler/src/ml_parser/tokens.ts"; export interface HtmlParseOptions { /** @@ -93,12 +88,6 @@ export function parseHtml( ); } -export function isInterpolationToken( - token: InterpolatedTextToken, -): token is InterpolationToken { - return token.type === TokenType.INTERPOLATION; -} - let xmlParser: XmlParser; export function parseXml(input: string) { xmlParser ??= new XmlParser(); @@ -108,6 +97,7 @@ export function parseXml(input: string) { // For prettier export { TagContentType } from "../../compiler/src/ml_parser/tags.ts"; +export { TokenType } from "../../compiler/src/ml_parser/tokens.ts"; export { RecursiveVisitor, visitAll, diff --git a/packages/angular-html-parser/test/index_spec.ts b/packages/angular-html-parser/test/index_spec.ts index 296a5443ffc8..89e101cb94f9 100644 --- a/packages/angular-html-parser/test/index_spec.ts +++ b/packages/angular-html-parser/test/index_spec.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from "vitest"; -import { isInterpolationToken, parse, TagContentType } from "../src/index.ts"; +import { parse, TagContentType, TokenType } from "../src/index.ts"; import { humanizeDom } from "../../compiler/test/ml_parser/ast_spec_utils.ts"; import * as ast from "../../compiler/src/ml_parser/ast.ts"; @@ -288,12 +288,13 @@ it("Edge cases", () => { }); describe("public token API", () => { - it("should expose interpolation token helpers", () => { + it("should expose TokenType", () => { const node = parse('{{ "}}" }}').rootNodes[0] as ast.Text; expect(node).toBeInstanceOf(ast.Text); - const tokens = node.tokens; - const token = tokens.find(isInterpolationToken)!; + const token = node.tokens.find( + ({ type }) => type === TokenType.INTERPOLATION, + )!; expect(token.parts).toEqual(["{{", ' "}}" ', "}}"]); }); });