Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
│ ││ │╰─ tagArgs.value "notEmpty(data.colors)"
│ ││ ╰─ tagArgs "(notEmpty(data.colors))"
│ │╰─ tagName "if"
│ ├─ text "\n"
╰─ ╰─ openTagStart
3╭─ </if>
│ │ │ ╰─ closeTagEnd(if)
│ │ ╰─ closeTagName "if"
│ ├─ text "\n"
╰─ ╰─ closeTagStart "</"
4╭─ ---
╰─ ╰─ text "\n"
4╰─ ---
18 changes: 10 additions & 8 deletions src/__tests__/fixtures/complex/__snapshots__/complex.expected.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
1╭─ --
2╭─ This is top-level text
╰─ ╰─ text "\nThis is top-level text\n"
╰─ ╰─ text "This is top-level text"
3├─ --
4╭─ p
╰─ ╰─ tagName
5╭─ --
╰─ ╰─ openTagEnd
6╭─ This is text that spans multiple lines.
╰─ ╰─ text "\n This is text that spans multiple lines.\n\n "
╰─ ╰─ text "This is text that spans multiple lines.\n"
7├─
8╭─ <strong>You can throw in some HTML markup if you want!</strong>
│ ││ ││ │ │ ╰─ closeTagEnd(strong)
Expand All @@ -17,18 +17,20 @@
│ ││ ╰─ openTagEnd
│ │╰─ tagName "strong"
╰─ ╰─ openTagStart
9╭─ --
╰─ ╰─ text "\n"
9├─ --
10╭─ p
│ ├─ closeTagEnd(p)
╰─ ╰─ tagName
11╭─ -----
╰─ ╰─ openTagEnd
12╭─ If you really want to you can change the block delimiter for the following
╰─ ╰─ text "\n If you really want to you can change the block delimiter for the following\n reasons:\n - Avoid accidentally ending a block\n - To improve readability\n"
13├─ reasons:
14├─ - Avoid accidentally ending a block
15├─ - To improve readability
╰─ ╰─ text "If you really want to you can change the block delimiter for the following"
13╭─ reasons:
╰─ ╰─ text "reasons:"
14╭─ - Avoid accidentally ending a block
╰─ ╰─ text "- Avoid accidentally ending a block"
15╭─ - To improve readability
╰─ ╰─ text "- To improve readability"
16├─ -----
17╭─ i -- This text will be in italics
│ │ │ ╰─ text "This text will be in italics"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
1╭─ --
2╭─ hi
╰─ ╰─ text "\nhi\n"
╰─ ╰─ text "hi"
3├─ --
4├─
5├─ --
6╭─ foo
╰─ ╰─ text "\nfoo\n\n"
╰─ ╰─ text "foo"
7├─
8╰─
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
6╭─ ---
╰─ ╰─ openTagEnd
7╭─ var a = 'marko';
╰─ ╰─ text "\n var a = 'marko';\n"
╰─ ╰─ text "var a = 'marko';"
8╭─ ---
│ ├─ closeTagEnd(html)
│ ├─ closeTagEnd(body)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
1╭─ ---
2╭─ ---
╰─ ╰─ text "\n"
2╰─ ---
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
2╭─ --
╰─ ╰─ openTagEnd
3╭─ Hello World
╰─ ╰─ text "\n Hello World\n Hello Again\n"
4├─ Hello Again
╰─ ╰─ text "Hello World"
4╭─ Hello Again
╰─ ╰─ text "Hello Again"
5├─
6╭─ script --
│ │ ╰─ openTagEnd
│ ├─ closeTagEnd(div)
╰─ ╰─ tagName "script"
7╭─ console.log('foo');
╰─ ╰─ text "\n console.log('foo');\n alert('bar');\n"
8├─ alert('bar');
╰─ ╰─ text "console.log('foo');"
8╭─ alert('bar');
╰─ ╰─ text "alert('bar');"
9├─
10╭─ --
╰─ ╰─ closeTagEnd(script)
11╭─ Multi-line text
╰─ ╰─ text "\nMulti-line text\nReached EOF"
╰─ ╰─ text "Multi-line text\nReached EOF"
12╰─ Reached EOF
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
2╭─ ---
╰─ ╰─ openTagEnd
3╭─ ---
│ │ ╰─ closeTagEnd(p)
╰─ ╰─ text "\n"
╰─ ╰─ closeTagEnd(p)
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
2╭─ ---
╰─ ╰─ openTagEnd
3╭─ Hello <strong>Frank</strong>
││ ││ │ │ ╰─ closeTagEnd(strong)
││ ││ │ ╰─ closeTagName "strong"
││ ││ ╰─ closeTagStart "</"
││ │╰─ text "Frank"
││ ╰─ openTagEnd
│╰─ tagName "strong"
╰─ openTagStart
╰─ ╰─ text "\n Hello "
││ ││ │ │ ╰─ closeTagEnd(strong)
││ ││ │ ╰─ closeTagName "strong"
││ ││ ╰─ closeTagStart "</"
││ │╰─ text "Frank"
││ ╰─ openTagEnd
│╰─ tagName "strong"
╰─ openTagStart
╰─ ╰─ text "Hello "
4╭─ Line 2
╰─ ╰─ text "\n Line 2\n"
╰─ ╰─ text "Line 2"
5╭─ ---
╰─ ╰─ closeTagEnd(p)
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
│ │ ╰─ openTagEnd
╰─ ╰─ tagName "div"
2╭─ Hello World
╰─ ╰─ text "\n Hello World\n Hello Again\n"
3├─ Hello Again
╰─ ╰─ text "Hello World"
3╭─ Hello Again
╰─ ╰─ text "Hello Again"
4├─ --
5╭─ span --
│ │ ╰─ openTagEnd
╰─ ╰─ tagName "span"
6╭─ Goodbye
╰─ ╰─ text "\n Goodbye\n"
╰─ ╰─ text "Goodbye"
7╭─ --
│ ├─ closeTagEnd(div)
╰─ ╰─ closeTagEnd(span)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
│ │ ││ ╰─ openTagEnd
│ │ │╰─ tagName "strong"
│ │ ╰─ openTagStart
╰─ ╰─ text "\nHello "
╰─ ╰─ text "Hello "
3╭─ Line 2
╰─ ╰─ text "\nLine 2\n"
╰─ ╰─ text "Line 2"
4╰─ ---
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1╭─ --
2╭─ A
╰─ ╰─ text "\nA\n"
╰─ ╰─ text
3╭─ ---
╰─ ╰─ error(INVALID_CHARACTER:A concise mode closing block delimiter can only be followed by whitespace.)
4├─ B
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1╭─ ---
2╭─ - Line 1
╰─ ╰─ text "\n- Line 1\n- Line 2\n"
╰─ ╰─ text "- Line 1\n- Line 2"
3├─ - Line 2
4╰─ ---
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1╭─ ---
2╭─ Line 1
╰─ ╰─ text "\nLine 1\nLine 2\n"
╰─ ╰─ text "Line 1\nLine 2"
3├─ Line 2
4╰─ ---
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
2╭─ ---
╰─ ╰─ openTagEnd
3╭─ This is
╰─ ╰─ text "\n This is\n multi-line text\n"
4├─ multi-line text
╰─ ╰─ text "This is"
4╭─ multi-line text
╰─ ╰─ text "multi-line text"
5├─ ---
6╭─ span -- This is body text of span
│ │ │ ╰─ text "This is body text of span"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
│ ││ │ ╰─ attrValue "=\"marko.png\""
│ ││ ╰─ attrName "src"
│ │╰─ tagName "img"
│ ├─ text "\n"
╰─ ╰─ openTagStart
3╭─ This is not allowed!
╰─ ╰─ text "\n This is not allowed!\n"
╰─ ╰─ text " This is not allowed!\n"
4╭─ </img>
│ ├─ error(EXTRA_CLOSING_TAG:The closing "img" tag was not expected) "</img>"
╰─ ╰─ closeTagStart "</"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
2╭─ ---
╰─ ╰─ openTagEnd
3╭─ This is text
╰─ ╰─ text "\n This is text\n within the </script> block\n"
4├─ within the </script> block
╰─ ╰─ text "This is text"
4╭─ within the </script> block
╰─ ╰─ text "within the </script> block"
5├─ ---
6╭─ -- This should be okay too
╰─ ╰─ text "This should be okay too"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
1╭─ ---
2╭─ $ {
│ ├─ text "\n"
╰─ ╰─ scriptlet:block "$ {\n var foo = 123;\n var bar = 456;\n}"
3╭─ var foo = 123;
╰─ ╰─ scriptlet:block.value "\n var foo = 123;\n var bar = 456;\n"
4├─ var bar = 456;
5├─ }
6╭─ ---
╰─ ╰─ text "\n"
6╰─ ---
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
1╭─ ---
2╭─ $ var foo = 123;
│ │ ╰─ scriptlet.value "var foo = 123;"
│ ├─ text "\n"
╰─ ╰─ scriptlet "$ var foo = 123;"
3╭─ ---
╰─ ╰─ text "\n"
3╰─ ---
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1╭─ ---
2╭─ hello $ var foo = 123;
╰─ ╰─ text "\nhello $ var foo = 123;\n"
╰─ ╰─ text "hello $ var foo = 123;"
3╰─ ---
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1╭─ ---
2╭─ test
╰─ ╰─ text "\ntest\n"
╰─ ╰─ text "test"
3├─ ---
4╰─
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
│ │ ╰─ tagVar "/style"
╰─ ╰─ tagName "style"
2╭─ header {
╰─ ╰─ text "\n header {\n color: green\n }\n"
3├─ color: green
4├─ }
╰─ ╰─ text "header {"
3╭─ color: green
╰─ ╰─ text " color: green"
4╭─ }
╰─ ╰─ text
5╭─
╰─ ╰─ closeTagEnd(style)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
3╭─ ---
╰─ ╰─ openTagEnd
4╭─ Test
╰─ ╰─ text "\n Test\n "
╰─ ╰─ text "Test"
5╭─ <b>Hello World</b>
│ ││││ │ │╰─ closeTagEnd(b)
│ ││││ │ ╰─ closeTagName
Expand All @@ -16,6 +16,5 @@
│ │╰─ tagName
╰─ ╰─ openTagStart
6╭─ ---
│ │ ├─ closeTagEnd(div)
│ │ ╰─ closeTagEnd(span)
╰─ ╰─ text "\n"
│ ├─ closeTagEnd(div)
╰─ ╰─ closeTagEnd(span)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
│ ├─ closeTagEnd(span)
╰─ ╰─ tagName "span"
11╭─ hi
╰─ ╰─ text "\n hi\n"
╰─ ╰─ text "hi"
12├─
13╭─ span.e --
│ │ ││ ╰─ openTagEnd
Expand All @@ -41,8 +41,9 @@
│ ├─ closeTagEnd(span)
╰─ ╰─ tagName "span"
14╭─ hi
╰─ ╰─ text "\n hi\n you\n"
15├─ you
╰─ ╰─ text "hi"
15╭─ you
╰─ ╰─ text "you"
16├─
17╭─ span.f
│ │ │╰─ tagShorthandClass.quasis[0]
Expand All @@ -52,7 +53,7 @@
18╭─ --
╰─ ╰─ openTagEnd
19╭─ hi
╰─ ╰─ text "\n hi\n"
╰─ ╰─ text "hi"
20├─ --
21├─
22╭─ span.g
Expand All @@ -63,8 +64,9 @@
23╭─ --
╰─ ╰─ openTagEnd
24╭─ hi
╰─ ╰─ text "\n hi\n you\n"
25├─ you
╰─ ╰─ text "hi"
25╭─ you
╰─ ╰─ text "you"
26├─ --
27├─
28╭─ <span.h>hi</span>
Expand Down
4 changes: 3 additions & 1 deletion src/core/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export class Parser {
endText() {
const start = this.textPos;
if (start !== -1) {
this.options.onText?.({ start, end: this.pos });
if (start !== this.pos) {
this.options.onText?.({ start, end: this.pos });
}
this.textPos = -1;
}
}
Expand Down
Loading