Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/angular-html-parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ export {
ParseSourceFile,
} from "../../compiler/src/parse_util.js";
export { getHtmlTagDefinition } from "../../compiler/src/ml_parser/html_tags.js";

// Types
export type { ParseTreeResult } from "../../compiler/src/ml_parser/parser.js";
export type * as Ast from "../../compiler/src/ml_parser/ast.js";
42 changes: 21 additions & 21 deletions packages/angular-html-parser/test/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("options", () => {

it("should be able to parse MJML", () => {
const MJML_RAW_TAGS = new Set(["mj-style", "mj-raw"]);
const result = parse('<mj-raw></p></mj-raw>', {
const result = parse("<mj-raw></p></mj-raw>", {
getTagContentType: (tagName) =>
MJML_RAW_TAGS.has(tagName) ? TagContentType.RAW_TEXT : undefined,
});
Expand All @@ -68,15 +68,15 @@ describe("AST format", () => {
const input = `<!DOCTYPE html> <el attr></el>txt<!-- --><![CDATA[foo]]>`;
const ast = parse(input);
expect(ast.rootNodes).toEqual([
expect.objectContaining({ type: "docType" }),
expect.objectContaining({ type: "text" }),
expect.objectContaining({ kind: "docType" }),
expect.objectContaining({ kind: "text" }),
expect.objectContaining({
type: "element",
attrs: [expect.objectContaining({ type: "attribute" })],
kind: "element",
attrs: [expect.objectContaining({ kind: "attribute" })],
}),
expect.objectContaining({ type: "text" }),
expect.objectContaining({ type: "comment" }),
expect.objectContaining({ type: "cdata" }),
expect.objectContaining({ kind: "text" }),
expect.objectContaining({ kind: "comment" }),
expect.objectContaining({ kind: "cdata" }),
]);
});

Expand All @@ -86,23 +86,23 @@ describe("AST format", () => {
expect(ast.rootNodes).toEqual([
expect.objectContaining({
name: "if",
type: "block",
kind: "block",
parameters: [
expect.objectContaining({
type: "blockParameter",
kind: "blockParameter",
expression: "user.isHuman",
}),
],
children: [
expect.objectContaining({ type: "text", value: " " }),
expect.objectContaining({ kind: "text", value: " " }),
expect.objectContaining({
type: "element",
kind: "element",
name: "p",
children: [
expect.objectContaining({ type: "text", value: "Hello human" }),
expect.objectContaining({ kind: "text", value: "Hello human" }),
],
}),
expect.objectContaining({ type: "text", value: " " }),
expect.objectContaining({ kind: "text", value: " " }),
],
}),
]);
Expand All @@ -114,7 +114,7 @@ describe("AST format", () => {
expect(ast.rootNodes).toEqual([
expect.objectContaining({
name: "foo",
type: "letDeclaration",
kind: "letDeclaration",
value: "'bar'",
}),
]);
Expand All @@ -129,11 +129,11 @@ describe("AST format", () => {
expect(ast.rootNodes).toEqual([
expect.objectContaining({
name: "div",
type: "element",
kind: "element",
directives: [
expect.objectContaining({
name: "Dir",
type: "directive",
kind: "directive",
}),
],
}),
Expand All @@ -149,7 +149,7 @@ describe("AST format", () => {
expect.objectContaining({
fullName: "MyComp",
componentName: "MyComp",
type: "component",
kind: "component",
}),
]);
}
Expand All @@ -160,7 +160,7 @@ describe("AST format", () => {
expect.objectContaining({
fullName: "MyComp",
componentName: "MyComp",
type: "component",
kind: "component",
}),
]);
}
Expand All @@ -173,7 +173,7 @@ describe("AST format", () => {
expect.objectContaining({
fullName: "MyComp:button",
componentName: "MyComp",
type: "component",
kind: "component",
}),
]);
}
Expand All @@ -186,7 +186,7 @@ describe("AST format", () => {
expect.objectContaining({
fullName: "MyComp:svg:title",
componentName: "MyComp",
type: "component",
kind: "component",
}),
]);
}
Expand Down
25 changes: 13 additions & 12 deletions packages/compiler/src/ml_parser/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Text extends NodeWithI18n {
override visit(visitor: Visitor, context: any): any {
return visitor.visitText(this, context);
}
readonly type = 'text';
readonly kind = 'text';
}

export class CDATA extends NodeWithI18n {
Expand All @@ -66,7 +66,7 @@ export class CDATA extends NodeWithI18n {
override visit(visitor: Visitor, context: any): any {
return visitor.visitCdata(this, context);
}
readonly type = 'cdata';
readonly kind = 'cdata';
}

export class Expansion extends NodeWithI18n {
Expand All @@ -83,6 +83,7 @@ export class Expansion extends NodeWithI18n {
override visit(visitor: Visitor, context: any): any {
return visitor.visitExpansion(this, context);
}
readonly kind = 'expansion';
}

export class ExpansionCase implements BaseNode {
Expand All @@ -98,7 +99,7 @@ export class ExpansionCase implements BaseNode {
return visitor.visitExpansionCase(this, context);
}

readonly type = 'expansionCase';
readonly kind = 'expansionCase';
}

export class Attribute extends NodeWithI18n {
Expand All @@ -116,7 +117,7 @@ export class Attribute extends NodeWithI18n {
override visit(visitor: Visitor, context: any): any {
return visitor.visitAttribute(this, context);
}
readonly type = 'attribute';
readonly kind = 'attribute';
// angular-html-parser: backwards compatibility for Prettier
get nameSpan() {
return this.keySpan;
Expand All @@ -142,7 +143,7 @@ export class Element extends NodeWithI18n {
override visit(visitor: Visitor, context: any): any {
return visitor.visitElement(this, context);
}
readonly type = 'element';
readonly kind = 'element';
}

export class Comment implements BaseNode {
Expand All @@ -153,15 +154,15 @@ export class Comment implements BaseNode {
visit(visitor: Visitor, context: any): any {
return visitor.visitComment(this, context);
}
readonly type = 'comment';
readonly kind = 'comment';
}

export class DocType implements BaseNode {
constructor(public value: string|null, public sourceSpan: ParseSourceSpan) {}
visit(visitor: Visitor, context: any): any {
return visitor.visitDocType(this, context);
}
readonly type = 'docType';
readonly kind = 'docType';
}

export class Block extends NodeWithI18n {
Expand All @@ -182,7 +183,7 @@ export class Block extends NodeWithI18n {
return visitor.visitBlock(this, context);
}

readonly type = 'block';
readonly kind = 'block';
}

export class Component extends NodeWithI18n {
Expand All @@ -206,7 +207,7 @@ export class Component extends NodeWithI18n {
return visitor.visitComponent(this, context);
}

readonly type = 'component';
readonly kind = 'component';
}

export class Directive implements BaseNode {
Expand All @@ -222,7 +223,7 @@ export class Directive implements BaseNode {
return visitor.visitDirective(this, context);
}

readonly type = 'directive';
readonly kind = 'directive';
}

export class BlockParameter implements BaseNode {
Expand All @@ -235,7 +236,7 @@ export class BlockParameter implements BaseNode {
return visitor.visitBlockParameter(this, context);
}

readonly type = 'blockParameter';
readonly kind = 'blockParameter';
readonly startSourceSpan: null = null;
readonly endSourceSpan: null = null;
}
Expand All @@ -253,7 +254,7 @@ export class LetDeclaration implements BaseNode {
return visitor.visitLetDeclaration(this, context);
}

readonly type = 'letDeclaration';
readonly kind = 'letDeclaration';
readonly startSourceSpan: null = null;
readonly endSourceSpan: null = null;
}
Expand Down