diff --git a/scripts/update-fixtures-document-fragment.js b/scripts/update-fixtures-document-fragment.js index c2596b30..c9122c26 100644 --- a/scripts/update-fixtures-document-fragment.js +++ b/scripts/update-fixtures-document-fragment.js @@ -61,8 +61,53 @@ for (const name of TARGETS) { const actual = result.services.getDocumentFragment() const resultPath = path.join(ROOT, `${name}/document-fragment.json`) + const tokenRangesPath = path.join(ROOT, `${name}/token-ranges.json`) + const treePath = path.join(ROOT, `${name}/tree.json`) console.log("Update:", name) + const tokenRanges = getAllTokens(actual).map(t => + source.slice(t.range[0], t.range[1]) + ) + const tree = getTree(source, actual) + fs.writeFileSync(resultPath, JSON.stringify(actual, replacer, 4)) + fs.writeFileSync(tokenRangesPath, JSON.stringify(tokenRanges, replacer, 4)) + fs.writeFileSync(treePath, JSON.stringify(tree, replacer, 4)) +} + +function getAllTokens(fgAst) { + const tokenArrays = [fgAst.tokens, fgAst.comments] + + return Array.prototype.concat.apply([], tokenArrays) +} + +/** + * Create simple tree. + * @param {string} source The source code. + * @param {VDocumentFragment} fgAst The root node. + * @returns {object} Simple tree. + */ +function getTree(source, fgAst) { + const stack = [] + const root = { children: [] } + let current = root + + parser.AST.traverseNodes(fgAst, { + enterNode(node) { + stack.push(current) + current.children.push( + (current = { + type: node.type, + text: source.slice(node.range[0], node.range[1]), + children: [], + }) + ) + }, + leaveNode() { + current = stack.pop() + }, + }) + + return root.children } diff --git a/src/html/parser.ts b/src/html/parser.ts index c225f390..cc26c691 100644 --- a/src/html/parser.ts +++ b/src/html/parser.ts @@ -3,6 +3,7 @@ * @copyright 2017 Toru Nagashima. All rights reserved. * See LICENSE file in root directory for full license. */ +import * as path from "path" import assert from "assert" import last from "lodash/last" import findLastIndex from "lodash/findLastIndex" @@ -150,6 +151,7 @@ export class Parser { private tokenizer: IntermediateTokenizer private locationCalculator: LocationCalculator private parserOptions: ParserOptions + private isSFC: boolean private document: VDocumentFragment private elementStack: VElement[] private vPreElement: VElement | null @@ -230,6 +232,8 @@ export class Parser { tokenizer.lineTerminators, ) this.parserOptions = parserOptions + this.isSFC = + path.extname(parserOptions.filePath || "unknown.vue") === ".vue" this.document = { type: "VDocumentFragment", range: [0, 0], @@ -516,27 +520,40 @@ export class Parser { // Update the content type of this element. if (namespace === NS.HTML) { - if ( - element.name === "template" && - element.parent.type === "VDocumentFragment" - ) { + if (element.parent.type === "VDocumentFragment") { const langAttr = element.startTag.attributes.find( a => !a.directive && a.key.name === "lang", ) as VAttribute | undefined - const lang = - (langAttr && langAttr.value && langAttr.value.value) || - "html" - - if (lang !== "html") { + const lang = langAttr?.value?.value + + if (element.name === "template") { + if (lang && lang !== "html") { + // It is not an HTML template. + this.tokenizer.state = "RAWTEXT" + } + this.expressionEnabled = true + } else if (this.isSFC) { + // Element is Custom Block. e.g. + // Referred to the Vue parser. See https://github.com/vuejs/vue-next/blob/cbaa3805064cb581fc2007cf63774c91d39844fe/packages/compiler-sfc/src/parse.ts#L127 + if (!lang || lang !== "html") { + // Custom Block is not HTML. + this.tokenizer.state = "RAWTEXT" + } + } else { + if (HTML_RCDATA_TAGS.has(element.name)) { + this.tokenizer.state = "RCDATA" + } + if (HTML_RAWTEXT_TAGS.has(element.name)) { + this.tokenizer.state = "RAWTEXT" + } + } + } else { + if (HTML_RCDATA_TAGS.has(element.name)) { + this.tokenizer.state = "RCDATA" + } + if (HTML_RAWTEXT_TAGS.has(element.name)) { this.tokenizer.state = "RAWTEXT" } - this.expressionEnabled = true - } - if (HTML_RCDATA_TAGS.has(element.name)) { - this.tokenizer.state = "RCDATA" - } - if (HTML_RAWTEXT_TAGS.has(element.name)) { - this.tokenizer.state = "RAWTEXT" } } } diff --git a/src/html/tokenizer.ts b/src/html/tokenizer.ts index 6acb2183..74b1cf68 100644 --- a/src/html/tokenizer.ts +++ b/src/html/tokenizer.ts @@ -955,7 +955,7 @@ export class Tokenizer { this.endToken() return "BEFORE_ATTRIBUTE_NAME" } - if (!isLetter(cp)) { + if (!isLetter(cp) && !maybeValidCustomBlock.call(this, cp)) { this.rollbackProvisionalToken() this.appendTokenValue(LESS_THAN_SIGN, "HTMLRawText") this.appendTokenValue(SOLIDUS, "HTMLRawText") @@ -973,6 +973,16 @@ export class Tokenizer { cp = this.consumeNextCodePoint() } + + function maybeValidCustomBlock(this: Tokenizer, nextCp: number) { + return ( + this.currentToken && + this.lastTagOpenToken && + this.lastTagOpenToken.value.startsWith( + this.currentToken.value + String.fromCodePoint(nextCp), + ) + ) + } } /** diff --git a/test/document-fragment.js b/test/document-fragment.js index 3c54e7bf..8b2be093 100644 --- a/test/document-fragment.js +++ b/test/document-fragment.js @@ -75,6 +75,23 @@ describe("services.getDocumentFragment", () => { expected ) }) + + it("should have correct range.", () => { + const resultPath = path.join(ROOT, `${name}/token-ranges.json`) + const expectedText = fs.readFileSync(resultPath, "utf8") + const tokens = getAllTokens(actual).map(t => + source.slice(t.range[0], t.range[1]) + ) + const actualText = JSON.stringify(tokens, null, 4) + + assert.strictEqual(actualText, expectedText) + }) }) } }) + +function getAllTokens(fgAst) { + const tokenArrays = [fgAst.tokens, fgAst.comments] + + return Array.prototype.concat.apply([], tokenArrays) +} diff --git a/test/fixtures/document-fragment/custom-block-end-tag-in-attr/document-fragment.json b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/document-fragment.json new file mode 100644 index 00000000..f8925217 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/document-fragment.json @@ -0,0 +1,1530 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 231 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 64 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "name": "custom-block", + "rawName": "custom-block", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 14, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "value": "\n End Tag in Attr e.g. " + }, + { + "type": "VText", + "range": [ + 73, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 58 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": " is Invalid!\n" + }, + { + "type": "VText", + "range": [ + 101, + 103 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "VElement", + "range": [ + 103, + 231 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "name": "custom-block-html", + "rawName": "custom-block-html", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 103, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 122, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 122, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 127, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "value": "html" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 134, + 158 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "value": "\n End Tag in Attr e.g. " + }, + { + "type": "VElement", + "range": [ + 158, + 198 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 63 + } + }, + "name": "foo", + "rawName": "foo", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 158, + 192 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 57 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 163, + 190 + ], + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 55 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 163, + 167 + ], + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 32 + } + }, + "name": "attr", + "rawName": "attr" + }, + "value": { + "type": "VLiteral", + "range": [ + 168, + 190 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 55 + } + }, + "value": "" + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 192, + 198 + ], + "loc": { + "start": { + "line": 6, + "column": 57 + }, + "end": { + "line": 6, + "column": 63 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 198, + 211 + ], + "loc": { + "start": { + "line": 6, + "column": 63 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": " is Invalid!\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 211, + 231 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "variables": [] + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "End" + }, + { + "type": "HTMLWhitespace", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 21, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "Tag" + }, + { + "type": "HTMLWhitespace", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 25, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": "in" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": "Attr" + }, + { + "type": "HTMLWhitespace", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "value": "e.g." + }, + { + "type": "HTMLWhitespace", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 38, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 67, + 72 + ], + "loc": { + "start": { + "line": 2, + "column": 52 + }, + "end": { + "line": 2, + "column": 57 + } + }, + "value": "foo" + }, + { + "type": "HTMLTagClose", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 57 + }, + "end": { + "line": 2, + "column": 58 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 58 + }, + "end": { + "line": 2, + "column": 59 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 74, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 59 + }, + "end": { + "line": 2, + "column": 61 + } + }, + "value": "is" + }, + { + "type": "HTMLWhitespace", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 2, + "column": 61 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 77, + 85 + ], + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 2, + "column": 70 + } + }, + "value": "Invalid!" + }, + { + "type": "HTMLWhitespace", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 70 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 86, + 100 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLTagClose", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 101, + 103 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 103, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "value": "custom-block-html" + }, + { + "type": "HTMLIdentifier", + "range": [ + 122, + 126 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 24 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 127, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 30 + } + }, + "value": "html" + }, + { + "type": "HTMLTagClose", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 134, + 137 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLText", + "range": [ + 137, + 140 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "value": "End" + }, + { + "type": "HTMLWhitespace", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 141, + 144 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "Tag" + }, + { + "type": "HTMLWhitespace", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 145, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "value": "in" + }, + { + "type": "HTMLWhitespace", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 148, + 152 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "Attr" + }, + { + "type": "HTMLWhitespace", + "range": [ + 152, + 153 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 153, + 157 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "value": "e.g." + }, + { + "type": "HTMLWhitespace", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "value": " " + }, + { + "type": "HTMLTagOpen", + "range": [ + 158, + 162 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "value": "foo" + }, + { + "type": "HTMLIdentifier", + "range": [ + 163, + 167 + ], + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 32 + } + }, + "value": "attr" + }, + { + "type": "HTMLAssociation", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 6, + "column": 33 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 168, + 190 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 55 + } + }, + "value": "" + }, + { + "type": "HTMLTagClose", + "range": [ + 191, + 192 + ], + "loc": { + "start": { + "line": 6, + "column": 56 + }, + "end": { + "line": 6, + "column": 57 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 192, + 197 + ], + "loc": { + "start": { + "line": 6, + "column": 57 + }, + "end": { + "line": 6, + "column": 62 + } + }, + "value": "foo" + }, + { + "type": "HTMLTagClose", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 6, + "column": 62 + }, + "end": { + "line": 6, + "column": 63 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 198, + 199 + ], + "loc": { + "start": { + "line": 6, + "column": 63 + }, + "end": { + "line": 6, + "column": 64 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 199, + 201 + ], + "loc": { + "start": { + "line": 6, + "column": 64 + }, + "end": { + "line": 6, + "column": 66 + } + }, + "value": "is" + }, + { + "type": "HTMLWhitespace", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 6, + "column": 66 + }, + "end": { + "line": 6, + "column": 67 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 202, + 210 + ], + "loc": { + "start": { + "line": 6, + "column": 67 + }, + "end": { + "line": 6, + "column": 75 + } + }, + "value": "Invalid!" + }, + { + "type": "HTMLWhitespace", + "range": [ + 210, + 211 + ], + "loc": { + "start": { + "line": 6, + "column": 75 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 211, + 230 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "value": "custom-block-html" + }, + { + "type": "HTMLTagClose", + "range": [ + 230, + 231 + ], + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "value": "" + } + ], + "comments": [], + "errors": [ + { + "message": "x-invalid-end-tag", + "index": 67, + "lineNumber": 2, + "column": 52 + }, + { + "message": "x-invalid-end-tag", + "index": 86, + "lineNumber": 3, + "column": 0 + } + ] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-end-tag-in-attr/source.vue b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/source.vue new file mode 100644 index 00000000..485aee43 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/source.vue @@ -0,0 +1,7 @@ + + End Tag in Attr e.g. is Invalid! + + + + End Tag in Attr e.g. is Invalid! + \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-end-tag-in-attr/token-ranges.json b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/token-ranges.json new file mode 100644 index 00000000..384e3e80 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/token-ranges.json @@ -0,0 +1,63 @@ +[ + "", + "\n ", + "End", + " ", + "Tag", + " ", + "in", + " ", + "Attr", + " ", + "e.g.", + " ", + "", + "\"", + " ", + ">", + "", + " ", + "is", + " ", + "Invalid!", + "\n", + "", + "\n\n", + "", + "\n ", + "End", + " ", + "Tag", + " ", + "in", + " ", + "Attr", + " ", + "e.g.", + " ", + "\"", + ">", + "", + " ", + "is", + " ", + "Invalid!", + "\n", + "" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-end-tag-in-attr/tree.json b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/tree.json new file mode 100644 index 00000000..52b717a3 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-end-tag-in-attr/tree.json @@ -0,0 +1,120 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n End Tag in Attr e.g. \" > is Invalid!\n\n\n\n End Tag in Attr e.g. \" > is Invalid!\n", + "children": [ + { + "type": "VElement", + "text": "\n End Tag in Attr e.g. ", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n End Tag in Attr e.g. ", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\" >", + "children": [] + }, + { + "type": "VText", + "text": " is Invalid!\n", + "children": [] + }, + { + "type": "VText", + "text": "\n\n", + "children": [] + }, + { + "type": "VElement", + "text": "\n End Tag in Attr e.g. \" > is Invalid!\n", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [ + { + "type": "VAttribute", + "text": "lang=\"html\"", + "children": [ + { + "type": "VIdentifier", + "text": "lang", + "children": [] + }, + { + "type": "VLiteral", + "text": "\"html\"", + "children": [] + } + ] + } + ] + }, + { + "type": "VText", + "text": "\n End Tag in Attr e.g. ", + "children": [] + }, + { + "type": "VElement", + "text": "\" >", + "children": [ + { + "type": "VStartTag", + "text": "\" >", + "children": [ + { + "type": "VAttribute", + "text": "attr=\"\"", + "children": [ + { + "type": "VIdentifier", + "text": "attr", + "children": [] + }, + { + "type": "VLiteral", + "text": "\"\"", + "children": [] + } + ] + } + ] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": " is Invalid!\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-escape-like/document-fragment.json b/test/fixtures/document-fragment/custom-block-escape-like/document-fragment.json new file mode 100644 index 00000000..96cab896 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-escape-like/document-fragment.json @@ -0,0 +1,370 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 55 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "name": "custom-block", + "rawName": "custom-block", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 14, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n Do not escape <>\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 40, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "Do" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "not" + }, + { + "type": "HTMLWhitespace", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 24, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": "escape" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "value": "<>" + }, + { + "type": "HTMLWhitespace", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 40, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLTagClose", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-escape-like/source.vue b/test/fixtures/document-fragment/custom-block-escape-like/source.vue new file mode 100644 index 00000000..d58f980e --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-escape-like/source.vue @@ -0,0 +1,3 @@ + + Do not escape <> + diff --git a/test/fixtures/document-fragment/custom-block-escape-like/token-ranges.json b/test/fixtures/document-fragment/custom-block-escape-like/token-ranges.json new file mode 100644 index 00000000..c66fb500 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-escape-like/token-ranges.json @@ -0,0 +1,16 @@ +[ + "", + "\n ", + "Do", + " ", + "not", + " ", + "escape", + " ", + "<>", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-escape-like/tree.json b/test/fixtures/document-fragment/custom-block-escape-like/tree.json new file mode 100644 index 00000000..ee80eb25 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-escape-like/tree.json @@ -0,0 +1,34 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n Do not escape <>\n\n", + "children": [ + { + "type": "VElement", + "text": "\n Do not escape <>\n", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n Do not escape <>\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-html/document-fragment.json b/test/fixtures/document-fragment/custom-block-html/document-fragment.json new file mode 100644 index 00000000..98dd0050 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-html/document-fragment.json @@ -0,0 +1,1161 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 190 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 108 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "name": "custom-block", + "rawName": "custom-block", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 14, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 19, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "value": "html" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 26, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 29, + 92 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 65 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 29, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VElement", + "range": [ + 34, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 59 + } + }, + "name": "h1", + "rawName": "h1", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 34, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 38, + 81 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "value": "lang =\"html\" parses the as HTML" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 81, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 59 + } + } + }, + "variables": [] + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 86, + 92 + ], + "loc": { + "start": { + "line": 2, + "column": 59 + }, + "end": { + "line": 2, + "column": 65 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 2, + "column": 65 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 93, + 108 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 108, + 110 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "VElement", + "range": [ + 110, + 190 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "name": "custom-block-no-html", + "rawName": "custom-block-no-html", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 110, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 132, + 167 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n

Is Not HTML

\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 167, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 23 + } + } + }, + "variables": [] + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "value": "html" + }, + { + "type": "HTMLTagClose", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 26, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 29, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLTagOpen", + "range": [ + 34, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": "h1" + }, + { + "type": "HTMLTagClose", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 38, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": "lang" + }, + { + "type": "HTMLWhitespace", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 43, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "value": "=\"html\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 51, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "value": "parses" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 58, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "value": "the" + }, + { + "type": "HTMLWhitespace", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 62, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 46 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 46 + }, + "end": { + "line": 2, + "column": 47 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 74, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 47 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "value": "as" + }, + { + "type": "HTMLWhitespace", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 77, + 81 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "value": "HTML" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 81, + 85 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 58 + } + }, + "value": "h1" + }, + { + "type": "HTMLTagClose", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 2, + "column": 58 + }, + "end": { + "line": 2, + "column": 59 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 86, + 91 + ], + "loc": { + "start": { + "line": 2, + "column": 59 + }, + "end": { + "line": 2, + "column": 64 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 2, + "column": 64 + }, + "end": { + "line": 2, + "column": 65 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 2, + "column": 65 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 93, + 107 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLTagClose", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 110 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 110, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "value": "custom-block-no-html" + }, + { + "type": "HTMLTagClose", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 132, + 135 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 135, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "value": "

Is" + }, + { + "type": "HTMLWhitespace", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 147, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "Not" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 151 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 151, + 166 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 33 + } + }, + "value": "HTML

" + }, + { + "type": "HTMLWhitespace", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 167, + 189 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 22 + } + }, + "value": "custom-block-no-html" + }, + { + "type": "HTMLTagClose", + "range": [ + 189, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "value": "" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-html/source.vue b/test/fixtures/document-fragment/custom-block-html/source.vue new file mode 100644 index 00000000..0d0705f9 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-html/source.vue @@ -0,0 +1,7 @@ + +

lang ="html" parses the <tag> as HTML

+
+ + +

Is Not HTML

+
\ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-html/token-ranges.json b/test/fixtures/document-fragment/custom-block-html/token-ranges.json new file mode 100644 index 00000000..1acd5bf9 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-html/token-ranges.json @@ -0,0 +1,44 @@ +[ + "", + "\n ", + "", + "", + "lang", + " ", + "=\"html\"", + " ", + "parses", + " ", + "the", + " ", + "<tag>", + " ", + "as", + " ", + "HTML", + "", + "", + "\n", + "", + "\n\n", + "", + "\n ", + "

Is", + " ", + "Not", + " ", + "HTML

", + "\n", + "
" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block-html/tree.json b/test/fixtures/document-fragment/custom-block-html/tree.json new file mode 100644 index 00000000..303fdc8a --- /dev/null +++ b/test/fixtures/document-fragment/custom-block-html/tree.json @@ -0,0 +1,114 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n

lang =\"html\" parses the <tag> as HTML

\n
\n\n\n

Is Not HTML

\n
", + "children": [ + { + "type": "VElement", + "text": "\n

lang =\"html\" parses the <tag> as HTML

\n
", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [ + { + "type": "VAttribute", + "text": "lang=\"html\"", + "children": [ + { + "type": "VIdentifier", + "text": "lang", + "children": [] + }, + { + "type": "VLiteral", + "text": "\"html\"", + "children": [] + } + ] + } + ] + }, + { + "type": "VText", + "text": "\n ", + "children": [] + }, + { + "type": "VElement", + "text": "

lang =\"html\" parses the <tag> as HTML

", + "children": [ + { + "type": "VStartTag", + "text": "
", + "children": [] + }, + { + "type": "VElement", + "text": "

lang =\"html\" parses the <tag> as HTML

", + "children": [ + { + "type": "VStartTag", + "text": "

", + "children": [] + }, + { + "type": "VText", + "text": "lang =\"html\" parses the <tag> as HTML", + "children": [] + }, + { + "type": "VEndTag", + "text": "

", + "children": [] + } + ] + }, + { + "type": "VEndTag", + "text": "
", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "
", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n\n", + "children": [] + }, + { + "type": "VElement", + "text": "\n

Is Not HTML

\n
", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n

Is Not HTML

\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "
", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block/document-fragment.json b/test/fixtures/document-fragment/custom-block/document-fragment.json new file mode 100644 index 00000000..71010dfb --- /dev/null +++ b/test/fixtures/document-fragment/custom-block/document-fragment.json @@ -0,0 +1,370 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 54 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 53 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "name": "custom-block", + "rawName": "custom-block", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 14, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n This Is Custom Block\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 38, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLTagClose", + "range": [ + 13, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 14, + 17 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 17, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "This" + }, + { + "type": "HTMLWhitespace", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 22, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "Is" + }, + { + "type": "HTMLWhitespace", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 25, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "Custom" + }, + { + "type": "HTMLWhitespace", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 32, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "value": "Block" + }, + { + "type": "HTMLWhitespace", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 38, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "custom-block" + }, + { + "type": "HTMLTagClose", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block/source.vue b/test/fixtures/document-fragment/custom-block/source.vue new file mode 100644 index 00000000..b112ad66 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block/source.vue @@ -0,0 +1,3 @@ + + This Is Custom Block + diff --git a/test/fixtures/document-fragment/custom-block/token-ranges.json b/test/fixtures/document-fragment/custom-block/token-ranges.json new file mode 100644 index 00000000..b550be13 --- /dev/null +++ b/test/fixtures/document-fragment/custom-block/token-ranges.json @@ -0,0 +1,16 @@ +[ + "", + "\n ", + "This", + " ", + "Is", + " ", + "Custom", + " ", + "Block", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/custom-block/tree.json b/test/fixtures/document-fragment/custom-block/tree.json new file mode 100644 index 00000000..fdfdc48d --- /dev/null +++ b/test/fixtures/document-fragment/custom-block/tree.json @@ -0,0 +1,34 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n This Is Custom Block\n\n", + "children": [ + { + "type": "VElement", + "text": "\n This Is Custom Block\n", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n This Is Custom Block\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/html-file/token-ranges.json b/test/fixtures/document-fragment/html-file/token-ranges.json new file mode 100644 index 00000000..2ce8d28d --- /dev/null +++ b/test/fixtures/document-fragment/html-file/token-ranges.json @@ -0,0 +1,79 @@ +[ + "\n", + "", + "\n", + "", + "\n ", + "", + "\n ", + "a", + " ", + "{", + "\n ", + "color:", + " ", + "pink;", + "\n ", + "}", + "\n ", + "", + "\n", + "", + "\n", + "", + "\n ", + "", + "", + "\n ", + "", + "\n ", + "

Hello", + " ", + "hello", + " ", + "hello

", + "\n ", + "
", + "\n ", + "", + "\n ", + "Vue.component('hello-world',", + " ", + "{", + "\n ", + "template:", + " ", + "'#hello-world-template'", + "\n ", + "})", + "\n ", + "", + "\n", + "
", + "\n", + "
", + "" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/html-file/tree.json b/test/fixtures/document-fragment/html-file/tree.json new file mode 100644 index 00000000..8419f4af --- /dev/null +++ b/test/fixtures/document-fragment/html-file/tree.json @@ -0,0 +1,235 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n\n\n \n\n\n
\n \n \n\n", + "children": [ + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "\n\n \n\n\n
\n \n \n\n", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "\n \n", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n ", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "\n
\n \n \n", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n ", + "children": [] + }, + { + "type": "VElement", + "text": "
", + "children": [ + { + "type": "VStartTag", + "text": "
", + "children": [] + }, + { + "type": "VEndTag", + "text": "
", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n ", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n ", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/template-tag-is-absent/token-ranges.json b/test/fixtures/document-fragment/template-tag-is-absent/token-ranges.json new file mode 100644 index 00000000..9cb40b9c --- /dev/null +++ b/test/fixtures/document-fragment/template-tag-is-absent/token-ranges.json @@ -0,0 +1,46 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n", + "", + "\n", + "export", + " ", + "default", + " ", + "{", + "\n ", + "name:", + " ", + "'test'", + "\n", + "}", + "\n", + "", + "\n", + "", + "\n", + "a", + " ", + "{", + "\n ", + "color:", + " ", + "pink;", + "\n", + "}", + "\n", + "" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/template-tag-is-absent/tree.json b/test/fixtures/document-fragment/template-tag-is-absent/tree.json new file mode 100644 index 00000000..a1131305 --- /dev/null +++ b/test/fixtures/document-fragment/template-tag-is-absent/tree.json @@ -0,0 +1,102 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n\n", + "children": [ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/template-tag-is-present/document-fragment.json b/test/fixtures/document-fragment/template-tag-is-present/document-fragment.json index 37b74e40..52c22960 100644 --- a/test/fixtures/document-fragment/template-tag-is-present/document-fragment.json +++ b/test/fixtures/document-fragment/template-tag-is-present/document-fragment.json @@ -339,7 +339,7 @@ "value": "\n " }, { - "type": "HTMLText", + "type": "HTMLRawText", "range": [ 11, 14 diff --git a/test/fixtures/document-fragment/template-tag-is-present/token-ranges.json b/test/fixtures/document-fragment/template-tag-is-present/token-ranges.json new file mode 100644 index 00000000..37f86b4a --- /dev/null +++ b/test/fixtures/document-fragment/template-tag-is-present/token-ranges.json @@ -0,0 +1,43 @@ +[ + "", + "\n ", + "doc", + "\n", + "", + "\n", + "", + "\n", + "export", + " ", + "default", + " ", + "{", + "\n ", + "name:", + " ", + "'test'", + "\n", + "}", + "\n", + "", + "\n", + "", + "\n", + "a", + " ", + "{", + "\n ", + "color:", + " ", + "pink;", + "\n", + "}", + "\n", + "" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/template-tag-is-present/tree.json b/test/fixtures/document-fragment/template-tag-is-present/tree.json new file mode 100644 index 00000000..6743799a --- /dev/null +++ b/test/fixtures/document-fragment/template-tag-is-present/tree.json @@ -0,0 +1,81 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n doc\n\n\n", + "children": [ + { + "type": "VElement", + "text": "\n doc\n", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + }, + { + "type": "VText", + "text": "\n doc\n", + "children": [] + }, + { + "type": "VEndTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/textarea-custom-block/document-fragment.json b/test/fixtures/document-fragment/textarea-custom-block/document-fragment.json new file mode 100644 index 00000000..a03221b9 --- /dev/null +++ b/test/fixtures/document-fragment/textarea-custom-block/document-fragment.json @@ -0,0 +1,977 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 117 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 52 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "textarea", + "rawName": "textarea", + "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, + 41 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n < custom block >
\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 41, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "VElement", + "range": [ + 54, + 116 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "name": "textarea", + "rawName": "textarea", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 54, + 76 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 64, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 64, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "value": "html" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 76, + 100 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "value": "\n < not RCDATA > " + }, + { + "type": "VElement", + "range": [ + 100, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "name": "br", + "rawName": "br", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 100, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 105, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "textarea" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 13, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "<" + }, + { + "type": "HTMLWhitespace", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 18, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": "custom" + }, + { + "type": "HTMLWhitespace", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 25, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "block" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "value": ">" + }, + { + "type": "HTMLWhitespace", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 36, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": "
" + }, + { + "type": "HTMLWhitespace", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 41, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "textarea" + }, + { + "type": "HTMLTagClose", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 54, + 63 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "textarea" + }, + { + "type": "HTMLIdentifier", + "range": [ + 64, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 21 + } + }, + "value": "html" + }, + { + "type": "HTMLTagClose", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 22 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 76, + 79 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLText", + "range": [ + 79, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "<" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 6 + }, + "end": { + "line": 6, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 84, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "not" + }, + { + "type": "HTMLWhitespace", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 88, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "RCDATA" + }, + { + "type": "HTMLWhitespace", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 95, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "value": ">" + }, + { + "type": "HTMLWhitespace", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "value": " " + }, + { + "type": "HTMLTagOpen", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "value": "br" + }, + { + "type": "HTMLTagClose", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 27 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 105, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "textarea" + }, + { + "type": "HTMLTagClose", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/textarea-custom-block/source.vue b/test/fixtures/document-fragment/textarea-custom-block/source.vue new file mode 100644 index 00000000..66a4da98 --- /dev/null +++ b/test/fixtures/document-fragment/textarea-custom-block/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/document-fragment/textarea-custom-block/token-ranges.json b/test/fixtures/document-fragment/textarea-custom-block/token-ranges.json new file mode 100644 index 00000000..cefee57b --- /dev/null +++ b/test/fixtures/document-fragment/textarea-custom-block/token-ranges.json @@ -0,0 +1,38 @@ +[ + "", + "\n ", + "<", + " ", + "custom", + " ", + "block", + " ", + ">", + " ", + "
", + "\n", + "
", + "\n\n", + "", + "\n ", + "<", + " ", + "not", + " ", + "RCDATA", + " ", + ">", + " ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/textarea-custom-block/tree.json b/test/fixtures/document-fragment/textarea-custom-block/tree.json new file mode 100644 index 00000000..b69d234f --- /dev/null +++ b/test/fixtures/document-fragment/textarea-custom-block/tree.json @@ -0,0 +1,93 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n\n\n", + "children": [ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/textarea-in-html/document-fragment.json b/test/fixtures/document-fragment/textarea-in-html/document-fragment.json new file mode 100644 index 00000000..e87cf382 --- /dev/null +++ b/test/fixtures/document-fragment/textarea-in-html/document-fragment.json @@ -0,0 +1,444 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 58 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 58 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "textarea", + "rawName": "textarea", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 10, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 10, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 15, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "value": "html" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 22, + 47 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n < RCDATA >
\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 47, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [] + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "textarea" + }, + { + "type": "HTMLIdentifier", + "range": [ + 10, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 14, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 15, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "value": "html" + }, + { + "type": "HTMLTagClose", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 22, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRCDataText", + "range": [ + 25, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "<" + }, + { + "type": "HTMLWhitespace", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRCDataText", + "range": [ + 30, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": "RCDATA" + }, + { + "type": "HTMLWhitespace", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRCDataText", + "range": [ + 37, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": ">" + }, + { + "type": "HTMLWhitespace", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRCDataText", + "range": [ + 42, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "value": "
" + }, + { + "type": "HTMLWhitespace", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 47, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "textarea" + }, + { + "type": "HTMLTagClose", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/textarea-in-html/source.html b/test/fixtures/document-fragment/textarea-in-html/source.html new file mode 100644 index 00000000..cbad1a36 --- /dev/null +++ b/test/fixtures/document-fragment/textarea-in-html/source.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/test/fixtures/document-fragment/textarea-in-html/token-ranges.json b/test/fixtures/document-fragment/textarea-in-html/token-ranges.json new file mode 100644 index 00000000..762c1a1b --- /dev/null +++ b/test/fixtures/document-fragment/textarea-in-html/token-ranges.json @@ -0,0 +1,18 @@ +[ + "", + "\n ", + "<", + " ", + "RCDATA", + " ", + ">", + " ", + "
", + "\n", + "
" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/textarea-in-html/tree.json b/test/fixtures/document-fragment/textarea-in-html/tree.json new file mode 100644 index 00000000..ab6b3002 --- /dev/null +++ b/test/fixtures/document-fragment/textarea-in-html/tree.json @@ -0,0 +1,46 @@ +[ + { + "type": "VDocumentFragment", + "text": "", + "children": [ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file