diff --git a/src/template/index.ts b/src/template/index.ts index 318b635..cdb8265 100644 --- a/src/template/index.ts +++ b/src/template/index.ts @@ -703,7 +703,7 @@ function convertForVBindSameNameShorthandValue( } // v-bind same-name shorthand (Vue 3.4+) const vId = directive.key.argument - const camelName = camelize(vId.name) + const camelName = camelize(vId.rawName) let result: ESLintExtendedProgram | null = null try { result = parseScriptFragment( diff --git a/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/ast.json b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/ast.json new file mode 100644 index 0000000..06d41c7 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/ast.json @@ -0,0 +1,968 @@ +{ + "type": "Program", + "start": 15, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 15, + 60 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 15, + 60 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 21, + 60 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "range": [ + 21, + 27 + ], + "name": "srcUrl" + }, + "init": { + "type": "Literal", + "start": 30, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "range": [ + 30, + 60 + ], + "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": [ + 72, + 110 + ], + "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": [ + 72, + 82 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 82, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 85, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "name": "img", + "rawName": "img", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 85, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 90, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 90, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 14 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "column": 7, + "line": 6 + }, + "end": { + "column": 8, + "line": 6 + } + }, + "name": "bind", + "rawName": ":" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 91, + 97 + ], + "loc": { + "start": { + "column": 8, + "line": 6 + }, + "end": { + "column": 14, + "line": 6 + } + }, + "name": "srcurl", + "rawName": "srcUrl" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 91, + 97 + ], + "loc": { + "start": { + "column": 8, + "line": 6 + }, + "end": { + "column": 14, + "line": 6 + } + }, + "expression": { + "type": "Identifier", + "start": 91, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "column": 14, + "line": 6 + } + }, + "range": [ + 91, + 97 + ], + "name": "srcUrl" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 91, + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "column": 14, + "line": 6 + } + }, + "range": [ + 91, + 97 + ], + "name": "srcUrl" + }, + "mode": "r", + "variable": null + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 99, + 110 + ], + "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, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + }, + "value": "srcUrl" + }, + { + "type": "HTMLWhitespace", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 30, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "value": "\"https://github.com/vuejs.png\"" + }, + { + "type": "HTMLWhitespace", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 61, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 70, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 72, + 81 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 82, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 85, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 6 + } + }, + "value": "img" + }, + { + "type": "Punctuator", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "column": 7, + "line": 6 + }, + "end": { + "column": 8, + "line": 6 + } + }, + "value": ":" + }, + { + "type": "HTMLIdentifier", + "range": [ + 91, + 97 + ], + "loc": { + "start": { + "column": 8, + "line": 6 + }, + "end": { + "column": 14, + "line": 6 + } + }, + "value": "srcUrl" + }, + { + "type": "HTMLTagClose", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 14 + }, + "end": { + "line": 6, + "column": 15 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 99, + 109 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 110, + 111 + ], + "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-shorthand07-camelcase/parser-options.json b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/parser-options.json new file mode 100644 index 0000000..2104ca4 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/requirements.json b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/requirements.json new file mode 100644 index 0000000..36659b1 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/scope.json b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/scope.json new file mode 100644 index 0000000..ca436a8 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/scope.json @@ -0,0 +1,154 @@ +{ + "type": "global", + "variables": [], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "srcUrl", + "identifiers": [ + { + "type": "Identifier", + "name": "srcUrl", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 45 + } + } + }, + "name": "srcUrl" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "srcUrl", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "srcUrl", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "srcUrl", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "srcUrl", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "srcUrl", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "srcUrl", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + "init": true + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/source.vue b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/source.vue new file mode 100644 index 0000000..6888a5e --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/token-ranges.json b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/token-ranges.json new file mode 100644 index 0000000..9fa6dc6 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/token-ranges.json @@ -0,0 +1,34 @@ +[ + "", + "", + "\n", + "const", + " ", + "srcUrl", + " ", + "=", + " ", + "\"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-shorthand07-camelcase/tree.json b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/tree.json new file mode 100644 index 0000000..75a9fb2 --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/tree.json @@ -0,0 +1,73 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file