Skip to content

Commit

Permalink
Fix: don't handle '{{}}' as an expression container
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jul 21, 2018
1 parent adbaf4b commit 7ded104
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 56 deletions.
9 changes: 9 additions & 0 deletions src/html/intermediate-tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,15 @@ export class IntermediateTokenizer {
const start = this.expressionStartToken
const end = last(this.expressionTokens) || start

// If it's '{{}}', it's handled as a text.
if (token.range[0] === start.range[1]) {
this.tokens.pop()
this.expressionStartToken = null
const result = this.processText(start)
this.processText(token)
return result
}

// If invalid notation `</>` exists directly before this token, separate it.
if (end.range[1] !== token.range[0]) {
const result = this.commit()
Expand Down
47 changes: 2 additions & 45 deletions test/fixtures/ast/error-message-empty/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,56 +63,19 @@
"type": "VText",
"range": [
10,
15
24
],
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 2,
"column": 4
}
},
"value": "\n "
},
{
"type": "VExpressionContainer",
"range": [
15,
19
],
"loc": {
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 8
}
},
"expression": null,
"references": []
},
{
"type": "VText",
"range": [
19,
24
],
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 3,
"column": 4
}
},
"value": "\n "
"value": "\n {{}}\n "
},
{
"type": "VExpressionContainer",
Expand Down Expand Up @@ -2166,12 +2129,6 @@
],
"comments": [],
"errors": [
{
"message": "Expected to be an expression, but got empty.",
"index": 17,
"lineNumber": 2,
"column": 6
},
{
"message": "Expected to be an expression, but got empty.",
"index": 26,
Expand Down
12 changes: 1 addition & 11 deletions test/fixtures/ast/error-message-empty/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@
},
{
"type": "VText",
"text": "\n ",
"children": []
},
{
"type": "VExpressionContainer",
"text": "{{}}",
"children": []
},
{
"type": "VText",
"text": "\n ",
"text": "\n {{}}\n ",
"children": []
},
{
Expand Down

0 comments on commit 7ded104

Please sign in to comment.