diff --git a/src/script-setup/scope-analyzer.ts b/src/script-setup/scope-analyzer.ts index d20ab82b..fbb5b7fa 100644 --- a/src/script-setup/scope-analyzer.ts +++ b/src/script-setup/scope-analyzer.ts @@ -15,6 +15,7 @@ import { isScriptElement, isScriptSetupElement, } from "../common/ast-utils" +import { camelize } from "../utils/utils" const BUILTIN_COMPONENTS = new Set([ "template", @@ -94,15 +95,6 @@ const COMPILER_MACROS_AT_ROOT = new Set([ "defineModel", ]) -/** - * `casing.camelCase()` converts the beginning to lowercase, - * but does not convert the case of the beginning character when converting with Vue3. - * @see https://github.com/vuejs/vue-next/blob/48de8a42b7fed7a03f7f1ff5d53d6a704252cafe/packages/shared/src/index.ts#L109 - */ -function camelize(str: string) { - return str.replace(/-(\w)/gu, (_, c) => (c ? c.toUpperCase() : "")) -} - function capitalize(str: string) { return str[0].toUpperCase() + str.slice(1) } diff --git a/src/template/index.ts b/src/template/index.ts index b58703e6..318b635c 100644 --- a/src/template/index.ts +++ b/src/template/index.ts @@ -7,6 +7,8 @@ import type { ParserOptions } from "../common/parser-options" import { isSFCFile } from "../common/parser-options" import type { ESLintExpression, + ESLintExtendedProgram, + ESLintIdentifier, Reference, Token, VAttribute, @@ -34,6 +36,7 @@ import { parseVOnExpression, parseSlotScopeExpression, parseGenericExpression, + parseScriptFragment, } from "../script" import { createSimpleToken, @@ -46,6 +49,7 @@ import { isTSLang, } from "../common/ast-utils" import { insertError } from "../common/error-utils" +import { camelize } from "../utils/utils" const shorthandSign = /^[.:@#]/u const shorthandNameMap = { ":": "bind", ".": "bind", "@": "on", "#": "slot" } @@ -626,6 +630,14 @@ export function convertToDirective( } if (node.value == null) { + if (directive.key.name.name === "bind") { + // v-bind same-name shorthand (Vue 3.4+) + convertForVBindSameNameShorthandValue( + directive, + parserOptions, + locationCalculator, + ) + } return } @@ -677,6 +689,65 @@ export function convertToDirective( } } +function convertForVBindSameNameShorthandValue( + directive: VDirective, + parserOptions: ParserOptions, + locationCalculator: LocationCalculatorForHtml, +) { + if ( + directive.key.name.name !== "bind" || + directive.key.argument == null || + directive.key.argument.type !== "VIdentifier" + ) { + return + } + // v-bind same-name shorthand (Vue 3.4+) + const vId = directive.key.argument + const camelName = camelize(vId.name) + let result: ESLintExtendedProgram | null = null + try { + result = parseScriptFragment( + camelName, + locationCalculator.getSubCalculatorAfter(vId.range[0]), + parserOptions, + ) + } catch (err) { + debug("[template] Parse error: %s", err) + } + if ( + result == null || + result.ast.body.length !== 1 || + result.ast.body[0].type !== "ExpressionStatement" || + result.ast.body[0].expression.type !== "Identifier" + ) { + return + } + const id: ESLintIdentifier = result.ast.body[0].expression + id.range[1] = vId.range[1] + id.loc.end = { ...vId.loc.end } + if (id.end != null) { + id.end = vId.end + } + directive.value = { + type: "VExpressionContainer", + range: [...vId.range], + loc: { + start: { ...vId.loc.start }, + end: { ...vId.loc.end }, + }, + parent: directive, + expression: id, + references: [ + { + id, + mode: "r", + variable: null, + }, + ], + } + id.parent = directive.value +} + /** * Parse the content of the given mustache. * @param parserOptions The parser options to parse expressions. diff --git a/src/utils/utils.ts b/src/utils/utils.ts new file mode 100644 index 00000000..1ecc2415 --- /dev/null +++ b/src/utils/utils.ts @@ -0,0 +1,6 @@ +/** + * @see https://github.com/vuejs/vue-next/blob/48de8a42b7fed7a03f7f1ff5d53d6a704252cafe/packages/shared/src/index.ts#L109 + */ +export function camelize(str: string) { + return str.replace(/-(\w)/gu, (_, c) => (c ? c.toUpperCase() : "")) +} diff --git a/test/fixtures/ast/directive-shorthands/ast.json b/test/fixtures/ast/directive-shorthands/ast.json index 546066ce..0a221c3c 100644 --- a/test/fixtures/ast/directive-shorthands/ast.json +++ b/test/fixtures/ast/directive-shorthands/ast.json @@ -207,7 +207,67 @@ } ] }, - "value": null + "value": { + "type": "VExpressionContainer", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "column": 10, + "line": 2 + }, + "end": { + "column": 11, + "line": 2 + } + }, + "expression": { + "type": "Identifier", + "start": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "column": 11, + "line": 2 + } + }, + "range": [ + 21, + 22 + ], + "name": "a" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "column": 11, + "line": 2 + } + }, + "range": [ + 21, + 22 + ], + "name": "a" + }, + "mode": "r", + "variable": null + } + ] + } } ] }, diff --git a/test/fixtures/ast/directive-shorthands/tree.json b/test/fixtures/ast/directive-shorthands/tree.json index a7e8083e..4fae3f96 100644 --- a/test/fixtures/ast/directive-shorthands/tree.json +++ b/test/fixtures/ast/directive-shorthands/tree.json @@ -45,6 +45,17 @@ "children": [] } ] + }, + { + "type": "VExpressionContainer", + "text": "a", + "children": [ + { + "type": "Identifier", + "text": "a", + "children": [] + } + ] } ] } diff --git a/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/ast.json new file mode 100644 index 00000000..085e4279 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/ast.json @@ -0,0 +1,968 @@ +{ + "type": "Program", + "start": 15, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 15, + 57 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 15, + 57 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 21, + 57 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "range": [ + 21, + 24 + ], + "name": "src" + }, + "init": { + "type": "Literal", + "start": 27, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 27, + 57 + ], + "value": "https://github.com/vuejs.png", + "raw": "\"https://github.com/vuejs.png\"" + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 69, + 104 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 69, + 79 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 79, + 82 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 82, + 92 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "name": "img", + "rawName": "img", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 82, + 92 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 87, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 87, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "column": 7, + "line": 6 + }, + "end": { + "column": 8, + "line": 6 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 88, + 91 + ], + "loc": { + "start": { + "column": 8, + "line": 6 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "name": "src", + "rawName": "src" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 88, + 91 + ], + "loc": { + "start": { + "column": 8, + "line": 6 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "expression": { + "type": "Identifier", + "start": 88, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "range": [ + 88, + 91 + ], + "name": "src" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 88, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "range": [ + 88, + 91 + ], + "name": "src" + }, + "mode": "r", + "variable": null + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 93, + 104 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + "variables": [], + "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, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 15, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 21, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "src" + }, + { + "type": "HTMLWhitespace", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 27, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "value": "\"https://github.com/vuejs.png\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 58, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 67, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 69, + 78 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 79, + 82 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 82, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "img" + }, + { + "type": "Punctuator", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "column": 7, + "line": 6 + }, + "end": { + "column": 8, + "line": 6 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 88, + 91 + ], + "loc": { + "start": { + "column": 8, + "line": 6 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "value": "src" + }, + { + "type": "HTMLTagClose", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 93, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/parser-options.json b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/scope.json b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/scope.json new file mode 100644 index 00000000..95d2857d --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/scope.json @@ -0,0 +1,154 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "src", + "identifiers": [ + { + "type": "Identifier", + "name": "src", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 42 + } + } + }, + "name": "src" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "src", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "src", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "src", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "src", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "src", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "src", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": true + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/source.vue b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/source.vue new file mode 100644 index 00000000..902ca750 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/token-ranges.json b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/token-ranges.json new file mode 100644 index 00000000..1666d2b9 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/token-ranges.json @@ -0,0 +1,34 @@ +[ + "", + "", + "\n", + "const", + " ", + "src", + " ", + "=", + " ", + "\"https://github.com/vuejs.png\"", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/tree.json b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/tree.json new file mode 100644 index 00000000..403f2688 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/tree.json @@ -0,0 +1,73 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json new file mode 100644 index 00000000..84add60c --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json @@ -0,0 +1,1644 @@ +{ + "type": "Program", + "start": 9, + "end": 104, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "range": [ + 9, + 104 + ], + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 9, + "end": 104, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "range": [ + 9, + 104 + ], + "declaration": { + "type": "ObjectExpression", + "start": 24, + "end": 104, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "range": [ + 24, + 104 + ], + "properties": [ + { + "type": "Property", + "start": 28, + "end": 102, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "range": [ + 28, + 102 + ], + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 28, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "range": [ + 28, + 32 + ], + "name": "data" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "start": 33, + "end": 102, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "range": [ + 33, + 102 + ], + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 102, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "range": [ + 36, + 102 + ], + "body": [ + { + "type": "ReturnStatement", + "start": 42, + "end": 98, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "range": [ + 42, + 98 + ], + "argument": { + "type": "ObjectExpression", + "start": 49, + "end": 98, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "range": [ + 49, + 98 + ], + "properties": [ + { + "type": "Property", + "start": 57, + "end": 92, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 41 + } + }, + "range": [ + 57, + 92 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 57, + "end": 60, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "range": [ + 57, + 60 + ], + "name": "src" + }, + "value": { + "type": "Literal", + "start": 62, + "end": 92, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 41 + } + }, + "range": [ + 62, + 92 + ], + "value": "https://github.com/vuejs.png", + "raw": "\"https://github.com/vuejs.png\"" + }, + "kind": "init" + } + ] + } + } + ] + } + } + } + ] + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 116, + 151 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 13, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 116, + 126 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 126, + 129 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 12, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 129, + 139 + ], + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "name": "img", + "rawName": "img", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 129, + 139 + ], + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "column": 7, + "line": 12 + }, + "end": { + "column": 8, + "line": 12 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 135, + 138 + ], + "loc": { + "start": { + "column": 8, + "line": 12 + }, + "end": { + "column": 11, + "line": 12 + } + }, + "name": "src", + "rawName": "src" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 135, + 138 + ], + "loc": { + "start": { + "column": 8, + "line": 12 + }, + "end": { + "column": 11, + "line": 12 + } + }, + "expression": { + "type": "Identifier", + "start": 135, + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "column": 11, + "line": 12 + } + }, + "range": [ + 135, + 138 + ], + "name": "src" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 135, + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "column": 11, + "line": 12 + } + }, + "range": [ + 135, + 138 + ], + "name": "src" + }, + "mode": "r", + "variable": null + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 12, + "column": 12 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 140, + 151 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": "default" + }, + { + "type": "HTMLWhitespace", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 25, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 32 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "value": "data" + }, + { + "type": "HTMLWhitespace", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 37, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 42, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "value": "return" + }, + { + "type": "HTMLWhitespace", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 50, + 57 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 57, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "src:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 62, + 92 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 41 + } + }, + "value": "\"https://github.com/vuejs.png\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 92, + 97 + ], + "loc": { + "start": { + "line": 5, + "column": 41 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 98, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 105, + 113 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 114, + 116 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 116, + 125 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 126, + 129 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 12, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 129, + 133 + ], + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 6 + } + }, + "value": "img" + }, + { + "type": "Punctuator", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "column": 7, + "line": 12 + }, + "end": { + "column": 8, + "line": 12 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 135, + 138 + ], + "loc": { + "start": { + "column": 8, + "line": 12 + }, + "end": { + "column": 11, + "line": 12 + } + }, + "value": "src" + }, + { + "type": "HTMLTagClose", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 12 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 12, + "column": 12 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 140, + 150 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 150, + 151 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 13, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 151, + 152 + ], + "loc": { + "start": { + "line": 13, + "column": 11 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand02-options/parser-options.json b/test/fixtures/ast/v-bind-same-name-shorthand02-options/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/v-bind-same-name-shorthand02-options/scope.json b/test/fixtures/ast/v-bind-same-name-shorthand02-options/scope.json new file mode 100644 index 00000000..19cca0f2 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/scope.json @@ -0,0 +1,30 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "arguments", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand02-options/source.vue b/test/fixtures/ast/v-bind-same-name-shorthand02-options/source.vue new file mode 100644 index 00000000..633c03c2 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/source.vue @@ -0,0 +1,13 @@ + + + diff --git a/test/fixtures/ast/v-bind-same-name-shorthand02-options/token-ranges.json b/test/fixtures/ast/v-bind-same-name-shorthand02-options/token-ranges.json new file mode 100644 index 00000000..75da3231 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/token-ranges.json @@ -0,0 +1,62 @@ +[ + "", + "", + "\n", + "export", + " ", + "default", + " ", + "{", + "\n ", + "data", + " ", + "()", + " ", + "{", + "\n ", + "return", + " ", + "{", + "\n ", + "src:", + " ", + "\"https://github.com/vuejs.png\"", + "\n ", + "}", + "\n ", + "}", + "\n", + "}", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand02-options/tree.json b/test/fixtures/ast/v-bind-same-name-shorthand02-options/tree.json new file mode 100644 index 00000000..403f2688 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/tree.json @@ -0,0 +1,73 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/ast.json new file mode 100644 index 00000000..64389542 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/ast.json @@ -0,0 +1,1736 @@ +{ + "type": "Program", + "start": 15, + "end": 120, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "range": [ + 15, + 120 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 120, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "range": [ + 15, + 120 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 120, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "range": [ + 21, + 120 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 28, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "range": [ + 21, + 28 + ], + "name": "srcList" + }, + "init": { + "type": "ArrayExpression", + "start": 31, + "end": 120, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "range": [ + 31, + 120 + ], + "elements": [ + { + "type": "Literal", + "start": 41, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 38 + } + }, + "range": [ + 41, + 71 + ], + "value": "https://github.com/vuejs.png", + "raw": "\"https://github.com/vuejs.png\"" + }, + { + "type": "Literal", + "start": 81, + "end": 112, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 39 + } + }, + "range": [ + 81, + 112 + ], + "value": "https://github.com/vitejs.png", + "raw": "\"https://github.com/vitejs.png\"" + } + ] + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 132, + 209 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 132, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 142, + 145 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 145, + 197 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 11, + "column": 8 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 145, + 150 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 150, + 155 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 10, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 155, + 188 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 37 + } + }, + "name": "img", + "rawName": "img", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 155, + 188 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 37 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 160, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 31 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 160, + 165 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 14 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 160, + 165 + ], + "loc": { + "start": { + "column": 9, + "line": 10 + }, + "end": { + "column": 14, + "line": 10 + } + }, + "name": "for", + "rawName": "for" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 166, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 31 + } + }, + "expression": { + "type": "VForExpression", + "range": [ + 167, + 181 + ], + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 30 + } + }, + "left": [ + { + "type": "Identifier", + "start": 167, + "end": 170, + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "range": [ + 167, + 170 + ], + "name": "src" + } + ], + "right": { + "type": "Identifier", + "start": 174, + "end": 181, + "loc": { + "start": { + "line": 10, + "column": 23 + }, + "end": { + "line": 10, + "column": 30 + } + }, + "range": [ + 174, + 181 + ], + "name": "srcList" + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 174, + "end": 181, + "loc": { + "start": { + "line": 10, + "column": 23 + }, + "end": { + "line": 10, + "column": 30 + } + }, + "range": [ + 174, + 181 + ], + "name": "srcList" + }, + "mode": "r" + } + ] + } + }, + { + "type": "VAttribute", + "range": [ + 183, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 32 + }, + "end": { + "line": 10, + "column": 36 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 183, + 187 + ], + "loc": { + "start": { + "line": 10, + "column": 32 + }, + "end": { + "line": 10, + "column": 36 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 183, + 184 + ], + "loc": { + "start": { + "column": 32, + "line": 10 + }, + "end": { + "column": 33, + "line": 10 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 184, + 187 + ], + "loc": { + "start": { + "column": 33, + "line": 10 + }, + "end": { + "column": 36, + "line": 10 + } + }, + "name": "src", + "rawName": "src" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 184, + 187 + ], + "loc": { + "start": { + "column": 33, + "line": 10 + }, + "end": { + "column": 36, + "line": 10 + } + }, + "expression": { + "type": "Identifier", + "start": 184, + "loc": { + "start": { + "line": 10, + "column": 33 + }, + "end": { + "column": 36, + "line": 10 + } + }, + "range": [ + 184, + 187 + ], + "name": "src" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 184, + "loc": { + "start": { + "line": 10, + "column": 33 + }, + "end": { + "column": 36, + "line": 10 + } + }, + "range": [ + 184, + 187 + ], + "name": "src" + }, + "mode": "r", + "variable": { + "id": { + "type": "Identifier", + "start": 167, + "end": 170, + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "range": [ + 167, + 170 + ], + "name": "src" + }, + "kind": "v-for" + } + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [ + { + "id": { + "type": "Identifier", + "start": 167, + "end": 170, + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "range": [ + 167, + 170 + ], + "name": "src" + }, + "kind": "v-for" + } + ] + }, + { + "type": "VText", + "range": [ + 188, + 191 + ], + "loc": { + "start": { + "line": 10, + "column": 37 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 191, + 197 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 8 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 198, + 209 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 11 + } + } + }, + "variables": [], + "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, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 15, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 21, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": "srcList" + }, + { + "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, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": "[" + }, + { + "type": "HTMLWhitespace", + "range": [ + 32, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 41, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "value": "\"https://github.com/vuejs.png\"," + }, + { + "type": "HTMLWhitespace", + "range": [ + 72, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 39 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 81, + 112 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 39 + } + }, + "value": "\"https://github.com/vitejs.png\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 119 + ], + "loc": { + "start": { + "line": 4, + "column": 39 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 119, + 120 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "]" + }, + { + "type": "HTMLWhitespace", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 121, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 130, + 132 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 132, + 141 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 142, + 145 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 145, + 149 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 155 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 10, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 155, + 159 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "img" + }, + { + "type": "HTMLIdentifier", + "range": [ + 160, + 165 + ], + "loc": { + "start": { + "column": 9, + "line": 10 + }, + "end": { + "column": 14, + "line": 10 + } + }, + "value": "v-for" + }, + { + "type": "HTMLAssociation", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 15 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 10, + "column": 15 + }, + "end": { + "line": 10, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "src", + "start": 167, + "end": 170, + "loc": { + "start": { + "line": 10, + "column": 16 + }, + "end": { + "line": 10, + "column": 19 + } + }, + "range": [ + 167, + 170 + ] + }, + { + "type": "Keyword", + "value": "in", + "start": 171, + "end": 173, + "loc": { + "start": { + "line": 10, + "column": 20 + }, + "end": { + "line": 10, + "column": 22 + } + }, + "range": [ + 171, + 173 + ] + }, + { + "type": "Identifier", + "value": "srcList", + "start": 174, + "end": 181, + "loc": { + "start": { + "line": 10, + "column": 23 + }, + "end": { + "line": 10, + "column": 30 + } + }, + "range": [ + 174, + 181 + ] + }, + { + "type": "Punctuator", + "range": [ + 181, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 30 + }, + "end": { + "line": 10, + "column": 31 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 183, + 184 + ], + "loc": { + "start": { + "column": 32, + "line": 10 + }, + "end": { + "column": 33, + "line": 10 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 184, + 187 + ], + "loc": { + "start": { + "column": 33, + "line": 10 + }, + "end": { + "column": 36, + "line": 10 + } + }, + "value": "src" + }, + { + "type": "HTMLTagClose", + "range": [ + 187, + 188 + ], + "loc": { + "start": { + "line": 10, + "column": 36 + }, + "end": { + "line": 10, + "column": 37 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 188, + 191 + ], + "loc": { + "start": { + "line": 10, + "column": 37 + }, + "end": { + "line": 11, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 191, + 196 + ], + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 7 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 11, + "column": 7 + }, + "end": { + "line": 11, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 198, + 208 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 208, + 209 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 209, + 210 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/parser-options.json b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/scope.json b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/scope.json new file mode 100644 index 00000000..9c8001a6 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/scope.json @@ -0,0 +1,154 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "srcList", + "identifiers": [ + { + "type": "Identifier", + "name": "srcList", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + "name": "srcList" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "srcList", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "srcList", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "srcList", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "srcList", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "srcList", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "srcList", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "init": true + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/source.vue b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/source.vue new file mode 100644 index 00000000..5a8ed1db --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/source.vue @@ -0,0 +1,12 @@ + + + diff --git a/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/token-ranges.json b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/token-ranges.json new file mode 100644 index 00000000..5550abfa --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/token-ranges.json @@ -0,0 +1,57 @@ +[ + "", + "", + "\n", + "const", + " ", + "srcList", + " ", + "=", + " ", + "[", + "\n ", + "\"https://github.com/vuejs.png\",", + "\n ", + "\"https://github.com/vitejs.png\"", + "\n ", + "]", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n ", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/tree.json b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/tree.json new file mode 100644 index 00000000..3f22d76a --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/tree.json @@ -0,0 +1,138 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json new file mode 100644 index 00000000..7a0ab7e5 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json @@ -0,0 +1,2412 @@ +{ + "type": "Program", + "start": 9, + "end": 167, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 11, + "column": 1 + } + }, + "range": [ + 9, + 167 + ], + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 9, + "end": 167, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 11, + "column": 1 + } + }, + "range": [ + 9, + 167 + ], + "declaration": { + "type": "ObjectExpression", + "start": 24, + "end": 167, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 11, + "column": 1 + } + }, + "range": [ + 24, + 167 + ], + "properties": [ + { + "type": "Property", + "start": 28, + "end": 165, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "range": [ + 28, + 165 + ], + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 28, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "range": [ + 28, + 32 + ], + "name": "data" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "start": 33, + "end": 165, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "range": [ + 33, + 165 + ], + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 165, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "range": [ + 36, + 165 + ], + "body": [ + { + "type": "ReturnStatement", + "start": 42, + "end": 161, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "range": [ + 42, + 161 + ], + "argument": { + "type": "ObjectExpression", + "start": 49, + "end": 161, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "range": [ + 49, + 161 + ], + "properties": [ + { + "type": "Property", + "start": 57, + "end": 155, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "range": [ + 57, + 155 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 57, + "end": 64, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "range": [ + 57, + 64 + ], + "name": "srcList" + }, + "value": { + "type": "ArrayExpression", + "start": 66, + "end": 155, + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "range": [ + 66, + 155 + ], + "elements": [ + { + "type": "Literal", + "start": 76, + "end": 106, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 38 + } + }, + "range": [ + 76, + 106 + ], + "value": "https://github.com/vuejs.png", + "raw": "\"https://github.com/vuejs.png\"" + }, + { + "type": "Literal", + "start": 116, + "end": 147, + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 39 + } + }, + "range": [ + 116, + 147 + ], + "value": "https://github.com/vitejs.png", + "raw": "\"https://github.com/vitejs.png\"" + } + ] + }, + "kind": "init" + } + ] + } + } + ] + } + } + } + ] + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 179, + 256 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 18, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 179, + 189 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 189, + 192 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 192, + 244 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 17, + "column": 8 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 192, + 197 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 197, + 202 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 16, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 202, + 235 + ], + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 37 + } + }, + "name": "img", + "rawName": "img", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 202, + 235 + ], + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 37 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 207, + 229 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 31 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 207, + 212 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 14 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 207, + 212 + ], + "loc": { + "start": { + "column": 9, + "line": 16 + }, + "end": { + "column": 14, + "line": 16 + } + }, + "name": "for", + "rawName": "for" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 213, + 229 + ], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 31 + } + }, + "expression": { + "type": "VForExpression", + "range": [ + 214, + 228 + ], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 30 + } + }, + "left": [ + { + "type": "Identifier", + "start": 214, + "end": 217, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + }, + "range": [ + 214, + 217 + ], + "name": "src" + } + ], + "right": { + "type": "Identifier", + "start": 221, + "end": 228, + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 30 + } + }, + "range": [ + 221, + 228 + ], + "name": "srcList" + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 221, + "end": 228, + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 30 + } + }, + "range": [ + 221, + 228 + ], + "name": "srcList" + }, + "mode": "r" + } + ] + } + }, + { + "type": "VAttribute", + "range": [ + 230, + 234 + ], + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 16, + "column": 36 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 230, + 234 + ], + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 16, + "column": 36 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 230, + 231 + ], + "loc": { + "start": { + "column": 32, + "line": 16 + }, + "end": { + "column": 33, + "line": 16 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 231, + 234 + ], + "loc": { + "start": { + "column": 33, + "line": 16 + }, + "end": { + "column": 36, + "line": 16 + } + }, + "name": "src", + "rawName": "src" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 231, + 234 + ], + "loc": { + "start": { + "column": 33, + "line": 16 + }, + "end": { + "column": 36, + "line": 16 + } + }, + "expression": { + "type": "Identifier", + "start": 231, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "column": 36, + "line": 16 + } + }, + "range": [ + 231, + 234 + ], + "name": "src" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 231, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "column": 36, + "line": 16 + } + }, + "range": [ + 231, + 234 + ], + "name": "src" + }, + "mode": "r", + "variable": { + "id": { + "type": "Identifier", + "start": 214, + "end": 217, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + }, + "range": [ + 214, + 217 + ], + "name": "src" + }, + "kind": "v-for" + } + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [ + { + "id": { + "type": "Identifier", + "start": 214, + "end": 217, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + }, + "range": [ + 214, + 217 + ], + "name": "src" + }, + "kind": "v-for" + } + ] + }, + { + "type": "VText", + "range": [ + 235, + 238 + ], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 17, + "column": 2 + } + }, + "value": "\n " + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 238, + 244 + ], + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 244, + 245 + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 245, + 256 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 8, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 9, + 15 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": "export" + }, + { + "type": "HTMLWhitespace", + "range": [ + 15, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 16, + 23 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": "default" + }, + { + "type": "HTMLWhitespace", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 25, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 32 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + } + }, + "value": "data" + }, + { + "type": "HTMLWhitespace", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 35 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 37, + 42 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 42, + 48 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 10 + } + }, + "value": "return" + }, + { + "type": "HTMLWhitespace", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 12 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 50, + 57 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 57, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "srcList:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 15 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 15 + }, + "end": { + "line": 5, + "column": 16 + } + }, + "value": "[" + }, + { + "type": "HTMLWhitespace", + "range": [ + 67, + 76 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 76, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 39 + } + }, + "value": "\"https://github.com/vuejs.png\"," + }, + { + "type": "HTMLWhitespace", + "range": [ + 107, + 116 + ], + "loc": { + "start": { + "line": 6, + "column": 39 + }, + "end": { + "line": 7, + "column": 8 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 116, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 39 + } + }, + "value": "\"https://github.com/vitejs.png\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 147, + 154 + ], + "loc": { + "start": { + "line": 7, + "column": 39 + }, + "end": { + "line": 8, + "column": 6 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + }, + "value": "]" + }, + { + "type": "HTMLWhitespace", + "range": [ + 155, + 160 + ], + "loc": { + "start": { + "line": 8, + "column": 7 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 160, + 161 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 161, + 164 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 164, + 165 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 1 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 168, + 176 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 179 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 179, + 188 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 188, + 189 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 189, + 192 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 192, + 196 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 197, + 202 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 16, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 202, + 206 + ], + "loc": { + "start": { + "line": 16, + "column": 4 + }, + "end": { + "line": 16, + "column": 8 + } + }, + "value": "img" + }, + { + "type": "HTMLIdentifier", + "range": [ + 207, + 212 + ], + "loc": { + "start": { + "column": 9, + "line": 16 + }, + "end": { + "column": 14, + "line": 16 + } + }, + "value": "v-for" + }, + { + "type": "HTMLAssociation", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "src", + "start": 214, + "end": 217, + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 19 + } + }, + "range": [ + 214, + 217 + ] + }, + { + "type": "Keyword", + "value": "in", + "start": 218, + "end": 220, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 22 + } + }, + "range": [ + 218, + 220 + ] + }, + { + "type": "Identifier", + "value": "srcList", + "start": 221, + "end": 228, + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 30 + } + }, + "range": [ + 221, + 228 + ] + }, + { + "type": "Punctuator", + "range": [ + 228, + 229 + ], + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 31 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "range": [ + 230, + 231 + ], + "loc": { + "start": { + "column": 32, + "line": 16 + }, + "end": { + "column": 33, + "line": 16 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 231, + 234 + ], + "loc": { + "start": { + "column": 33, + "line": 16 + }, + "end": { + "column": 36, + "line": 16 + } + }, + "value": "src" + }, + { + "type": "HTMLTagClose", + "range": [ + 234, + 235 + ], + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 16, + "column": 37 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 235, + 238 + ], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 17, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 238, + 243 + ], + "loc": { + "start": { + "line": 17, + "column": 2 + }, + "end": { + "line": 17, + "column": 7 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 243, + 244 + ], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 244, + 245 + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 245, + 255 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 255, + 256 + ], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 256, + 257 + ], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/parser-options.json b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/scope.json b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/scope.json new file mode 100644 index 00000000..19cca0f2 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/scope.json @@ -0,0 +1,30 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "arguments", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/source.vue b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/source.vue new file mode 100644 index 00000000..5717a8b8 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/source.vue @@ -0,0 +1,18 @@ + + + diff --git a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/token-ranges.json b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/token-ranges.json new file mode 100644 index 00000000..6b5b352b --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/token-ranges.json @@ -0,0 +1,85 @@ +[ + "", + "", + "\n", + "export", + " ", + "default", + " ", + "{", + "\n ", + "data", + " ", + "()", + " ", + "{", + "\n ", + "return", + " ", + "{", + "\n ", + "srcList:", + " ", + "[", + "\n ", + "\"https://github.com/vuejs.png\",", + "\n ", + "\"https://github.com/vitejs.png\"", + "\n ", + "]", + "\n ", + "}", + "\n ", + "}", + "\n", + "}", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n ", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/tree.json b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/tree.json new file mode 100644 index 00000000..3f22d76a --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/tree.json @@ -0,0 +1,138 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/ast.json new file mode 100644 index 00000000..1825f93e --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/ast.json @@ -0,0 +1,1166 @@ +{ + "type": "Program", + "start": 15, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 15, + 40 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 15, + 40 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 21, + 40 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "range": [ + 21, + 30 + ], + "name": "ariaLabel" + }, + "init": { + "type": "Literal", + "start": 33, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 33, + 40 + ], + "value": "Close", + "raw": "\"Close\"" + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 52, + 125 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 52, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 62, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 65, + 113 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 50 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 65, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 40 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 73, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 73, + 84 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "column": 10, + "line": 6 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 74, + 84 + ], + "loc": { + "start": { + "column": 11, + "line": 6 + }, + "end": { + "column": 21, + "line": 6 + } + }, + "name": "aria-label", + "rawName": "aria-label" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 74, + 84 + ], + "loc": { + "start": { + "column": 11, + "line": 6 + }, + "end": { + "column": 21, + "line": 6 + } + }, + "expression": { + "type": "Identifier", + "start": 74, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "column": 21, + "line": 6 + } + }, + "range": [ + 74, + 84 + ], + "name": "ariaLabel" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 74, + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "column": 21, + "line": 6 + } + }, + "range": [ + 74, + 84 + ], + "name": "ariaLabel" + }, + "mode": "r", + "variable": null + } + ] + } + }, + { + "type": "VAttribute", + "range": [ + 85, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 39 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 85, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "name": "id", + "rawName": "id" + }, + "value": { + "type": "VLiteral", + "range": [ + 88, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 39 + } + }, + "value": "close-button" + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 40 + }, + "end": { + "line": 6, + "column": 41 + } + }, + "value": "X" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 104, + 113 + ], + "loc": { + "start": { + "line": 6, + "column": 41 + }, + "end": { + "line": 6, + "column": 50 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 50 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 114, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + "variables": [], + "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, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 15, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 21, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": "ariaLabel" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 33, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": "\"Close\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 41, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 50, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 52, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 62, + 65 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 65, + 72 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "column": 10, + "line": 6 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 74, + 84 + ], + "loc": { + "start": { + "column": 11, + "line": 6 + }, + "end": { + "column": 21, + "line": 6 + } + }, + "value": "aria-label" + }, + { + "type": "HTMLIdentifier", + "range": [ + 85, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 22 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "value": "id" + }, + { + "type": "HTMLAssociation", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 88, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 39 + } + }, + "value": "close-button" + }, + { + "type": "HTMLTagClose", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 39 + }, + "end": { + "line": 6, + "column": 40 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 40 + }, + "end": { + "line": 6, + "column": 41 + } + }, + "value": "X" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 104, + 112 + ], + "loc": { + "start": { + "line": 6, + "column": 41 + }, + "end": { + "line": 6, + "column": 49 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 6, + "column": 49 + }, + "end": { + "line": 6, + "column": 50 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 50 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 114, + 124 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/parser-options.json b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/scope.json b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/scope.json new file mode 100644 index 00000000..b6a55688 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/scope.json @@ -0,0 +1,154 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "ariaLabel", + "identifiers": [ + { + "type": "Identifier", + "name": "ariaLabel", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "name": "ariaLabel" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "ariaLabel", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "ariaLabel", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "ariaLabel", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "ariaLabel", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "ariaLabel", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "ariaLabel", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + "init": true + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/source.vue b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/source.vue new file mode 100644 index 00000000..8ec33eb1 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/token-ranges.json b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/token-ranges.json new file mode 100644 index 00000000..da1ef87b --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/token-ranges.json @@ -0,0 +1,40 @@ +[ + "", + "", + "\n", + "const", + " ", + "ariaLabel", + " ", + "=", + " ", + "\"Close\"", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "X", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/tree.json b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/tree.json new file mode 100644 index 00000000..aca3bf7e --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/tree.json @@ -0,0 +1,99 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/ast.json new file mode 100644 index 00000000..2077a1b0 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/ast.json @@ -0,0 +1,1078 @@ +{ + "type": "Program", + "start": 15, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 15, + 36 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 15, + 36 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 21, + 36 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 21, + 26 + ], + "name": "title" + }, + "init": { + "type": "Literal", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 29, + 36 + ], + "value": "title", + "raw": "'title'" + } + } + ], + "kind": "const" + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 14 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "value": "" + } + ], + "templateBody": { + "type": "VElement", + "range": [ + 48, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 48, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 58, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 61, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 61, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 69, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 69, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "column": 10, + "line": 6 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VExpressionContainer", + "range": [ + 70, + 77 + ], + "loc": { + "start": { + "column": 11, + "line": 6 + }, + "end": { + "column": 18, + "line": 6 + } + }, + "expression": { + "type": "Identifier", + "start": 71, + "end": 76, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "range": [ + 71, + 76 + ], + "name": "title" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 71, + "end": 76, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "range": [ + 71, + 76 + ], + "name": "title" + }, + "mode": "r" + } + ] + }, + "modifiers": [] + }, + "value": null + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "value": "X" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 80, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 90, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 11 + } + } + }, + "variables": [], + "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, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 15, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "title" + }, + { + "type": "HTMLWhitespace", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 29, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "value": "'title'" + }, + { + "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, + 57 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 58, + 61 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 61, + 68 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "column": 10, + "line": 6 + }, + "end": { + "column": 11, + "line": 6 + } + }, + "value": ":" + }, + { + "type": "Punctuator", + "range": [ + 70, + 71 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 12 + } + }, + "value": "[" + }, + { + "type": "Identifier", + "value": "title", + "start": 71, + "end": 76, + "loc": { + "start": { + "line": 6, + "column": 12 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "range": [ + 71, + 76 + ] + }, + { + "type": "Punctuator", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "]" + }, + { + "type": "HTMLTagClose", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 21 + } + }, + "value": "X" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 80, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 90, + 100 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/parser-options.json b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/scope.json b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/scope.json new file mode 100644 index 00000000..eb7b762d --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/scope.json @@ -0,0 +1,154 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "title", + "identifiers": [ + { + "type": "Identifier", + "name": "title", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "name": "title" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "title", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "title", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "title", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "title", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "title", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "title", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/source.vue b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/source.vue new file mode 100644 index 00000000..9fae2ab1 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/token-ranges.json b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/token-ranges.json new file mode 100644 index 00000000..27b0500b --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/token-ranges.json @@ -0,0 +1,39 @@ +[ + "", + "", + "\n", + "const", + " ", + "title", + " ", + "=", + " ", + "'title'", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "X", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/tree.json b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/tree.json new file mode 100644 index 00000000..c5fdc90c --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/tree.json @@ -0,0 +1,78 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/variables-references.js b/test/variables-references.js index 8bd41148..e70ca530 100644 --- a/test/variables-references.js +++ b/test/variables-references.js @@ -358,3 +358,32 @@ describe("Variables of v-for and references of dynamic arguments", () => { assert(vBindKeyReferences[0].variable === variables[0]) }) }) + +describe("Variables of v-for and references of v-bind same-name shorthand", () => { + const code = '' + let variables = null + let vForReferences = null + let vBindReferences = null + + before(() => { + const ast = parse( + code, + Object.assign({ filePath: "test.vue" }, PARSER_OPTIONS), + ).ast + variables = ast.templateBody.children[0].variables + vForReferences = + ast.templateBody.children[0].startTag.attributes[0].value.references + vBindReferences = + ast.templateBody.children[0].startTag.attributes[1].value.references + }) + + it("should have relationship each other", () => { + assert(variables.length === 1) + assert(vForReferences.length === 1) + assert(vBindReferences.length === 1) + assert(variables[0].references.length === 1) + assert(variables[0].references[0] === vBindReferences[0]) + assert(vForReferences[0].variable === null) + assert(vBindReferences[0].variable === variables[0]) + }) +})