Skip to content

Commit f753390

Browse files
authored
feat: support parsing template syntax (#24)
* feat: add templatable, templates tokens * refactor * feat: templates attributes * feat: templates data * feat: templates comment * feat: script content template * feat: templates content end * feat: add templatable, template container node * feat: construct node * format
1 parent f3d474e commit f753390

File tree

96 files changed

+2877
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2877
-389
lines changed

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ coverage
33
yarn.lock
44
dist
55
website
6-
.yarn
6+
.yarn
7+
__file_snapshots__

src/parser/__tests__/__snapshots__/token-adapter.spec.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ exports[`parse basic 1`] = `
2222
5,
2323
12,
2424
],
25+
"templates": [],
2526
"type": "Text",
2627
"value": "content",
2728
},
@@ -167,6 +168,7 @@ exports[`parse basic 1`] = `
167168
5,
168169
12,
169170
],
171+
"templates": [],
170172
"type": "Text",
171173
"value": "content",
172174
},
@@ -214,6 +216,7 @@ exports[`parse token adapter 1`] = `
214216
6,
215217
13,
216218
],
219+
"templates": [],
217220
"type": "Text",
218221
"value": "content",
219222
},
@@ -359,6 +362,7 @@ exports[`parse token adapter 1`] = `
359362
6,
360363
13,
361364
],
365+
"templates": [],
362366
"type": "Text",
363367
"value": "content",
364368
},

src/parser/parse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Options } from "../types/parse";
77

88
export function parse(html: string, options?: Options): ParseResult {
99
const tokenAdapter = (options && options.tokenAdapter) || defaultTokenAdapter;
10-
const { tokens } = tokenize(html, tokenAdapter);
11-
const { ast } = constructTree(tokens, undefined);
10+
const { tokens } = tokenize(html, tokenAdapter, options?.templateRanges);
11+
const { ast } = constructTree(tokens);
1212
return {
1313
ast: clearParent(ast),
1414
tokens,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div ${key}></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id=${id}></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="one ${two} ${three}"></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id="${id}"></div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!--${comment}-->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
${content}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>${children}</div>

0 commit comments

Comments
 (0)