Skip to content

Commit 7ded104

Browse files
committed
Fix: don't handle '{{}}' as an expression container
https://jsfiddle.net/mysticatea/zuyjom9m/25/
1 parent adbaf4b commit 7ded104

File tree

3 files changed

+12
-56
lines changed

3 files changed

+12
-56
lines changed

Diff for: src/html/intermediate-tokenizer.ts

+9
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,15 @@ export class IntermediateTokenizer {
557557
const start = this.expressionStartToken
558558
const end = last(this.expressionTokens) || start
559559

560+
// If it's '{{}}', it's handled as a text.
561+
if (token.range[0] === start.range[1]) {
562+
this.tokens.pop()
563+
this.expressionStartToken = null
564+
const result = this.processText(start)
565+
this.processText(token)
566+
return result
567+
}
568+
560569
// If invalid notation `</>` exists directly before this token, separate it.
561570
if (end.range[1] !== token.range[0]) {
562571
const result = this.commit()

Diff for: test/fixtures/ast/error-message-empty/ast.json

+2-45
Original file line numberDiff line numberDiff line change
@@ -63,56 +63,19 @@
6363
"type": "VText",
6464
"range": [
6565
10,
66-
15
66+
24
6767
],
6868
"loc": {
6969
"start": {
7070
"line": 1,
7171
"column": 10
7272
},
73-
"end": {
74-
"line": 2,
75-
"column": 4
76-
}
77-
},
78-
"value": "\n "
79-
},
80-
{
81-
"type": "VExpressionContainer",
82-
"range": [
83-
15,
84-
19
85-
],
86-
"loc": {
87-
"start": {
88-
"line": 2,
89-
"column": 4
90-
},
91-
"end": {
92-
"line": 2,
93-
"column": 8
94-
}
95-
},
96-
"expression": null,
97-
"references": []
98-
},
99-
{
100-
"type": "VText",
101-
"range": [
102-
19,
103-
24
104-
],
105-
"loc": {
106-
"start": {
107-
"line": 2,
108-
"column": 8
109-
},
11073
"end": {
11174
"line": 3,
11275
"column": 4
11376
}
11477
},
115-
"value": "\n "
78+
"value": "\n {{}}\n "
11679
},
11780
{
11881
"type": "VExpressionContainer",
@@ -2166,12 +2129,6 @@
21662129
],
21672130
"comments": [],
21682131
"errors": [
2169-
{
2170-
"message": "Expected to be an expression, but got empty.",
2171-
"index": 17,
2172-
"lineNumber": 2,
2173-
"column": 6
2174-
},
21752132
{
21762133
"message": "Expected to be an expression, but got empty.",
21772134
"index": 26,

Diff for: test/fixtures/ast/error-message-empty/tree.json

+1-11
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@
1010
},
1111
{
1212
"type": "VText",
13-
"text": "\n ",
14-
"children": []
15-
},
16-
{
17-
"type": "VExpressionContainer",
18-
"text": "{{}}",
19-
"children": []
20-
},
21-
{
22-
"type": "VText",
23-
"text": "\n ",
13+
"text": "\n {{}}\n ",
2414
"children": []
2515
},
2616
{

0 commit comments

Comments
 (0)