From 9ab4ff9832983ca67abcb0dc622ef22b78886101 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 17 Jul 2021 13:55:08 +0900 Subject: [PATCH 01/10] Change to parse expressions in style vars Also added an option to decide whether to enable this feature. The default is enable. See also to [here](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0043-sfc-style-variables.md). I tried to handle this feature with a check rule instead of a parser, but it was difficult to get the correct location, so I implement it in the parser. --- README.md | 7 + docs/ast.md | 2 +- src/ast/nodes.ts | 12 +- src/common/ast-utils.ts | 30 +- src/common/error-utils.ts | 27 + src/common/parser-options.ts | 1 + src/common/token-utils.ts | 159 + src/index.ts | 10 + src/style/index.ts | 262 + src/template/index.ts | 133 +- .../style-variables01/document-fragment.json | 4244 +++++++++++++++++ .../style-variables01/source.vue | 25 + .../style-variables01/token-ranges.json | 101 + .../style-variables01/tree.json | 172 + .../style-variables02/document-fragment.json | 1091 +++++ .../style-variables02/source.vue | 8 + .../style-variables02/token-ranges.json | 42 + .../style-variables02/tree.json | 88 + .../style-variables03/document-fragment.json | 1066 +++++ .../style-variables03/source.vue | 10 + .../style-variables03/token-ranges.json | 39 + .../style-variables03/tree.json | 99 + .../style-variables04/document-fragment.json | 399 ++ .../style-variables04/source.vue | 1 + .../style-variables04/token-ranges.json | 13 + .../style-variables04/tree.json | 50 + .../document-fragment.json | 3 +- .../document-fragment.json | 3 +- 28 files changed, 7966 insertions(+), 131 deletions(-) create mode 100644 src/common/error-utils.ts create mode 100644 src/common/token-utils.ts create mode 100644 src/style/index.ts create mode 100644 test/fixtures/document-fragment/style-variables01/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables01/source.vue create mode 100644 test/fixtures/document-fragment/style-variables01/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables01/tree.json create mode 100644 test/fixtures/document-fragment/style-variables02/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables02/source.vue create mode 100644 test/fixtures/document-fragment/style-variables02/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables02/tree.json create mode 100644 test/fixtures/document-fragment/style-variables03/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables03/source.vue create mode 100644 test/fixtures/document-fragment/style-variables03/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables03/tree.json create mode 100644 test/fixtures/document-fragment/style-variables04/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables04/source.vue create mode 100644 test/fixtures/document-fragment/style-variables04/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables04/tree.json diff --git a/README.md b/README.md index 1741faa5..0a19c556 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ For example: "vueFeatures": { "filter": true, "interpolationAsNonHTML": false, + "styleVariables": true, } } } @@ -189,6 +190,12 @@ The following template can be parsed well. But, it cannot be parsed with Vue 2. +### parserOptions.vueFeatures.styleVariables + +If set to `true`, to parse expressions in `v-bind` CSS functions inside ` diff --git a/test/fixtures/document-fragment/style-variables01/token-ranges.json b/test/fixtures/document-fragment/style-variables01/token-ranges.json new file mode 100644 index 00000000..413e4922 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables01/token-ranges.json @@ -0,0 +1,101 @@ +[ + "", + "\n ", + "", + "hello", + "", + "\n", + "", + "\n\n", + "", + "\n ", + "export", + " ", + "default", + " ", + "{", + "\n ", + "data()", + " ", + "{", + "\n ", + "return", + " ", + "{", + "\n ", + "color:", + " ", + "'red',", + "\n ", + "font:", + " ", + "{", + "\n ", + "size:", + " ", + "'2em',", + "\n ", + "},", + "\n ", + "}", + "\n ", + "},", + "\n ", + "}", + "\n", + "", + "\n\n", + "", + "\n ", + ".text", + " ", + "{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "color", + ")", + ";", + "\n\n ", + "/*", + " ", + "expressions", + " ", + "(wrap", + " ", + "in", + " ", + "quotes)", + " ", + "*/", + "\n ", + "font-size:", + " ", + "v-bind", + "(", + "'", + "font", + ".", + "size", + "'", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables01/tree.json b/test/fixtures/document-fragment/style-variables01/tree.json new file mode 100644 index 00000000..0e52c1c6 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables01/tree.json @@ -0,0 +1,172 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n\n\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\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/style-variables02/document-fragment.json b/test/fixtures/document-fragment/style-variables02/document-fragment.json new file mode 100644 index 00000000..ab1fa7d0 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables02/document-fragment.json @@ -0,0 +1,1091 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 113 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 112 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 7, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "\n .text {\n color: v-bind(" + }, + { + "type": "VExpressionContainer", + "range": [ + 29, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 36, + 41 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 36, + 41 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 42, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "value": " .text {\n font-size: v-bind(" + }, + { + "type": "VExpressionContainer", + "range": [ + 73, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 40 + } + }, + "expression": { + "type": "MemberExpression", + "start": 81, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 38 + } + }, + "range": [ + 81, + 96 + ], + "object": { + "type": "MemberExpression", + "start": 81, + "end": 91, + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 33 + } + }, + "range": [ + 81, + 91 + ], + "object": { + "type": "Identifier", + "start": 81, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "range": [ + 81, + 86 + ], + "name": "theme" + }, + "property": { + "type": "Identifier", + "start": 87, + "end": 91, + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 33 + } + }, + "range": [ + 87, + 91 + ], + "name": "font" + }, + "computed": false + }, + "property": { + "type": "Identifier", + "start": 92, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 34 + }, + "end": { + "line": 6, + "column": 38 + } + }, + "range": [ + 92, + 96 + ], + "name": "size" + }, + "computed": false + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 81, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "range": [ + 81, + 86 + ], + "name": "theme" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 98, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 40 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 104, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 7, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": ".text" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 22, + 28 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 29, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 36, + 41 + ] + }, + { + "type": "Punctuator", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 43, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 47, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 50, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": ".text" + }, + { + "type": "HTMLWhitespace", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 62, + 72 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "value": "font-size:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 73, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 22 + } + }, + "value": "(" + }, + { + "type": "Punctuator", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "value": "'" + }, + { + "type": "Identifier", + "value": "theme", + "start": 81, + "end": 86, + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "range": [ + 81, + 86 + ] + }, + { + "type": "Punctuator", + "value": ".", + "start": 86, + "end": 87, + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "range": [ + 86, + 87 + ] + }, + { + "type": "Identifier", + "value": "font", + "start": 87, + "end": 91, + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 33 + } + }, + "range": [ + 87, + 91 + ] + }, + { + "type": "Punctuator", + "value": ".", + "start": 91, + "end": 92, + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 34 + } + }, + "range": [ + 91, + 92 + ] + }, + { + "type": "Identifier", + "value": "size", + "start": 92, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 34 + }, + "end": { + "line": 6, + "column": 38 + } + }, + "range": [ + 92, + 96 + ] + }, + { + "type": "Punctuator", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 38 + }, + "end": { + "line": 6, + "column": 39 + } + }, + "value": "'" + }, + { + "type": "Punctuator", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 39 + }, + "end": { + "line": 6, + "column": 40 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 40 + }, + "end": { + "line": 6, + "column": 41 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 99, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 41 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 104, + 111 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables02/source.vue b/test/fixtures/document-fragment/style-variables02/source.vue new file mode 100644 index 00000000..f8bce52f --- /dev/null +++ b/test/fixtures/document-fragment/style-variables02/source.vue @@ -0,0 +1,8 @@ + diff --git a/test/fixtures/document-fragment/style-variables02/token-ranges.json b/test/fixtures/document-fragment/style-variables02/token-ranges.json new file mode 100644 index 00000000..eafcce25 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables02/token-ranges.json @@ -0,0 +1,42 @@ +[ + "", + "\n ", + ".text", + " ", + "{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "}", + "\n ", + ".text", + " ", + "{", + "\n ", + "font-size:", + " ", + "v-bind", + "(", + "'", + "theme", + ".", + "font", + ".", + "size", + "'", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables02/tree.json b/test/fixtures/document-fragment/style-variables02/tree.json new file mode 100644 index 00000000..2a7d9e06 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables02/tree.json @@ -0,0 +1,88 @@ +[ + { + "type": "VDocumentFragment", + "text": "\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/style-variables03/document-fragment.json b/test/fixtures/document-fragment/style-variables03/document-fragment.json new file mode 100644 index 00000000..7fa26d8c --- /dev/null +++ b/test/fixtures/document-fragment/style-variables03/document-fragment.json @@ -0,0 +1,1066 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 117 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 55 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 7, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "\n .text {\n color:v-bind(" + }, + { + "type": "VExpressionContainer", + "range": [ + 28, + 41 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "expression": { + "type": "Identifier", + "start": 35, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 35, + 40 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 35, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 35, + 40 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 41, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 47, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 55, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "VElement", + "range": [ + 57, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 57, + 71 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "name": "scoped", + "rawName": "scoped" + }, + "value": null + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 71, + 93 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": "\n .text {\n color: v-bind(color);}\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 93, + 106 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 100, + "end": 105, + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "range": [ + 100, + 105 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 100, + "end": 105, + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "range": [ + 100, + 105 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 106, + 109 + ], + "loc": { + "start": { + "line": 9, + "column": 24 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 109, + 117 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + } + }, + "variables": [], + "style": true + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 7, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": ".text" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 22, + 28 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLText", + "range": [ + 28, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 35, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 22 + } + }, + "range": [ + 35, + 40 + ] + }, + { + "type": "Punctuator", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 3, + "column": 22 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 42, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 47, + 54 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 55, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 57, + 63 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLIdentifier", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "scoped" + }, + { + "type": "HTMLTagClose", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 71, + 74 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 74, + 79 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": ".text" + }, + { + "type": "HTMLWhitespace", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 81, + 86 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 86, + 92 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 93, + 99 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 100, + "end": 105, + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 23 + } + }, + "range": [ + 100, + 105 + ] + }, + { + "type": "Punctuator", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 9, + "column": 23 + }, + "end": { + "line": 9, + "column": 24 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 106, + 108 + ], + "loc": { + "start": { + "line": 9, + "column": 24 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "value": ";}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 109, + 116 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables03/source.vue b/test/fixtures/document-fragment/style-variables03/source.vue new file mode 100644 index 00000000..2ed3c09d --- /dev/null +++ b/test/fixtures/document-fragment/style-variables03/source.vue @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables03/token-ranges.json b/test/fixtures/document-fragment/style-variables03/token-ranges.json new file mode 100644 index 00000000..40e5942a --- /dev/null +++ b/test/fixtures/document-fragment/style-variables03/token-ranges.json @@ -0,0 +1,39 @@ +[ + "", + "\n ", + ".text", + " ", + "{", + "\n ", + "color:", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n\n", + "", + "\n ", + ".text", + " ", + "{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "color", + ")", + ";}", + "\n", + "" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables03/tree.json b/test/fixtures/document-fragment/style-variables03/tree.json new file mode 100644 index 00000000..83907c09 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables03/tree.json @@ -0,0 +1,99 @@ +[ + { + "type": "VDocumentFragment", + "text": "\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": [] + } + ] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables04/document-fragment.json b/test/fixtures/document-fragment/style-variables04/document-fragment.json new file mode 100644 index 00000000..9acecb95 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables04/document-fragment.json @@ -0,0 +1,399 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 43 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 42 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 7, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": ".text{color:v-bind(" + }, + { + "type": "VExpressionContainer", + "range": [ + 19, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "Identifier", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 26, + 31 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 26, + 31 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 32, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "value": "" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 34, + 42 + ], + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 42 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLRawText", + "range": [ + 7, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": ".text{color:" + }, + { + "type": "HTMLText", + "range": [ + 19, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "range": [ + 26, + 31 + ] + }, + { + "type": "Punctuator", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 32, + 34 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "value": ";}" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 34, + 41 + ], + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 1, + "column": 41 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables04/source.vue b/test/fixtures/document-fragment/style-variables04/source.vue new file mode 100644 index 00000000..71127427 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables04/source.vue @@ -0,0 +1 @@ + diff --git a/test/fixtures/document-fragment/style-variables04/token-ranges.json b/test/fixtures/document-fragment/style-variables04/token-ranges.json new file mode 100644 index 00000000..9068022d --- /dev/null +++ b/test/fixtures/document-fragment/style-variables04/token-ranges.json @@ -0,0 +1,13 @@ +[ + "", + ".text{color:", + "v-bind", + "(", + "color", + ")", + ";}", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables04/tree.json b/test/fixtures/document-fragment/style-variables04/tree.json new file mode 100644 index 00000000..de0f73bd --- /dev/null +++ b/test/fixtures/document-fragment/style-variables04/tree.json @@ -0,0 +1,50 @@ +[ + { + "type": "VDocumentFragment", + "text": "\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/template-tag-is-absent/document-fragment.json b/test/fixtures/document-fragment/template-tag-is-absent/document-fragment.json index 66170fd2..f51aedc7 100644 --- a/test/fixtures/document-fragment/template-tag-is-absent/document-fragment.json +++ b/test/fixtures/document-fragment/template-tag-is-absent/document-fragment.json @@ -1152,7 +1152,8 @@ } } }, - "variables": [] + "variables": [], + "style": true } ], "tokens": [ 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 52c22960..6a148a10 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 @@ -280,7 +280,8 @@ } } }, - "variables": [] + "variables": [], + "style": true } ], "tokens": [ From 8298f2679506c7490c1a438def3463e03fe3b98a Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 17 Jul 2021 14:26:22 +0900 Subject: [PATCH 02/10] fix --- src/style/index.ts | 179 +- .../document-fragment.json | 487 ++++ .../style-variables-with-error/source.vue | 5 + .../token-ranges.json | 20 + .../style-variables-with-error/tree.json | 44 + .../style-variables01/document-fragment.json | 6 +- .../style-variables02/document-fragment.json | 6 +- .../style-variables03/document-fragment.json | 8 +- .../style-variables04/document-fragment.json | 4 +- .../style-variables05/document-fragment.json | 2176 +++++++++++++++++ .../style-variables05/source.vue | 18 + .../style-variables05/token-ranges.json | 91 + .../style-variables05/tree.json | 132 + 13 files changed, 3080 insertions(+), 96 deletions(-) create mode 100644 test/fixtures/document-fragment/style-variables-with-error/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables-with-error/source.vue create mode 100644 test/fixtures/document-fragment/style-variables-with-error/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables-with-error/tree.json create mode 100644 test/fixtures/document-fragment/style-variables05/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables05/source.vue create mode 100644 test/fixtures/document-fragment/style-variables05/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables05/tree.json diff --git a/src/style/index.ts b/src/style/index.ts index f938d5d0..998398c7 100644 --- a/src/style/index.ts +++ b/src/style/index.ts @@ -1,5 +1,6 @@ import type { OffsetRange, + Token, VElement, VExpressionContainer, VStyleElement, @@ -85,6 +86,82 @@ function parseStyle( expression: null, references: [], } + + const beforeTokens: Token[] = [ + createSimpleToken( + "HTMLText", + container.range[0], + container.range[0] + 6 /* v-bind */, + "v-bind", + locationCalculator, + ), + createSimpleToken( + "Punctuator", + container.range[0] + 6 /* v-bind */, + container.range[0] + 7, + "(", + locationCalculator, + ), + ] + const afterTokens: Token[] = [ + createSimpleToken( + "Punctuator", + container.range[1] - 1, + container.range[1], + ")", + locationCalculator, + ), + ] + if (quote) { + const openStart = locationCalculator.getOffsetWithGap( + exprOffset - 1, + ) + beforeTokens.push( + createSimpleToken( + "Punctuator", + openStart, + openStart + 1, + quote, + locationCalculator, + ), + ) + const closeStart = locationCalculator.getOffsetWithGap( + exprOffset + expr.length, + ) + afterTokens.unshift( + createSimpleToken( + "Punctuator", + closeStart, + closeStart + 1, + quote, + locationCalculator, + ), + ) + } + + const lastChild = style.children[style.children.length - 1] + style.children.push(container) + if (lastChild.type === "VText") { + const newTextNode: VText = { + type: "VText", + range: [container.range[1], lastChild.range[1]], + loc: { + start: { ...container.loc.end }, + end: { ...lastChild.loc.end }, + }, + parent: style, + value: text.slice(range[1] - textNode.range[0]), + } + style.children.push(newTextNode) + + lastChild.range[1] = container.range[0] + lastChild.loc.end = { ...container.loc.start } + lastChild.value = text.slice( + textStart, + range[0] - textNode.range[0], + ) + textStart = range[1] - textNode.range[0] + } try { const ret = parseExpression( expr, @@ -96,98 +173,31 @@ function parseStyle( ret.expression.parent = container container.expression = ret.expression container.references = ret.references - ret.tokens.unshift( - createSimpleToken( - "HTMLText", - container.range[0], - container.range[0] + 6 /* v-bind */, - "v-bind", - locationCalculator, - ), - createSimpleToken( - "Punctuator", - container.range[0] + 6 /* v-bind */, - container.range[0] + 7, - "(", - locationCalculator, - ), - ...(quote - ? [ - (() => { - const start = - locationCalculator.getOffsetWithGap( - exprOffset - 1, - ) - return createSimpleToken( - "Punctuator", - start, - start + 1, - quote, - locationCalculator, - ) - })(), - ] - : []), - ) - ret.tokens.push( - ...(quote - ? [ - (() => { - const start = - locationCalculator.getOffsetWithGap( - exprOffset + expr.length, - ) - return createSimpleToken( - "Punctuator", - start, - start + 1, - quote, - locationCalculator, - ) - })(), - ] - : []), - createSimpleToken( - "Punctuator", - container.range[1] - 1, - container.range[1], - ")", - locationCalculator, - ), - ) - - replaceAndSplitTokens(document, container, ret.tokens) } + replaceAndSplitTokens(document, container, [ + ...beforeTokens, + ...ret.tokens, + ...afterTokens, + ]) insertComments(document, ret.comments) - const lastChild = style.children[style.children.length - 1] - style.children.push(container) - for (const variable of ret.variables) { style.variables.push(variable) } resolveReferences(container) - - if (lastChild.type === "VText") { - const newTextNode: VText = { - type: "VText", - range: [container.range[1], lastChild.range[1]], - loc: { - start: { ...container.loc.end }, - end: { ...lastChild.loc.end }, - }, - parent: style, - value: text.slice(range[1]), - } - style.children.push(newTextNode) - - lastChild.range[1] = container.range[0] - lastChild.loc.end = { ...container.loc.start } - lastChild.value = text.slice(textStart, range[0]) - textStart = range[1] - } } catch (err) { + replaceAndSplitTokens(document, container, [ + ...beforeTokens, + createSimpleToken( + "HTMLText", + beforeTokens[beforeTokens.length - 1].range[1], + afterTokens[0].range[0], + expr, + locationCalculator, + ), + ...afterTokens, + ]) debug("[style] Parse error: %s", err) if (ParseError.isParseError(err)) { @@ -221,8 +231,9 @@ function* iterateVBind( for (let index = re.lastIndex; index < text.length; index++) { const c = text[index] if (c === "\\") { + index++ // escaping continue - } // escaping + } if (c === startOrVBind) { re.lastIndex = index + 1 break diff --git a/test/fixtures/document-fragment/style-variables-with-error/document-fragment.json b/test/fixtures/document-fragment/style-variables-with-error/document-fragment.json new file mode 100644 index 00000000..fe1b83b4 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-with-error/document-fragment.json @@ -0,0 +1,487 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 62 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 61 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 7, + 28 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "\n .text{\n color: " + }, + { + "type": "VExpressionContainer", + "range": [ + 28, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "expression": null, + "references": [] + }, + { + "type": "VText", + "range": [ + 47, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": ";\n }\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 53, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 8 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 6, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 7, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 10, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": ".text{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 16, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 21, + 27 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 28, + 34 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "HTMLText", + "range": [ + 35, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 29 + } + }, + "value": "color error" + }, + { + "type": "Punctuator", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 48, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 53, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [ + { + "message": "Unexpected token error", + "index": 41, + "lineNumber": 3, + "column": 24 + } + ] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-with-error/source.vue b/test/fixtures/document-fragment/style-variables-with-error/source.vue new file mode 100644 index 00000000..de3885e9 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-with-error/source.vue @@ -0,0 +1,5 @@ + diff --git a/test/fixtures/document-fragment/style-variables-with-error/token-ranges.json b/test/fixtures/document-fragment/style-variables-with-error/token-ranges.json new file mode 100644 index 00000000..54e21f0d --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-with-error/token-ranges.json @@ -0,0 +1,20 @@ +[ + "", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "color error", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-with-error/tree.json b/test/fixtures/document-fragment/style-variables-with-error/tree.json new file mode 100644 index 00000000..c71c59a5 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-with-error/tree.json @@ -0,0 +1,44 @@ +[ + { + "type": "VDocumentFragment", + "text": "\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/style-variables01/document-fragment.json b/test/fixtures/document-fragment/style-variables01/document-fragment.json index 63a437af..ad788a15 100644 --- a/test/fixtures/document-fragment/style-variables01/document-fragment.json +++ b/test/fixtures/document-fragment/style-variables01/document-fragment.json @@ -2205,7 +2205,7 @@ "column": 11 } }, - "value": "\n .text {\n color: v-bind(color);\n\n /* expressions (wrap in quotes) */\n font-size: v-bind('font.size');\n }\n" + "value": "\n .text {\n color: " }, { "type": "VExpressionContainer", @@ -2285,7 +2285,7 @@ "column": 15 } }, - "value": "" + "value": ";\n\n /* expressions (wrap in quotes) */\n font-size: " }, { "type": "VExpressionContainer", @@ -2405,7 +2405,7 @@ "column": 0 } }, - "value": "" + "value": ";\n }\n" } ], "endTag": { diff --git a/test/fixtures/document-fragment/style-variables02/document-fragment.json b/test/fixtures/document-fragment/style-variables02/document-fragment.json index ab1fa7d0..3ea5850b 100644 --- a/test/fixtures/document-fragment/style-variables02/document-fragment.json +++ b/test/fixtures/document-fragment/style-variables02/document-fragment.json @@ -70,7 +70,7 @@ "column": 11 } }, - "value": "\n .text {\n color: v-bind(" + "value": "\n .text {\n color: " }, { "type": "VExpressionContainer", @@ -150,7 +150,7 @@ "column": 15 } }, - "value": " .text {\n font-size: v-bind(" + "value": ";\n }\n .text {\n font-size: " }, { "type": "VExpressionContainer", @@ -310,7 +310,7 @@ "column": 0 } }, - "value": "" + "value": ";\n }\n" } ], "endTag": { diff --git a/test/fixtures/document-fragment/style-variables03/document-fragment.json b/test/fixtures/document-fragment/style-variables03/document-fragment.json index 7fa26d8c..8f6b3606 100644 --- a/test/fixtures/document-fragment/style-variables03/document-fragment.json +++ b/test/fixtures/document-fragment/style-variables03/document-fragment.json @@ -70,7 +70,7 @@ "column": 10 } }, - "value": "\n .text {\n color:v-bind(" + "value": "\n .text {\n color:" }, { "type": "VExpressionContainer", @@ -150,7 +150,7 @@ "column": 0 } }, - "value": "" + "value": ";\n }\n" } ], "endTag": { @@ -285,7 +285,7 @@ "column": 11 } }, - "value": "\n .text {\n color: v-bind(color);}\n" + "value": "\n .text {\n color: " }, { "type": "VExpressionContainer", @@ -365,7 +365,7 @@ "column": 0 } }, - "value": "" + "value": ";}\n" } ], "endTag": { diff --git a/test/fixtures/document-fragment/style-variables04/document-fragment.json b/test/fixtures/document-fragment/style-variables04/document-fragment.json index 9acecb95..e9beb1c0 100644 --- a/test/fixtures/document-fragment/style-variables04/document-fragment.json +++ b/test/fixtures/document-fragment/style-variables04/document-fragment.json @@ -70,7 +70,7 @@ "column": 19 } }, - "value": ".text{color:v-bind(" + "value": ".text{color:" }, { "type": "VExpressionContainer", @@ -150,7 +150,7 @@ "column": 34 } }, - "value": "" + "value": ";}" } ], "endTag": { diff --git a/test/fixtures/document-fragment/style-variables05/document-fragment.json b/test/fixtures/document-fragment/style-variables05/document-fragment.json new file mode 100644 index 00000000..91952fba --- /dev/null +++ b/test/fixtures/document-fragment/style-variables05/document-fragment.json @@ -0,0 +1,2176 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 365 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 364 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 7, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 7, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 12, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "scss" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 19, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "\n .text{\n color: " + }, + { + "type": "VExpressionContainer", + "range": [ + 40, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 47, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 47, + 52 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 47, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 47, + 52 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 53, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": ";\n }\n .text{\n color: " + }, + { + "type": "VExpressionContainer", + "range": [ + 79, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "expression": { + "type": "MemberExpression", + "start": 87, + "end": 97, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "range": [ + 87, + 97 + ], + "object": { + "type": "Identifier", + "start": 87, + "end": 93, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "range": [ + 87, + 93 + ], + "name": "colors" + }, + "property": { + "type": "Literal", + "start": 94, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "range": [ + 94, + 96 + ], + "value": 42, + "raw": "42" + }, + "computed": true + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 87, + "end": 93, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "range": [ + 87, + 93 + ], + "name": "colors" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 99, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": ";\n }\n .text{\n color: " + }, + { + "type": "VExpressionContainer", + "range": [ + 125, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 31 + } + }, + "expression": { + "type": "CallExpression", + "start": 133, + "end": 143, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "range": [ + 133, + 143 + ], + "callee": { + "type": "Identifier", + "start": 133, + "end": 141, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 133, + 141 + ], + "name": "getColor" + }, + "arguments": [] + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 133, + "end": 141, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 133, + 141 + ], + "name": "getColor" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 145, + 337 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 16, + "column": 15 + } + }, + "value": ";\n }\n .str-and-comments{\n content: \"v-bind('getColor()')\";\n content: \"v-bind('getColor()')\\\"v-bind(color)\";\n // color: v-bind(color);\n /* color: v-bind(color); */\n color: /**/" + }, + { + "type": "VExpressionContainer", + "range": [ + 337, + 350 + ], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 28 + } + }, + "expression": { + "type": "Identifier", + "start": 344, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "range": [ + 344, + 349 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 344, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "range": [ + 344, + 349 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 350, + 356 + ], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": ";\n }\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 356, + 364 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 364, + 365 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLIdentifier", + "range": [ + 7, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 12, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "scss" + }, + { + "type": "HTMLTagClose", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 22, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": ".text{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 28, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 40, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 47, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 47, + 52 + ] + }, + { + "type": "Punctuator", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 54, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 58, + 61 + ], + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 61, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": ".text{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 67, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 72, + 78 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Punctuator", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "colors", + "start": 87, + "end": 93, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "range": [ + 87, + 93 + ] + }, + { + "type": "Punctuator", + "value": "[", + "start": 93, + "end": 94, + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "range": [ + 93, + 94 + ] + }, + { + "type": "Numeric", + "value": "42", + "start": 94, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "range": [ + 94, + 96 + ] + }, + { + "type": "Punctuator", + "value": "]", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "range": [ + 96, + 97 + ] + }, + { + "type": "Punctuator", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 32 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 104, + 107 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 107, + 113 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": ".text{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 113, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 124 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 125, + 131 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Punctuator", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "value": "'" + }, + { + "type": "Identifier", + "value": "getColor", + "start": 133, + "end": 141, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 133, + 141 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 141, + "end": 142, + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "range": [ + 141, + 142 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 142, + "end": 143, + "loc": { + "start": { + "line": 9, + "column": 28 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "range": [ + 142, + 143 + ] + }, + { + "type": "Punctuator", + "range": [ + 143, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 29 + }, + "end": { + "line": 9, + "column": 30 + } + }, + "value": "'" + }, + { + "type": "Punctuator", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 31 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 9, + "column": 32 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 146, + 149 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 153 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 153, + 171 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "value": ".str-and-comments{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 171, + 176 + ], + "loc": { + "start": { + "line": 11, + "column": 20 + }, + "end": { + "line": 12, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 176, + 184 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "value": "content:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 12, + "column": 12 + }, + "end": { + "line": 12, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 185, + 208 + ], + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 36 + } + }, + "value": "\"v-bind('getColor()')\";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 208, + 213 + ], + "loc": { + "start": { + "line": 12, + "column": 36 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 213, + 221 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 12 + } + }, + "value": "content:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 13, + "column": 12 + }, + "end": { + "line": 13, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 222, + 260 + ], + "loc": { + "start": { + "line": 13, + "column": 13 + }, + "end": { + "line": 13, + "column": 51 + } + }, + "value": "\"v-bind('getColor()')\\\"v-bind(color)\";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 260, + 265 + ], + "loc": { + "start": { + "line": 13, + "column": 51 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 265, + 267 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 6 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 267, + 268 + ], + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 268, + 274 + ], + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 13 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 274, + 275 + ], + "loc": { + "start": { + "line": 14, + "column": 13 + }, + "end": { + "line": 14, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 275, + 289 + ], + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "value": "v-bind(color);" + }, + { + "type": "HTMLWhitespace", + "range": [ + 289, + 294 + ], + "loc": { + "start": { + "line": 14, + "column": 28 + }, + "end": { + "line": 15, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 294, + 296 + ], + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": "/*" + }, + { + "type": "HTMLWhitespace", + "range": [ + 296, + 297 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 297, + 303 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 13 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 303, + 304 + ], + "loc": { + "start": { + "line": 15, + "column": 13 + }, + "end": { + "line": 15, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 304, + 318 + ], + "loc": { + "start": { + "line": 15, + "column": 14 + }, + "end": { + "line": 15, + "column": 28 + } + }, + "value": "v-bind(color);" + }, + { + "type": "HTMLWhitespace", + "range": [ + 318, + 319 + ], + "loc": { + "start": { + "line": 15, + "column": 28 + }, + "end": { + "line": 15, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 319, + 321 + ], + "loc": { + "start": { + "line": 15, + "column": 29 + }, + "end": { + "line": 15, + "column": 31 + } + }, + "value": "*/" + }, + { + "type": "HTMLWhitespace", + "range": [ + 321, + 326 + ], + "loc": { + "start": { + "line": 15, + "column": 31 + }, + "end": { + "line": 16, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 326, + 332 + ], + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 332, + 333 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 333, + 337 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 15 + } + }, + "value": "/**/" + }, + { + "type": "HTMLText", + "range": [ + 337, + 343 + ], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 21 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 343, + 344 + ], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 22 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 344, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "range": [ + 344, + 349 + ] + }, + { + "type": "Punctuator", + "range": [ + 349, + 350 + ], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 28 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 350, + 351 + ], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 29 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 351, + 354 + ], + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 17, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 354, + 355 + ], + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 355, + 356 + ], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 356, + 363 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 363, + 364 + ], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 364, + 365 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables05/source.vue b/test/fixtures/document-fragment/style-variables05/source.vue new file mode 100644 index 00000000..70c9f9fd --- /dev/null +++ b/test/fixtures/document-fragment/style-variables05/source.vue @@ -0,0 +1,18 @@ + diff --git a/test/fixtures/document-fragment/style-variables05/token-ranges.json b/test/fixtures/document-fragment/style-variables05/token-ranges.json new file mode 100644 index 00000000..2faa5238 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables05/token-ranges.json @@ -0,0 +1,91 @@ +[ + "", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "}", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "\"", + "colors", + "[", + "42", + "]", + "\"", + ")", + ";", + "\n ", + "}", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "'", + "getColor", + "(", + ")", + "'", + ")", + ";", + "\n ", + "}", + "\n ", + ".str-and-comments{", + "\n ", + "content:", + " ", + "\"v-bind('getColor()')\";", + "\n ", + "content:", + " ", + "\"v-bind('getColor()')\\\"v-bind(color)\";", + "\n ", + "//", + " ", + "color:", + " ", + "v-bind(color);", + "\n ", + "/*", + " ", + "color:", + " ", + "v-bind(color);", + " ", + "*/", + "\n ", + "color:", + " ", + "/**/", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables05/tree.json b/test/fixtures/document-fragment/style-variables05/tree.json new file mode 100644 index 00000000..58e58424 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables05/tree.json @@ -0,0 +1,132 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n", + "children": [ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + } + ] + } +] \ No newline at end of file From df729cc29cc08d5686a75955d665b0d25a0a0c91 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 17 Jul 2021 14:50:33 +0900 Subject: [PATCH 03/10] fix --- src/style/index.ts | 2 +- .../style-variables06/document-fragment.json | 1389 +++++++++++++++++ .../style-variables06/source.vue | 13 + .../style-variables06/token-ranges.json | 62 + .../style-variables06/tree.json | 89 ++ 5 files changed, 1554 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/document-fragment/style-variables06/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables06/source.vue create mode 100644 test/fixtures/document-fragment/style-variables06/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables06/tree.json diff --git a/src/style/index.ts b/src/style/index.ts index 998398c7..945f8fa5 100644 --- a/src/style/index.ts +++ b/src/style/index.ts @@ -226,7 +226,7 @@ function* iterateVBind( let match while ((match = re.exec(text))) { const startOrVBind = match[0] - if (startOrVBind === '"' || startOrVBind === '"') { + if (startOrVBind === '"' || startOrVBind === "'") { // skip string for (let index = re.lastIndex; index < text.length; index++) { const c = text[index] diff --git a/test/fixtures/document-fragment/style-variables06/document-fragment.json b/test/fixtures/document-fragment/style-variables06/document-fragment.json new file mode 100644 index 00000000..dbcc5ea7 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables06/document-fragment.json @@ -0,0 +1,1389 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 249 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 87 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "name": "script", + "rawName": "script", + "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": [ + { + "type": "VAttribute", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "setup", + "rawName": "setup" + }, + "value": null + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 14, + 78 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n /* eslint script-setup-uses-vars: 1 */\n const color = 'red'\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 78, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "VElement", + "range": [ + 89, + 248 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 89, + 108 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 96, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 96, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 101, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "scss" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 108, + 240 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n .v-bind .color {\n color: 'v-bind(color)';\n background-color: 'v-bind(color)';\n }\n /* v-bind(color) */\n // v-bind(color)\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 240, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 8 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 248, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "setup" + }, + { + "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": "/*" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 20, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "eslint" + }, + { + "type": "HTMLWhitespace", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 27, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "value": "script-setup-uses-vars:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 36 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "value": "1" + }, + { + "type": "HTMLWhitespace", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 53, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "value": "*/" + }, + { + "type": "HTMLWhitespace", + "range": [ + 55, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 58, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 64, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "value": "color" + }, + { + "type": "HTMLWhitespace", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 71, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 72, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "value": "'red'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 78, + 86 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 87, + 89 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 89, + 95 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLIdentifier", + "range": [ + 96, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 101, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "scss" + }, + { + "type": "HTMLTagClose", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": ".v-bind" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 119, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "value": ".color" + }, + { + "type": "HTMLWhitespace", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 127, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 132, + 138 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 139, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 27 + } + }, + "value": "'v-bind(color)';" + }, + { + "type": "HTMLWhitespace", + "range": [ + 155, + 160 + ], + "loc": { + "start": { + "line": 8, + "column": 27 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 160, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 21 + } + }, + "value": "background-color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 9, + "column": 21 + }, + "end": { + "line": 9, + "column": 22 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 178, + 194 + ], + "loc": { + "start": { + "line": 9, + "column": 22 + }, + "end": { + "line": 9, + "column": 38 + } + }, + "value": "'v-bind(color)';" + }, + { + "type": "HTMLWhitespace", + "range": [ + 194, + 197 + ], + "loc": { + "start": { + "line": 9, + "column": 38 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 198, + 201 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 201, + 203 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 4 + } + }, + "value": "/*" + }, + { + "type": "HTMLWhitespace", + "range": [ + 203, + 204 + ], + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 204, + 217 + ], + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 18 + } + }, + "value": "v-bind(color)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 11, + "column": 18 + }, + "end": { + "line": 11, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 218, + 220 + ], + "loc": { + "start": { + "line": 11, + "column": 19 + }, + "end": { + "line": 11, + "column": 21 + } + }, + "value": "*/" + }, + { + "type": "HTMLWhitespace", + "range": [ + 220, + 223 + ], + "loc": { + "start": { + "line": 11, + "column": 21 + }, + "end": { + "line": 12, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 223, + 225 + ], + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 4 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 226, + 239 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 18 + } + }, + "value": "v-bind(color)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 239, + 240 + ], + "loc": { + "start": { + "line": 12, + "column": 18 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 240, + 247 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 247, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 7 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 248, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables06/source.vue b/test/fixtures/document-fragment/style-variables06/source.vue new file mode 100644 index 00000000..d1b4dcff --- /dev/null +++ b/test/fixtures/document-fragment/style-variables06/source.vue @@ -0,0 +1,13 @@ + + + diff --git a/test/fixtures/document-fragment/style-variables06/token-ranges.json b/test/fixtures/document-fragment/style-variables06/token-ranges.json new file mode 100644 index 00000000..c88e791b --- /dev/null +++ b/test/fixtures/document-fragment/style-variables06/token-ranges.json @@ -0,0 +1,62 @@ +[ + "", + "\n ", + "/*", + " ", + "eslint", + " ", + "script-setup-uses-vars:", + " ", + "1", + " ", + "*/", + "\n ", + "const", + " ", + "color", + " ", + "=", + " ", + "'red'", + "\n", + "", + "\n\n", + "", + "\n ", + ".v-bind", + " ", + ".color", + " ", + "{", + "\n ", + "color:", + " ", + "'v-bind(color)';", + "\n ", + "background-color:", + " ", + "'v-bind(color)';", + "\n ", + "}", + "\n ", + "/*", + " ", + "v-bind(color)", + " ", + "*/", + "\n ", + "//", + " ", + "v-bind(color)", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables06/tree.json b/test/fixtures/document-fragment/style-variables06/tree.json new file mode 100644 index 00000000..df932eb9 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables06/tree.json @@ -0,0 +1,89 @@ +[ + { + "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 From 099e95a7ec3bd163716ffbade32bc13b58fca7aa Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 17 Jul 2021 17:15:56 +0900 Subject: [PATCH 04/10] Add test cases --- src/parser-services.ts | 2 +- src/sfc/custom-block/index.ts | 10 - src/style/index.ts | 65 +- .../document-fragment.json | 636 ++--- .../source.vue | 1 - .../token-ranges.json | 10 - .../tree.json | 6 +- .../document-fragment.json | 2176 +++++++++++++++++ .../style-variables-ignores02/source.vue | 18 + .../token-ranges.json | 91 + .../style-variables-ignores02/tree.json | 132 + .../document-fragment.json | 1037 ++++++++ .../source.vue | 9 + .../token-ranges.json | 41 + .../tree.json | 88 + .../style-variables05/document-fragment.json | 1777 +++++--------- .../style-variables05/source.vue | 24 +- .../style-variables05/token-ranges.json | 66 +- .../style-variables05/tree.json | 73 +- 19 files changed, 4491 insertions(+), 1771 deletions(-) rename test/fixtures/document-fragment/{style-variables06 => style-variables-ignores01}/document-fragment.json (77%) rename test/fixtures/document-fragment/{style-variables06 => style-variables-ignores01}/source.vue (83%) rename test/fixtures/document-fragment/{style-variables06 => style-variables-ignores01}/token-ranges.json (83%) rename test/fixtures/document-fragment/{style-variables06 => style-variables-ignores01}/tree.json (86%) create mode 100644 test/fixtures/document-fragment/style-variables-ignores02/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables-ignores02/source.vue create mode 100644 test/fixtures/document-fragment/style-variables-ignores02/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables-ignores02/tree.json create mode 100644 test/fixtures/document-fragment/style-variables-inline-comment-like/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables-inline-comment-like/source.vue create mode 100644 test/fixtures/document-fragment/style-variables-inline-comment-like/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables-inline-comment-like/tree.json diff --git a/src/parser-services.ts b/src/parser-services.ts index 33d8900d..845201c7 100644 --- a/src/parser-services.ts +++ b/src/parser-services.ts @@ -22,11 +22,11 @@ import type { import { createCustomBlockSharedContext, getCustomBlocks, - getLang, parseCustomBlockElement, } from "./sfc/custom-block" import type { ParserOptions } from "./common/parser-options" import { isSFCFile } from "./common/parser-options" +import { getLang } from "./common/ast-utils" //------------------------------------------------------------------------------ // Helpers diff --git a/src/sfc/custom-block/index.ts b/src/sfc/custom-block/index.ts index 542f2ad0..dc7153c2 100644 --- a/src/sfc/custom-block/index.ts +++ b/src/sfc/custom-block/index.ts @@ -4,7 +4,6 @@ import type { ESLintExtendedProgram, Node, OffsetRange, - VAttribute, VDocumentFragment, VElement, VExpressionContainer, @@ -69,15 +68,6 @@ export function getCustomBlocks( : [] } -export function getLang(customBlock: VElement) { - return ( - customBlock.startTag.attributes.find( - (attr): attr is VAttribute => - !attr.directive && attr.key.name === "lang", - )?.value?.value || null - ) -} - /** * Parse the source code of the given custom block element. * @param node The custom block element to parse. diff --git a/src/style/index.ts b/src/style/index.ts index 945f8fa5..bfe565c6 100644 --- a/src/style/index.ts +++ b/src/style/index.ts @@ -7,7 +7,7 @@ import type { VText, } from "../ast" import { ParseError } from "../ast" -import { getOwnerDocument } from "../common/ast-utils" +import { getLang, getOwnerDocument } from "../common/ast-utils" import { debug } from "../common/debug" import { insertError } from "../common/error-utils" import type { LocationCalculatorForHtml } from "../common/location-calculator" @@ -44,6 +44,9 @@ export function parseStyleElements( style as VStyleElement, globalLocationCalculator, parserOptions, + { + inlineComment: (getLang(style) || "css") !== "css", + }, ) } } @@ -52,6 +55,7 @@ function parseStyle( style: VStyleElement, locationCalculator: LocationCalculatorForHtml, parserOptions: ParserOptions, + cssOptions: { inlineComment?: boolean }, ) { if (style.children.length !== 1) { return @@ -71,6 +75,7 @@ function parseStyle( for (const { range, expr, exprOffset, quote } of iterateVBind( textNode.range[0], text, + cssOptions, )) { const container: VExpressionContainer = { type: "VExpressionContainer", @@ -179,7 +184,6 @@ function parseStyle( ...ret.tokens, ...afterTokens, ]) - insertComments(document, ret.comments) for (const variable of ret.variables) { @@ -216,41 +220,29 @@ type VBindLocations = { quote: '"' | "'" | null } -// eslint-disable-next-line complexity +/** + * Iterate the `v-bind()` information. + */ function* iterateVBind( offset: number, text: string, + cssOptions: { inlineComment?: boolean }, ): IterableIterator { - const re = - /"|'|\/\*|\/\/|\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/gu + const re = cssOptions.inlineComment + ? /"|'|\/\*|\/\/|\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/gu + : /"|'|\/\*|\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/gu let match while ((match = re.exec(text))) { const startOrVBind = match[0] if (startOrVBind === '"' || startOrVBind === "'") { // skip string - for (let index = re.lastIndex; index < text.length; index++) { - const c = text[index] - if (c === "\\") { - index++ // escaping - continue - } - if (c === startOrVBind) { - re.lastIndex = index + 1 - break - } - } - } else if (startOrVBind === "/*") { + re.lastIndex = skipString(startOrVBind, re.lastIndex) + } else if (startOrVBind === "/*" || startOrVBind === "//") { // skip comment - const index = text.indexOf("*/", re.lastIndex) - if (index >= re.lastIndex) { - re.lastIndex = index - } - } else if (startOrVBind === "//") { - // skip inline comment - const index = text.indexOf("\n", re.lastIndex) - if (index >= re.lastIndex) { - re.lastIndex = index - } + re.lastIndex = skipComment( + startOrVBind === "/*" ? "block" : "line", + re.lastIndex, + ) } else { // v-bind const vBind = startOrVBind @@ -270,4 +262,23 @@ function* iterateVBind( } } } + + function skipString(quote: string, nextIndex: number): number { + for (let index = nextIndex; index < text.length; index++) { + const c = text[index] + if (c === "\\") { + index++ // escaping + continue + } + if (c === quote) { + return index + 1 + } + } + return nextIndex + } + + function skipComment(kind: "block" | "line", nextIndex: number): number { + const index = text.indexOf(kind === "block" ? "*/" : "\n", nextIndex) + return Math.max(index, nextIndex) + } } diff --git a/test/fixtures/document-fragment/style-variables06/document-fragment.json b/test/fixtures/document-fragment/style-variables-ignores01/document-fragment.json similarity index 77% rename from test/fixtures/document-fragment/style-variables06/document-fragment.json rename to test/fixtures/document-fragment/style-variables-ignores01/document-fragment.json index dbcc5ea7..ff952fa5 100644 --- a/test/fixtures/document-fragment/style-variables06/document-fragment.json +++ b/test/fixtures/document-fragment/style-variables-ignores01/document-fragment.json @@ -2,7 +2,7 @@ "type": "VDocumentFragment", "range": [ 0, - 249 + 208 ], "loc": { "start": { @@ -10,7 +10,7 @@ "column": 0 }, "end": { - "line": 14, + "line": 13, "column": 0 } }, @@ -19,7 +19,7 @@ "type": "VElement", "range": [ 0, - 87 + 46 ], "loc": { "start": { @@ -27,7 +27,7 @@ "column": 0 }, "end": { - "line": 4, + "line": 3, "column": 9 } }, @@ -97,7 +97,7 @@ "type": "VText", "range": [ 14, - 78 + 37 ], "loc": { "start": { @@ -105,26 +105,26 @@ "column": 14 }, "end": { - "line": 4, + "line": 3, "column": 0 } }, - "value": "\n /* eslint script-setup-uses-vars: 1 */\n const color = 'red'\n" + "value": "\n const color = 'red'\n" } ], "endTag": { "type": "VEndTag", "range": [ - 78, - 87 + 37, + 46 ], "loc": { "start": { - "line": 4, + "line": 3, "column": 0 }, "end": { - "line": 4, + "line": 3, "column": 9 } } @@ -134,16 +134,16 @@ { "type": "VText", "range": [ - 87, - 89 + 46, + 48 ], "loc": { "start": { - "line": 4, + "line": 3, "column": 9 }, "end": { - "line": 6, + "line": 5, "column": 0 } }, @@ -152,16 +152,16 @@ { "type": "VElement", "range": [ - 89, - 248 + 48, + 207 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 0 }, "end": { - "line": 13, + "line": 12, "column": 8 } }, @@ -171,16 +171,16 @@ "startTag": { "type": "VStartTag", "range": [ - 89, - 108 + 48, + 67 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 0 }, "end": { - "line": 6, + "line": 5, "column": 19 } }, @@ -189,16 +189,16 @@ { "type": "VAttribute", "range": [ - 96, - 107 + 55, + 66 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 7 }, "end": { - "line": 6, + "line": 5, "column": 18 } }, @@ -206,16 +206,16 @@ "key": { "type": "VIdentifier", "range": [ - 96, - 100 + 55, + 59 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 7 }, "end": { - "line": 6, + "line": 5, "column": 11 } }, @@ -225,16 +225,16 @@ "value": { "type": "VLiteral", "range": [ - 101, - 107 + 60, + 66 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 12 }, "end": { - "line": 6, + "line": 5, "column": 18 } }, @@ -247,16 +247,16 @@ { "type": "VText", "range": [ - 108, - 240 + 67, + 199 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 19 }, "end": { - "line": 13, + "line": 12, "column": 0 } }, @@ -266,16 +266,16 @@ "endTag": { "type": "VEndTag", "range": [ - 240, - 248 + 199, + 207 ], "loc": { "start": { - "line": 13, + "line": 12, "column": 0 }, "end": { - "line": 13, + "line": 12, "column": 8 } } @@ -286,16 +286,16 @@ { "type": "VText", "range": [ - 248, - 249 + 207, + 208 ], "loc": { "start": { - "line": 13, + "line": 12, "column": 8 }, "end": { - "line": 14, + "line": 13, "column": 0 } }, @@ -379,7 +379,7 @@ "type": "HTMLRawText", "range": [ 17, - 19 + 22 ], "loc": { "start": { @@ -388,186 +388,6 @@ }, "end": { "line": 2, - "column": 4 - } - }, - "value": "/*" - }, - { - "type": "HTMLWhitespace", - "range": [ - 19, - 20 - ], - "loc": { - "start": { - "line": 2, - "column": 4 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "value": " " - }, - { - "type": "HTMLRawText", - "range": [ - 20, - 26 - ], - "loc": { - "start": { - "line": 2, - "column": 5 - }, - "end": { - "line": 2, - "column": 11 - } - }, - "value": "eslint" - }, - { - "type": "HTMLWhitespace", - "range": [ - 26, - 27 - ], - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 12 - } - }, - "value": " " - }, - { - "type": "HTMLRawText", - "range": [ - 27, - 50 - ], - "loc": { - "start": { - "line": 2, - "column": 12 - }, - "end": { - "line": 2, - "column": 35 - } - }, - "value": "script-setup-uses-vars:" - }, - { - "type": "HTMLWhitespace", - "range": [ - 50, - 51 - ], - "loc": { - "start": { - "line": 2, - "column": 35 - }, - "end": { - "line": 2, - "column": 36 - } - }, - "value": " " - }, - { - "type": "HTMLRawText", - "range": [ - 51, - 52 - ], - "loc": { - "start": { - "line": 2, - "column": 36 - }, - "end": { - "line": 2, - "column": 37 - } - }, - "value": "1" - }, - { - "type": "HTMLWhitespace", - "range": [ - 52, - 53 - ], - "loc": { - "start": { - "line": 2, - "column": 37 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "value": " " - }, - { - "type": "HTMLRawText", - "range": [ - 53, - 55 - ], - "loc": { - "start": { - "line": 2, - "column": 38 - }, - "end": { - "line": 2, - "column": 40 - } - }, - "value": "*/" - }, - { - "type": "HTMLWhitespace", - "range": [ - 55, - 58 - ], - "loc": { - "start": { - "line": 2, - "column": 40 - }, - "end": { - "line": 3, - "column": 2 - } - }, - "value": "\n " - }, - { - "type": "HTMLRawText", - "range": [ - 58, - 63 - ], - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, "column": 7 } }, @@ -576,16 +396,16 @@ { "type": "HTMLWhitespace", "range": [ - 63, - 64 + 22, + 23 ], "loc": { "start": { - "line": 3, + "line": 2, "column": 7 }, "end": { - "line": 3, + "line": 2, "column": 8 } }, @@ -594,16 +414,16 @@ { "type": "HTMLRawText", "range": [ - 64, - 69 + 23, + 28 ], "loc": { "start": { - "line": 3, + "line": 2, "column": 8 }, "end": { - "line": 3, + "line": 2, "column": 13 } }, @@ -612,16 +432,16 @@ { "type": "HTMLWhitespace", "range": [ - 69, - 70 + 28, + 29 ], "loc": { "start": { - "line": 3, + "line": 2, "column": 13 }, "end": { - "line": 3, + "line": 2, "column": 14 } }, @@ -630,16 +450,16 @@ { "type": "HTMLRawText", "range": [ - 70, - 71 + 29, + 30 ], "loc": { "start": { - "line": 3, + "line": 2, "column": 14 }, "end": { - "line": 3, + "line": 2, "column": 15 } }, @@ -648,16 +468,16 @@ { "type": "HTMLWhitespace", "range": [ - 71, - 72 + 30, + 31 ], "loc": { "start": { - "line": 3, + "line": 2, "column": 15 }, "end": { - "line": 3, + "line": 2, "column": 16 } }, @@ -666,16 +486,16 @@ { "type": "HTMLRawText", "range": [ - 72, - 77 + 31, + 36 ], "loc": { "start": { - "line": 3, + "line": 2, "column": 16 }, "end": { - "line": 3, + "line": 2, "column": 21 } }, @@ -684,16 +504,16 @@ { "type": "HTMLWhitespace", "range": [ - 77, - 78 + 36, + 37 ], "loc": { "start": { - "line": 3, + "line": 2, "column": 21 }, "end": { - "line": 4, + "line": 3, "column": 0 } }, @@ -702,16 +522,16 @@ { "type": "HTMLEndTagOpen", "range": [ - 78, - 86 + 37, + 45 ], "loc": { "start": { - "line": 4, + "line": 3, "column": 0 }, "end": { - "line": 4, + "line": 3, "column": 8 } }, @@ -720,16 +540,16 @@ { "type": "HTMLTagClose", "range": [ - 86, - 87 + 45, + 46 ], "loc": { "start": { - "line": 4, + "line": 3, "column": 8 }, "end": { - "line": 4, + "line": 3, "column": 9 } }, @@ -738,16 +558,16 @@ { "type": "HTMLWhitespace", "range": [ - 87, - 89 + 46, + 48 ], "loc": { "start": { - "line": 4, + "line": 3, "column": 9 }, "end": { - "line": 6, + "line": 5, "column": 0 } }, @@ -756,16 +576,16 @@ { "type": "HTMLTagOpen", "range": [ - 89, - 95 + 48, + 54 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 0 }, "end": { - "line": 6, + "line": 5, "column": 6 } }, @@ -774,16 +594,16 @@ { "type": "HTMLIdentifier", "range": [ - 96, - 100 + 55, + 59 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 7 }, "end": { - "line": 6, + "line": 5, "column": 11 } }, @@ -792,16 +612,16 @@ { "type": "HTMLAssociation", "range": [ - 100, - 101 + 59, + 60 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 11 }, "end": { - "line": 6, + "line": 5, "column": 12 } }, @@ -810,16 +630,16 @@ { "type": "HTMLLiteral", "range": [ - 101, - 107 + 60, + 66 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 12 }, "end": { - "line": 6, + "line": 5, "column": 18 } }, @@ -828,16 +648,16 @@ { "type": "HTMLTagClose", "range": [ - 107, - 108 + 66, + 67 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 18 }, "end": { - "line": 6, + "line": 5, "column": 19 } }, @@ -846,16 +666,16 @@ { "type": "HTMLWhitespace", "range": [ - 108, - 111 + 67, + 70 ], "loc": { "start": { - "line": 6, + "line": 5, "column": 19 }, "end": { - "line": 7, + "line": 6, "column": 2 } }, @@ -864,16 +684,16 @@ { "type": "HTMLRawText", "range": [ - 111, - 118 + 70, + 77 ], "loc": { "start": { - "line": 7, + "line": 6, "column": 2 }, "end": { - "line": 7, + "line": 6, "column": 9 } }, @@ -882,16 +702,16 @@ { "type": "HTMLWhitespace", "range": [ - 118, - 119 + 77, + 78 ], "loc": { "start": { - "line": 7, + "line": 6, "column": 9 }, "end": { - "line": 7, + "line": 6, "column": 10 } }, @@ -900,16 +720,16 @@ { "type": "HTMLRawText", "range": [ - 119, - 125 + 78, + 84 ], "loc": { "start": { - "line": 7, + "line": 6, "column": 10 }, "end": { - "line": 7, + "line": 6, "column": 16 } }, @@ -918,16 +738,16 @@ { "type": "HTMLWhitespace", "range": [ - 125, - 126 + 84, + 85 ], "loc": { "start": { - "line": 7, + "line": 6, "column": 16 }, "end": { - "line": 7, + "line": 6, "column": 17 } }, @@ -936,16 +756,16 @@ { "type": "HTMLRawText", "range": [ - 126, - 127 + 85, + 86 ], "loc": { "start": { - "line": 7, + "line": 6, "column": 17 }, "end": { - "line": 7, + "line": 6, "column": 18 } }, @@ -954,16 +774,16 @@ { "type": "HTMLWhitespace", "range": [ - 127, - 132 + 86, + 91 ], "loc": { "start": { - "line": 7, + "line": 6, "column": 18 }, "end": { - "line": 8, + "line": 7, "column": 4 } }, @@ -972,16 +792,16 @@ { "type": "HTMLRawText", "range": [ - 132, - 138 + 91, + 97 ], "loc": { "start": { - "line": 8, + "line": 7, "column": 4 }, "end": { - "line": 8, + "line": 7, "column": 10 } }, @@ -990,16 +810,16 @@ { "type": "HTMLWhitespace", "range": [ - 138, - 139 + 97, + 98 ], "loc": { "start": { - "line": 8, + "line": 7, "column": 10 }, "end": { - "line": 8, + "line": 7, "column": 11 } }, @@ -1008,16 +828,16 @@ { "type": "HTMLRawText", "range": [ - 139, - 155 + 98, + 114 ], "loc": { "start": { - "line": 8, + "line": 7, "column": 11 }, "end": { - "line": 8, + "line": 7, "column": 27 } }, @@ -1026,16 +846,16 @@ { "type": "HTMLWhitespace", "range": [ - 155, - 160 + 114, + 119 ], "loc": { "start": { - "line": 8, + "line": 7, "column": 27 }, "end": { - "line": 9, + "line": 8, "column": 4 } }, @@ -1044,16 +864,16 @@ { "type": "HTMLRawText", "range": [ - 160, - 177 + 119, + 136 ], "loc": { "start": { - "line": 9, + "line": 8, "column": 4 }, "end": { - "line": 9, + "line": 8, "column": 21 } }, @@ -1062,16 +882,16 @@ { "type": "HTMLWhitespace", "range": [ - 177, - 178 + 136, + 137 ], "loc": { "start": { - "line": 9, + "line": 8, "column": 21 }, "end": { - "line": 9, + "line": 8, "column": 22 } }, @@ -1080,16 +900,16 @@ { "type": "HTMLRawText", "range": [ - 178, - 194 + 137, + 153 ], "loc": { "start": { - "line": 9, + "line": 8, "column": 22 }, "end": { - "line": 9, + "line": 8, "column": 38 } }, @@ -1098,16 +918,16 @@ { "type": "HTMLWhitespace", "range": [ - 194, - 197 + 153, + 156 ], "loc": { "start": { - "line": 9, + "line": 8, "column": 38 }, "end": { - "line": 10, + "line": 9, "column": 2 } }, @@ -1116,16 +936,16 @@ { "type": "HTMLRawText", "range": [ - 197, - 198 + 156, + 157 ], "loc": { "start": { - "line": 10, + "line": 9, "column": 2 }, "end": { - "line": 10, + "line": 9, "column": 3 } }, @@ -1134,16 +954,16 @@ { "type": "HTMLWhitespace", "range": [ - 198, - 201 + 157, + 160 ], "loc": { "start": { - "line": 10, + "line": 9, "column": 3 }, "end": { - "line": 11, + "line": 10, "column": 2 } }, @@ -1152,16 +972,16 @@ { "type": "HTMLRawText", "range": [ - 201, - 203 + 160, + 162 ], "loc": { "start": { - "line": 11, + "line": 10, "column": 2 }, "end": { - "line": 11, + "line": 10, "column": 4 } }, @@ -1170,16 +990,16 @@ { "type": "HTMLWhitespace", "range": [ - 203, - 204 + 162, + 163 ], "loc": { "start": { - "line": 11, + "line": 10, "column": 4 }, "end": { - "line": 11, + "line": 10, "column": 5 } }, @@ -1188,16 +1008,16 @@ { "type": "HTMLRawText", "range": [ - 204, - 217 + 163, + 176 ], "loc": { "start": { - "line": 11, + "line": 10, "column": 5 }, "end": { - "line": 11, + "line": 10, "column": 18 } }, @@ -1206,16 +1026,16 @@ { "type": "HTMLWhitespace", "range": [ - 217, - 218 + 176, + 177 ], "loc": { "start": { - "line": 11, + "line": 10, "column": 18 }, "end": { - "line": 11, + "line": 10, "column": 19 } }, @@ -1224,16 +1044,16 @@ { "type": "HTMLRawText", "range": [ - 218, - 220 + 177, + 179 ], "loc": { "start": { - "line": 11, + "line": 10, "column": 19 }, "end": { - "line": 11, + "line": 10, "column": 21 } }, @@ -1242,16 +1062,16 @@ { "type": "HTMLWhitespace", "range": [ - 220, - 223 + 179, + 182 ], "loc": { "start": { - "line": 11, + "line": 10, "column": 21 }, "end": { - "line": 12, + "line": 11, "column": 2 } }, @@ -1260,16 +1080,16 @@ { "type": "HTMLRawText", "range": [ - 223, - 225 + 182, + 184 ], "loc": { "start": { - "line": 12, + "line": 11, "column": 2 }, "end": { - "line": 12, + "line": 11, "column": 4 } }, @@ -1278,16 +1098,16 @@ { "type": "HTMLWhitespace", "range": [ - 225, - 226 + 184, + 185 ], "loc": { "start": { - "line": 12, + "line": 11, "column": 4 }, "end": { - "line": 12, + "line": 11, "column": 5 } }, @@ -1296,16 +1116,16 @@ { "type": "HTMLRawText", "range": [ - 226, - 239 + 185, + 198 ], "loc": { "start": { - "line": 12, + "line": 11, "column": 5 }, "end": { - "line": 12, + "line": 11, "column": 18 } }, @@ -1314,16 +1134,16 @@ { "type": "HTMLWhitespace", "range": [ - 239, - 240 + 198, + 199 ], "loc": { "start": { - "line": 12, + "line": 11, "column": 18 }, "end": { - "line": 13, + "line": 12, "column": 0 } }, @@ -1332,16 +1152,16 @@ { "type": "HTMLEndTagOpen", "range": [ - 240, - 247 + 199, + 206 ], "loc": { "start": { - "line": 13, + "line": 12, "column": 0 }, "end": { - "line": 13, + "line": 12, "column": 7 } }, @@ -1350,16 +1170,16 @@ { "type": "HTMLTagClose", "range": [ - 247, - 248 + 206, + 207 ], "loc": { "start": { - "line": 13, + "line": 12, "column": 7 }, "end": { - "line": 13, + "line": 12, "column": 8 } }, @@ -1368,16 +1188,16 @@ { "type": "HTMLWhitespace", "range": [ - 248, - 249 + 207, + 208 ], "loc": { "start": { - "line": 13, + "line": 12, "column": 8 }, "end": { - "line": 14, + "line": 13, "column": 0 } }, diff --git a/test/fixtures/document-fragment/style-variables06/source.vue b/test/fixtures/document-fragment/style-variables-ignores01/source.vue similarity index 83% rename from test/fixtures/document-fragment/style-variables06/source.vue rename to test/fixtures/document-fragment/style-variables-ignores01/source.vue index d1b4dcff..ac9b8e4b 100644 --- a/test/fixtures/document-fragment/style-variables06/source.vue +++ b/test/fixtures/document-fragment/style-variables-ignores01/source.vue @@ -1,5 +1,4 @@ diff --git a/test/fixtures/document-fragment/style-variables06/token-ranges.json b/test/fixtures/document-fragment/style-variables-ignores01/token-ranges.json similarity index 83% rename from test/fixtures/document-fragment/style-variables06/token-ranges.json rename to test/fixtures/document-fragment/style-variables-ignores01/token-ranges.json index c88e791b..353a19fb 100644 --- a/test/fixtures/document-fragment/style-variables06/token-ranges.json +++ b/test/fixtures/document-fragment/style-variables-ignores01/token-ranges.json @@ -3,16 +3,6 @@ "setup", ">", "\n ", - "/*", - " ", - "eslint", - " ", - "script-setup-uses-vars:", - " ", - "1", - " ", - "*/", - "\n ", "const", " ", "color", diff --git a/test/fixtures/document-fragment/style-variables06/tree.json b/test/fixtures/document-fragment/style-variables-ignores01/tree.json similarity index 86% rename from test/fixtures/document-fragment/style-variables06/tree.json rename to test/fixtures/document-fragment/style-variables-ignores01/tree.json index df932eb9..e64cf346 100644 --- a/test/fixtures/document-fragment/style-variables06/tree.json +++ b/test/fixtures/document-fragment/style-variables-ignores01/tree.json @@ -1,11 +1,11 @@ [ { "type": "VDocumentFragment", - "text": "\n\n\n", + "text": "\n\n\n", "children": [ { "type": "VElement", - "text": "", + "text": "", "children": [ { "type": "VStartTag", @@ -26,7 +26,7 @@ }, { "type": "VText", - "text": "\n /* eslint script-setup-uses-vars: 1 */\n const color = 'red'\n", + "text": "\n const color = 'red'\n", "children": [] }, { diff --git a/test/fixtures/document-fragment/style-variables-ignores02/document-fragment.json b/test/fixtures/document-fragment/style-variables-ignores02/document-fragment.json new file mode 100644 index 00000000..91952fba --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-ignores02/document-fragment.json @@ -0,0 +1,2176 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 365 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 364 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 7, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 7, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 12, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "scss" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 19, + 40 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "\n .text{\n color: " + }, + { + "type": "VExpressionContainer", + "range": [ + 40, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 47, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 47, + 52 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 47, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 47, + 52 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 53, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": ";\n }\n .text{\n color: " + }, + { + "type": "VExpressionContainer", + "range": [ + 79, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "expression": { + "type": "MemberExpression", + "start": 87, + "end": 97, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "range": [ + 87, + 97 + ], + "object": { + "type": "Identifier", + "start": 87, + "end": 93, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "range": [ + 87, + 93 + ], + "name": "colors" + }, + "property": { + "type": "Literal", + "start": 94, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "range": [ + 94, + 96 + ], + "value": 42, + "raw": "42" + }, + "computed": true + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 87, + "end": 93, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "range": [ + 87, + 93 + ], + "name": "colors" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 99, + 125 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": ";\n }\n .text{\n color: " + }, + { + "type": "VExpressionContainer", + "range": [ + 125, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 31 + } + }, + "expression": { + "type": "CallExpression", + "start": 133, + "end": 143, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "range": [ + 133, + 143 + ], + "callee": { + "type": "Identifier", + "start": 133, + "end": 141, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 133, + 141 + ], + "name": "getColor" + }, + "arguments": [] + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 133, + "end": 141, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 133, + 141 + ], + "name": "getColor" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 145, + 337 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 16, + "column": 15 + } + }, + "value": ";\n }\n .str-and-comments{\n content: \"v-bind('getColor()')\";\n content: \"v-bind('getColor()')\\\"v-bind(color)\";\n // color: v-bind(color);\n /* color: v-bind(color); */\n color: /**/" + }, + { + "type": "VExpressionContainer", + "range": [ + 337, + 350 + ], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 28 + } + }, + "expression": { + "type": "Identifier", + "start": 344, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "range": [ + 344, + 349 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 344, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "range": [ + 344, + 349 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 350, + 356 + ], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": ";\n }\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 356, + 364 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 364, + 365 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 6 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLIdentifier", + "range": [ + 7, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 12, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "scss" + }, + { + "type": "HTMLTagClose", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 19, + 22 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 2, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 22, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": ".text{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 28, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 40, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 3, + "column": 17 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 47, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "range": [ + 47, + 52 + ] + }, + { + "type": "Punctuator", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 54, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 58, + 61 + ], + "loc": { + "start": { + "line": 4, + "column": 3 + }, + "end": { + "line": 5, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 61, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": ".text{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 67, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 72, + 78 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Punctuator", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "colors", + "start": 87, + "end": 93, + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "range": [ + 87, + 93 + ] + }, + { + "type": "Punctuator", + "value": "[", + "start": 93, + "end": 94, + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 26 + } + }, + "range": [ + 93, + 94 + ] + }, + { + "type": "Numeric", + "value": "42", + "start": 94, + "end": 96, + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 28 + } + }, + "range": [ + 94, + 96 + ] + }, + { + "type": "Punctuator", + "value": "]", + "start": 96, + "end": 97, + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "range": [ + 96, + 97 + ] + }, + { + "type": "Punctuator", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 31 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 32 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 104, + 107 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 107, + 113 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": ".text{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 113, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 124 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 125, + 131 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": "(" + }, + { + "type": "Punctuator", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "value": "'" + }, + { + "type": "Identifier", + "value": "getColor", + "start": 133, + "end": 141, + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 27 + } + }, + "range": [ + 133, + 141 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 141, + "end": 142, + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "range": [ + 141, + 142 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 142, + "end": 143, + "loc": { + "start": { + "line": 9, + "column": 28 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "range": [ + 142, + 143 + ] + }, + { + "type": "Punctuator", + "range": [ + 143, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 29 + }, + "end": { + "line": 9, + "column": 30 + } + }, + "value": "'" + }, + { + "type": "Punctuator", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 31 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 9, + "column": 31 + }, + "end": { + "line": 9, + "column": 32 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 146, + 149 + ], + "loc": { + "start": { + "line": 9, + "column": 32 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 153 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 153, + 171 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "value": ".str-and-comments{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 171, + 176 + ], + "loc": { + "start": { + "line": 11, + "column": 20 + }, + "end": { + "line": 12, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 176, + 184 + ], + "loc": { + "start": { + "line": 12, + "column": 4 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "value": "content:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 12, + "column": 12 + }, + "end": { + "line": 12, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 185, + 208 + ], + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 36 + } + }, + "value": "\"v-bind('getColor()')\";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 208, + 213 + ], + "loc": { + "start": { + "line": 12, + "column": 36 + }, + "end": { + "line": 13, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 213, + 221 + ], + "loc": { + "start": { + "line": 13, + "column": 4 + }, + "end": { + "line": 13, + "column": 12 + } + }, + "value": "content:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 13, + "column": 12 + }, + "end": { + "line": 13, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 222, + 260 + ], + "loc": { + "start": { + "line": 13, + "column": 13 + }, + "end": { + "line": 13, + "column": 51 + } + }, + "value": "\"v-bind('getColor()')\\\"v-bind(color)\";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 260, + 265 + ], + "loc": { + "start": { + "line": 13, + "column": 51 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 265, + 267 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 6 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 267, + 268 + ], + "loc": { + "start": { + "line": 14, + "column": 6 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 268, + 274 + ], + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 14, + "column": 13 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 274, + 275 + ], + "loc": { + "start": { + "line": 14, + "column": 13 + }, + "end": { + "line": 14, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 275, + 289 + ], + "loc": { + "start": { + "line": 14, + "column": 14 + }, + "end": { + "line": 14, + "column": 28 + } + }, + "value": "v-bind(color);" + }, + { + "type": "HTMLWhitespace", + "range": [ + 289, + 294 + ], + "loc": { + "start": { + "line": 14, + "column": 28 + }, + "end": { + "line": 15, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 294, + 296 + ], + "loc": { + "start": { + "line": 15, + "column": 4 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": "/*" + }, + { + "type": "HTMLWhitespace", + "range": [ + 296, + 297 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 297, + 303 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 13 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 303, + 304 + ], + "loc": { + "start": { + "line": 15, + "column": 13 + }, + "end": { + "line": 15, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 304, + 318 + ], + "loc": { + "start": { + "line": 15, + "column": 14 + }, + "end": { + "line": 15, + "column": 28 + } + }, + "value": "v-bind(color);" + }, + { + "type": "HTMLWhitespace", + "range": [ + 318, + 319 + ], + "loc": { + "start": { + "line": 15, + "column": 28 + }, + "end": { + "line": 15, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 319, + 321 + ], + "loc": { + "start": { + "line": 15, + "column": 29 + }, + "end": { + "line": 15, + "column": 31 + } + }, + "value": "*/" + }, + { + "type": "HTMLWhitespace", + "range": [ + 321, + 326 + ], + "loc": { + "start": { + "line": 15, + "column": 31 + }, + "end": { + "line": 16, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 326, + 332 + ], + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 332, + 333 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 333, + 337 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 15 + } + }, + "value": "/**/" + }, + { + "type": "HTMLText", + "range": [ + 337, + 343 + ], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 21 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 343, + 344 + ], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 22 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 344, + "end": 349, + "loc": { + "start": { + "line": 16, + "column": 22 + }, + "end": { + "line": 16, + "column": 27 + } + }, + "range": [ + 344, + 349 + ] + }, + { + "type": "Punctuator", + "range": [ + 349, + 350 + ], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 28 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 350, + 351 + ], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 29 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 351, + 354 + ], + "loc": { + "start": { + "line": 16, + "column": 29 + }, + "end": { + "line": 17, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 354, + 355 + ], + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 355, + 356 + ], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 356, + 363 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 363, + 364 + ], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 364, + 365 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-ignores02/source.vue b/test/fixtures/document-fragment/style-variables-ignores02/source.vue new file mode 100644 index 00000000..70c9f9fd --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-ignores02/source.vue @@ -0,0 +1,18 @@ + diff --git a/test/fixtures/document-fragment/style-variables-ignores02/token-ranges.json b/test/fixtures/document-fragment/style-variables-ignores02/token-ranges.json new file mode 100644 index 00000000..2faa5238 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-ignores02/token-ranges.json @@ -0,0 +1,91 @@ +[ + "", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "}", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "\"", + "colors", + "[", + "42", + "]", + "\"", + ")", + ";", + "\n ", + "}", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "'", + "getColor", + "(", + ")", + "'", + ")", + ";", + "\n ", + "}", + "\n ", + ".str-and-comments{", + "\n ", + "content:", + " ", + "\"v-bind('getColor()')\";", + "\n ", + "content:", + " ", + "\"v-bind('getColor()')\\\"v-bind(color)\";", + "\n ", + "//", + " ", + "color:", + " ", + "v-bind(color);", + "\n ", + "/*", + " ", + "color:", + " ", + "v-bind(color);", + " ", + "*/", + "\n ", + "color:", + " ", + "/**/", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-ignores02/tree.json b/test/fixtures/document-fragment/style-variables-ignores02/tree.json new file mode 100644 index 00000000..58e58424 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-ignores02/tree.json @@ -0,0 +1,132 @@ +[ + { + "type": "VDocumentFragment", + "text": "\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/style-variables-inline-comment-like/document-fragment.json b/test/fixtures/document-fragment/style-variables-inline-comment-like/document-fragment.json new file mode 100644 index 00000000..c9f02bee --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-inline-comment-like/document-fragment.json @@ -0,0 +1,1037 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 117 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 46 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "name": "script", + "rawName": "script", + "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": [ + { + "type": "VAttribute", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "setup", + "rawName": "setup" + }, + "value": null + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 14, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n const color = 'red'\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 37, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 46, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "VElement", + "range": [ + 48, + 116 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "name": "style", + "rawName": "style", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 48, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 55, + 89 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": "\n .v-bind .color {\n color: // " + }, + { + "type": "VExpressionContainer", + "range": [ + 89, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 27 + } + }, + "expression": { + "type": "Identifier", + "start": 96, + "end": 101, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 26 + } + }, + "range": [ + 96, + 101 + ], + "name": "color" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 96, + "end": 101, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 26 + } + }, + "range": [ + 96, + 101 + ], + "name": "color" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 102, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 27 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": ";\n }\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 108, + 116 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + "variables": [], + "style": true + }, + { + "type": "VText", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + } + ], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "value": "setup" + }, + { + "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, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 22, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 23, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": "color" + }, + { + "type": "HTMLWhitespace", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "value": "'red'" + }, + { + "type": "HTMLWhitespace", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 37, + 45 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 46, + 48 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 48, + 54 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 55, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 58, + 65 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": ".v-bind" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 66, + 72 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "value": ".color" + }, + { + "type": "HTMLWhitespace", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 74, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "color:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 86, + 88 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 13 + } + }, + "value": "//" + }, + { + "type": "HTMLWhitespace", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 89, + 95 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "value": "v-bind" + }, + { + "type": "Punctuator", + "range": [ + 95, + 96 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 21 + } + }, + "value": "(" + }, + { + "type": "Identifier", + "value": "color", + "start": 96, + "end": 101, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 26 + } + }, + "range": [ + 96, + 101 + ] + }, + { + "type": "Punctuator", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 26 + }, + "end": { + "line": 7, + "column": 27 + } + }, + "value": ")" + }, + { + "type": "HTMLRawText", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 27 + }, + "end": { + "line": 7, + "column": 28 + } + }, + "value": ";" + }, + { + "type": "HTMLWhitespace", + "range": [ + 103, + 106 + ], + "loc": { + "start": { + "line": 7, + "column": 28 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 108, + 115 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "value": "style" + }, + { + "type": "HTMLTagClose", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-inline-comment-like/source.vue b/test/fixtures/document-fragment/style-variables-inline-comment-like/source.vue new file mode 100644 index 00000000..d2278e0e --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-inline-comment-like/source.vue @@ -0,0 +1,9 @@ + + + diff --git a/test/fixtures/document-fragment/style-variables-inline-comment-like/token-ranges.json b/test/fixtures/document-fragment/style-variables-inline-comment-like/token-ranges.json new file mode 100644 index 00000000..c4a25866 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-inline-comment-like/token-ranges.json @@ -0,0 +1,41 @@ +[ + "", + "\n ", + "const", + " ", + "color", + " ", + "=", + " ", + "'red'", + "\n", + "", + "\n\n", + "", + "\n ", + ".v-bind", + " ", + ".color", + " ", + "{", + "\n ", + "color:", + " ", + "//", + " ", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-inline-comment-like/tree.json b/test/fixtures/document-fragment/style-variables-inline-comment-like/tree.json new file mode 100644 index 00000000..bf090868 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-inline-comment-like/tree.json @@ -0,0 +1,88 @@ +[ + { + "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/style-variables05/document-fragment.json b/test/fixtures/document-fragment/style-variables05/document-fragment.json index 91952fba..76214b8f 100644 --- a/test/fixtures/document-fragment/style-variables05/document-fragment.json +++ b/test/fixtures/document-fragment/style-variables05/document-fragment.json @@ -2,7 +2,7 @@ "type": "VDocumentFragment", "range": [ 0, - 365 + 236 ], "loc": { "start": { @@ -10,7 +10,7 @@ "column": 0 }, "end": { - "line": 19, + "line": 13, "column": 0 } }, @@ -19,7 +19,7 @@ "type": "VElement", "range": [ 0, - 364 + 235 ], "loc": { "start": { @@ -27,7 +27,7 @@ "column": 0 }, "end": { - "line": 18, + "line": 12, "column": 8 } }, @@ -38,7 +38,7 @@ "type": "VStartTag", "range": [ 0, - 19 + 7 ], "loc": { "start": { @@ -47,79 +47,23 @@ }, "end": { "line": 1, - "column": 19 + "column": 7 } }, "selfClosing": false, - "attributes": [ - { - "type": "VAttribute", - "range": [ - 7, - 18 - ], - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "directive": false, - "key": { - "type": "VIdentifier", - "range": [ - 7, - 11 - ], - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 11 - } - }, - "name": "lang", - "rawName": "lang" - }, - "value": { - "type": "VLiteral", - "range": [ - 12, - 18 - ], - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "value": "scss" - } - } - ] + "attributes": [] }, "children": [ { "type": "VText", "range": [ - 19, - 40 + 7, + 28 ], "loc": { "start": { "line": 1, - "column": 19 + "column": 7 }, "end": { "line": 3, @@ -131,8 +75,8 @@ { "type": "VExpressionContainer", "range": [ - 40, - 53 + 28, + 45 ], "loc": { "start": { @@ -141,26 +85,26 @@ }, "end": { "line": 3, - "column": 24 + "column": 28 } }, "expression": { "type": "Identifier", - "start": 47, - "end": 52, + "start": 37, + "end": 42, "loc": { "start": { "line": 3, - "column": 18 + "column": 20 }, "end": { "line": 3, - "column": 23 + "column": 25 } }, "range": [ - 47, - 52 + 37, + 42 ], "name": "color" }, @@ -168,21 +112,21 @@ { "id": { "type": "Identifier", - "start": 47, - "end": 52, + "start": 37, + "end": 42, "loc": { "start": { "line": 3, - "column": 18 + "column": 20 }, "end": { "line": 3, - "column": 23 + "column": 25 } }, "range": [ - 47, - 52 + 37, + 42 ], "name": "color" }, @@ -193,119 +137,118 @@ { "type": "VText", "range": [ - 53, - 79 + 45, + 62 ], "loc": { "start": { "line": 3, - "column": 24 + "column": 28 }, "end": { - "line": 6, - "column": 11 + "line": 4, + "column": 15 } }, - "value": ";\n }\n .text{\n color: " + "value": ";\n font-size: " }, { "type": "VExpressionContainer", "range": [ - 79, - 99 + 62, + 85 ], "loc": { "start": { - "line": 6, - "column": 11 + "line": 4, + "column": 15 }, "end": { - "line": 6, - "column": 31 + "line": 4, + "column": 38 } }, "expression": { "type": "MemberExpression", - "start": 87, - "end": 97, + "start": 72, + "end": 81, "loc": { "start": { - "line": 6, - "column": 19 + "line": 4, + "column": 25 }, "end": { - "line": 6, - "column": 29 + "line": 4, + "column": 34 } }, "range": [ - 87, - 97 + 72, + 81 ], "object": { "type": "Identifier", - "start": 87, - "end": 93, + "start": 72, + "end": 76, "loc": { "start": { - "line": 6, - "column": 19 + "line": 4, + "column": 25 }, "end": { - "line": 6, - "column": 25 + "line": 4, + "column": 29 } }, "range": [ - 87, - 93 + 72, + 76 ], - "name": "colors" + "name": "font" }, "property": { - "type": "Literal", - "start": 94, - "end": 96, + "type": "Identifier", + "start": 77, + "end": 81, "loc": { "start": { - "line": 6, - "column": 26 + "line": 4, + "column": 30 }, "end": { - "line": 6, - "column": 28 + "line": 4, + "column": 34 } }, "range": [ - 94, - 96 + 77, + 81 ], - "value": 42, - "raw": "42" + "name": "size" }, - "computed": true + "computed": false }, "references": [ { "id": { "type": "Identifier", - "start": 87, - "end": 93, + "start": 72, + "end": 76, "loc": { "start": { - "line": 6, - "column": 19 + "line": 4, + "column": 25 }, "end": { - "line": 6, - "column": 25 + "line": 4, + "column": 29 } }, "range": [ - 87, - 93 + 72, + 76 ], - "name": "colors" + "name": "font" }, "mode": "r" } @@ -314,98 +257,120 @@ { "type": "VText", "range": [ - 99, - 125 + 85, + 105 ], "loc": { "start": { - "line": 6, - "column": 31 + "line": 4, + "column": 38 }, "end": { - "line": 9, - "column": 11 + "line": 5, + "column": 18 } }, - "value": ";\n }\n .text{\n color: " + "value": ";\n border-color: " }, { "type": "VExpressionContainer", "range": [ - 125, - 145 + 105, + 138 ], "loc": { "start": { - "line": 9, - "column": 11 + "line": 5, + "column": 18 }, "end": { - "line": 9, - "column": 31 + "line": 5, + "column": 51 } }, "expression": { "type": "CallExpression", - "start": 133, - "end": 143, + "start": 115, + "end": 133, "loc": { "start": { - "line": 9, - "column": 19 + "line": 5, + "column": 28 }, "end": { - "line": 9, - "column": 29 + "line": 5, + "column": 46 } }, "range": [ - 133, - 143 + 115, + 133 ], "callee": { "type": "Identifier", - "start": 133, - "end": 141, + "start": 115, + "end": 121, "loc": { "start": { - "line": 9, - "column": 19 + "line": 5, + "column": 28 }, "end": { - "line": 9, - "column": 27 + "line": 5, + "column": 34 } }, "range": [ - 133, - 141 + 115, + 121 ], - "name": "getColor" + "name": "border" }, - "arguments": [] + "arguments": [ + { + "type": "Literal", + "start": 124, + "end": 131, + "loc": { + "start": { + "line": 5, + "column": 37 + }, + "end": { + "line": 5, + "column": 44 + } + }, + "range": [ + 124, + 131 + ], + "value": "color", + "raw": "'color'" + } + ] }, "references": [ { "id": { "type": "Identifier", - "start": 133, - "end": 141, + "start": 115, + "end": 121, "loc": { "start": { - "line": 9, - "column": 19 + "line": 5, + "column": 28 }, "end": { - "line": 9, - "column": 27 + "line": 5, + "column": 34 } }, "range": [ - 133, - 141 + 115, + 121 ], - "name": "getColor" + "name": "border" }, "mode": "r" } @@ -414,78 +379,118 @@ { "type": "VText", "range": [ - 145, - 337 + 138, + 163 ], "loc": { "start": { - "line": 9, - "column": 31 + "line": 5, + "column": 51 }, "end": { - "line": 16, - "column": 15 + "line": 6, + "column": 22 } }, - "value": ";\n }\n .str-and-comments{\n content: \"v-bind('getColor()')\";\n content: \"v-bind('getColor()')\\\"v-bind(color)\";\n // color: v-bind(color);\n /* color: v-bind(color); */\n color: /**/" + "value": ";;\n background-color: " }, { "type": "VExpressionContainer", "range": [ - 337, - 350 + 163, + 221 ], "loc": { "start": { - "line": 16, - "column": 15 + "line": 6, + "column": 22 }, "end": { - "line": 16, - "column": 28 + "line": 10, + "column": 5 } }, "expression": { - "type": "Identifier", - "start": 344, - "end": 349, + "type": "MemberExpression", + "start": 181, + "end": 215, "loc": { "start": { - "line": 16, - "column": 22 + "line": 7, + "column": 8 }, "end": { - "line": 16, - "column": 27 + "line": 9, + "column": 13 } }, "range": [ - 344, - 349 + 181, + 215 ], - "name": "color" + "object": { + "type": "Identifier", + "start": 181, + "end": 191, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "range": [ + 181, + 191 + ], + "name": "background" + }, + "property": { + "type": "Identifier", + "start": 210, + "end": 215, + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 13 + } + }, + "range": [ + 210, + 215 + ], + "name": "color" + }, + "computed": false }, "references": [ { "id": { "type": "Identifier", - "start": 344, - "end": 349, + "start": 181, + "end": 191, "loc": { "start": { - "line": 16, - "column": 22 + "line": 7, + "column": 8 }, "end": { - "line": 16, - "column": 27 + "line": 7, + "column": 18 } }, "range": [ - 344, - 349 + 181, + 191 ], - "name": "color" + "name": "background" }, "mode": "r" } @@ -494,16 +499,16 @@ { "type": "VText", "range": [ - 350, - 356 + 221, + 227 ], "loc": { "start": { - "line": 16, - "column": 28 + "line": 10, + "column": 5 }, "end": { - "line": 18, + "line": 12, "column": 0 } }, @@ -513,16 +518,16 @@ "endTag": { "type": "VEndTag", "range": [ - 356, - 364 + 227, + 235 ], "loc": { "start": { - "line": 18, + "line": 12, "column": 0 }, "end": { - "line": 18, + "line": 12, "column": 8 } } @@ -533,16 +538,16 @@ { "type": "VText", "range": [ - 364, - 365 + 235, + 236 ], "loc": { "start": { - "line": 18, + "line": 12, "column": 8 }, "end": { - "line": 19, + "line": 13, "column": 0 } }, @@ -568,74 +573,20 @@ }, "value": "style" }, - { - "type": "HTMLIdentifier", - "range": [ - 7, - 11 - ], - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 11 - } - }, - "value": "lang" - }, - { - "type": "HTMLAssociation", - "range": [ - 11, - 12 - ], - "loc": { - "start": { - "line": 1, - "column": 11 - }, - "end": { - "line": 1, - "column": 12 - } - }, - "value": "" - }, - { - "type": "HTMLLiteral", - "range": [ - 12, - 18 - ], - "loc": { - "start": { - "line": 1, - "column": 12 - }, - "end": { - "line": 1, - "column": 18 - } - }, - "value": "scss" - }, { "type": "HTMLTagClose", "range": [ - 18, - 19 + 6, + 7 ], "loc": { "start": { "line": 1, - "column": 18 + "column": 6 }, "end": { "line": 1, - "column": 19 + "column": 7 } }, "value": "" @@ -643,13 +594,13 @@ { "type": "HTMLWhitespace", "range": [ - 19, - 22 + 7, + 10 ], "loc": { "start": { "line": 1, - "column": 19 + "column": 7 }, "end": { "line": 2, @@ -661,8 +612,8 @@ { "type": "HTMLRawText", "range": [ - 22, - 28 + 10, + 16 ], "loc": { "start": { @@ -679,8 +630,8 @@ { "type": "HTMLWhitespace", "range": [ - 28, - 33 + 16, + 21 ], "loc": { "start": { @@ -697,8 +648,8 @@ { "type": "HTMLRawText", "range": [ - 33, - 39 + 21, + 27 ], "loc": { "start": { @@ -715,8 +666,8 @@ { "type": "HTMLWhitespace", "range": [ - 39, - 40 + 27, + 28 ], "loc": { "start": { @@ -733,8 +684,8 @@ { "type": "HTMLText", "range": [ - 40, - 46 + 28, + 34 ], "loc": { "start": { @@ -751,8 +702,8 @@ { "type": "Punctuator", "range": [ - 46, - 47 + 34, + 35 ], "loc": { "start": { @@ -769,37 +720,37 @@ { "type": "Identifier", "value": "color", - "start": 47, - "end": 52, + "start": 37, + "end": 42, "loc": { "start": { "line": 3, - "column": 18 + "column": 20 }, "end": { "line": 3, - "column": 23 + "column": 25 } }, "range": [ - 47, - 52 + 37, + 42 ] }, { "type": "Punctuator", "range": [ - 52, - 53 + 44, + 45 ], "loc": { "start": { "line": 3, - "column": 23 + "column": 27 }, "end": { "line": 3, - "column": 24 + "column": 28 } }, "value": ")" @@ -807,17 +758,17 @@ { "type": "HTMLRawText", "range": [ - 53, - 54 + 45, + 46 ], "loc": { "start": { "line": 3, - "column": 24 + "column": 28 }, "end": { "line": 3, - "column": 25 + "column": 29 } }, "value": ";" @@ -825,840 +776,238 @@ { "type": "HTMLWhitespace", "range": [ - 54, - 57 + 46, + 51 ], "loc": { "start": { "line": 3, - "column": 25 + "column": 29 }, "end": { "line": 4, - "column": 2 + "column": 4 } }, - "value": "\n " + "value": "\n " }, { "type": "HTMLRawText", "range": [ - 57, - 58 + 51, + 61 ], "loc": { "start": { "line": 4, - "column": 2 + "column": 4 }, "end": { "line": 4, - "column": 3 + "column": 14 } }, - "value": "}" + "value": "font-size:" }, { "type": "HTMLWhitespace", "range": [ - 58, - 61 + 61, + 62 ], "loc": { "start": { "line": 4, - "column": 3 + "column": 14 }, "end": { - "line": 5, - "column": 2 + "line": 4, + "column": 15 } }, - "value": "\n " + "value": " " }, { - "type": "HTMLRawText", + "type": "HTMLText", "range": [ - 61, - 67 + 62, + 68 ], "loc": { "start": { - "line": 5, - "column": 2 + "line": 4, + "column": 15 }, "end": { - "line": 5, - "column": 8 + "line": 4, + "column": 21 } }, - "value": ".text{" + "value": "v-bind" }, { - "type": "HTMLWhitespace", + "type": "Punctuator", "range": [ - 67, - 72 + 68, + 69 ], "loc": { "start": { - "line": 5, - "column": 8 + "line": 4, + "column": 21 }, "end": { - "line": 6, - "column": 4 + "line": 4, + "column": 22 } }, - "value": "\n " + "value": "(" }, { - "type": "HTMLRawText", + "type": "Punctuator", "range": [ - 72, - 78 + 71, + 72 ], "loc": { "start": { - "line": 6, - "column": 4 + "line": 4, + "column": 24 }, "end": { - "line": 6, - "column": 10 + "line": 4, + "column": 25 } }, - "value": "color:" + "value": "'" }, { - "type": "HTMLWhitespace", - "range": [ - 78, - 79 - ], + "type": "Identifier", + "value": "font", + "start": 72, + "end": 76, "loc": { "start": { - "line": 6, - "column": 10 + "line": 4, + "column": 25 }, "end": { - "line": 6, - "column": 11 + "line": 4, + "column": 29 } }, - "value": " " + "range": [ + 72, + 76 + ] }, { - "type": "HTMLText", - "range": [ - 79, - 85 - ], + "type": "Punctuator", + "value": ".", + "start": 76, + "end": 77, "loc": { "start": { - "line": 6, - "column": 11 + "line": 4, + "column": 29 }, "end": { - "line": 6, - "column": 17 - } - }, - "value": "v-bind" - }, - { - "type": "Punctuator", - "range": [ - 85, - 86 - ], - "loc": { - "start": { - "line": 6, - "column": 17 - }, - "end": { - "line": 6, - "column": 18 - } - }, - "value": "(" - }, - { - "type": "Punctuator", - "range": [ - 86, - 87 - ], - "loc": { - "start": { - "line": 6, - "column": 18 - }, - "end": { - "line": 6, - "column": 19 - } - }, - "value": "\"" - }, - { - "type": "Identifier", - "value": "colors", - "start": 87, - "end": 93, - "loc": { - "start": { - "line": 6, - "column": 19 - }, - "end": { - "line": 6, - "column": 25 - } - }, - "range": [ - 87, - 93 - ] - }, - { - "type": "Punctuator", - "value": "[", - "start": 93, - "end": 94, - "loc": { - "start": { - "line": 6, - "column": 25 - }, - "end": { - "line": 6, - "column": 26 - } - }, - "range": [ - 93, - 94 - ] - }, - { - "type": "Numeric", - "value": "42", - "start": 94, - "end": 96, - "loc": { - "start": { - "line": 6, - "column": 26 - }, - "end": { - "line": 6, - "column": 28 - } - }, - "range": [ - 94, - 96 - ] - }, - { - "type": "Punctuator", - "value": "]", - "start": 96, - "end": 97, - "loc": { - "start": { - "line": 6, - "column": 28 - }, - "end": { - "line": 6, - "column": 29 - } - }, - "range": [ - 96, - 97 - ] - }, - { - "type": "Punctuator", - "range": [ - 97, - 98 - ], - "loc": { - "start": { - "line": 6, - "column": 29 - }, - "end": { - "line": 6, - "column": 30 - } - }, - "value": "\"" - }, - { - "type": "Punctuator", - "range": [ - 98, - 99 - ], - "loc": { - "start": { - "line": 6, - "column": 30 - }, - "end": { - "line": 6, - "column": 31 - } - }, - "value": ")" - }, - { - "type": "HTMLRawText", - "range": [ - 99, - 100 - ], - "loc": { - "start": { - "line": 6, - "column": 31 - }, - "end": { - "line": 6, - "column": 32 - } - }, - "value": ";" - }, - { - "type": "HTMLWhitespace", - "range": [ - 100, - 103 - ], - "loc": { - "start": { - "line": 6, - "column": 32 - }, - "end": { - "line": 7, - "column": 2 - } - }, - "value": "\n " - }, - { - "type": "HTMLRawText", - "range": [ - 103, - 104 - ], - "loc": { - "start": { - "line": 7, - "column": 2 - }, - "end": { - "line": 7, - "column": 3 - } - }, - "value": "}" - }, - { - "type": "HTMLWhitespace", - "range": [ - 104, - 107 - ], - "loc": { - "start": { - "line": 7, - "column": 3 - }, - "end": { - "line": 8, - "column": 2 - } - }, - "value": "\n " - }, - { - "type": "HTMLRawText", - "range": [ - 107, - 113 - ], - "loc": { - "start": { - "line": 8, - "column": 2 - }, - "end": { - "line": 8, - "column": 8 - } - }, - "value": ".text{" - }, - { - "type": "HTMLWhitespace", - "range": [ - 113, - 118 - ], - "loc": { - "start": { - "line": 8, - "column": 8 - }, - "end": { - "line": 9, - "column": 4 - } - }, - "value": "\n " - }, - { - "type": "HTMLRawText", - "range": [ - 118, - 124 - ], - "loc": { - "start": { - "line": 9, - "column": 4 - }, - "end": { - "line": 9, - "column": 10 - } - }, - "value": "color:" - }, - { - "type": "HTMLWhitespace", - "range": [ - 124, - 125 - ], - "loc": { - "start": { - "line": 9, - "column": 10 - }, - "end": { - "line": 9, - "column": 11 - } - }, - "value": " " - }, - { - "type": "HTMLText", - "range": [ - 125, - 131 - ], - "loc": { - "start": { - "line": 9, - "column": 11 - }, - "end": { - "line": 9, - "column": 17 - } - }, - "value": "v-bind" - }, - { - "type": "Punctuator", - "range": [ - 131, - 132 - ], - "loc": { - "start": { - "line": 9, - "column": 17 - }, - "end": { - "line": 9, - "column": 18 - } - }, - "value": "(" - }, - { - "type": "Punctuator", - "range": [ - 132, - 133 - ], - "loc": { - "start": { - "line": 9, - "column": 18 - }, - "end": { - "line": 9, - "column": 19 - } - }, - "value": "'" - }, - { - "type": "Identifier", - "value": "getColor", - "start": 133, - "end": 141, - "loc": { - "start": { - "line": 9, - "column": 19 - }, - "end": { - "line": 9, - "column": 27 - } - }, - "range": [ - 133, - 141 - ] - }, - { - "type": "Punctuator", - "value": "(", - "start": 141, - "end": 142, - "loc": { - "start": { - "line": 9, - "column": 27 - }, - "end": { - "line": 9, - "column": 28 - } - }, - "range": [ - 141, - 142 - ] - }, - { - "type": "Punctuator", - "value": ")", - "start": 142, - "end": 143, - "loc": { - "start": { - "line": 9, - "column": 28 - }, - "end": { - "line": 9, - "column": 29 - } - }, - "range": [ - 142, - 143 - ] - }, - { - "type": "Punctuator", - "range": [ - 143, - 144 - ], - "loc": { - "start": { - "line": 9, - "column": 29 - }, - "end": { - "line": 9, - "column": 30 - } - }, - "value": "'" - }, - { - "type": "Punctuator", - "range": [ - 144, - 145 - ], - "loc": { - "start": { - "line": 9, + "line": 4, "column": 30 - }, - "end": { - "line": 9, - "column": 31 - } - }, - "value": ")" - }, - { - "type": "HTMLRawText", - "range": [ - 145, - 146 - ], - "loc": { - "start": { - "line": 9, - "column": 31 - }, - "end": { - "line": 9, - "column": 32 - } - }, - "value": ";" - }, - { - "type": "HTMLWhitespace", - "range": [ - 146, - 149 - ], - "loc": { - "start": { - "line": 9, - "column": 32 - }, - "end": { - "line": 10, - "column": 2 - } - }, - "value": "\n " - }, - { - "type": "HTMLRawText", - "range": [ - 149, - 150 - ], - "loc": { - "start": { - "line": 10, - "column": 2 - }, - "end": { - "line": 10, - "column": 3 - } - }, - "value": "}" - }, - { - "type": "HTMLWhitespace", - "range": [ - 150, - 153 - ], - "loc": { - "start": { - "line": 10, - "column": 3 - }, - "end": { - "line": 11, - "column": 2 - } - }, - "value": "\n " - }, - { - "type": "HTMLRawText", - "range": [ - 153, - 171 - ], - "loc": { - "start": { - "line": 11, - "column": 2 - }, - "end": { - "line": 11, - "column": 20 - } - }, - "value": ".str-and-comments{" - }, - { - "type": "HTMLWhitespace", - "range": [ - 171, - 176 - ], - "loc": { - "start": { - "line": 11, - "column": 20 - }, - "end": { - "line": 12, - "column": 4 - } - }, - "value": "\n " - }, - { - "type": "HTMLRawText", - "range": [ - 176, - 184 - ], - "loc": { - "start": { - "line": 12, - "column": 4 - }, - "end": { - "line": 12, - "column": 12 - } - }, - "value": "content:" - }, - { - "type": "HTMLWhitespace", - "range": [ - 184, - 185 - ], - "loc": { - "start": { - "line": 12, - "column": 12 - }, - "end": { - "line": 12, - "column": 13 } }, - "value": " " - }, - { - "type": "HTMLRawText", "range": [ - 185, - 208 - ], - "loc": { - "start": { - "line": 12, - "column": 13 - }, - "end": { - "line": 12, - "column": 36 - } - }, - "value": "\"v-bind('getColor()')\";" + 76, + 77 + ] }, { - "type": "HTMLWhitespace", - "range": [ - 208, - 213 - ], + "type": "Identifier", + "value": "size", + "start": 77, + "end": 81, "loc": { "start": { - "line": 12, - "column": 36 + "line": 4, + "column": 30 }, "end": { - "line": 13, - "column": 4 + "line": 4, + "column": 34 } }, - "value": "\n " + "range": [ + 77, + 81 + ] }, { - "type": "HTMLRawText", + "type": "Punctuator", "range": [ - 213, - 221 + 81, + 82 ], "loc": { "start": { - "line": 13, - "column": 4 + "line": 4, + "column": 34 }, "end": { - "line": 13, - "column": 12 + "line": 4, + "column": 35 } }, - "value": "content:" + "value": "'" }, { - "type": "HTMLWhitespace", + "type": "Punctuator", "range": [ - 221, - 222 + 84, + 85 ], "loc": { "start": { - "line": 13, - "column": 12 + "line": 4, + "column": 37 }, "end": { - "line": 13, - "column": 13 + "line": 4, + "column": 38 } }, - "value": " " + "value": ")" }, { "type": "HTMLRawText", "range": [ - 222, - 260 + 85, + 86 ], "loc": { "start": { - "line": 13, - "column": 13 + "line": 4, + "column": 38 }, "end": { - "line": 13, - "column": 51 + "line": 4, + "column": 39 } }, - "value": "\"v-bind('getColor()')\\\"v-bind(color)\";" + "value": ";" }, { "type": "HTMLWhitespace", "range": [ - 260, - 265 + 86, + 91 ], "loc": { "start": { - "line": 13, - "column": 51 + "line": 4, + "column": 39 }, "end": { - "line": 14, + "line": 5, "column": 4 } }, @@ -1667,250 +1016,240 @@ { "type": "HTMLRawText", "range": [ - 265, - 267 + 91, + 104 ], "loc": { "start": { - "line": 14, + "line": 5, "column": 4 }, "end": { - "line": 14, - "column": 6 + "line": 5, + "column": 17 } }, - "value": "//" + "value": "border-color:" }, { "type": "HTMLWhitespace", "range": [ - 267, - 268 + 104, + 105 ], "loc": { "start": { - "line": 14, - "column": 6 + "line": 5, + "column": 17 }, "end": { - "line": 14, - "column": 7 + "line": 5, + "column": 18 } }, "value": " " }, { - "type": "HTMLRawText", + "type": "HTMLText", "range": [ - 268, - 274 + 105, + 111 ], "loc": { "start": { - "line": 14, - "column": 7 + "line": 5, + "column": 18 }, "end": { - "line": 14, - "column": 13 + "line": 5, + "column": 24 } }, - "value": "color:" + "value": "v-bind" }, { - "type": "HTMLWhitespace", + "type": "Punctuator", "range": [ - 274, - 275 + 111, + 112 ], "loc": { "start": { - "line": 14, - "column": 13 + "line": 5, + "column": 24 }, "end": { - "line": 14, - "column": 14 + "line": 5, + "column": 25 } }, - "value": " " + "value": "(" }, { - "type": "HTMLRawText", + "type": "Punctuator", "range": [ - 275, - 289 + 114, + 115 ], "loc": { "start": { - "line": 14, - "column": 14 + "line": 5, + "column": 27 }, "end": { - "line": 14, + "line": 5, "column": 28 } }, - "value": "v-bind(color);" + "value": "\"" }, { - "type": "HTMLWhitespace", - "range": [ - 289, - 294 - ], + "type": "Identifier", + "value": "border", + "start": 115, + "end": 121, "loc": { "start": { - "line": 14, + "line": 5, "column": 28 }, "end": { - "line": 15, - "column": 4 + "line": 5, + "column": 34 } }, - "value": "\n " - }, - { - "type": "HTMLRawText", "range": [ - 294, - 296 - ], - "loc": { - "start": { - "line": 15, - "column": 4 - }, - "end": { - "line": 15, - "column": 6 - } - }, - "value": "/*" + 115, + 121 + ] }, { - "type": "HTMLWhitespace", - "range": [ - 296, - 297 - ], + "type": "Punctuator", + "value": "(", + "start": 122, + "end": 123, "loc": { "start": { - "line": 15, - "column": 6 + "line": 5, + "column": 35 }, "end": { - "line": 15, - "column": 7 + "line": 5, + "column": 36 } }, - "value": " " + "range": [ + 122, + 123 + ] }, { - "type": "HTMLRawText", - "range": [ - 297, - 303 - ], + "type": "String", + "value": "'color'", + "start": 124, + "end": 131, "loc": { "start": { - "line": 15, - "column": 7 + "line": 5, + "column": 37 }, "end": { - "line": 15, - "column": 13 + "line": 5, + "column": 44 } }, - "value": "color:" + "range": [ + 124, + 131 + ] }, { - "type": "HTMLWhitespace", - "range": [ - 303, - 304 - ], + "type": "Punctuator", + "value": ")", + "start": 132, + "end": 133, "loc": { "start": { - "line": 15, - "column": 13 + "line": 5, + "column": 45 }, "end": { - "line": 15, - "column": 14 + "line": 5, + "column": 46 } }, - "value": " " + "range": [ + 132, + 133 + ] }, { - "type": "HTMLRawText", + "type": "Punctuator", "range": [ - 304, - 318 + 134, + 135 ], "loc": { "start": { - "line": 15, - "column": 14 + "line": 5, + "column": 47 }, "end": { - "line": 15, - "column": 28 + "line": 5, + "column": 48 } }, - "value": "v-bind(color);" + "value": "\"" }, { - "type": "HTMLWhitespace", + "type": "Punctuator", "range": [ - 318, - 319 + 137, + 138 ], "loc": { "start": { - "line": 15, - "column": 28 + "line": 5, + "column": 50 }, "end": { - "line": 15, - "column": 29 + "line": 5, + "column": 51 } }, - "value": " " + "value": ")" }, { "type": "HTMLRawText", "range": [ - 319, - 321 + 138, + 140 ], "loc": { "start": { - "line": 15, - "column": 29 + "line": 5, + "column": 51 }, "end": { - "line": 15, - "column": 31 + "line": 5, + "column": 53 } }, - "value": "*/" + "value": ";;" }, { "type": "HTMLWhitespace", "range": [ - 321, - 326 + 140, + 145 ], "loc": { "start": { - "line": 15, - "column": 31 + "line": 5, + "column": 53 }, "end": { - "line": 16, + "line": 6, "column": 4 } }, @@ -1919,127 +1258,149 @@ { "type": "HTMLRawText", "range": [ - 326, - 332 + 145, + 162 ], "loc": { "start": { - "line": 16, + "line": 6, "column": 4 }, "end": { - "line": 16, - "column": 10 + "line": 6, + "column": 21 } }, - "value": "color:" + "value": "background-color:" }, { "type": "HTMLWhitespace", "range": [ - 332, - 333 + 162, + 163 ], "loc": { "start": { - "line": 16, - "column": 10 + "line": 6, + "column": 21 }, "end": { - "line": 16, - "column": 11 + "line": 6, + "column": 22 } }, "value": " " }, { - "type": "HTMLRawText", + "type": "HTMLText", "range": [ - 333, - 337 + 163, + 169 ], "loc": { "start": { - "line": 16, - "column": 11 + "line": 6, + "column": 22 }, "end": { - "line": 16, - "column": 15 + "line": 6, + "column": 28 } }, - "value": "/**/" + "value": "v-bind" }, { - "type": "HTMLText", + "type": "Punctuator", "range": [ - 337, - 343 + 169, + 170 ], "loc": { "start": { - "line": 16, - "column": 15 + "line": 6, + "column": 28 }, "end": { - "line": 16, - "column": 21 + "line": 6, + "column": 29 } }, - "value": "v-bind" + "value": "(" }, { - "type": "Punctuator", + "type": "Identifier", + "value": "background", + "start": 181, + "end": 191, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 18 + } + }, "range": [ - 343, - 344 - ], + 181, + 191 + ] + }, + { + "type": "Punctuator", + "value": ".", + "start": 200, + "end": 201, "loc": { "start": { - "line": 16, - "column": 21 + "line": 8, + "column": 8 }, "end": { - "line": 16, - "column": 22 + "line": 8, + "column": 9 } }, - "value": "(" + "range": [ + 200, + 201 + ] }, { "type": "Identifier", "value": "color", - "start": 344, - "end": 349, + "start": 210, + "end": 215, "loc": { "start": { - "line": 16, - "column": 22 + "line": 9, + "column": 8 }, "end": { - "line": 16, - "column": 27 + "line": 9, + "column": 13 } }, "range": [ - 344, - 349 + 210, + 215 ] }, { "type": "Punctuator", "range": [ - 349, - 350 + 220, + 221 ], "loc": { "start": { - "line": 16, - "column": 27 + "line": 10, + "column": 4 }, "end": { - "line": 16, - "column": 28 + "line": 10, + "column": 5 } }, "value": ")" @@ -2047,17 +1408,17 @@ { "type": "HTMLRawText", "range": [ - 350, - 351 + 221, + 222 ], "loc": { "start": { - "line": 16, - "column": 28 + "line": 10, + "column": 5 }, "end": { - "line": 16, - "column": 29 + "line": 10, + "column": 6 } }, "value": ";" @@ -2065,16 +1426,16 @@ { "type": "HTMLWhitespace", "range": [ - 351, - 354 + 222, + 225 ], "loc": { "start": { - "line": 16, - "column": 29 + "line": 10, + "column": 6 }, "end": { - "line": 17, + "line": 11, "column": 2 } }, @@ -2083,16 +1444,16 @@ { "type": "HTMLRawText", "range": [ - 354, - 355 + 225, + 226 ], "loc": { "start": { - "line": 17, + "line": 11, "column": 2 }, "end": { - "line": 17, + "line": 11, "column": 3 } }, @@ -2101,16 +1462,16 @@ { "type": "HTMLWhitespace", "range": [ - 355, - 356 + 226, + 227 ], "loc": { "start": { - "line": 17, + "line": 11, "column": 3 }, "end": { - "line": 18, + "line": 12, "column": 0 } }, @@ -2119,16 +1480,16 @@ { "type": "HTMLEndTagOpen", "range": [ - 356, - 363 + 227, + 234 ], "loc": { "start": { - "line": 18, + "line": 12, "column": 0 }, "end": { - "line": 18, + "line": 12, "column": 7 } }, @@ -2137,16 +1498,16 @@ { "type": "HTMLTagClose", "range": [ - 363, - 364 + 234, + 235 ], "loc": { "start": { - "line": 18, + "line": 12, "column": 7 }, "end": { - "line": 18, + "line": 12, "column": 8 } }, @@ -2155,16 +1516,16 @@ { "type": "HTMLWhitespace", "range": [ - 364, - 365 + 235, + 236 ], "loc": { "start": { - "line": 18, + "line": 12, "column": 8 }, "end": { - "line": 19, + "line": 13, "column": 0 } }, diff --git a/test/fixtures/document-fragment/style-variables05/source.vue b/test/fixtures/document-fragment/style-variables05/source.vue index 70c9f9fd..3518cba8 100644 --- a/test/fixtures/document-fragment/style-variables05/source.vue +++ b/test/fixtures/document-fragment/style-variables05/source.vue @@ -1,18 +1,12 @@ - diff --git a/test/fixtures/document-fragment/style-variables05/token-ranges.json b/test/fixtures/document-fragment/style-variables05/token-ranges.json index 2faa5238..1e9c52c5 100644 --- a/test/fixtures/document-fragment/style-variables05/token-ranges.json +++ b/test/fixtures/document-fragment/style-variables05/token-ranges.json @@ -1,8 +1,5 @@ [ "", "\n ", ".text{", @@ -14,71 +11,38 @@ "color", ")", ";", - "\n ", - "}", - "\n ", - ".text{", "\n ", - "color:", + "font-size:", " ", "v-bind", "(", - "\"", - "colors", - "[", - "42", - "]", - "\"", + "'", + "font", + ".", + "size", + "'", ")", ";", - "\n ", - "}", - "\n ", - ".text{", "\n ", - "color:", + "border-color:", " ", "v-bind", "(", - "'", - "getColor", + "\"", + "border", "(", + "'color'", ")", - "'", + "\"", ")", - ";", - "\n ", - "}", - "\n ", - ".str-and-comments{", - "\n ", - "content:", - " ", - "\"v-bind('getColor()')\";", - "\n ", - "content:", - " ", - "\"v-bind('getColor()')\\\"v-bind(color)\";", - "\n ", - "//", - " ", - "color:", - " ", - "v-bind(color);", + ";;", "\n ", - "/*", - " ", - "color:", - " ", - "v-bind(color);", - " ", - "*/", - "\n ", - "color:", + "background-color:", " ", - "/**/", "v-bind", "(", + "background", + ".", "color", ")", ";", diff --git a/test/fixtures/document-fragment/style-variables05/tree.json b/test/fixtures/document-fragment/style-variables05/tree.json index 58e58424..4dce1239 100644 --- a/test/fixtures/document-fragment/style-variables05/tree.json +++ b/test/fixtures/document-fragment/style-variables05/tree.json @@ -1,33 +1,16 @@ [ { "type": "VDocumentFragment", - "text": "\n", + "text": "\n", "children": [ { "type": "VElement", - "text": "", + "text": "", "children": [ { "type": "VStartTag", - "text": "\n", + "text": "\n", "children": [ { "type": "VElement", - "text": "", + "text": "", "children": [ { "type": "VStartTag", @@ -35,7 +35,7 @@ }, { "type": "VExpressionContainer", - "text": "v-bind( 'font.size' )", + "text": "v-bind( ' font.size ' )", "children": [ { "type": "MemberExpression", @@ -62,7 +62,7 @@ }, { "type": "VExpressionContainer", - "text": "v-bind( \"border ( 'color' ) \" )", + "text": "v-bind( \" border ( 'color' ) \" )", "children": [ { "type": "CallExpression", From 6ae92594cdf0a859d82499c0a252ee74ff3827ca Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 17 Jul 2021 18:46:29 +0900 Subject: [PATCH 06/10] add testcases and upadte --- src/style/index.ts | 220 +- .../fixtures/ast/mustache-with-space/ast.json | 366 +++ .../ast/mustache-with-space/source.vue | 3 + .../ast/mustache-with-space/token-ranges.json | 12 + .../ast/mustache-with-space/tree.json | 39 + .../document-fragment.json | 1978 +++++++++++++++++ .../style-variables-edge-cases/source.vue | 10 + .../token-ranges.json | 79 + .../style-variables-edge-cases/tree.json | 131 ++ .../document-fragment.json | 42 +- .../token-ranges.json | 4 +- 11 files changed, 2834 insertions(+), 50 deletions(-) create mode 100644 test/fixtures/ast/mustache-with-space/ast.json create mode 100644 test/fixtures/ast/mustache-with-space/source.vue create mode 100644 test/fixtures/ast/mustache-with-space/token-ranges.json create mode 100644 test/fixtures/ast/mustache-with-space/tree.json create mode 100644 test/fixtures/document-fragment/style-variables-edge-cases/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables-edge-cases/source.vue create mode 100644 test/fixtures/document-fragment/style-variables-edge-cases/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables-edge-cases/tree.json diff --git a/src/style/index.ts b/src/style/index.ts index bfe565c6..0a5ceab9 100644 --- a/src/style/index.ts +++ b/src/style/index.ts @@ -21,6 +21,8 @@ import { parseExpression } from "../script" import { DEFAULT_ECMA_VERSION } from "../script-setup/parser-options" import { resolveReferences } from "../template" +type CSSParseOption = { inlineComment?: boolean } + /** * Parse the source code of the given ` diff --git a/test/fixtures/document-fragment/style-variables-edge-cases/token-ranges.json b/test/fixtures/document-fragment/style-variables-edge-cases/token-ranges.json new file mode 100644 index 00000000..3dffb9c3 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-edge-cases/token-ranges.json @@ -0,0 +1,79 @@ +[ + "", + "\n ", + ".text{", + "\n ", + "color:", + " ", + "v-bind", + "(", + "color", + ")", + ";", + "\n ", + "font-size:", + " ", + "v-bind", + "(", + "'", + "font", + ".", + "size", + "'", + ")", + ";", + " ", + "/*", + " ", + "vue", + " ", + "3.1", + " ", + "may", + " ", + "not", + " ", + "work", + " ", + "well.", + " ", + "*/", + "\n ", + "border-color:", + " ", + "v-bind", + "(", + "\"", + "border", + "(", + "'color'", + ")", + "\"", + ")", + ";", + "\n ", + "background-color:", + " ", + "v-bind", + "(", + "\"", + "background", + ".", + "color", + "\"", + ")", + ";", + "\n ", + "}", + "\n", + "", + "\n", + "/* comment1 */", + "/* comment2 ", + "/* comment3 ", + "// comment4", + "/*comment5*/", + "/*comment6*/" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-edge-cases/tree.json b/test/fixtures/document-fragment/style-variables-edge-cases/tree.json new file mode 100644 index 00000000..3c4ffbe6 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-edge-cases/tree.json @@ -0,0 +1,131 @@ +[ + { + "type": "VDocumentFragment", + "text": "\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/style-variables-with-error/document-fragment.json b/test/fixtures/document-fragment/style-variables-with-error/document-fragment.json index fe1b83b4..6df073da 100644 --- a/test/fixtures/document-fragment/style-variables-with-error/document-fragment.json +++ b/test/fixtures/document-fragment/style-variables-with-error/document-fragment.json @@ -313,22 +313,58 @@ "value": "(" }, { - "type": "HTMLText", + "type": "HTMLRawText", "range": [ 35, - 46 + 40 ], "loc": { "start": { "line": 3, "column": 18 }, + "end": { + "line": 3, + "column": 23 + } + }, + "value": "color" + }, + { + "type": "HTMLWhitespace", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 41, + 46 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, "end": { "line": 3, "column": 29 } }, - "value": "color error" + "value": "error" }, { "type": "Punctuator", diff --git a/test/fixtures/document-fragment/style-variables-with-error/token-ranges.json b/test/fixtures/document-fragment/style-variables-with-error/token-ranges.json index 54e21f0d..6cbaa046 100644 --- a/test/fixtures/document-fragment/style-variables-with-error/token-ranges.json +++ b/test/fixtures/document-fragment/style-variables-with-error/token-ranges.json @@ -8,7 +8,9 @@ " ", "v-bind", "(", - "color error", + "color", + " ", + "error", ")", ";", "\n ", From a6074ef56b3cba3332fa5f61c59f232adc29dac7 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 18 Jul 2021 08:25:36 +0900 Subject: [PATCH 07/10] Add test cases --- README.md | 4 +- scripts/update-fixtures-document-fragment.js | 17 +- src/common/parser-options.ts | 2 +- src/index.ts | 2 +- test/document-fragment.js | 12 +- .../document-fragment.json | 3595 +++++++++++++++++ .../parser-options.json | 5 + .../source.vue | 25 + .../token-ranges.json | 89 + .../tree.json | 129 + 10 files changed, 3867 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/document-fragment/style-variables-with-option-false/document-fragment.json create mode 100644 test/fixtures/document-fragment/style-variables-with-option-false/parser-options.json create mode 100644 test/fixtures/document-fragment/style-variables-with-option-false/source.vue create mode 100644 test/fixtures/document-fragment/style-variables-with-option-false/token-ranges.json create mode 100644 test/fixtures/document-fragment/style-variables-with-option-false/tree.json diff --git a/README.md b/README.md index 0a19c556..73831c41 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ For example: "vueFeatures": { "filter": true, "interpolationAsNonHTML": false, - "styleVariables": true, + "styleCSSVariableInjection": true, } } } @@ -190,7 +190,7 @@ The following template can be parsed well. But, it cannot be parsed with Vue 2. -### parserOptions.vueFeatures.styleVariables +### parserOptions.vueFeatures.styleCSSVariableInjection If set to `true`, to parse expressions in `v-bind` CSS functions inside ` diff --git a/test/fixtures/document-fragment/style-variables-with-option-false/token-ranges.json b/test/fixtures/document-fragment/style-variables-with-option-false/token-ranges.json new file mode 100644 index 00000000..ac5d560e --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-with-option-false/token-ranges.json @@ -0,0 +1,89 @@ +[ + "", + "\n ", + "", + "hello", + "", + "\n", + "", + "\n\n", + "", + "\n ", + "export", + " ", + "default", + " ", + "{", + "\n ", + "data()", + " ", + "{", + "\n ", + "return", + " ", + "{", + "\n ", + "color:", + " ", + "'red',", + "\n ", + "font:", + " ", + "{", + "\n ", + "size:", + " ", + "'2em',", + "\n ", + "},", + "\n ", + "}", + "\n ", + "},", + "\n ", + "}", + "\n", + "", + "\n\n", + "", + "\n ", + ".text", + " ", + "{", + "\n ", + "color:", + " ", + "v-bind(color);", + "\n\n ", + "/*", + " ", + "expressions", + " ", + "(wrap", + " ", + "in", + " ", + "quotes)", + " ", + "*/", + "\n ", + "font-size:", + " ", + "v-bind('font.size');", + "\n ", + "}", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/style-variables-with-option-false/tree.json b/test/fixtures/document-fragment/style-variables-with-option-false/tree.json new file mode 100644 index 00000000..3badd1c0 --- /dev/null +++ b/test/fixtures/document-fragment/style-variables-with-option-false/tree.json @@ -0,0 +1,129 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n\n\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\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + } + ] + } +] \ No newline at end of file From 281c8b6076ae47ecc5fa24a2d8867a7e978223ff Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 18 Jul 2021 08:29:59 +0900 Subject: [PATCH 08/10] update doc --- docs/ast.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ast.md b/docs/ast.md index a7dab8c2..2960b051 100644 --- a/docs/ast.md +++ b/docs/ast.md @@ -124,7 +124,7 @@ interface VFilter <: Node { } ``` -- This is mustaches or directive values or style variables. +- This is mustaches or directive values or `v-bind()` in `\n", + "text": "\n", "children": [ { "type": "VElement", - "text": "", + "text": "", "children": [ { "type": "VStartTag", @@ -57,7 +57,7 @@ }, { "type": "VText", - "text": ";\n border-color: ", + "text": ";\n border-color: /**/", "children": [] }, {