From 6484709544aef14851d89e43906695567fd61e7a Mon Sep 17 00:00:00 2001 From: Woongsik Choi Date: Tue, 18 Mar 2025 20:35:05 +0900 Subject: [PATCH] fix: reset vExpressionScriptState when ending mustache --- src/html/tokenizer.ts | 9 +- .../ast.json | 618 ++++++++++++++++++ .../source.vue | 4 + .../token-ranges.json | 22 + .../tree.json | 65 ++ 5 files changed, 715 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/ast/mustache-without-open-in-textarea/ast.json create mode 100644 test/fixtures/ast/mustache-without-open-in-textarea/source.vue create mode 100644 test/fixtures/ast/mustache-without-open-in-textarea/token-ranges.json create mode 100644 test/fixtures/ast/mustache-without-open-in-textarea/tree.json diff --git a/src/html/tokenizer.ts b/src/html/tokenizer.ts index 6285cdfa..da071715 100644 --- a/src/html/tokenizer.ts +++ b/src/html/tokenizer.ts @@ -1942,9 +1942,12 @@ export class Tokenizer { this.startToken("VExpressionEnd") this.appendTokenValue(RIGHT_CURLY_BRACKET, null) this.appendTokenValue(RIGHT_CURLY_BRACKET, null) - return this.vExpressionScriptState - ? this.vExpressionScriptState.state - : this.returnState + if (this.vExpressionScriptState) { + const state = this.vExpressionScriptState.state + this.vExpressionScriptState = null + return state + } + return this.returnState } this.appendTokenValue(RIGHT_CURLY_BRACKET, null) diff --git a/test/fixtures/ast/mustache-without-open-in-textarea/ast.json b/test/fixtures/ast/mustache-without-open-in-textarea/ast.json new file mode 100644 index 00000000..cc24dc1c --- /dev/null +++ b/test/fixtures/ast/mustache-without-open-in-textarea/ast.json @@ -0,0 +1,618 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "module", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 67 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VExpressionContainer", + "range": [ + 13, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "expression": { + "type": "Literal", + "start": 16, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "range": [ + 16, + 19 + ], + "value": 123, + "raw": "123" + }, + "references": [] + }, + { + "type": "VText", + "range": [ + 22, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 25, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 32 + } + }, + "name": "textarea", + "rawName": "textarea", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 25, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 35, + 44 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "value": " }}
+ {{ 123 }} + + diff --git a/test/fixtures/ast/mustache-without-open-in-textarea/token-ranges.json b/test/fixtures/ast/mustache-without-open-in-textarea/token-ranges.json new file mode 100644 index 00000000..8d08b5f6 --- /dev/null +++ b/test/fixtures/ast/mustache-without-open-in-textarea/token-ranges.json @@ -0,0 +1,22 @@ +[ + "", + "\n ", + "{{", + "123", + "}}", + "\n ", + "", + " ", + "}}", + " ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/mustache-without-open-in-textarea/tree.json b/test/fixtures/ast/mustache-without-open-in-textarea/tree.json new file mode 100644 index 00000000..7312fcac --- /dev/null +++ b/test/fixtures/ast/mustache-without-open-in-textarea/tree.json @@ -0,0 +1,65 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file