Skip to content

Commit df33959

Browse files
authored
Rename Node.type to Node.kind (#49)
1 parent 180647f commit df33959

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

packages/angular-html-parser/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,7 @@ export {
9797
ParseSourceFile,
9898
} from "../../compiler/src/parse_util.js";
9999
export { getHtmlTagDefinition } from "../../compiler/src/ml_parser/html_tags.js";
100+
101+
// Types
102+
export type { ParseTreeResult } from "../../compiler/src/ml_parser/parser.js";
103+
export type * as Ast from "../../compiler/src/ml_parser/ast.js";

packages/angular-html-parser/test/index_spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe("options", () => {
5151

5252
it("should be able to parse MJML", () => {
5353
const MJML_RAW_TAGS = new Set(["mj-style", "mj-raw"]);
54-
const result = parse('<mj-raw></p></mj-raw>', {
54+
const result = parse("<mj-raw></p></mj-raw>", {
5555
getTagContentType: (tagName) =>
5656
MJML_RAW_TAGS.has(tagName) ? TagContentType.RAW_TEXT : undefined,
5757
});
@@ -68,15 +68,15 @@ describe("AST format", () => {
6868
const input = `<!DOCTYPE html> <el attr></el>txt<!-- --><![CDATA[foo]]>`;
6969
const ast = parse(input);
7070
expect(ast.rootNodes).toEqual([
71-
expect.objectContaining({ type: "docType" }),
72-
expect.objectContaining({ type: "text" }),
71+
expect.objectContaining({ kind: "docType" }),
72+
expect.objectContaining({ kind: "text" }),
7373
expect.objectContaining({
74-
type: "element",
75-
attrs: [expect.objectContaining({ type: "attribute" })],
74+
kind: "element",
75+
attrs: [expect.objectContaining({ kind: "attribute" })],
7676
}),
77-
expect.objectContaining({ type: "text" }),
78-
expect.objectContaining({ type: "comment" }),
79-
expect.objectContaining({ type: "cdata" }),
77+
expect.objectContaining({ kind: "text" }),
78+
expect.objectContaining({ kind: "comment" }),
79+
expect.objectContaining({ kind: "cdata" }),
8080
]);
8181
});
8282

@@ -86,23 +86,23 @@ describe("AST format", () => {
8686
expect(ast.rootNodes).toEqual([
8787
expect.objectContaining({
8888
name: "if",
89-
type: "block",
89+
kind: "block",
9090
parameters: [
9191
expect.objectContaining({
92-
type: "blockParameter",
92+
kind: "blockParameter",
9393
expression: "user.isHuman",
9494
}),
9595
],
9696
children: [
97-
expect.objectContaining({ type: "text", value: " " }),
97+
expect.objectContaining({ kind: "text", value: " " }),
9898
expect.objectContaining({
99-
type: "element",
99+
kind: "element",
100100
name: "p",
101101
children: [
102-
expect.objectContaining({ type: "text", value: "Hello human" }),
102+
expect.objectContaining({ kind: "text", value: "Hello human" }),
103103
],
104104
}),
105-
expect.objectContaining({ type: "text", value: " " }),
105+
expect.objectContaining({ kind: "text", value: " " }),
106106
],
107107
}),
108108
]);
@@ -114,7 +114,7 @@ describe("AST format", () => {
114114
expect(ast.rootNodes).toEqual([
115115
expect.objectContaining({
116116
name: "foo",
117-
type: "letDeclaration",
117+
kind: "letDeclaration",
118118
value: "'bar'",
119119
}),
120120
]);
@@ -129,11 +129,11 @@ describe("AST format", () => {
129129
expect(ast.rootNodes).toEqual([
130130
expect.objectContaining({
131131
name: "div",
132-
type: "element",
132+
kind: "element",
133133
directives: [
134134
expect.objectContaining({
135135
name: "Dir",
136-
type: "directive",
136+
kind: "directive",
137137
}),
138138
],
139139
}),
@@ -149,7 +149,7 @@ describe("AST format", () => {
149149
expect.objectContaining({
150150
fullName: "MyComp",
151151
componentName: "MyComp",
152-
type: "component",
152+
kind: "component",
153153
}),
154154
]);
155155
}
@@ -160,7 +160,7 @@ describe("AST format", () => {
160160
expect.objectContaining({
161161
fullName: "MyComp",
162162
componentName: "MyComp",
163-
type: "component",
163+
kind: "component",
164164
}),
165165
]);
166166
}
@@ -173,7 +173,7 @@ describe("AST format", () => {
173173
expect.objectContaining({
174174
fullName: "MyComp:button",
175175
componentName: "MyComp",
176-
type: "component",
176+
kind: "component",
177177
}),
178178
]);
179179
}
@@ -186,7 +186,7 @@ describe("AST format", () => {
186186
expect.objectContaining({
187187
fullName: "MyComp:svg:title",
188188
componentName: "MyComp",
189-
type: "component",
189+
kind: "component",
190190
}),
191191
]);
192192
}

packages/compiler/src/ml_parser/ast.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class Text extends NodeWithI18n {
5151
override visit(visitor: Visitor, context: any): any {
5252
return visitor.visitText(this, context);
5353
}
54-
readonly type = 'text';
54+
readonly kind = 'text';
5555
}
5656

5757
export class CDATA extends NodeWithI18n {
@@ -66,7 +66,7 @@ export class CDATA extends NodeWithI18n {
6666
override visit(visitor: Visitor, context: any): any {
6767
return visitor.visitCdata(this, context);
6868
}
69-
readonly type = 'cdata';
69+
readonly kind = 'cdata';
7070
}
7171

7272
export class Expansion extends NodeWithI18n {
@@ -83,6 +83,7 @@ export class Expansion extends NodeWithI18n {
8383
override visit(visitor: Visitor, context: any): any {
8484
return visitor.visitExpansion(this, context);
8585
}
86+
readonly kind = 'expansion';
8687
}
8788

8889
export class ExpansionCase implements BaseNode {
@@ -98,7 +99,7 @@ export class ExpansionCase implements BaseNode {
9899
return visitor.visitExpansionCase(this, context);
99100
}
100101

101-
readonly type = 'expansionCase';
102+
readonly kind = 'expansionCase';
102103
}
103104

104105
export class Attribute extends NodeWithI18n {
@@ -116,7 +117,7 @@ export class Attribute extends NodeWithI18n {
116117
override visit(visitor: Visitor, context: any): any {
117118
return visitor.visitAttribute(this, context);
118119
}
119-
readonly type = 'attribute';
120+
readonly kind = 'attribute';
120121
// angular-html-parser: backwards compatibility for Prettier
121122
get nameSpan() {
122123
return this.keySpan;
@@ -142,7 +143,7 @@ export class Element extends NodeWithI18n {
142143
override visit(visitor: Visitor, context: any): any {
143144
return visitor.visitElement(this, context);
144145
}
145-
readonly type = 'element';
146+
readonly kind = 'element';
146147
}
147148

148149
export class Comment implements BaseNode {
@@ -153,15 +154,15 @@ export class Comment implements BaseNode {
153154
visit(visitor: Visitor, context: any): any {
154155
return visitor.visitComment(this, context);
155156
}
156-
readonly type = 'comment';
157+
readonly kind = 'comment';
157158
}
158159

159160
export class DocType implements BaseNode {
160161
constructor(public value: string|null, public sourceSpan: ParseSourceSpan) {}
161162
visit(visitor: Visitor, context: any): any {
162163
return visitor.visitDocType(this, context);
163164
}
164-
readonly type = 'docType';
165+
readonly kind = 'docType';
165166
}
166167

167168
export class Block extends NodeWithI18n {
@@ -182,7 +183,7 @@ export class Block extends NodeWithI18n {
182183
return visitor.visitBlock(this, context);
183184
}
184185

185-
readonly type = 'block';
186+
readonly kind = 'block';
186187
}
187188

188189
export class Component extends NodeWithI18n {
@@ -206,7 +207,7 @@ export class Component extends NodeWithI18n {
206207
return visitor.visitComponent(this, context);
207208
}
208209

209-
readonly type = 'component';
210+
readonly kind = 'component';
210211
}
211212

212213
export class Directive implements BaseNode {
@@ -222,7 +223,7 @@ export class Directive implements BaseNode {
222223
return visitor.visitDirective(this, context);
223224
}
224225

225-
readonly type = 'directive';
226+
readonly kind = 'directive';
226227
}
227228

228229
export class BlockParameter implements BaseNode {
@@ -235,7 +236,7 @@ export class BlockParameter implements BaseNode {
235236
return visitor.visitBlockParameter(this, context);
236237
}
237238

238-
readonly type = 'blockParameter';
239+
readonly kind = 'blockParameter';
239240
readonly startSourceSpan: null = null;
240241
readonly endSourceSpan: null = null;
241242
}
@@ -253,7 +254,7 @@ export class LetDeclaration implements BaseNode {
253254
return visitor.visitLetDeclaration(this, context);
254255
}
255256

256-
readonly type = 'letDeclaration';
257+
readonly kind = 'letDeclaration';
257258
readonly startSourceSpan: null = null;
258259
readonly endSourceSpan: null = null;
259260
}

0 commit comments

Comments
 (0)