From 9d3857219aa011ecf8887e36a3c8ad165aecb21b Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sun, 31 Dec 2023 08:24:36 +0900 Subject: [PATCH 01/36] chore: fix ci error for Vue 3.4 (#214) --- .../script-setup-with-typescript-eslint/package.json | 2 +- .../integrations/script-setup-with-typescript-eslint/vue.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/integrations/script-setup-with-typescript-eslint/package.json b/test/fixtures/integrations/script-setup-with-typescript-eslint/package.json index f16b529e..d9d36dfe 100644 --- a/test/fixtures/integrations/script-setup-with-typescript-eslint/package.json +++ b/test/fixtures/integrations/script-setup-with-typescript-eslint/package.json @@ -3,7 +3,7 @@ "eslint": "^8.8.0", "@typescript-eslint/parser": "^5.57.0", "@typescript-eslint/eslint-plugin": "^5.57.0", - "vue": "^3.2.47", + "vue": "^3.4.0", "typescript": "^5.0.2" } } diff --git a/test/fixtures/integrations/script-setup-with-typescript-eslint/vue.d.ts b/test/fixtures/integrations/script-setup-with-typescript-eslint/vue.d.ts index be556739..cf5931b6 100644 --- a/test/fixtures/integrations/script-setup-with-typescript-eslint/vue.d.ts +++ b/test/fixtures/integrations/script-setup-with-typescript-eslint/vue.d.ts @@ -1 +1 @@ -/// \ No newline at end of file +/// \ No newline at end of file From aa2de99765b03c706921cd0843fd219d48fb88a0 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sun, 31 Dec 2023 08:42:01 +0900 Subject: [PATCH 02/36] Add support for defineModel (#213) * Add support for defineModel * fix * fix * fix --- src/script-setup/scope-analyzer.ts | 4 +- test/fixtures/ast/define-model01/ast.json | 1067 +++++++ .../ast/define-model01/parser-options.json | 3 + .../ast/define-model01/requirements.json | 3 + test/fixtures/ast/define-model01/scope.json | 217 ++ test/fixtures/ast/define-model01/source.vue | 7 + .../ast/define-model01/token-ranges.json | 39 + test/fixtures/ast/define-model01/tree.json | 68 + .../ast/define-model02-with-type/ast.json | 1360 ++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../ast/define-model02-with-type/scope.json | 275 ++ .../ast/define-model02-with-type/source.vue | 7 + .../token-ranges.json | 50 + .../ast/define-model02-with-type/tree.json | 68 + .../ast/define-model03-with-name/ast.json | 1549 +++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../ast/define-model03-with-name/scope.json | 217 ++ .../ast/define-model03-with-name/source.vue | 8 + .../token-ranges.json | 54 + .../ast/define-model03-with-name/tree.json | 111 + .../ast.json | 2113 +++++++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 275 ++ .../source.vue | 8 + .../token-ranges.json | 76 + .../tree.json | 111 + .../define-model05-with-modifiers/ast.json | 2509 +++++++++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../define-model05-with-modifiers/scope.json | 644 ++++ .../define-model05-with-modifiers/source.vue | 14 + .../token-ranges.json | 93 + .../define-model05-with-modifiers/tree.json | 68 + .../ast/define-model06-with-ts/ast.json | 1183 +++++++ .../parser-options.json | 4 + .../define-model06-with-ts/requirements.json | 3 + .../ast/define-model06-with-ts/scope.json | 1099 +++++++ .../ast/define-model06-with-ts/source.vue | 7 + .../define-model06-with-ts/token-ranges.json | 45 + .../ast/define-model06-with-ts/tree.json | 68 + .../ast/define-model07-with-ts/ast.json | 1459 +++++++++ .../parser-options.json | 4 + .../define-model07-with-ts/requirements.json | 3 + .../ast/define-model07-with-ts/scope.json | 1099 +++++++ .../ast/define-model07-with-ts/source.vue | 7 + .../define-model07-with-ts/token-ranges.json | 56 + .../ast/define-model07-with-ts/tree.json | 68 + .../ast.json | 2800 +++++++++++++++++ .../parser-options.json | 4 + .../requirements.json | 3 + .../scope.json | 1526 +++++++++ .../source.vue | 14 + .../token-ranges.json | 109 + .../tree.json | 68 + 57 files changed, 20670 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/ast/define-model01/ast.json create mode 100644 test/fixtures/ast/define-model01/parser-options.json create mode 100644 test/fixtures/ast/define-model01/requirements.json create mode 100644 test/fixtures/ast/define-model01/scope.json create mode 100644 test/fixtures/ast/define-model01/source.vue create mode 100644 test/fixtures/ast/define-model01/token-ranges.json create mode 100644 test/fixtures/ast/define-model01/tree.json create mode 100644 test/fixtures/ast/define-model02-with-type/ast.json create mode 100644 test/fixtures/ast/define-model02-with-type/parser-options.json create mode 100644 test/fixtures/ast/define-model02-with-type/requirements.json create mode 100644 test/fixtures/ast/define-model02-with-type/scope.json create mode 100644 test/fixtures/ast/define-model02-with-type/source.vue create mode 100644 test/fixtures/ast/define-model02-with-type/token-ranges.json create mode 100644 test/fixtures/ast/define-model02-with-type/tree.json create mode 100644 test/fixtures/ast/define-model03-with-name/ast.json create mode 100644 test/fixtures/ast/define-model03-with-name/parser-options.json create mode 100644 test/fixtures/ast/define-model03-with-name/requirements.json create mode 100644 test/fixtures/ast/define-model03-with-name/scope.json create mode 100644 test/fixtures/ast/define-model03-with-name/source.vue create mode 100644 test/fixtures/ast/define-model03-with-name/token-ranges.json create mode 100644 test/fixtures/ast/define-model03-with-name/tree.json create mode 100644 test/fixtures/ast/define-model04-with-name-and-type/ast.json create mode 100644 test/fixtures/ast/define-model04-with-name-and-type/parser-options.json create mode 100644 test/fixtures/ast/define-model04-with-name-and-type/requirements.json create mode 100644 test/fixtures/ast/define-model04-with-name-and-type/scope.json create mode 100644 test/fixtures/ast/define-model04-with-name-and-type/source.vue create mode 100644 test/fixtures/ast/define-model04-with-name-and-type/token-ranges.json create mode 100644 test/fixtures/ast/define-model04-with-name-and-type/tree.json create mode 100644 test/fixtures/ast/define-model05-with-modifiers/ast.json create mode 100644 test/fixtures/ast/define-model05-with-modifiers/parser-options.json create mode 100644 test/fixtures/ast/define-model05-with-modifiers/requirements.json create mode 100644 test/fixtures/ast/define-model05-with-modifiers/scope.json create mode 100644 test/fixtures/ast/define-model05-with-modifiers/source.vue create mode 100644 test/fixtures/ast/define-model05-with-modifiers/token-ranges.json create mode 100644 test/fixtures/ast/define-model05-with-modifiers/tree.json create mode 100644 test/fixtures/ast/define-model06-with-ts/ast.json create mode 100644 test/fixtures/ast/define-model06-with-ts/parser-options.json create mode 100644 test/fixtures/ast/define-model06-with-ts/requirements.json create mode 100644 test/fixtures/ast/define-model06-with-ts/scope.json create mode 100644 test/fixtures/ast/define-model06-with-ts/source.vue create mode 100644 test/fixtures/ast/define-model06-with-ts/token-ranges.json create mode 100644 test/fixtures/ast/define-model06-with-ts/tree.json create mode 100644 test/fixtures/ast/define-model07-with-ts/ast.json create mode 100644 test/fixtures/ast/define-model07-with-ts/parser-options.json create mode 100644 test/fixtures/ast/define-model07-with-ts/requirements.json create mode 100644 test/fixtures/ast/define-model07-with-ts/scope.json create mode 100644 test/fixtures/ast/define-model07-with-ts/source.vue create mode 100644 test/fixtures/ast/define-model07-with-ts/token-ranges.json create mode 100644 test/fixtures/ast/define-model07-with-ts/tree.json create mode 100644 test/fixtures/ast/define-model08-with-ts-and-modifiers/ast.json create mode 100644 test/fixtures/ast/define-model08-with-ts-and-modifiers/parser-options.json create mode 100644 test/fixtures/ast/define-model08-with-ts-and-modifiers/requirements.json create mode 100644 test/fixtures/ast/define-model08-with-ts-and-modifiers/scope.json create mode 100644 test/fixtures/ast/define-model08-with-ts-and-modifiers/source.vue create mode 100644 test/fixtures/ast/define-model08-with-ts-and-modifiers/token-ranges.json create mode 100644 test/fixtures/ast/define-model08-with-ts-and-modifiers/tree.json diff --git a/src/script-setup/scope-analyzer.ts b/src/script-setup/scope-analyzer.ts index 46ae6cef..d20ab82b 100644 --- a/src/script-setup/scope-analyzer.ts +++ b/src/script-setup/scope-analyzer.ts @@ -87,9 +87,11 @@ const COMPILER_MACROS_AT_ROOT = new Set([ "defineEmits", "defineExpose", "withDefaults", - // Added in vue 3.3 + // Added in Vue 3.3 "defineOptions", "defineSlots", + // Added in Vue 3.4 + "defineModel", ]) /** diff --git a/test/fixtures/ast/define-model01/ast.json b/test/fixtures/ast/define-model01/ast.json new file mode 100644 index 00000000..a6e593d2 --- /dev/null +++ b/test/fixtures/ast/define-model01/ast.json @@ -0,0 +1,1067 @@ +{ + "type": "Program", + "start": 15, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 15, + 42 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 15, + 42 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 21, + 42 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 21, + 26 + ], + "name": "model" + }, + "init": { + "type": "CallExpression", + "start": 29, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 29, + 42 + ], + "callee": { + "type": "Identifier", + "start": 29, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 29, + 40 + ], + "name": "defineModel" + }, + "arguments": [], + "optional": false + } + } + ], + "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": [ + 54, + 102 + ], + "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": [ + 54, + 64 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 64, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 67, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "name": "input", + "rawName": "input", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 67, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 74, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 74, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 74, + 81 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "name": "model", + "rawName": "model" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 82, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 83, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "range": [ + 83, + 88 + ], + "name": "model" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 83, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "range": [ + 83, + 88 + ], + "name": "model" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 91, + 102 + ], + "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": "model" + }, + { + "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, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "value": "defineModel()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 43, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 52, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 54, + 63 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 64, + 67 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 67, + 73 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "input" + }, + { + "type": "HTMLIdentifier", + "range": [ + 74, + 81 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "value": "v-model" + }, + { + "type": "HTMLAssociation", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "model", + "start": 83, + "end": 88, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "range": [ + 83, + 88 + ] + }, + { + "type": "Punctuator", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 91, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "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/define-model01/parser-options.json b/test/fixtures/ast/define-model01/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/define-model01/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/define-model01/requirements.json b/test/fixtures/ast/define-model01/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model01/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model01/scope.json b/test/fixtures/ast/define-model01/scope.json new file mode 100644 index 00000000..2c12dbf9 --- /dev/null +++ b/test/fixtures/ast/define-model01/scope.json @@ -0,0 +1,217 @@ +{ + "type": "global", + "variables": [ + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "model", + "identifiers": [ + { + "type": "Identifier", + "name": "model", + "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": 27 + } + } + }, + "name": "model" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model01/source.vue b/test/fixtures/ast/define-model01/source.vue new file mode 100644 index 00000000..c218c848 --- /dev/null +++ b/test/fixtures/ast/define-model01/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/define-model01/token-ranges.json b/test/fixtures/ast/define-model01/token-ranges.json new file mode 100644 index 00000000..437fe645 --- /dev/null +++ b/test/fixtures/ast/define-model01/token-ranges.json @@ -0,0 +1,39 @@ +[ + "", + "", + "\n", + "const", + " ", + "model", + " ", + "=", + " ", + "defineModel()", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model01/tree.json b/test/fixtures/ast/define-model01/tree.json new file mode 100644 index 00000000..29e6678f --- /dev/null +++ b/test/fixtures/ast/define-model01/tree.json @@ -0,0 +1,68 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model02-with-type/ast.json b/test/fixtures/ast/define-model02-with-type/ast.json new file mode 100644 index 00000000..0cfec54a --- /dev/null +++ b/test/fixtures/ast/define-model02-with-type/ast.json @@ -0,0 +1,1360 @@ +{ + "type": "Program", + "start": 15, + "end": 58, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 15, + 58 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 58, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 15, + 58 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 58, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 21, + 58 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 21, + 26 + ], + "name": "model" + }, + "init": { + "type": "CallExpression", + "start": 29, + "end": 58, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 29, + 58 + ], + "callee": { + "type": "Identifier", + "start": 29, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 29, + 40 + ], + "name": "defineModel" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 41, + "end": 57, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 41, + 57 + ], + "properties": [ + { + "type": "Property", + "start": 43, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 43, + 55 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 43, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 43, + 47 + ], + "name": "type" + }, + "value": { + "type": "Identifier", + "start": 49, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 49, + 55 + ], + "name": "String" + }, + "kind": "init" + } + ] + } + ], + "optional": false + } + } + ], + "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": [ + 70, + 118 + ], + "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": [ + 70, + 80 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 80, + 83 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 83, + 106 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "name": "input", + "rawName": "input", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 83, + 106 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 90, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 90, + 97 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 90, + 97 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "name": "model", + "rawName": "model" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 98, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 99, + "end": 104, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "range": [ + 99, + 104 + ], + "name": "model" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 99, + "end": 104, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "range": [ + 99, + 104 + ], + "name": "model" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 107, + 118 + ], + "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": "model" + }, + { + "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, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "value": "defineModel({" + }, + { + "type": "HTMLWhitespace", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 43, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "value": "type:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 49, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "value": "String" + }, + { + "type": "HTMLWhitespace", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 56, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "value": "})" + }, + { + "type": "HTMLWhitespace", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 59, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 68, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 70, + 79 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 80, + 83 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 83, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "input" + }, + { + "type": "HTMLIdentifier", + "range": [ + 90, + 97 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "value": "v-model" + }, + { + "type": "HTMLAssociation", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "model", + "start": 99, + "end": 104, + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 23 + } + }, + "range": [ + 99, + 104 + ] + }, + { + "type": "Punctuator", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 23 + }, + "end": { + "line": 6, + "column": 24 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 6, + "column": 24 + }, + "end": { + "line": 6, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 106, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 107, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 119 + ], + "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/define-model02-with-type/parser-options.json b/test/fixtures/ast/define-model02-with-type/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/define-model02-with-type/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/define-model02-with-type/requirements.json b/test/fixtures/ast/define-model02-with-type/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model02-with-type/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model02-with-type/scope.json b/test/fixtures/ast/define-model02-with-type/scope.json new file mode 100644 index 00000000..d7323392 --- /dev/null +++ b/test/fixtures/ast/define-model02-with-type/scope.json @@ -0,0 +1,275 @@ +{ + "type": "global", + "variables": [ + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "model", + "identifiers": [ + { + "type": "Identifier", + "name": "model", + "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": 43 + } + } + }, + "name": "model" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "model", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "String", + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 40 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "String", + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 40 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "String", + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 40 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model02-with-type/source.vue b/test/fixtures/ast/define-model02-with-type/source.vue new file mode 100644 index 00000000..aa5714d2 --- /dev/null +++ b/test/fixtures/ast/define-model02-with-type/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/define-model02-with-type/token-ranges.json b/test/fixtures/ast/define-model02-with-type/token-ranges.json new file mode 100644 index 00000000..1373164a --- /dev/null +++ b/test/fixtures/ast/define-model02-with-type/token-ranges.json @@ -0,0 +1,50 @@ +[ + "", + "", + "\n", + "const", + " ", + "model", + " ", + "=", + " ", + "defineModel({", + " ", + "type:", + " ", + "String", + " ", + "})", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model02-with-type/tree.json b/test/fixtures/ast/define-model02-with-type/tree.json new file mode 100644 index 00000000..29e6678f --- /dev/null +++ b/test/fixtures/ast/define-model02-with-type/tree.json @@ -0,0 +1,68 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model03-with-name/ast.json b/test/fixtures/ast/define-model03-with-name/ast.json new file mode 100644 index 00000000..38ff3721 --- /dev/null +++ b/test/fixtures/ast/define-model03-with-name/ast.json @@ -0,0 +1,1549 @@ +{ + "type": "Program", + "start": 15, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 15, + 47 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 15, + 47 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 19, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 19, + 47 + ], + "id": { + "type": "Identifier", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "range": [ + 19, + 24 + ], + "name": "count" + }, + "init": { + "type": "CallExpression", + "start": 27, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 27, + 47 + ], + "callee": { + "type": "Identifier", + "start": 27, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 27, + 38 + ], + "name": "defineModel" + }, + "arguments": [ + { + "type": "Literal", + "start": 39, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "range": [ + 39, + 46 + ], + "value": "count", + "raw": "'count'" + } + ], + "optional": false + } + } + ], + "kind": "let" + } + ], + "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": [ + 59, + 146 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 59, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 69, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VExpressionContainer", + "range": [ + 72, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "expression": { + "type": "Identifier", + "start": 75, + "end": 80, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "range": [ + 75, + 80 + ], + "name": "count" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 75, + "end": 80, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "range": [ + 75, + 80 + ], + "name": "count" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 83, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 86, + 134 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 50 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 86, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 33 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 94, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 94, + 100 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "column": 10, + "line": 7 + }, + "end": { + "column": 11, + "line": 7 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 95, + 100 + ], + "loc": { + "start": { + "column": 11, + "line": 7 + }, + "end": { + "column": 16, + "line": 7 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 101, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 102, + "end": 115, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "range": [ + 102, + 115 + ], + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "UpdateExpression", + "start": 108, + "end": 115, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "range": [ + 108, + 115 + ], + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "start": 108, + "end": 113, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "range": [ + 108, + 113 + ], + "name": "count" + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 108, + "end": 113, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "range": [ + 108, + 113 + ], + "name": "count" + }, + "mode": "rw" + } + ] + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 117, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 33 + }, + "end": { + "line": 7, + "column": 41 + } + }, + "value": "Click Me" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 125, + 134 + ], + "loc": { + "start": { + "line": 7, + "column": 41 + }, + "end": { + "line": 7, + "column": 50 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 50 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 135, + 146 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "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, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 3 + } + }, + "value": "let" + }, + { + "type": "HTMLWhitespace", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 19, + 24 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "value": "count" + }, + { + "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, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "value": "defineModel('count')" + }, + { + "type": "HTMLWhitespace", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 48, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 59 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 59, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 69, + 72 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VExpressionStart", + "range": [ + 72, + 74 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "count", + "start": 75, + "end": 80, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "range": [ + 75, + 80 + ] + }, + { + "type": "VExpressionEnd", + "range": [ + 81, + 83 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 86, + 93 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 94, + 95 + ], + "loc": { + "start": { + "column": 10, + "line": 7 + }, + "end": { + "column": 11, + "line": 7 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 95, + 100 + ], + "loc": { + "start": { + "column": 11, + "line": 7 + }, + "end": { + "column": 16, + "line": 7 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "value": "(", + "start": 102, + "end": 103, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "range": [ + 102, + 103 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 103, + "end": 104, + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "range": [ + 103, + 104 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "start": 105, + "end": 107, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "range": [ + 105, + 107 + ] + }, + { + "type": "Identifier", + "value": "count", + "start": 108, + "end": 113, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "range": [ + 108, + 113 + ] + }, + { + "type": "Punctuator", + "value": "++", + "start": 113, + "end": 115, + "loc": { + "start": { + "line": 7, + "column": 29 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "range": [ + 113, + 115 + ] + }, + { + "type": "Punctuator", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 33 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 117, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 33 + }, + "end": { + "line": 7, + "column": 38 + } + }, + "value": "Click" + }, + { + "type": "HTMLWhitespace", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 123, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 39 + }, + "end": { + "line": 7, + "column": 41 + } + }, + "value": "Me" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 125, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 41 + }, + "end": { + "line": 7, + "column": 49 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 7, + "column": 49 + }, + "end": { + "line": 7, + "column": 50 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 50 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 135, + 145 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 145, + 146 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model03-with-name/parser-options.json b/test/fixtures/ast/define-model03-with-name/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/define-model03-with-name/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/define-model03-with-name/requirements.json b/test/fixtures/ast/define-model03-with-name/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model03-with-name/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model03-with-name/scope.json b/test/fixtures/ast/define-model03-with-name/scope.json new file mode 100644 index 00000000..a4545126 --- /dev/null +++ b/test/fixtures/ast/define-model03-with-name/scope.json @@ -0,0 +1,217 @@ +{ + "type": "global", + "variables": [ + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "count", + "identifiers": [ + { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "name": "count" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model03-with-name/source.vue b/test/fixtures/ast/define-model03-with-name/source.vue new file mode 100644 index 00000000..df47bdf9 --- /dev/null +++ b/test/fixtures/ast/define-model03-with-name/source.vue @@ -0,0 +1,8 @@ + + + diff --git a/test/fixtures/ast/define-model03-with-name/token-ranges.json b/test/fixtures/ast/define-model03-with-name/token-ranges.json new file mode 100644 index 00000000..666dde32 --- /dev/null +++ b/test/fixtures/ast/define-model03-with-name/token-ranges.json @@ -0,0 +1,54 @@ +[ + "", + "", + "\n", + "let", + " ", + "count", + " ", + "=", + " ", + "defineModel('count')", + "\n", + "", + "\n\n", + "", + "\n ", + "{{", + "count", + "}}", + "\n ", + "", + "count", + "++", + "\"", + ">", + "Click", + " ", + "Me", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model03-with-name/tree.json b/test/fixtures/ast/define-model03-with-name/tree.json new file mode 100644 index 00000000..f4127339 --- /dev/null +++ b/test/fixtures/ast/define-model03-with-name/tree.json @@ -0,0 +1,111 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model04-with-name-and-type/ast.json b/test/fixtures/ast/define-model04-with-name-and-type/ast.json new file mode 100644 index 00000000..d1ebf275 --- /dev/null +++ b/test/fixtures/ast/define-model04-with-name-and-type/ast.json @@ -0,0 +1,2113 @@ +{ + "type": "Program", + "start": 15, + "end": 79, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 64 + } + }, + "range": [ + 15, + 79 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 79, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 64 + } + }, + "range": [ + 15, + 79 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 79, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 64 + } + }, + "range": [ + 21, + 79 + ], + "id": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "range": [ + 21, + 26 + ], + "name": "count" + }, + "init": { + "type": "CallExpression", + "start": 29, + "end": 79, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 64 + } + }, + "range": [ + 29, + 79 + ], + "callee": { + "type": "Identifier", + "start": 29, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 29, + 40 + ], + "name": "defineModel" + }, + "arguments": [ + { + "type": "Literal", + "start": 41, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 41, + 48 + ], + "value": "count", + "raw": "'count'" + }, + { + "type": "ObjectExpression", + "start": 50, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "range": [ + 50, + 78 + ], + "properties": [ + { + "type": "Property", + "start": 52, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 52, + 64 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 52, + "end": 56, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 52, + 56 + ], + "name": "type" + }, + "value": { + "type": "Identifier", + "start": 58, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 58, + 64 + ], + "name": "Number" + }, + "kind": "init" + }, + { + "type": "Property", + "start": 66, + "end": 76, + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 2, + "column": 61 + } + }, + "range": [ + 66, + 76 + ], + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 66, + "end": 73, + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 2, + "column": 58 + } + }, + "range": [ + 66, + 73 + ], + "name": "default" + }, + "value": { + "type": "Literal", + "start": 75, + "end": 76, + "loc": { + "start": { + "line": 2, + "column": 60 + }, + "end": { + "line": 2, + "column": 61 + } + }, + "range": [ + 75, + 76 + ], + "value": 0, + "raw": "0" + }, + "kind": "init" + } + ] + } + ], + "optional": false + } + } + ], + "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": [ + 91, + 178 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 91, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 101, + 104 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VExpressionContainer", + "range": [ + 104, + 115 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "expression": { + "type": "Identifier", + "start": 107, + "end": 112, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "range": [ + 107, + 112 + ], + "name": "count" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 107, + "end": 112, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "range": [ + 107, + 112 + ], + "name": "count" + }, + "mode": "r" + } + ] + }, + { + "type": "VText", + "range": [ + 115, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 118, + 166 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 50 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 118, + 149 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 33 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 126, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 126, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "column": 10, + "line": 7 + }, + "end": { + "column": 11, + "line": 7 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 127, + 132 + ], + "loc": { + "start": { + "column": 11, + "line": 7 + }, + "end": { + "column": 16, + "line": 7 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 133, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 134, + "end": 147, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "range": [ + 134, + 147 + ], + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "UpdateExpression", + "start": 140, + "end": 147, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "range": [ + 140, + 147 + ], + "operator": "++", + "prefix": false, + "argument": { + "type": "Identifier", + "start": 140, + "end": 145, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "range": [ + 140, + 145 + ], + "name": "count" + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 140, + "end": 145, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "range": [ + 140, + 145 + ], + "name": "count" + }, + "mode": "rw" + } + ] + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 149, + 157 + ], + "loc": { + "start": { + "line": 7, + "column": 33 + }, + "end": { + "line": 7, + "column": 41 + } + }, + "value": "Click Me" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 157, + 166 + ], + "loc": { + "start": { + "line": 7, + "column": 41 + }, + "end": { + "line": 7, + "column": 50 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 7, + "column": 50 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 167, + 178 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "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": "count" + }, + { + "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, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "value": "defineModel('count'," + }, + { + "type": "HTMLWhitespace", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 36 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 52, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "value": "type:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 58, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "value": "Number," + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 51 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 66, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 2, + "column": 59 + } + }, + "value": "default:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 59 + }, + "end": { + "line": 2, + "column": 60 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 60 + }, + "end": { + "line": 2, + "column": 61 + } + }, + "value": "0" + }, + { + "type": "HTMLWhitespace", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 2, + "column": 61 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 77, + 79 + ], + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 2, + "column": 64 + } + }, + "value": "})" + }, + { + "type": "HTMLWhitespace", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 2, + "column": 64 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 80, + 88 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 89, + 91 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 91, + 100 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 101, + 104 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VExpressionStart", + "range": [ + 104, + 106 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "count", + "start": 107, + "end": 112, + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "range": [ + 107, + 112 + ] + }, + { + "type": "VExpressionEnd", + "range": [ + 113, + 115 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 13 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 115, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 13 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 118, + 125 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 9 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "column": 10, + "line": 7 + }, + "end": { + "column": 11, + "line": 7 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 127, + 132 + ], + "loc": { + "start": { + "column": 11, + "line": 7 + }, + "end": { + "column": 16, + "line": 7 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "value": "(", + "start": 134, + "end": 135, + "loc": { + "start": { + "line": 7, + "column": 18 + }, + "end": { + "line": 7, + "column": 19 + } + }, + "range": [ + 134, + 135 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 135, + "end": 136, + "loc": { + "start": { + "line": 7, + "column": 19 + }, + "end": { + "line": 7, + "column": 20 + } + }, + "range": [ + 135, + 136 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "start": 137, + "end": 139, + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 23 + } + }, + "range": [ + 137, + 139 + ] + }, + { + "type": "Identifier", + "value": "count", + "start": 140, + "end": 145, + "loc": { + "start": { + "line": 7, + "column": 24 + }, + "end": { + "line": 7, + "column": 29 + } + }, + "range": [ + 140, + 145 + ] + }, + { + "type": "Punctuator", + "value": "++", + "start": 145, + "end": 147, + "loc": { + "start": { + "line": 7, + "column": 29 + }, + "end": { + "line": 7, + "column": 31 + } + }, + "range": [ + 145, + 147 + ] + }, + { + "type": "Punctuator", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 33 + } + }, + "value": "" + }, + { + "type": "HTMLText", + "range": [ + 149, + 154 + ], + "loc": { + "start": { + "line": 7, + "column": 33 + }, + "end": { + "line": 7, + "column": 38 + } + }, + "value": "Click" + }, + { + "type": "HTMLWhitespace", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 7, + "column": 38 + }, + "end": { + "line": 7, + "column": 39 + } + }, + "value": " " + }, + { + "type": "HTMLText", + "range": [ + 155, + 157 + ], + "loc": { + "start": { + "line": 7, + "column": 39 + }, + "end": { + "line": 7, + "column": 41 + } + }, + "value": "Me" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 157, + 165 + ], + "loc": { + "start": { + "line": 7, + "column": 41 + }, + "end": { + "line": 7, + "column": 49 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 7, + "column": 49 + }, + "end": { + "line": 7, + "column": 50 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 7, + "column": 50 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 167, + 177 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 178, + 179 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model04-with-name-and-type/parser-options.json b/test/fixtures/ast/define-model04-with-name-and-type/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/define-model04-with-name-and-type/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/define-model04-with-name-and-type/requirements.json b/test/fixtures/ast/define-model04-with-name-and-type/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model04-with-name-and-type/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model04-with-name-and-type/scope.json b/test/fixtures/ast/define-model04-with-name-and-type/scope.json new file mode 100644 index 00000000..02fcb9fb --- /dev/null +++ b/test/fixtures/ast/define-model04-with-name-and-type/scope.json @@ -0,0 +1,275 @@ +{ + "type": "global", + "variables": [ + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "count", + "identifiers": [ + { + "type": "Identifier", + "name": "count", + "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": 64 + } + } + }, + "name": "count" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "count", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "Number", + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 49 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + "from": "module", + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "Number", + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 49 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "Number", + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 49 + } + } + }, + "from": "module", + "resolved": null, + "init": null + } + ] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model04-with-name-and-type/source.vue b/test/fixtures/ast/define-model04-with-name-and-type/source.vue new file mode 100644 index 00000000..55956bf6 --- /dev/null +++ b/test/fixtures/ast/define-model04-with-name-and-type/source.vue @@ -0,0 +1,8 @@ + + + diff --git a/test/fixtures/ast/define-model04-with-name-and-type/token-ranges.json b/test/fixtures/ast/define-model04-with-name-and-type/token-ranges.json new file mode 100644 index 00000000..9b2c7856 --- /dev/null +++ b/test/fixtures/ast/define-model04-with-name-and-type/token-ranges.json @@ -0,0 +1,76 @@ +[ + "", + "", + "\n", + "const", + " ", + "count", + " ", + "=", + " ", + "defineModel('count',", + " ", + "{", + " ", + "type:", + " ", + "Number,", + " ", + "default:", + " ", + "0", + " ", + "})", + "\n", + "", + "\n\n", + "", + "\n ", + "{{", + "count", + "}}", + "\n ", + "", + "count", + "++", + "\"", + ">", + "Click", + " ", + "Me", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model04-with-name-and-type/tree.json b/test/fixtures/ast/define-model04-with-name-and-type/tree.json new file mode 100644 index 00000000..f4127339 --- /dev/null +++ b/test/fixtures/ast/define-model04-with-name-and-type/tree.json @@ -0,0 +1,111 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model05-with-modifiers/ast.json b/test/fixtures/ast/define-model05-with-modifiers/ast.json new file mode 100644 index 00000000..fc25e5f3 --- /dev/null +++ b/test/fixtures/ast/define-model05-with-modifiers/ast.json @@ -0,0 +1,2509 @@ +{ + "type": "Program", + "start": 15, + "end": 167, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "range": [ + 15, + 167 + ], + "body": [ + { + "type": "VariableDeclaration", + "start": 15, + "end": 167, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "range": [ + 15, + 167 + ], + "declarations": [ + { + "type": "VariableDeclarator", + "start": 21, + "end": 167, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "range": [ + 21, + 167 + ], + "id": { + "type": "ArrayPattern", + "start": 21, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "range": [ + 21, + 49 + ], + "elements": [ + { + "type": "Identifier", + "start": 22, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "range": [ + 22, + 32 + ], + "name": "modelValue" + }, + { + "type": "Identifier", + "start": 34, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "range": [ + 34, + 48 + ], + "name": "modelModifiers" + } + ] + }, + "init": { + "type": "CallExpression", + "start": 52, + "end": 167, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "range": [ + 52, + 167 + ], + "callee": { + "type": "Identifier", + "start": 52, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 52, + 63 + ], + "name": "defineModel" + }, + "arguments": [ + { + "type": "ObjectExpression", + "start": 64, + "end": 166, + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "range": [ + 64, + 166 + ], + "properties": [ + { + "type": "Property", + "start": 68, + "end": 164, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "range": [ + 68, + 164 + ], + "method": true, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 68, + "end": 71, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "range": [ + 68, + 71 + ], + "name": "set" + }, + "kind": "init", + "value": { + "type": "FunctionExpression", + "start": 71, + "end": 164, + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "range": [ + 71, + 164 + ], + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 72, + "end": 77, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "range": [ + 72, + 77 + ], + "name": "value" + } + ], + "body": { + "type": "BlockStatement", + "start": 79, + "end": 164, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "range": [ + 79, + 164 + ], + "body": [ + { + "type": "IfStatement", + "start": 85, + "end": 143, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "range": [ + 85, + 143 + ], + "test": { + "type": "MemberExpression", + "start": 89, + "end": 108, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "range": [ + 89, + 108 + ], + "object": { + "type": "Identifier", + "start": 89, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "range": [ + 89, + 103 + ], + "name": "modelModifiers" + }, + "property": { + "type": "Identifier", + "start": 104, + "end": 108, + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 27 + } + }, + "range": [ + 104, + 108 + ], + "name": "trim" + }, + "computed": false, + "optional": false + }, + "consequent": { + "type": "BlockStatement", + "start": 110, + "end": 143, + "loc": { + "start": { + "line": 4, + "column": 29 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "range": [ + 110, + 143 + ], + "body": [ + { + "type": "ReturnStatement", + "start": 118, + "end": 137, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "range": [ + 118, + 137 + ], + "argument": { + "type": "CallExpression", + "start": 125, + "end": 137, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "range": [ + 125, + 137 + ], + "callee": { + "type": "MemberExpression", + "start": 125, + "end": 135, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "range": [ + 125, + 135 + ], + "object": { + "type": "Identifier", + "start": 125, + "end": 130, + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + }, + "range": [ + 125, + 130 + ], + "name": "value" + }, + "property": { + "type": "Identifier", + "start": 131, + "end": 135, + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 23 + } + }, + "range": [ + 131, + 135 + ], + "name": "trim" + }, + "computed": false, + "optional": false + }, + "arguments": [], + "optional": false + } + } + ] + }, + "alternate": null + }, + { + "type": "ReturnStatement", + "start": 148, + "end": 160, + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "range": [ + 148, + 160 + ], + "argument": { + "type": "Identifier", + "start": 155, + "end": 160, + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "range": [ + 155, + 160 + ], + "name": "value" + } + } + ] + } + } + } + ] + } + ], + "optional": false + } + } + ], + "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": [ + 179, + 232 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 179, + 189 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 189, + 192 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 192, + 220 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 30 + } + }, + "name": "input", + "rawName": "input", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 192, + 220 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 30 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 199, + 219 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 199, + 206 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 199, + 206 + ], + "loc": { + "start": { + "column": 9, + "line": 13 + }, + "end": { + "column": 16, + "line": 13 + } + }, + "name": "model", + "rawName": "model" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 207, + 219 + ], + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "start": 208, + "end": 218, + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "range": [ + 208, + 218 + ], + "name": "modelValue" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 208, + "end": 218, + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "range": [ + 208, + 218 + ], + "name": "modelValue" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 220, + 221 + ], + "loc": { + "start": { + "line": 13, + "column": 30 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 221, + 232 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "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, + 33 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "[modelValue," + }, + { + "type": "HTMLWhitespace", + "range": [ + 33, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 34, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "value": "modelModifiers]" + }, + { + "type": "HTMLWhitespace", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 36 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 52, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "value": "defineModel({" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 68 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 68, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "value": "set(value)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 78, + 79 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 79, + 80 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 80, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 85, + 87 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "value": "if" + }, + { + "type": "HTMLWhitespace", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 88, + 109 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 28 + } + }, + "value": "(modelModifiers.trim)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 4, + "column": 28 + }, + "end": { + "line": 4, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 4, + "column": 29 + }, + "end": { + "line": 4, + "column": 30 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 4, + "column": 30 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 118, + 124 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "value": "return" + }, + { + "type": "HTMLWhitespace", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 125, + 137 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "value": "value.trim()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 137, + 142 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 142, + 143 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 143, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 148, + 154 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "return" + }, + { + "type": "HTMLWhitespace", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 155, + 160 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "value": "value" + }, + { + "type": "HTMLWhitespace", + "range": [ + 160, + 163 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 163, + 164 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 164, + 165 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 165, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "})" + }, + { + "type": "HTMLWhitespace", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 168, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 179 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 179, + 188 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 188, + 189 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 189, + 192 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 192, + 198 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "input" + }, + { + "type": "HTMLIdentifier", + "range": [ + 199, + 206 + ], + "loc": { + "start": { + "column": 9, + "line": 13 + }, + "end": { + "column": 16, + "line": 13 + } + }, + "value": "v-model" + }, + { + "type": "HTMLAssociation", + "range": [ + 206, + 207 + ], + "loc": { + "start": { + "line": 13, + "column": 16 + }, + "end": { + "line": 13, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 207, + 208 + ], + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "modelValue", + "start": 208, + "end": 218, + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 28 + } + }, + "range": [ + 208, + 218 + ] + }, + { + "type": "Punctuator", + "range": [ + 218, + 219 + ], + "loc": { + "start": { + "line": 13, + "column": 28 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 219, + 220 + ], + "loc": { + "start": { + "line": 13, + "column": 29 + }, + "end": { + "line": 13, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 220, + 221 + ], + "loc": { + "start": { + "line": 13, + "column": 30 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 221, + 231 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 231, + 232 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 232, + 233 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model05-with-modifiers/parser-options.json b/test/fixtures/ast/define-model05-with-modifiers/parser-options.json new file mode 100644 index 00000000..2104ca43 --- /dev/null +++ b/test/fixtures/ast/define-model05-with-modifiers/parser-options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} diff --git a/test/fixtures/ast/define-model05-with-modifiers/requirements.json b/test/fixtures/ast/define-model05-with-modifiers/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model05-with-modifiers/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model05-with-modifiers/scope.json b/test/fixtures/ast/define-model05-with-modifiers/scope.json new file mode 100644 index 00000000..f5c1a1c9 --- /dev/null +++ b/test/fixtures/ast/define-model05-with-modifiers/scope.json @@ -0,0 +1,644 @@ +{ + "type": "global", + "variables": [ + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 48 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "modelValue", + "identifiers": [ + { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "name": "modelValue" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + }, + { + "name": "modelModifiers", + "identifiers": [ + { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "name": "modelModifiers" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + "init": null + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 48 + } + } + }, + "from": "module", + "init": null + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "arguments", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "value", + "identifiers": [ + { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "node": { + "type": "FunctionExpression", + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 8, + "column": 3 + } + } + }, + "name": "value" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "from": "block", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ], + "childScopes": [ + { + "type": "block", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "from": "block", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "from": "block", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "modelModifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 33 + } + } + }, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 48 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model05-with-modifiers/source.vue b/test/fixtures/ast/define-model05-with-modifiers/source.vue new file mode 100644 index 00000000..e51fd0e6 --- /dev/null +++ b/test/fixtures/ast/define-model05-with-modifiers/source.vue @@ -0,0 +1,14 @@ + + + diff --git a/test/fixtures/ast/define-model05-with-modifiers/token-ranges.json b/test/fixtures/ast/define-model05-with-modifiers/token-ranges.json new file mode 100644 index 00000000..b69ee4c8 --- /dev/null +++ b/test/fixtures/ast/define-model05-with-modifiers/token-ranges.json @@ -0,0 +1,93 @@ +[ + "", + "", + "\n", + "const", + " ", + "[modelValue,", + " ", + "modelModifiers]", + " ", + "=", + " ", + "defineModel({", + "\n ", + "set(value)", + " ", + "{", + "\n ", + "if", + " ", + "(modelModifiers.trim)", + " ", + "{", + "\n ", + "return", + " ", + "value.trim()", + "\n ", + "}", + "\n ", + "return", + " ", + "value", + "\n ", + "}", + "\n", + "})", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model05-with-modifiers/tree.json b/test/fixtures/ast/define-model05-with-modifiers/tree.json new file mode 100644 index 00000000..9c7ccfa3 --- /dev/null +++ b/test/fixtures/ast/define-model05-with-modifiers/tree.json @@ -0,0 +1,68 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model06-with-ts/ast.json b/test/fixtures/ast/define-model06-with-ts/ast.json new file mode 100644 index 00000000..cde9a60a --- /dev/null +++ b/test/fixtures/ast/define-model06-with-ts/ast.json @@ -0,0 +1,1183 @@ +{ + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 31, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineModel", + "range": [ + 44, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 44, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 55, + 63 + ], + "params": [ + { + "type": "TSStringKeyword", + "range": [ + 56, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 38 + } + } + } + }, + "range": [ + 31, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 40 + } + } + } + ], + "kind": "const", + "range": [ + 25, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 40 + } + } + } + ], + "sourceType": "module", + "range": [ + 25, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 77, + 130 + ], + "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": [ + 77, + 87 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 87, + 90 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 90, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "name": "input", + "rawName": "input", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 90, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 97, + 117 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 97, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 97, + 104 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "name": "model", + "rawName": "model" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 105, + 117 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 106, + 116 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 106, + 116 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 119, + 130 + ], + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLTagClose", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 25, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "modelValue" + }, + { + "type": "HTMLWhitespace", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 44, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "value": "defineModel()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 66, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 77, + 86 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 87, + 90 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 90, + 96 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "input" + }, + { + "type": "HTMLIdentifier", + "range": [ + 97, + 104 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "value": "v-model" + }, + { + "type": "HTMLAssociation", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 105, + 106 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "modelValue", + "range": [ + 106, + 116 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 119, + 129 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 130, + 131 + ], + "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/define-model06-with-ts/parser-options.json b/test/fixtures/ast/define-model06-with-ts/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/define-model06-with-ts/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/define-model06-with-ts/requirements.json b/test/fixtures/ast/define-model06-with-ts/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model06-with-ts/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model06-with-ts/scope.json b/test/fixtures/ast/define-model06-with-ts/scope.json new file mode 100644 index 00000000..ce177e84 --- /dev/null +++ b/test/fixtures/ast/define-model06-with-ts/scope.json @@ -0,0 +1,1099 @@ +{ + "type": "global", + "variables": [ + { + "name": "ClassMemberDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassMethodDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassGetterDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassSetterDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorTarget", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassFieldDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MethodDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ParameterDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Symbol", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyKey", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptorMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Object", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ObjectConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Function", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "FunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisParameterType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "OmitThisParameter", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "CallableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NewableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IArguments", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "String", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "StringConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Boolean", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BooleanConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Number", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NumberConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TemplateStringsArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportMeta", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportCallOptions", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportAssertions", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Math", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Date", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DateConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpMatchArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpExecArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExp", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Error", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "JSON", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConcatArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypedPropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructorLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Promise", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Awaited", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Partial", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Required", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Readonly", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Pick", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Record", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Exclude", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Extract", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Omit", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NonNullable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Parameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConstructorParameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReturnType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "InstanceType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uppercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Lowercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Capitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uncapitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferTypes", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataViewConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Intl", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Map", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Set", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlySet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SymbolConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorYieldResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorReturnResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Generator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyHandler", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Reflect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Atomics", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGenerator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "const", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "modelValue", + "identifiers": [ + { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 40 + } + } + }, + "name": "modelValue" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "from": "module", + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model06-with-ts/source.vue b/test/fixtures/ast/define-model06-with-ts/source.vue new file mode 100644 index 00000000..b7355420 --- /dev/null +++ b/test/fixtures/ast/define-model06-with-ts/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/define-model06-with-ts/token-ranges.json b/test/fixtures/ast/define-model06-with-ts/token-ranges.json new file mode 100644 index 00000000..17a14b43 --- /dev/null +++ b/test/fixtures/ast/define-model06-with-ts/token-ranges.json @@ -0,0 +1,45 @@ +[ + "", + "", + "\n", + "const", + " ", + "modelValue", + " ", + "=", + " ", + "defineModel()", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model06-with-ts/tree.json b/test/fixtures/ast/define-model06-with-ts/tree.json new file mode 100644 index 00000000..9c7ccfa3 --- /dev/null +++ b/test/fixtures/ast/define-model06-with-ts/tree.json @@ -0,0 +1,68 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model07-with-ts/ast.json b/test/fixtures/ast/define-model07-with-ts/ast.json new file mode 100644 index 00000000..6c22d6dd --- /dev/null +++ b/test/fixtures/ast/define-model07-with-ts/ast.json @@ -0,0 +1,1459 @@ +{ + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 31, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineModel", + "range": [ + 44, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "arguments": [ + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "required", + "range": [ + 66, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 49 + } + } + }, + "value": { + "type": "Literal", + "value": true, + "raw": "true", + "range": [ + 76, + 80 + ], + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 2, + "column": 55 + } + } + }, + "computed": false, + "method": false, + "shorthand": false, + "kind": "init", + "range": [ + 66, + 80 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 55 + } + } + } + ], + "range": [ + 64, + 82 + ], + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 57 + } + } + } + ], + "optional": false, + "range": [ + 44, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 58 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 55, + 63 + ], + "params": [ + { + "type": "TSStringKeyword", + "range": [ + 56, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 38 + } + } + } + }, + "range": [ + 31, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 58 + } + } + } + ], + "kind": "const", + "range": [ + 25, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 58 + } + } + } + ], + "sourceType": "module", + "range": [ + 25, + 84 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 95, + 148 + ], + "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": [ + 95, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 108, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "name": "input", + "rawName": "input", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 108, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 115, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "name": "model", + "rawName": "model" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 123, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 124, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 124, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 137, + 148 + ], + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLTagClose", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 25, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "modelValue" + }, + { + "type": "HTMLWhitespace", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 44, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "value": "defineModel({" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 66, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "value": "required:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 51 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 76, + 80 + ], + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 2, + "column": 55 + } + }, + "value": "true" + }, + { + "type": "HTMLWhitespace", + "range": [ + 80, + 81 + ], + "loc": { + "start": { + "line": 2, + "column": 55 + }, + "end": { + "line": 2, + "column": 56 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 81, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 56 + }, + "end": { + "line": 2, + "column": 58 + } + }, + "value": "})" + }, + { + "type": "HTMLWhitespace", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 2, + "column": 58 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 84, + 92 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 93, + 95 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 95, + 104 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 6, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 108, + 114 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "input" + }, + { + "type": "HTMLIdentifier", + "range": [ + 115, + 122 + ], + "loc": { + "start": { + "column": 9, + "line": 6 + }, + "end": { + "column": 16, + "line": 6 + } + }, + "value": "v-model" + }, + { + "type": "HTMLAssociation", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 123, + 124 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "modelValue", + "range": [ + 124, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 6, + "column": 28 + }, + "end": { + "line": 6, + "column": 29 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 137, + 147 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 148, + 149 + ], + "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/define-model07-with-ts/parser-options.json b/test/fixtures/ast/define-model07-with-ts/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/define-model07-with-ts/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/define-model07-with-ts/requirements.json b/test/fixtures/ast/define-model07-with-ts/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model07-with-ts/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model07-with-ts/scope.json b/test/fixtures/ast/define-model07-with-ts/scope.json new file mode 100644 index 00000000..d15f8bef --- /dev/null +++ b/test/fixtures/ast/define-model07-with-ts/scope.json @@ -0,0 +1,1099 @@ +{ + "type": "global", + "variables": [ + { + "name": "ClassMemberDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassMethodDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassGetterDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassSetterDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorTarget", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassFieldDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MethodDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ParameterDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Symbol", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyKey", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptorMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Object", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ObjectConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Function", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "FunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisParameterType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "OmitThisParameter", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "CallableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NewableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IArguments", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "String", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "StringConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Boolean", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BooleanConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Number", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NumberConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TemplateStringsArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportMeta", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportCallOptions", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportAssertions", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Math", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Date", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DateConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpMatchArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpExecArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExp", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Error", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "JSON", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConcatArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypedPropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructorLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Promise", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Awaited", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Partial", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Required", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Readonly", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Pick", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Record", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Exclude", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Extract", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Omit", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NonNullable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Parameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConstructorParameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReturnType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "InstanceType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uppercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Lowercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Capitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uncapitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferTypes", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataViewConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Intl", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Map", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Set", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlySet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SymbolConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorYieldResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorReturnResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Generator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyHandler", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Reflect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Atomics", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGenerator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "const", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "modelValue", + "identifiers": [ + { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 58 + } + } + }, + "name": "modelValue" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "from": "module", + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model07-with-ts/source.vue b/test/fixtures/ast/define-model07-with-ts/source.vue new file mode 100644 index 00000000..ac3ce605 --- /dev/null +++ b/test/fixtures/ast/define-model07-with-ts/source.vue @@ -0,0 +1,7 @@ + + + diff --git a/test/fixtures/ast/define-model07-with-ts/token-ranges.json b/test/fixtures/ast/define-model07-with-ts/token-ranges.json new file mode 100644 index 00000000..f74d7a0a --- /dev/null +++ b/test/fixtures/ast/define-model07-with-ts/token-ranges.json @@ -0,0 +1,56 @@ +[ + "", + "", + "\n", + "const", + " ", + "modelValue", + " ", + "=", + " ", + "defineModel({", + " ", + "required:", + " ", + "true", + " ", + "})", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model07-with-ts/tree.json b/test/fixtures/ast/define-model07-with-ts/tree.json new file mode 100644 index 00000000..9c7ccfa3 --- /dev/null +++ b/test/fixtures/ast/define-model07-with-ts/tree.json @@ -0,0 +1,68 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model08-with-ts-and-modifiers/ast.json b/test/fixtures/ast/define-model08-with-ts-and-modifiers/ast.json new file mode 100644 index 00000000..b8d7ba48 --- /dev/null +++ b/test/fixtures/ast/define-model08-with-ts-and-modifiers/ast.json @@ -0,0 +1,2800 @@ +{ + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "ArrayPattern", + "elements": [ + { + "type": "Identifier", + "name": "modelValue", + "range": [ + 32, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Identifier", + "name": "modifiers", + "range": [ + 44, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + } + ], + "range": [ + 31, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 29 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineModel", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 43 + } + } + }, + "arguments": [ + { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "set", + "range": [ + 103, + 106 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + } + }, + "value": { + "type": "FunctionExpression", + "id": null, + "generator": false, + "expression": false, + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "IfStatement", + "test": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "modifiers", + "range": [ + 124, + 133 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + "property": { + "type": "Identifier", + "name": "trim", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 124, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 22 + } + } + }, + "consequent": { + "type": "BlockStatement", + "body": [ + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "value", + "range": [ + 155, + 160 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "property": { + "type": "Identifier", + "name": "trim", + "range": [ + 161, + 165 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 155, + 165 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 23 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 155, + 167 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "range": [ + 148, + 167 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 25 + } + } + } + ], + "range": [ + 140, + 173 + ], + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + "alternate": null, + "range": [ + 120, + 173 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "value", + "range": [ + 185, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + "range": [ + 178, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 16 + } + } + } + ], + "range": [ + 114, + 194 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 8, + "column": 3 + } + } + }, + "range": [ + 106, + 194 + ], + "params": [ + { + "type": "Identifier", + "name": "value", + "range": [ + 107, + 112 + ], + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 8, + "column": 3 + } + } + }, + "computed": false, + "method": true, + "shorthand": false, + "kind": "init", + "range": [ + 103, + 194 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + } + } + ], + "range": [ + 99, + 196 + ], + "loc": { + "start": { + "line": 2, + "column": 74 + }, + "end": { + "line": 9, + "column": 1 + } + } + } + ], + "optional": false, + "range": [ + 57, + 197 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 68, + 98 + ], + "params": [ + { + "type": "TSStringKeyword", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 50 + } + } + }, + { + "type": "TSUnionType", + "types": [ + { + "type": "TSLiteralType", + "literal": { + "type": "Literal", + "value": "trim", + "raw": "'trim'", + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 52 + }, + "end": { + "line": 2, + "column": 58 + } + } + }, + "range": [ + 77, + 83 + ], + "loc": { + "start": { + "line": 2, + "column": 52 + }, + "end": { + "line": 2, + "column": 58 + } + } + }, + { + "type": "TSLiteralType", + "literal": { + "type": "Literal", + "value": "uppercase", + "raw": "'uppercase'", + "range": [ + 86, + 97 + ], + "loc": { + "start": { + "line": 2, + "column": 61 + }, + "end": { + "line": 2, + "column": 72 + } + } + }, + "range": [ + 86, + 97 + ], + "loc": { + "start": { + "line": 2, + "column": 61 + }, + "end": { + "line": 2, + "column": 72 + } + } + } + ], + "range": [ + 77, + 97 + ], + "loc": { + "start": { + "line": 2, + "column": 52 + }, + "end": { + "line": 2, + "column": 72 + } + } + } + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 73 + } + } + } + }, + "range": [ + 31, + 197 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 9, + "column": 2 + } + } + } + ], + "kind": "const", + "range": [ + 25, + 197 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + } + } + ], + "sourceType": "module", + "range": [ + 25, + 198 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 209, + 262 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 209, + 219 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 219, + 222 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 222, + 250 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 30 + } + }, + "name": "input", + "rawName": "input", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 222, + 250 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 30 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 229, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 229, + 236 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 16 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 229, + 236 + ], + "loc": { + "start": { + "column": 9, + "line": 13 + }, + "end": { + "column": 16, + "line": 13 + } + }, + "name": "model", + "rawName": "model" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 237, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "expression": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 238, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 28 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "modelValue", + "range": [ + 238, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 28 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + } + } + ] + }, + "children": [], + "endTag": null, + "variables": [] + }, + { + "type": "VText", + "range": [ + 250, + 251 + ], + "loc": { + "start": { + "line": 13, + "column": 30 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 251, + 262 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLTagClose", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 2, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 25, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 31, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "[modelValue," + }, + { + "type": "HTMLWhitespace", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 44, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": "modifiers]" + }, + { + "type": "HTMLWhitespace", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 57, + 76 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 51 + } + }, + "value": "defineModel({" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 2, + "column": 75 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 113 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "value": "set(value)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 113, + 114 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 115, + 120 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 4, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 120, + 122 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 6 + } + }, + "value": "if" + }, + { + "type": "HTMLWhitespace", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 7 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 123, + 139 + ], + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "value": "(modifiers.trim)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "value": "{" + }, + { + "type": "HTMLWhitespace", + "range": [ + 141, + 148 + ], + "loc": { + "start": { + "line": 4, + "column": 25 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 148, + 154 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "value": "return" + }, + { + "type": "HTMLWhitespace", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 155, + 167 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "value": "value.trim()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 167, + 172 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 173, + 178 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 7, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 178, + 184 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + }, + "value": "return" + }, + { + "type": "HTMLWhitespace", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 185, + 190 + ], + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + }, + "value": "value" + }, + { + "type": "HTMLWhitespace", + "range": [ + 190, + 193 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLRawText", + "range": [ + 193, + 194 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 3 + } + }, + "value": "}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 194, + 195 + ], + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 195, + 197 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "})" + }, + { + "type": "HTMLWhitespace", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 198, + 206 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 206, + 207 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 207, + 209 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 209, + 218 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 218, + 219 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 219, + 222 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 222, + 228 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "input" + }, + { + "type": "HTMLIdentifier", + "range": [ + 229, + 236 + ], + "loc": { + "start": { + "column": 9, + "line": 13 + }, + "end": { + "column": 16, + "line": 13 + } + }, + "value": "v-model" + }, + { + "type": "HTMLAssociation", + "range": [ + 236, + 237 + ], + "loc": { + "start": { + "line": 13, + "column": 16 + }, + "end": { + "line": 13, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 237, + 238 + ], + "loc": { + "start": { + "line": 13, + "column": 17 + }, + "end": { + "line": 13, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "modelValue", + "range": [ + 238, + 248 + ], + "loc": { + "start": { + "line": 13, + "column": 18 + }, + "end": { + "line": 13, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "range": [ + 248, + 249 + ], + "loc": { + "start": { + "line": 13, + "column": 28 + }, + "end": { + "line": 13, + "column": 29 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 249, + 250 + ], + "loc": { + "start": { + "line": 13, + "column": 29 + }, + "end": { + "line": 13, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 250, + 251 + ], + "loc": { + "start": { + "line": 13, + "column": 30 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 251, + 261 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 261, + 262 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 262, + 263 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model08-with-ts-and-modifiers/parser-options.json b/test/fixtures/ast/define-model08-with-ts-and-modifiers/parser-options.json new file mode 100644 index 00000000..6e1a0ab4 --- /dev/null +++ b/test/fixtures/ast/define-model08-with-ts-and-modifiers/parser-options.json @@ -0,0 +1,4 @@ +{ + "sourceType": "module", + "parser": "@typescript-eslint/parser" +} diff --git a/test/fixtures/ast/define-model08-with-ts-and-modifiers/requirements.json b/test/fixtures/ast/define-model08-with-ts-and-modifiers/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/define-model08-with-ts-and-modifiers/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model08-with-ts-and-modifiers/scope.json b/test/fixtures/ast/define-model08-with-ts-and-modifiers/scope.json new file mode 100644 index 00000000..43e387c4 --- /dev/null +++ b/test/fixtures/ast/define-model08-with-ts-and-modifiers/scope.json @@ -0,0 +1,1526 @@ +{ + "type": "global", + "variables": [ + { + "name": "ClassMemberDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassMethodDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassGetterDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassSetterDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorTarget", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassAccessorDecoratorResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassFieldDecoratorContext", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ClassDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MethodDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ParameterDecorator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Symbol", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyKey", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PropertyDescriptorMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Object", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ObjectConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Function", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "FunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisParameterType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "OmitThisParameter", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "CallableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NewableFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IArguments", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "String", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "StringConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Boolean", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "BooleanConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Number", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NumberConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TemplateStringsArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportMeta", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportCallOptions", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ImportAssertions", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Math", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Date", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DateConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpMatchArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpExecArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExp", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RegExpConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Error", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "EvalErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "RangeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReferenceErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SyntaxErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypeErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIError", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "URIErrorConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "JSON", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConcatArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "TypedPropertyDescriptor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructorLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Promise", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Awaited", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Partial", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Required", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Readonly", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Pick", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Record", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Exclude", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Extract", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Omit", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "NonNullable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Parameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ConstructorParameters", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReturnType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "InstanceType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uppercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Lowercase", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Capitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uncapitalize", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ThisType", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferTypes", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferLike", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ArrayBufferView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataView", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "DataViewConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArray", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint8ClampedArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint16ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Int32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Uint32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float32ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64Array", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Float64ArrayConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Intl", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Map", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "MapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlyMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMap", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakMapConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Set", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ReadonlySet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSet", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "WeakSetConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SymbolConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorYieldResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorReturnResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IteratorResult", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Iterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "IterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "PromiseConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Generator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "GeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyHandler", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "ProxyConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Reflect", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBuffer", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "SharedArrayBufferConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "Atomics", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterable", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncIterableIterator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGenerator", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunction", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "AsyncGeneratorFunctionConstructor", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "const", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "defineModel", + "identifiers": [], + "defs": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 43 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "modelValue", + "identifiers": [ + { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "name": "modelValue" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": null, + "vueUsedInTemplate": true + } + ] + }, + { + "name": "modifiers", + "identifiers": [ + { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "node": { + "type": "VariableDeclarator", + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 9, + "column": 2 + } + } + }, + "name": "modifiers" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + "init": null + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modelValue", + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + "from": "module", + "resolved": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + "init": true + }, + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 43 + } + } + }, + "from": "module", + "init": null + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "arguments", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "value", + "identifiers": [ + { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "node": { + "type": "FunctionExpression", + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 8, + "column": 3 + } + } + }, + "name": "value" + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "from": "block", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + "init": null + }, + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 7, + "column": 11 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ], + "childScopes": [ + { + "type": "block", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "from": "block", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 18 + } + } + }, + "from": "block", + "resolved": { + "type": "Identifier", + "name": "value", + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + "from": "function", + "resolved": { + "type": "Identifier", + "name": "modifiers", + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + "init": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "defineModel", + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 43 + } + } + }, + "from": "module", + "init": null + } + ] + } + ], + "through": [] +} \ No newline at end of file diff --git a/test/fixtures/ast/define-model08-with-ts-and-modifiers/source.vue b/test/fixtures/ast/define-model08-with-ts-and-modifiers/source.vue new file mode 100644 index 00000000..c37ba2fb --- /dev/null +++ b/test/fixtures/ast/define-model08-with-ts-and-modifiers/source.vue @@ -0,0 +1,14 @@ + + + diff --git a/test/fixtures/ast/define-model08-with-ts-and-modifiers/token-ranges.json b/test/fixtures/ast/define-model08-with-ts-and-modifiers/token-ranges.json new file mode 100644 index 00000000..ce6d9690 --- /dev/null +++ b/test/fixtures/ast/define-model08-with-ts-and-modifiers/token-ranges.json @@ -0,0 +1,109 @@ +[ + "", + "", + "\n", + "const", + " ", + "[modelValue,", + " ", + "modifiers]", + " ", + "=", + " ", + "defineModel({", + "\n ", + "set(value)", + " ", + "{", + "\n ", + "if", + " ", + "(modifiers.trim)", + " ", + "{", + "\n ", + "return", + " ", + "value.trim()", + "\n ", + "}", + "\n ", + "return", + " ", + "value", + "\n ", + "}", + "\n", + "})", + "\n", + "", + "\n\n", + "", + "\n ", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/define-model08-with-ts-and-modifiers/tree.json b/test/fixtures/ast/define-model08-with-ts-and-modifiers/tree.json new file mode 100644 index 00000000..9c7ccfa3 --- /dev/null +++ b/test/fixtures/ast/define-model08-with-ts-and-modifiers/tree.json @@ -0,0 +1,68 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file From 9dc1d993248c28d34ff9a5883c9815546130e162 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 8 Jan 2024 22:42:47 +0900 Subject: [PATCH 03/36] Add support for v-bind same-name shorthand (#215) * Add support for v-bind same-name shorthand * fix * add test * fix --- src/script-setup/scope-analyzer.ts | 10 +- src/template/index.ts | 71 + src/utils/utils.ts | 6 + .../ast/directive-shorthands/ast.json | 62 +- .../ast/directive-shorthands/tree.json | 11 + .../ast.json | 968 +++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 154 ++ .../source.vue | 7 + .../token-ranges.json | 34 + .../tree.json | 73 + .../ast.json | 1644 +++++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 30 + .../source.vue | 13 + .../token-ranges.json | 62 + .../tree.json | 73 + .../ast.json | 1736 ++++++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 154 ++ .../source.vue | 12 + .../token-ranges.json | 57 + .../tree.json | 138 + .../ast.json | 2412 +++++++++++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 30 + .../source.vue | 18 + .../token-ranges.json | 85 + .../tree.json | 138 + .../ast.json | 1166 ++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 154 ++ .../source.vue | 7 + .../token-ranges.json | 40 + .../tree.json | 99 + .../ast.json | 1078 ++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 154 ++ .../source.vue | 7 + .../token-ranges.json | 39 + .../tree.json | 78 + test/variables-references.js | 58 + 48 files changed, 10904 insertions(+), 10 deletions(-) create mode 100644 src/utils/utils.ts create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/ast.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/parser-options.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/requirements.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/scope.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/source.vue create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/token-ranges.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/tree.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand02-options/ast.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand02-options/parser-options.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand02-options/requirements.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand02-options/scope.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand02-options/source.vue create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand02-options/token-ranges.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand02-options/tree.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/ast.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/parser-options.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/requirements.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/scope.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/source.vue create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/token-ranges.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/tree.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/ast.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/parser-options.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/requirements.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/scope.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/source.vue create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/token-ranges.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/tree.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand05-kebab/ast.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand05-kebab/parser-options.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand05-kebab/requirements.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand05-kebab/scope.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand05-kebab/source.vue create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand05-kebab/token-ranges.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand05-kebab/tree.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand06-invalid/ast.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand06-invalid/parser-options.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand06-invalid/requirements.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand06-invalid/scope.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand06-invalid/source.vue create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand06-invalid/token-ranges.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand06-invalid/tree.json 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/requirements.json b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand01-script-setup/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file 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/requirements.json b/test/fixtures/ast/v-bind-same-name-shorthand02-options/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand02-options/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file 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/requirements.json b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand03-with-v-for/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file 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/requirements.json b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand04-with-v-for/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file 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/requirements.json b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand05-kebab/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file 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/requirements.json b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/requirements.json new file mode 100644 index 00000000..36659b1f --- /dev/null +++ b/test/fixtures/ast/v-bind-same-name-shorthand06-invalid/requirements.json @@ -0,0 +1,3 @@ +{ + "eslint": ">=8" +} \ No newline at end of file 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..8a43d0a3 100644 --- a/test/variables-references.js +++ b/test/variables-references.js @@ -358,3 +358,61 @@ 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]) + }) +}) + +describe("Variables of v-for and references of v-bind same-name shorthand with kebab-case", () => { + 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]) + }) +}) From 4587eef81a037ae5e48ec96de34f3adffa1d4151 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 8 Jan 2024 23:26:40 +0900 Subject: [PATCH 04/36] 9.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ed63a8b..b582d70a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-eslint-parser", - "version": "9.3.2", + "version": "9.4.0", "description": "The ESLint custom parser for `.vue` files.", "engines": { "node": "^14.17.0 || >=16.0.0" From 7b1f6a169e72895660f2ee89d44f53ac9fc43d07 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 19 Jan 2024 13:36:11 +0900 Subject: [PATCH 05/36] Update bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index f5d3f904..2c55f6c5 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -29,7 +29,7 @@ body: - type: textarea id: eslint-plugin-vue-version attributes: - label: What version of `eslint-plugin-vue` and ` vue-eslint-parser` are you using? + label: What version of `eslint-plugin-vue` and `vue-eslint-parser` are you using? value: | - vue-eslint-parser@0.0.0 - eslint-plugin-vue@0.0.0 From 18e8e17d9515d75cbbc3a9d9284a448f3eaae754 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 22 Jan 2024 11:13:39 +0900 Subject: [PATCH 06/36] test: add scope test (#219) --- scripts/update-fixtures-ast.js | 144 ++------------------------------- test/ast.js | 53 +++++------- test/test-utils.js | 140 ++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+), 172 deletions(-) create mode 100644 test/test-utils.js diff --git a/scripts/update-fixtures-ast.js b/scripts/update-fixtures-ast.js index 89905747..cb32843c 100644 --- a/scripts/update-fixtures-ast.js +++ b/scripts/update-fixtures-ast.js @@ -12,8 +12,13 @@ const fs = require("fs") const path = require("path") const parser = require("../src") -const escope = require("eslint-scope") const semver = require("semver") +const { + scopeToJSON, + analyze, + replacer, + getAllTokens, +} = require("../test/test-utils") //------------------------------------------------------------------------------ // Helpers @@ -30,40 +35,6 @@ const PARSER_OPTIONS = { eslintScopeManager: true, } -/** - * Remove `parent` proeprties from the given AST. - * @param {string} key The key. - * @param {any} value The value of the key. - * @returns {any} The value of the key to output. - */ -function replacer(key, value) { - if (key === "parent") { - return undefined - } - if (key === "errors" && Array.isArray(value)) { - return value.map((e) => ({ - message: e.message, - index: e.index, - lineNumber: e.lineNumber, - column: e.column, - })) - } - return value -} - -/** - * Get all tokens of the given AST. - * @param {ASTNode} ast The root node of AST. - * @returns {Token[]} Tokens. - */ -function getAllTokens(ast) { - const tokenArrays = [ast.tokens, ast.comments] - if (ast.templateBody != null) { - tokenArrays.push(ast.templateBody.tokens, ast.templateBody.comments) - } - return Array.prototype.concat.apply([], tokenArrays) -} - /** * Create simple tree. * @param {string} source The source code. @@ -98,109 +69,6 @@ function getTree(source, ast) { return root.children } -function scopeToJSON(scopeManager) { - return JSON.stringify(normalizeScope(scopeManager.globalScope), replacer, 4) - - function normalizeScope(scope) { - return { - type: scope.type, - variables: scope.variables.map(normalizeVar), - references: scope.references.map(normalizeReference), - childScopes: scope.childScopes.map(normalizeScope), - through: scope.through.map(normalizeReference), - } - } - - function normalizeVar(v) { - return { - name: v.name, - identifiers: v.identifiers.map(normalizeId), - defs: v.defs.map(normalizeDef), - references: v.references.map(normalizeReference), - } - } - - function normalizeReference(reference) { - return { - identifier: normalizeId(reference.identifier), - from: reference.from.type, - resolved: normalizeId( - reference.resolved && - reference.resolved.defs && - reference.resolved.defs[0] && - reference.resolved.defs[0].name, - ), - init: reference.init || null, - vueUsedInTemplate: reference.vueUsedInTemplate - ? reference.vueUsedInTemplate - : undefined, - } - } - - function normalizeDef(def) { - return { - type: def.type, - node: normalizeDefNode(def.node), - name: def.name.name, - } - } - - function normalizeId(identifier) { - return ( - identifier && { - type: identifier.type, - name: identifier.name, - loc: identifier.loc, - } - ) - } - - function normalizeDefNode(node) { - return { - type: node.type, - loc: node.loc, - } - } -} - -/** - * Analyze scope - */ -function analyze(ast, parserOptions) { - const ecmaVersion = parserOptions.ecmaVersion || 2017 - const ecmaFeatures = parserOptions.ecmaFeatures || {} - const sourceType = parserOptions.sourceType || "script" - const result = escope.analyze(ast, { - ignoreEval: true, - nodejsScope: false, - impliedStrict: ecmaFeatures.impliedStrict, - ecmaVersion, - sourceType, - fallback: getFallbackKeys, - }) - - return result - - function getFallbackKeys(node) { - return Object.keys(node).filter(fallbackKeysFilter, node) - } - - function fallbackKeysFilter(key) { - const value = null - return ( - key !== "comments" && - key !== "leadingComments" && - key !== "loc" && - key !== "parent" && - key !== "range" && - key !== "tokens" && - key !== "trailingComments" && - typeof value === "object" && - (typeof value.type === "string" || Array.isArray(value)) - ) - } -} - //------------------------------------------------------------------------------ // Main //------------------------------------------------------------------------------ diff --git a/test/ast.js b/test/ast.js index c5e946af..31bc8e36 100644 --- a/test/ast.js +++ b/test/ast.js @@ -16,6 +16,7 @@ const lodash = require("lodash") const parser = require("../src") const Linter = require("./fixtures/eslint").Linter const semver = require("semver") +const { scopeToJSON, analyze, replacer, getAllTokens } = require("./test-utils") //------------------------------------------------------------------------------ // Helpers @@ -30,40 +31,7 @@ const PARSER_OPTIONS = { loc: true, range: true, tokens: true, -} - -/** - * Remove `parent` proeprties from the given AST. - * @param {string} key The key. - * @param {any} value The value of the key. - * @returns {any} The value of the key to output. - */ -function replacer(key, value) { - if (key === "parent") { - return undefined - } - if (key === "errors" && Array.isArray(value)) { - return value.map((e) => ({ - message: e.message, - index: e.index, - lineNumber: e.lineNumber, - column: e.column, - })) - } - return value -} - -/** - * Get all tokens of the given AST. - * @param {ASTNode} ast The root node of AST. - * @returns {Token[]} Tokens. - */ -function getAllTokens(ast) { - const tokenArrays = [ast.tokens, ast.comments] - if (ast.templateBody != null) { - tokenArrays.push(ast.templateBody.tokens, ast.templateBody.comments) - } - return Array.prototype.concat.apply([], tokenArrays) + eslintScopeManager: true, } /** @@ -305,6 +273,23 @@ describe("Template AST", () => { assert.strictEqual(actualText, expectedText) }) + it("should scope in the correct.", () => { + const version = require(`eslint/package.json`).version + if (!semver.satisfies(version, ">=8")) { + return + } + const resultPath = path.join(ROOT, `${name}/scope.json`) + if (!fs.existsSync(resultPath)) { + return + } + const expectedText = fs.readFileSync(resultPath, "utf8") + const actualText = scopeToJSON( + actual.scopeManager || analyze(actual.ast, options), + ) + + assert.strictEqual(actualText, expectedText) + }) + it("should have correct parent properties.", () => { validateParent(source, parserOptions) }) diff --git a/test/test-utils.js b/test/test-utils.js new file mode 100644 index 00000000..9373502d --- /dev/null +++ b/test/test-utils.js @@ -0,0 +1,140 @@ +const escope = require("eslint-scope") + +module.exports = { replacer, getAllTokens, scopeToJSON, analyze } + +/** + * Remove `parent` properties from the given AST. + * @param {string} key The key. + * @param {any} value The value of the key. + * @returns {any} The value of the key to output. + */ +function replacer(key, value) { + if (key === "parent") { + return undefined + } + if (key === "errors" && Array.isArray(value)) { + return value.map((e) => ({ + message: e.message, + index: e.index, + lineNumber: e.lineNumber, + column: e.column, + })) + } + return value +} + +/** + * Get all tokens of the given AST. + * @param {ASTNode} ast The root node of AST. + * @returns {Token[]} Tokens. + */ +function getAllTokens(ast) { + const tokenArrays = [ast.tokens, ast.comments] + if (ast.templateBody != null) { + tokenArrays.push(ast.templateBody.tokens, ast.templateBody.comments) + } + return Array.prototype.concat.apply([], tokenArrays) +} + +function scopeToJSON(scopeManager) { + return JSON.stringify(normalizeScope(scopeManager.globalScope), replacer, 4) + + function normalizeScope(scope) { + return { + type: scope.type, + variables: scope.variables.map(normalizeVar), + references: scope.references.map(normalizeReference), + childScopes: scope.childScopes.map(normalizeScope), + through: scope.through.map(normalizeReference), + } + } + + function normalizeVar(v) { + return { + name: v.name, + identifiers: v.identifiers.map(normalizeId), + defs: v.defs.map(normalizeDef), + references: v.references.map(normalizeReference), + } + } + + function normalizeReference(reference) { + return { + identifier: normalizeId(reference.identifier), + from: reference.from.type, + resolved: normalizeId( + reference.resolved && + reference.resolved.defs && + reference.resolved.defs[0] && + reference.resolved.defs[0].name, + ), + init: reference.init || null, + vueUsedInTemplate: reference.vueUsedInTemplate + ? reference.vueUsedInTemplate + : undefined, + } + } + + function normalizeDef(def) { + return { + type: def.type, + node: normalizeDefNode(def.node), + name: def.name.name, + } + } + + function normalizeId(identifier) { + return ( + identifier && { + type: identifier.type, + name: identifier.name, + loc: identifier.loc, + } + ) + } + + function normalizeDefNode(node) { + return { + type: node.type, + loc: node.loc, + } + } +} + +/** + * Analyze scope + */ +function analyze(ast, parserOptions) { + const ecmaVersion = parserOptions.ecmaVersion || 2017 + const ecmaFeatures = parserOptions.ecmaFeatures || {} + const sourceType = parserOptions.sourceType || "script" + const result = escope.analyze(ast, { + ignoreEval: true, + nodejsScope: false, + impliedStrict: ecmaFeatures.impliedStrict, + ecmaVersion, + sourceType, + fallback: getFallbackKeys, + }) + + return result + + function getFallbackKeys(node) { + return Object.keys(node).filter(fallbackKeysFilter, node) + } + + function fallbackKeysFilter(key) { + const value = null + return ( + key !== "comments" && + key !== "leadingComments" && + key !== "loc" && + key !== "parent" && + key !== "range" && + key !== "tokens" && + key !== "trailingComments" && + typeof value === "object" && + (typeof value.type === "string" || Array.isArray(value)) + ) + } +} From d4eef648cb237f0ec4a8a5e171121fb887aab3b0 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Mon, 22 Jan 2024 10:18:24 +0800 Subject: [PATCH 07/36] fix: shorthand camelize should be used in `rawName` (#218) * fix: shorthand camelize should be used in `rawName` * test: add camelcase test * chore: update scope --- src/template/index.ts | 2 +- .../ast.json | 968 ++++++++++++++++++ .../parser-options.json | 3 + .../requirements.json | 3 + .../scope.json | 154 +++ .../source.vue | 7 + .../token-ranges.json | 34 + .../tree.json | 73 ++ 8 files changed, 1243 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/ast.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/parser-options.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/requirements.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/scope.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/source.vue create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/token-ranges.json create mode 100644 test/fixtures/ast/v-bind-same-name-shorthand07-camelcase/tree.json diff --git a/src/template/index.ts b/src/template/index.ts index 318b635c..cdb8265e 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 00000000..06d41c77 --- /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 00000000..2104ca43 --- /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 00000000..36659b1f --- /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 00000000..ca436a8c --- /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 00000000..6888a5e6 --- /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 00000000..9fa6dc66 --- /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 00000000..75a9fb2c --- /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 From f3ac447098f4258f54dca1f2b97abb30c12d79f6 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 22 Jan 2024 13:10:26 +0900 Subject: [PATCH 08/36] Fix an error when using CRLF for generic directive (#220) --- src/script/generic.ts | 30 +- src/script/index.ts | 65 +- .../ast/vue3.3-generic-4-with-spaces/ast.json | 2633 +++++++++++++ .../parser-options.json | 6 + .../vue3.3-generic-4-with-spaces/source.vue | 15 + .../token-ranges.json | 104 + .../vue3.3-generic-4-with-spaces/tree.json | 39 + .../ast/vue3.3-generic-5-with-spaces/ast.json | 2759 ++++++++++++++ .../parser-options.json | 6 + .../vue3.3-generic-5-with-spaces/source.vue | 16 + .../token-ranges.json | 111 + .../vue3.3-generic-5-with-spaces/tree.json | 39 + .../document-fragment.json | 3346 +++++++++++++++++ .../parser-options.json | 6 + .../vue3.3-generic-5-with-spaces/source.vue | 16 + .../token-ranges.json | 74 + .../vue3.3-generic-5-with-spaces/tree.json | 194 + 17 files changed, 9441 insertions(+), 18 deletions(-) create mode 100644 test/fixtures/ast/vue3.3-generic-4-with-spaces/ast.json create mode 100644 test/fixtures/ast/vue3.3-generic-4-with-spaces/parser-options.json create mode 100644 test/fixtures/ast/vue3.3-generic-4-with-spaces/source.vue create mode 100644 test/fixtures/ast/vue3.3-generic-4-with-spaces/token-ranges.json create mode 100644 test/fixtures/ast/vue3.3-generic-4-with-spaces/tree.json create mode 100644 test/fixtures/ast/vue3.3-generic-5-with-spaces/ast.json create mode 100644 test/fixtures/ast/vue3.3-generic-5-with-spaces/parser-options.json create mode 100644 test/fixtures/ast/vue3.3-generic-5-with-spaces/source.vue create mode 100644 test/fixtures/ast/vue3.3-generic-5-with-spaces/token-ranges.json create mode 100644 test/fixtures/ast/vue3.3-generic-5-with-spaces/tree.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/document-fragment.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/parser-options.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/source.vue create mode 100644 test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/token-ranges.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/tree.json diff --git a/src/script/generic.ts b/src/script/generic.ts index 97ec38d7..28ab299b 100644 --- a/src/script/generic.ts +++ b/src/script/generic.ts @@ -124,11 +124,31 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) { if (!node.constraint) { return "unknown" } - const start = node.range[0] - return rawParam.slice( - node.constraint.range[0] - start, - node.constraint.range[1] - start, - ) + let startIndex = rawParam.indexOf(node.name.name) + node.name.name.length + while (startIndex < rawParam.length) { + if (rawParam.startsWith("extends", startIndex)) { + return rawParam.slice(startIndex + 7) + } + if (rawParam.startsWith("//", startIndex)) { + const lfIndex = rawParam.indexOf("\n", startIndex) + if (lfIndex >= 0) { + startIndex = lfIndex + 1 + continue + } + return "unknown" + } + if (rawParam.startsWith("/*", startIndex)) { + const endIndex = rawParam.indexOf("*/", startIndex) + if (endIndex >= 0) { + startIndex = endIndex + 2 + continue + } + return "unknown" + } + startIndex++ + } + + return "unknown" } /** Remove variable def */ diff --git a/src/script/index.ts b/src/script/index.ts index 6bb846b1..a0e620cb 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -212,9 +212,34 @@ export function parseScriptFragment( code: string, locationCalculator: LocationCalculator, parserOptions: ParserOptions, +): ESLintExtendedProgram { + return parseScriptFragmentWithOption( + code, + locationCalculator, + parserOptions, + ) +} + +/** + * Parse the given source code. + * + * @param code The source code to parse. + * @param locationCalculator The location calculator for fixLocations. + * @param parserOptions The parser options. + * @param processOptions The process options. + * @returns The result of parsing. + */ +function parseScriptFragmentWithOption( + code: string, + locationCalculator: LocationCalculator, + parserOptions: ParserOptions, + processOptions?: { + preFixLocationProcess?: (result: ESLintExtendedProgram) => void + }, ): ESLintExtendedProgram { try { const result = parseScript(code, parserOptions) + processOptions?.preFixLocationProcess?.(result) fixLocations(result, locationCalculator) return result } catch (err) { @@ -1259,19 +1284,38 @@ export function parseGenericExpression( throwEmptyError(locationCalculator, "a type parameter") } - try { - const result = parseScriptFragment( - `void function<${code}>(){}`, - locationCalculator.getSubCalculatorShift(-14), - { ...parserOptions, project: undefined }, - ) + function getParams(result: ESLintExtendedProgram) { const { ast } = result const statement = ast.body[0] as ESLintExpressionStatement const rawExpression = statement.expression as ESLintUnaryExpression const classDecl = rawExpression.argument as ESLintClassExpression const typeParameters = (classDecl as TSESTree.ClassExpression) .typeParameters - const params = typeParameters?.params + return typeParameters?.params + } + + try { + const rawParams: string[] = [] + const scriptLet = `void function<${code}>(){}` + const result = parseScriptFragmentWithOption( + scriptLet, + locationCalculator.getSubCalculatorShift(-14), + { ...parserOptions, project: undefined }, + { + preFixLocationProcess(preResult) { + const params = getParams(preResult) + if (params) { + for (const param of params) { + rawParams.push( + scriptLet.slice(param.range[0], param.range[1]), + ) + } + } + }, + }, + ) + const { ast } = result + const params = getParams(result) if (!params || params.length === 0) { return { @@ -1300,12 +1344,7 @@ export function parseGenericExpression( loc: { start: firstParam.loc.start, end: lastParam.loc.end }, parent: DUMMY_PARENT, params, - rawParams: params.map((param) => - code.slice( - param.range[0] - typeParameters.range[0] - 1, - param.range[1] - typeParameters.range[0] - 1, - ), - ), + rawParams, } // Modify parent. diff --git a/test/fixtures/ast/vue3.3-generic-4-with-spaces/ast.json b/test/fixtures/ast/vue3.3-generic-4-with-spaces/ast.json new file mode 100644 index 00000000..401cda3f --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-4-with-spaces/ast.json @@ -0,0 +1,2633 @@ +{ + "type": "Program", + "body": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Foo", + "range": [ + 97, + 100 + ], + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "range": [ + 103, + 109 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 17 + } + } + }, + { + "type": "TSStringKeyword", + "range": [ + 112, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 26 + } + } + } + ], + "range": [ + 103, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 26 + } + } + }, + "range": [ + 92, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 26 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineProps", + "range": [ + 129, + 140 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 21 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 129, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 40 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 140, + 157 + ], + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "foo", + "range": [ + 142, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 23 + }, + "end": { + "line": 9, + "column": 26 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 9, + "column": 28 + } + }, + "range": [ + 145, + 147 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 28 + } + } + }, + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 9, + "column": 27 + }, + "end": { + "line": 9, + "column": 28 + } + } + } + }, + "range": [ + 142, + 148 + ], + "loc": { + "start": { + "line": 9, + "column": 23 + }, + "end": { + "line": 9, + "column": 29 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 149, + 152 + ], + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 33 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 9, + "column": 33 + }, + "end": { + "line": 9, + "column": 36 + } + }, + "range": [ + 152, + 155 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "U", + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 9, + "column": 35 + }, + "end": { + "line": 9, + "column": 36 + } + } + }, + "range": [ + 154, + 155 + ], + "loc": { + "start": { + "line": 9, + "column": 35 + }, + "end": { + "line": 9, + "column": 36 + } + } + } + }, + "range": [ + 149, + 155 + ], + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 36 + } + } + } + ], + "range": [ + 141, + 156 + ], + "loc": { + "start": { + "line": 9, + "column": 22 + }, + "end": { + "line": 9, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 9, + "column": 21 + }, + "end": { + "line": 9, + "column": 38 + } + } + } + }, + "range": [ + 125, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 40 + } + } + } + ], + "kind": "const", + "range": [ + 119, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 40 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 166, + 169 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 9 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "range": [ + 174, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 172, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 17 + } + } + }, + "range": [ + 166, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 17 + } + } + } + ], + "kind": "const", + "range": [ + 160, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "range": [ + 178, + 185 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 7 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "range": [ + 186, + 189 + ], + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 11 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 178, + 189 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 11 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "foo", + "range": [ + 190, + 193 + ], + "loc": { + "start": { + "line": 11, + "column": 12 + }, + "end": { + "line": 11, + "column": 15 + } + } + } + ], + "optional": false, + "range": [ + 178, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 16 + } + } + }, + "range": [ + 178, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 16 + } + } + } + ], + "sourceType": "module", + "range": [ + 92, + 195 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 91 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 205, + 235 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 205, + 215 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 215, + 216 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 216, + 223 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "expression": { + "type": "Identifier", + "name": "foo", + "range": [ + 218, + 221 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 5 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 218, + 221 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 5 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 223, + 224 + ], + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 224, + 235 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 42, + 49 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 50, + 53 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 75, + 82 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 92, + 96 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "value": "type" + }, + { + "type": "HTMLWhitespace", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 97, + 100 + ], + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 8 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 8, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 109 + ], + "loc": { + "start": { + "line": 8, + "column": 11 + }, + "end": { + "line": 8, + "column": 17 + } + }, + "value": "number" + }, + { + "type": "HTMLWhitespace", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + }, + "value": "|" + }, + { + "type": "HTMLWhitespace", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 8, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 112, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 20 + }, + "end": { + "line": 8, + "column": 26 + } + }, + "value": "string" + }, + { + "type": "HTMLWhitespace", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 8, + "column": 26 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 119, + 124 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 124, + 125 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 125, + 126 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 127, + 128 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 129, + 148 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 29 + } + }, + "value": "defineProps<{foo:T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 9, + "column": 29 + }, + "end": { + "line": 9, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 149, + 153 + ], + "loc": { + "start": { + "line": 9, + "column": 30 + }, + "end": { + "line": 9, + "column": 34 + } + }, + "value": "bar:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 153, + 154 + ], + "loc": { + "start": { + "line": 9, + "column": 34 + }, + "end": { + "line": 9, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 154, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 35 + }, + "end": { + "line": 9, + "column": 40 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 9, + "column": 40 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 160, + 165 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 166, + 169 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 170, + 171 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 171, + 172 + ], + "loc": { + "start": { + "line": 10, + "column": 11 + }, + "end": { + "line": 10, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 172, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 12 + }, + "end": { + "line": 10, + "column": 17 + } + }, + "value": "p.foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 17 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 178, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 16 + } + }, + "value": "console.log(foo)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 194, + 195 + ], + "loc": { + "start": { + "line": 11, + "column": 16 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 195, + 203 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 203, + 204 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 204, + 205 + ], + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 205, + 214 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 214, + 215 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 215, + 216 + ], + "loc": { + "start": { + "line": 13, + "column": 10 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 216, + 218 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 218, + 221 + ], + "loc": { + "start": { + "line": 14, + "column": 2 + }, + "end": { + "line": 14, + "column": 5 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 221, + 223 + ], + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 7 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 223, + 224 + ], + "loc": { + "start": { + "line": 14, + "column": 7 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 224, + 234 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 234, + 235 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "Line", + "value": " Comments", + "range": [ + 59, + 70 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + } + ], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-4-with-spaces/parser-options.json b/test/fixtures/ast/vue3.3-generic-4-with-spaces/parser-options.json new file mode 100644 index 00000000..0ead30e9 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-4-with-spaces/parser-options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "parser": { + "ts": "@typescript-eslint/parser" + } +} diff --git a/test/fixtures/ast/vue3.3-generic-4-with-spaces/source.vue b/test/fixtures/ast/vue3.3-generic-4-with-spaces/source.vue new file mode 100644 index 00000000..7b4d167f --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-4-with-spaces/source.vue @@ -0,0 +1,15 @@ + + \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-4-with-spaces/token-ranges.json b/test/fixtures/ast/vue3.3-generic-4-with-spaces/token-ranges.json new file mode 100644 index 00000000..66951b9a --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-4-with-spaces/token-ranges.json @@ -0,0 +1,104 @@ +[ + "", + "", + "\n", + "type", + " ", + "Foo", + " ", + "=", + " ", + "number", + " ", + "|", + " ", + "string", + "\n", + "const", + " ", + "p", + " ", + "=", + " ", + "defineProps<{foo:T,", + " ", + "bar:", + " ", + "U}>()", + "\n", + "const", + " ", + "foo", + " ", + "=", + " ", + "p.foo", + "\n", + "console.log(foo)", + "\n", + "", + "\n", + "", + "\n", + "{{", + "foo", + "}}", + "\n", + "", + "// Comments" +] \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-4-with-spaces/tree.json b/test/fixtures/ast/vue3.3-generic-4-with-spaces/tree.json new file mode 100644 index 00000000..eea3840c --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-4-with-spaces/tree.json @@ -0,0 +1,39 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-5-with-spaces/ast.json b/test/fixtures/ast/vue3.3-generic-5-with-spaces/ast.json new file mode 100644 index 00000000..86d3fb49 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-5-with-spaces/ast.json @@ -0,0 +1,2759 @@ +{ + "type": "Program", + "body": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Foo", + "range": [ + 147, + 150 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 8 + } + } + }, + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "range": [ + 153, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + { + "type": "TSStringKeyword", + "range": [ + 162, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 26 + } + } + } + ], + "range": [ + 153, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 26 + } + } + }, + "range": [ + 142, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 26 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineProps", + "range": [ + 179, + 190 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 21 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 179, + 209 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 40 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 190, + 207 + ], + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "foo", + "range": [ + 192, + 195 + ], + "loc": { + "start": { + "line": 10, + "column": 23 + }, + "end": { + "line": 10, + "column": 26 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 10, + "column": 26 + }, + "end": { + "line": 10, + "column": 28 + } + }, + "range": [ + 195, + 197 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 10, + "column": 27 + }, + "end": { + "line": 10, + "column": 28 + } + } + }, + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 10, + "column": 27 + }, + "end": { + "line": 10, + "column": 28 + } + } + } + }, + "range": [ + 192, + 198 + ], + "loc": { + "start": { + "line": 10, + "column": 23 + }, + "end": { + "line": 10, + "column": 29 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 199, + 202 + ], + "loc": { + "start": { + "line": 10, + "column": 30 + }, + "end": { + "line": 10, + "column": 33 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 10, + "column": 33 + }, + "end": { + "line": 10, + "column": 36 + } + }, + "range": [ + 202, + 205 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "U", + "range": [ + 204, + 205 + ], + "loc": { + "start": { + "line": 10, + "column": 35 + }, + "end": { + "line": 10, + "column": 36 + } + } + }, + "range": [ + 204, + 205 + ], + "loc": { + "start": { + "line": 10, + "column": 35 + }, + "end": { + "line": 10, + "column": 36 + } + } + } + }, + "range": [ + 199, + 205 + ], + "loc": { + "start": { + "line": 10, + "column": 30 + }, + "end": { + "line": 10, + "column": 36 + } + } + } + ], + "range": [ + 191, + 206 + ], + "loc": { + "start": { + "line": 10, + "column": 22 + }, + "end": { + "line": 10, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 10, + "column": 21 + }, + "end": { + "line": 10, + "column": 38 + } + } + } + }, + "range": [ + 175, + 209 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 40 + } + } + } + ], + "kind": "const", + "range": [ + 169, + 209 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 40 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 216, + 219 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 9 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "range": [ + 222, + 223 + ], + "loc": { + "start": { + "line": 11, + "column": 12 + }, + "end": { + "line": 11, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "range": [ + 224, + 227 + ], + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 11, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 222, + 227 + ], + "loc": { + "start": { + "line": 11, + "column": 12 + }, + "end": { + "line": 11, + "column": 17 + } + } + }, + "range": [ + 216, + 227 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 17 + } + } + } + ], + "kind": "const", + "range": [ + 210, + 227 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "range": [ + 228, + 235 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 7 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "range": [ + 236, + 239 + ], + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 11 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 228, + 239 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 11 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "foo", + "range": [ + 240, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 12 + }, + "end": { + "line": 12, + "column": 15 + } + } + } + ], + "optional": false, + "range": [ + 228, + 244 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "range": [ + 228, + 244 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 16 + } + } + } + ], + "sourceType": "module", + "range": [ + 142, + 245 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 141 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 255, + 285 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 255, + 265 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 265, + 266 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 266, + 273 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "expression": { + "type": "Identifier", + "name": "foo", + "range": [ + 268, + 271 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 5 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 268, + 271 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 5 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 273, + 274 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 274, + 285 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 54, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 62, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 106, + 113 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 118, + 124 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 124, + 128 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 128, + 134 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 136, + 137 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 141, + 142 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 142, + 146 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "type" + }, + { + "type": "HTMLWhitespace", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 147, + 150 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 151 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 151, + 152 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 152, + 153 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 153, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "value": "number" + }, + { + "type": "HTMLWhitespace", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 160, + 161 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "value": "|" + }, + { + "type": "HTMLWhitespace", + "range": [ + 161, + 162 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 162, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "value": "string" + }, + { + "type": "HTMLWhitespace", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 169, + 174 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 178, + 179 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 179, + 198 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 29 + } + }, + "value": "defineProps<{foo:T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 198, + 199 + ], + "loc": { + "start": { + "line": 10, + "column": 29 + }, + "end": { + "line": 10, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 199, + 203 + ], + "loc": { + "start": { + "line": 10, + "column": 30 + }, + "end": { + "line": 10, + "column": 34 + } + }, + "value": "bar:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 203, + 204 + ], + "loc": { + "start": { + "line": 10, + "column": 34 + }, + "end": { + "line": 10, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 204, + 209 + ], + "loc": { + "start": { + "line": 10, + "column": 35 + }, + "end": { + "line": 10, + "column": 40 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 209, + 210 + ], + "loc": { + "start": { + "line": 10, + "column": 40 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 210, + 215 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 215, + 216 + ], + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 216, + 219 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 9 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 219, + 220 + ], + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 220, + 221 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 221, + 222 + ], + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 222, + 227 + ], + "loc": { + "start": { + "line": 11, + "column": 12 + }, + "end": { + "line": 11, + "column": 17 + } + }, + "value": "p.foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 227, + 228 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 228, + 244 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 16 + } + }, + "value": "console.log(foo)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 244, + 245 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 245, + 253 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 253, + 254 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 254, + 255 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 255, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 265, + 266 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 266, + 268 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 268, + 271 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 5 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 271, + 273 + ], + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 273, + 274 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 274, + 284 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 284, + 285 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "Line", + "value": " Comments", + "range": [ + 38, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Line", + "value": " Comments", + "range": [ + 71, + 82 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " Comments ", + "range": [ + 87, + 101 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 18 + } + } + } + ], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-5-with-spaces/parser-options.json b/test/fixtures/ast/vue3.3-generic-5-with-spaces/parser-options.json new file mode 100644 index 00000000..0ead30e9 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-5-with-spaces/parser-options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "parser": { + "ts": "@typescript-eslint/parser" + } +} diff --git a/test/fixtures/ast/vue3.3-generic-5-with-spaces/source.vue b/test/fixtures/ast/vue3.3-generic-5-with-spaces/source.vue new file mode 100644 index 00000000..1ce43570 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-5-with-spaces/source.vue @@ -0,0 +1,16 @@ + + \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-5-with-spaces/token-ranges.json b/test/fixtures/ast/vue3.3-generic-5-with-spaces/token-ranges.json new file mode 100644 index 00000000..1af7d0bd --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-5-with-spaces/token-ranges.json @@ -0,0 +1,111 @@ +[ + "", + "", + "\"", + ">", + "\n", + "type", + " ", + "Foo", + " ", + "=", + " ", + "number", + " ", + "|", + " ", + "string", + "\n", + "const", + " ", + "p", + " ", + "=", + " ", + "defineProps<{foo:T,", + " ", + "bar:", + " ", + "U}>()", + "\n", + "const", + " ", + "foo", + " ", + "=", + " ", + "p.foo", + "\n", + "console.log(foo)", + "\n", + "", + "\n", + "", + "\n", + "{{", + "foo", + "}}", + "\n", + "", + "// Comments", + "// Comments", + "/* Comments */" +] \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-5-with-spaces/tree.json b/test/fixtures/ast/vue3.3-generic-5-with-spaces/tree.json new file mode 100644 index 00000000..eea3840c --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-5-with-spaces/tree.json @@ -0,0 +1,39 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/document-fragment.json b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/document-fragment.json new file mode 100644 index 00000000..27212ef2 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/document-fragment.json @@ -0,0 +1,3346 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 283 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 252 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "name": "script", + "rawName": "script", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 139 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "setup", + "rawName": "setup" + }, + "value": null + }, + { + "type": "VAttribute", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + } + }, + { + "type": "VAttribute", + "range": [ + 24, + 138 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "name": "generic", + "rawName": "generic" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 32, + 138 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "expression": { + "type": "VGenericExpression", + "range": [ + 36, + 136 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 7, + "column": 24 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + "constraint": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Foo", + "range": [ + 61, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "range": [ + 61, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "in": false, + "out": false, + "const": false, + "range": [ + 36, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "U", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + "constraint": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Record", + "range": [ + 116, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 122, + 136 + ], + "params": [ + { + "type": "TSStringKeyword", + "range": [ + 126, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 23 + } + } + }, + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + "range": [ + 116, + 136 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + "in": false, + "out": false, + "const": false, + "range": [ + 84, + 136 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 7, + "column": 24 + } + } + } + ], + "rawParams": [ + "T // extends\n extends Foo", + "U /* extends */\n extends\n Record" + ] + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "Foo", + "range": [ + 61, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + "mode": "r", + "isValueReference": false, + "isTypeReference": true + } + ] + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 139, + 243 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\ntype Foo = number | string\nconst p = defineProps<{foo:T, bar: U}>()\nconst foo = p.foo\nconsole.log(foo)\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 243, + 252 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 9 + } + } + }, + "variables": [ + { + "id": { + "type": "Identifier", + "name": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + "kind": "generic" + }, + { + "id": { + "type": "Identifier", + "name": "U", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + "kind": "generic" + } + ] + }, + { + "type": "VText", + "range": [ + 252, + 253 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VElement", + "range": [ + 253, + 283 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 253, + 263 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 263, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 264, + 271 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "expression": { + "type": "Identifier", + "name": "foo", + "range": [ + 266, + 269 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 5 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 266, + 269 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 5 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 271, + 272 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 272, + 283 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 53, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 61, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 104, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 116, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 122, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 126, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 140, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "type" + }, + { + "type": "HTMLWhitespace", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 145, + 148 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 151 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 151, + 157 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "value": "number" + }, + { + "type": "HTMLWhitespace", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 158, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "value": "|" + }, + { + "type": "HTMLWhitespace", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 160, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "value": "string" + }, + { + "type": "HTMLWhitespace", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 167, + 172 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 173, + 174 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 177, + 196 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 29 + } + }, + "value": "defineProps<{foo:T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 10, + "column": 29 + }, + "end": { + "line": 10, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 197, + 201 + ], + "loc": { + "start": { + "line": 10, + "column": 30 + }, + "end": { + "line": 10, + "column": 34 + } + }, + "value": "bar:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 10, + "column": 34 + }, + "end": { + "line": 10, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 202, + 207 + ], + "loc": { + "start": { + "line": 10, + "column": 35 + }, + "end": { + "line": 10, + "column": 40 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 207, + 208 + ], + "loc": { + "start": { + "line": 10, + "column": 40 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 208, + 213 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 214, + 217 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 9 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 218, + 219 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 219, + 220 + ], + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 220, + 225 + ], + "loc": { + "start": { + "line": 11, + "column": 12 + }, + "end": { + "line": 11, + "column": 17 + } + }, + "value": "p.foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 226, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 16 + } + }, + "value": "console.log(foo)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 242, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 243, + 251 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 251, + 252 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 252, + 253 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 253, + 262 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 262, + 263 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 263, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 264, + 266 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 266, + 269 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 5 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 269, + 271 + ], + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 271, + 272 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 272, + 282 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 282, + 283 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "Line", + "value": " extends", + "range": [ + 38, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Line", + "value": " Comments", + "range": [ + 70, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " extends ", + "range": [ + 86, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 17 + } + } + } + ], + "errors": [] + } + ], + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 53, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 61, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 84, + 85 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 104, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 116, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 122, + 126 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 126, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 7, + "column": 22 + }, + "end": { + "line": 7, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 7, + "column": 23 + }, + "end": { + "line": 7, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 139, + 140 + ], + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 140, + 144 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 4 + } + }, + "value": "type" + }, + { + "type": "HTMLWhitespace", + "range": [ + 144, + 145 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 145, + 148 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 8 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 148, + 149 + ], + "loc": { + "start": { + "line": 9, + "column": 8 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 9, + "column": 10 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 151 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 151, + 157 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 17 + } + }, + "value": "number" + }, + { + "type": "HTMLWhitespace", + "range": [ + 157, + 158 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 158, + 159 + ], + "loc": { + "start": { + "line": 9, + "column": 18 + }, + "end": { + "line": 9, + "column": 19 + } + }, + "value": "|" + }, + { + "type": "HTMLWhitespace", + "range": [ + 159, + 160 + ], + "loc": { + "start": { + "line": 9, + "column": 19 + }, + "end": { + "line": 9, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 160, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 26 + } + }, + "value": "string" + }, + { + "type": "HTMLWhitespace", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 167, + 172 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 173, + 174 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 174, + 175 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 177, + 196 + ], + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 29 + } + }, + "value": "defineProps<{foo:T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 196, + 197 + ], + "loc": { + "start": { + "line": 10, + "column": 29 + }, + "end": { + "line": 10, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 197, + 201 + ], + "loc": { + "start": { + "line": 10, + "column": 30 + }, + "end": { + "line": 10, + "column": 34 + } + }, + "value": "bar:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 201, + 202 + ], + "loc": { + "start": { + "line": 10, + "column": 34 + }, + "end": { + "line": 10, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 202, + 207 + ], + "loc": { + "start": { + "line": 10, + "column": 35 + }, + "end": { + "line": 10, + "column": 40 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 207, + 208 + ], + "loc": { + "start": { + "line": 10, + "column": 40 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 208, + 213 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 213, + 214 + ], + "loc": { + "start": { + "line": 11, + "column": 5 + }, + "end": { + "line": 11, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 214, + 217 + ], + "loc": { + "start": { + "line": 11, + "column": 6 + }, + "end": { + "line": 11, + "column": 9 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 217, + 218 + ], + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 218, + 219 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 219, + 220 + ], + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 220, + 225 + ], + "loc": { + "start": { + "line": 11, + "column": 12 + }, + "end": { + "line": 11, + "column": 17 + } + }, + "value": "p.foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 11, + "column": 17 + }, + "end": { + "line": 12, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 226, + 242 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 16 + } + }, + "value": "console.log(foo)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 242, + 243 + ], + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 13, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 243, + 251 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 251, + 252 + ], + "loc": { + "start": { + "line": 13, + "column": 8 + }, + "end": { + "line": 13, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 252, + 253 + ], + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 253, + 262 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 262, + 263 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 263, + 264 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 264, + 266 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 266, + 269 + ], + "loc": { + "start": { + "line": 15, + "column": 2 + }, + "end": { + "line": 15, + "column": 5 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 269, + 271 + ], + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 271, + 272 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 272, + 282 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 282, + 283 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "Line", + "value": " extends", + "range": [ + 38, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Line", + "value": " Comments", + "range": [ + 70, + 81 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " extends ", + "range": [ + 86, + 99 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 17 + } + } + } + ], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/parser-options.json b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/parser-options.json new file mode 100644 index 00000000..0ead30e9 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/parser-options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "parser": { + "ts": "@typescript-eslint/parser" + } +} diff --git a/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/source.vue b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/source.vue new file mode 100644 index 00000000..a5a1b5eb --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/source.vue @@ -0,0 +1,16 @@ + + \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/token-ranges.json b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/token-ranges.json new file mode 100644 index 00000000..a58b113b --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/token-ranges.json @@ -0,0 +1,74 @@ +[ + "", + "\"", + ">", + "\n", + "type", + " ", + "Foo", + " ", + "=", + " ", + "number", + " ", + "|", + " ", + "string", + "\n", + "const", + " ", + "p", + " ", + "=", + " ", + "defineProps<{foo:T,", + " ", + "bar:", + " ", + "U}>()", + "\n", + "const", + " ", + "foo", + " ", + "=", + " ", + "p.foo", + "\n", + "console.log(foo)", + "\n", + "", + "\n", + "", + "\n", + "{{", + "foo", + "}}", + "\n", + "", + "// extends", + "// Comments", + "/* extends */" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/tree.json b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/tree.json new file mode 100644 index 00000000..4e69420d --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-5-with-spaces/tree.json @@ -0,0 +1,194 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n", + "children": [ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file From 7c9c24bdf7c36a035d324608b2809c7f2ef0fc3f Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Mon, 22 Jan 2024 16:36:13 +0900 Subject: [PATCH 09/36] 9.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b582d70a..f6f5defc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-eslint-parser", - "version": "9.4.0", + "version": "9.4.1", "description": "The ESLint custom parser for `.vue` files.", "engines": { "node": "^14.17.0 || >=16.0.0" From 2b3a762573e6ea351d4caf1fadd74eee9dd25b4b Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Tue, 23 Jan 2024 08:24:36 +0900 Subject: [PATCH 10/36] Fix an error when using default for generic (#222) --- src/script/generic.ts | 33 +- .../vue3.3-generic-6-with-default/ast.json | 2975 +++++++++++++ .../parser-options.json | 6 + .../vue3.3-generic-6-with-default/source.vue | 21 + .../token-ranges.json | 123 + .../vue3.3-generic-6-with-default/tree.json | 39 + .../document-fragment.json | 3883 +++++++++++++++++ .../parser-options.json | 6 + .../vue3.3-generic-6-with-default/source.vue | 21 + .../token-ranges.json | 86 + .../vue3.3-generic-6-with-default/tree.json | 226 + 11 files changed, 7407 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/ast/vue3.3-generic-6-with-default/ast.json create mode 100644 test/fixtures/ast/vue3.3-generic-6-with-default/parser-options.json create mode 100644 test/fixtures/ast/vue3.3-generic-6-with-default/source.vue create mode 100644 test/fixtures/ast/vue3.3-generic-6-with-default/token-ranges.json create mode 100644 test/fixtures/ast/vue3.3-generic-6-with-default/tree.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-6-with-default/document-fragment.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-6-with-default/parser-options.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-6-with-default/source.vue create mode 100644 test/fixtures/document-fragment/vue3.3-generic-6-with-default/token-ranges.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-6-with-default/tree.json diff --git a/src/script/generic.ts b/src/script/generic.ts index 28ab299b..0fa1eded 100644 --- a/src/script/generic.ts +++ b/src/script/generic.ts @@ -124,31 +124,40 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) { if (!node.constraint) { return "unknown" } - let startIndex = rawParam.indexOf(node.name.name) + node.name.name.length - while (startIndex < rawParam.length) { - if (rawParam.startsWith("extends", startIndex)) { - return rawParam.slice(startIndex + 7) + let index = rawParam.indexOf(node.name.name) + node.name.name.length + let startIndex: number | null = null + while (index < rawParam.length) { + if (startIndex == null) { + if (rawParam.startsWith("extends", index)) { + startIndex = index = index + 7 + continue + } + } else if (rawParam[index] === "=") { + return rawParam.slice(startIndex, index) } - if (rawParam.startsWith("//", startIndex)) { - const lfIndex = rawParam.indexOf("\n", startIndex) + if (rawParam.startsWith("//", index)) { + const lfIndex = rawParam.indexOf("\n", index) if (lfIndex >= 0) { - startIndex = lfIndex + 1 + index = lfIndex + 1 continue } return "unknown" } - if (rawParam.startsWith("/*", startIndex)) { - const endIndex = rawParam.indexOf("*/", startIndex) + if (rawParam.startsWith("/*", index)) { + const endIndex = rawParam.indexOf("*/", index) if (endIndex >= 0) { - startIndex = endIndex + 2 + index = endIndex + 2 continue } return "unknown" } - startIndex++ + index++ + } + if (startIndex == null) { + return "unknown" } - return "unknown" + return rawParam.slice(startIndex) } /** Remove variable def */ diff --git a/test/fixtures/ast/vue3.3-generic-6-with-default/ast.json b/test/fixtures/ast/vue3.3-generic-6-with-default/ast.json new file mode 100644 index 00000000..0c366303 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-6-with-default/ast.json @@ -0,0 +1,2975 @@ +{ + "type": "Program", + "body": [ + { + "type": "TSTypeAliasDeclaration", + "id": { + "type": "Identifier", + "name": "Foo", + "range": [ + 233, + 236 + ], + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 8 + } + } + }, + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSNumberKeyword", + "range": [ + 239, + 245 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 17 + } + } + }, + { + "type": "TSStringKeyword", + "range": [ + 248, + 254 + ], + "loc": { + "start": { + "line": 14, + "column": 20 + }, + "end": { + "line": 14, + "column": 26 + } + } + } + ], + "range": [ + 239, + 254 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 26 + } + } + }, + "range": [ + 228, + 254 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 26 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 261, + 262 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineProps", + "range": [ + 265, + 276 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 21 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 265, + 295 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 40 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 276, + 293 + ], + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "foo", + "range": [ + 278, + 281 + ], + "loc": { + "start": { + "line": 15, + "column": 23 + }, + "end": { + "line": 15, + "column": 26 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 15, + "column": 26 + }, + "end": { + "line": 15, + "column": 28 + } + }, + "range": [ + 281, + 283 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "range": [ + 282, + 283 + ], + "loc": { + "start": { + "line": 15, + "column": 27 + }, + "end": { + "line": 15, + "column": 28 + } + } + }, + "range": [ + 282, + 283 + ], + "loc": { + "start": { + "line": 15, + "column": 27 + }, + "end": { + "line": 15, + "column": 28 + } + } + } + }, + "range": [ + 278, + 284 + ], + "loc": { + "start": { + "line": 15, + "column": 23 + }, + "end": { + "line": 15, + "column": 29 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 285, + 288 + ], + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 33 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 15, + "column": 33 + }, + "end": { + "line": 15, + "column": 36 + } + }, + "range": [ + 288, + 291 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "U", + "range": [ + 290, + 291 + ], + "loc": { + "start": { + "line": 15, + "column": 35 + }, + "end": { + "line": 15, + "column": 36 + } + } + }, + "range": [ + 290, + 291 + ], + "loc": { + "start": { + "line": 15, + "column": 35 + }, + "end": { + "line": 15, + "column": 36 + } + } + } + }, + "range": [ + 285, + 291 + ], + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 36 + } + } + } + ], + "range": [ + 277, + 292 + ], + "loc": { + "start": { + "line": 15, + "column": 22 + }, + "end": { + "line": 15, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 15, + "column": 21 + }, + "end": { + "line": 15, + "column": 38 + } + } + } + }, + "range": [ + 261, + 295 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 40 + } + } + } + ], + "kind": "const", + "range": [ + 255, + 295 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 40 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 302, + 305 + ], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 9 + } + } + }, + "init": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "range": [ + 308, + 309 + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "property": { + "type": "Identifier", + "name": "foo", + "range": [ + 310, + 313 + ], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 308, + 313 + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "range": [ + 302, + 313 + ], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 17 + } + } + } + ], + "kind": "const", + "range": [ + 296, + 313 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "console", + "range": [ + 314, + 321 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 7 + } + } + }, + "property": { + "type": "Identifier", + "name": "log", + "range": [ + 322, + 325 + ], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 314, + 325 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "foo", + "range": [ + 326, + 329 + ], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 15 + } + } + } + ], + "optional": false, + "range": [ + 314, + 330 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "range": [ + 314, + 330 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 16 + } + } + } + ], + "sourceType": "module", + "range": [ + 228, + 331 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 227 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 341, + 371 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 21, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 341, + 351 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 351, + 352 + ], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 352, + 359 + ], + "loc": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 20, + "column": 7 + } + }, + "expression": { + "type": "Identifier", + "name": "foo", + "range": [ + 354, + 357 + ], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 354, + 357 + ], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 359, + 360 + ], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 360, + 371 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 21, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 54, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 70, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 33 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 122, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 140, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 165, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 171, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 190, + 191 + ], + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 199, + 205 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 205, + 206 + ], + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 206, + 212 + ], + "loc": { + "start": { + "line": 12, + "column": 14 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 12, + "column": 20 + }, + "end": { + "line": 12, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 214, + 220 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 220, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 28 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 226, + 227 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 227, + 228 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 228, + 232 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "type" + }, + { + "type": "HTMLWhitespace", + "range": [ + 232, + 233 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 233, + 236 + ], + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 236, + 237 + ], + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 237, + 238 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 238, + 239 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 239, + 245 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "value": "number" + }, + { + "type": "HTMLWhitespace", + "range": [ + 245, + 246 + ], + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 246, + 247 + ], + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "value": "|" + }, + { + "type": "HTMLWhitespace", + "range": [ + 247, + 248 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 14, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 248, + 254 + ], + "loc": { + "start": { + "line": 14, + "column": 20 + }, + "end": { + "line": 14, + "column": 26 + } + }, + "value": "string" + }, + { + "type": "HTMLWhitespace", + "range": [ + 254, + 255 + ], + "loc": { + "start": { + "line": 14, + "column": 26 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 255, + 260 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 260, + 261 + ], + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 261, + 262 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 262, + 263 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 263, + 264 + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 265, + 284 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 29 + } + }, + "value": "defineProps<{foo:T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 284, + 285 + ], + "loc": { + "start": { + "line": 15, + "column": 29 + }, + "end": { + "line": 15, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 285, + 289 + ], + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "value": "bar:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 289, + 290 + ], + "loc": { + "start": { + "line": 15, + "column": 34 + }, + "end": { + "line": 15, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 290, + 295 + ], + "loc": { + "start": { + "line": 15, + "column": 35 + }, + "end": { + "line": 15, + "column": 40 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 295, + 296 + ], + "loc": { + "start": { + "line": 15, + "column": 40 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 296, + 301 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 301, + 302 + ], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 302, + 305 + ], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 9 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 305, + 306 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 306, + 307 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 307, + 308 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 308, + 313 + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 17 + } + }, + "value": "p.foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 313, + 314 + ], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 314, + 330 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 16 + } + }, + "value": "console.log(foo)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 330, + 331 + ], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 331, + 339 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 339, + 340 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 340, + 341 + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 341, + 350 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 350, + 351 + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 351, + 352 + ], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 352, + 354 + ], + "loc": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 20, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 354, + 357 + ], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 357, + 359 + ], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 7 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 359, + 360 + ], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 360, + 370 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 370, + 371 + ], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "Line", + "value": " Comments", + "range": [ + 38, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " = ", + "range": [ + 62, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Line", + "value": " Comments", + "range": [ + 88, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " extends ", + "range": [ + 104, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Block", + "value": " = ", + "range": [ + 151, + 158 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 13 + } + } + }, + { + "type": "Line", + "value": " =", + "range": [ + 173, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 18 + } + } + } + ], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-6-with-default/parser-options.json b/test/fixtures/ast/vue3.3-generic-6-with-default/parser-options.json new file mode 100644 index 00000000..0ead30e9 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-6-with-default/parser-options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "parser": { + "ts": "@typescript-eslint/parser" + } +} diff --git a/test/fixtures/ast/vue3.3-generic-6-with-default/source.vue b/test/fixtures/ast/vue3.3-generic-6-with-default/source.vue new file mode 100644 index 00000000..a0ad29c8 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-6-with-default/source.vue @@ -0,0 +1,21 @@ + + \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-6-with-default/token-ranges.json b/test/fixtures/ast/vue3.3-generic-6-with-default/token-ranges.json new file mode 100644 index 00000000..25735e17 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-6-with-default/token-ranges.json @@ -0,0 +1,123 @@ +[ + "", + "", + "=", + "Record", + "<", + "string", + ",", + "number", + ">", + "\"", + ">", + "\n", + "type", + " ", + "Foo", + " ", + "=", + " ", + "number", + " ", + "|", + " ", + "string", + "\n", + "const", + " ", + "p", + " ", + "=", + " ", + "defineProps<{foo:T,", + " ", + "bar:", + " ", + "U}>()", + "\n", + "const", + " ", + "foo", + " ", + "=", + " ", + "p.foo", + "\n", + "console.log(foo)", + "\n", + "", + "\n", + "", + "\n", + "{{", + "foo", + "}}", + "\n", + "", + "// Comments", + "/* = */", + "// Comments", + "/* extends */", + "/* = */", + "// =" +] \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-6-with-default/tree.json b/test/fixtures/ast/vue3.3-generic-6-with-default/tree.json new file mode 100644 index 00000000..eea3840c --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-6-with-default/tree.json @@ -0,0 +1,39 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-6-with-default/document-fragment.json b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/document-fragment.json new file mode 100644 index 00000000..e1fb2002 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/document-fragment.json @@ -0,0 +1,3883 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 371 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 21, + "column": 11 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 340 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 18, + "column": 9 + } + }, + "name": "script", + "rawName": "script", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 227 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "setup", + "rawName": "setup" + }, + "value": null + }, + { + "type": "VAttribute", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + } + }, + { + "type": "VAttribute", + "range": [ + 24, + 226 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 13, + "column": 1 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "name": "generic", + "rawName": "generic" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 32, + 226 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 13, + "column": 1 + } + }, + "expression": { + "type": "VGenericExpression", + "range": [ + 36, + 224 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 12, + "column": 32 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + "constraint": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Foo", + "range": [ + 70, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "range": [ + 70, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "default": { + "type": "TSNumberKeyword", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + "in": false, + "out": false, + "const": false, + "range": [ + 36, + 82 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "U", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + "constraint": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Record", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 140, + 191 + ], + "params": [ + { + "type": "TSStringKeyword", + "range": [ + 165, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + } + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + "range": [ + 134, + 191 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + "default": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "Record", + "range": [ + 199, + 205 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 13 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 205, + 224 + ], + "params": [ + { + "type": "TSStringKeyword", + "range": [ + 206, + 212 + ], + "loc": { + "start": { + "line": 12, + "column": 14 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "TSNumberKeyword", + "range": [ + 214, + 220 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + "range": [ + 199, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + "in": false, + "out": false, + "const": false, + "range": [ + 102, + 224 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 12, + "column": 32 + } + } + } + ], + "rawParams": [ + "T // Comments\n extends /* = */ Foo = number", + "U /* extends */\n extends\n Record<\n /* = */\n string, // =\n T\n >\n = Record" + ] + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "Foo", + "range": [ + 70, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + "mode": "r", + "isValueReference": false, + "isTypeReference": true + } + ] + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 227, + 331 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\ntype Foo = number | string\nconst p = defineProps<{foo:T, bar: U}>()\nconst foo = p.foo\nconsole.log(foo)\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 331, + 340 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "variables": [ + { + "id": { + "type": "Identifier", + "name": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + "kind": "generic" + }, + { + "id": { + "type": "Identifier", + "name": "U", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + "kind": "generic" + } + ] + }, + { + "type": "VText", + "range": [ + 340, + 341 + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VElement", + "range": [ + 341, + 371 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 21, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 341, + 351 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 351, + 352 + ], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 352, + 359 + ], + "loc": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 20, + "column": 7 + } + }, + "expression": { + "type": "Identifier", + "name": "foo", + "range": [ + 354, + 357 + ], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 354, + 357 + ], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 359, + 360 + ], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 360, + 371 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 21, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 54, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 70, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 33 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 122, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 140, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 165, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 171, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 190, + 191 + ], + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 199, + 205 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 205, + 206 + ], + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 206, + 212 + ], + "loc": { + "start": { + "line": 12, + "column": 14 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 12, + "column": 20 + }, + "end": { + "line": 12, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 214, + 220 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 220, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 28 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 226, + 227 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 227, + 228 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 228, + 232 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "type" + }, + { + "type": "HTMLWhitespace", + "range": [ + 232, + 233 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 233, + 236 + ], + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 236, + 237 + ], + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 237, + 238 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 238, + 239 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 239, + 245 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "value": "number" + }, + { + "type": "HTMLWhitespace", + "range": [ + 245, + 246 + ], + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 246, + 247 + ], + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "value": "|" + }, + { + "type": "HTMLWhitespace", + "range": [ + 247, + 248 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 14, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 248, + 254 + ], + "loc": { + "start": { + "line": 14, + "column": 20 + }, + "end": { + "line": 14, + "column": 26 + } + }, + "value": "string" + }, + { + "type": "HTMLWhitespace", + "range": [ + 254, + 255 + ], + "loc": { + "start": { + "line": 14, + "column": 26 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 255, + 260 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 260, + 261 + ], + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 261, + 262 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 262, + 263 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 263, + 264 + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 265, + 284 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 29 + } + }, + "value": "defineProps<{foo:T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 284, + 285 + ], + "loc": { + "start": { + "line": 15, + "column": 29 + }, + "end": { + "line": 15, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 285, + 289 + ], + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "value": "bar:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 289, + 290 + ], + "loc": { + "start": { + "line": 15, + "column": 34 + }, + "end": { + "line": 15, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 290, + 295 + ], + "loc": { + "start": { + "line": 15, + "column": 35 + }, + "end": { + "line": 15, + "column": 40 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 295, + 296 + ], + "loc": { + "start": { + "line": 15, + "column": 40 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 296, + 301 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 301, + 302 + ], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 302, + 305 + ], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 9 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 305, + 306 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 306, + 307 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 307, + 308 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 308, + 313 + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 17 + } + }, + "value": "p.foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 313, + 314 + ], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 314, + 330 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 16 + } + }, + "value": "console.log(foo)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 330, + 331 + ], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 331, + 339 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 339, + 340 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 340, + 341 + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 341, + 350 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 350, + 351 + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 351, + 352 + ], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 352, + 354 + ], + "loc": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 20, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 354, + 357 + ], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 357, + 359 + ], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 7 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 359, + 360 + ], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 360, + 370 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 370, + 371 + ], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "Line", + "value": " Comments", + "range": [ + 38, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " = ", + "range": [ + 62, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Line", + "value": " Comments", + "range": [ + 88, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " extends ", + "range": [ + 104, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Block", + "value": " = ", + "range": [ + 151, + 158 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 13 + } + } + }, + { + "type": "Line", + "value": " =", + "range": [ + 173, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 18 + } + } + } + ], + "errors": [] + } + ], + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 54, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Foo", + "range": [ + 70, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 76, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 33 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 122, + 129 + ], + "loc": { + "start": { + "line": 6, + "column": 4 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 134, + 140 + ], + "loc": { + "start": { + "line": 7, + "column": 4 + }, + "end": { + "line": 7, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 140, + 144 + ], + "loc": { + "start": { + "line": 7, + "column": 10 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 165, + 171 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 171, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 12 + }, + "end": { + "line": 9, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 184, + 185 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 190, + 191 + ], + "loc": { + "start": { + "line": 11, + "column": 4 + }, + "end": { + "line": 11, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 197, + 198 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "Record", + "range": [ + 199, + 205 + ], + "loc": { + "start": { + "line": 12, + "column": 7 + }, + "end": { + "line": 12, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 205, + 206 + ], + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 206, + 212 + ], + "loc": { + "start": { + "line": 12, + "column": 14 + }, + "end": { + "line": 12, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 212, + 213 + ], + "loc": { + "start": { + "line": 12, + "column": 20 + }, + "end": { + "line": 12, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "number", + "range": [ + 214, + 220 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 220, + 224 + ], + "loc": { + "start": { + "line": 12, + "column": 28 + }, + "end": { + "line": 12, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "range": [ + 225, + 226 + ], + "loc": { + "start": { + "line": 13, + "column": 0 + }, + "end": { + "line": 13, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 226, + 227 + ], + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 227, + 228 + ], + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 14, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 228, + 232 + ], + "loc": { + "start": { + "line": 14, + "column": 0 + }, + "end": { + "line": 14, + "column": 4 + } + }, + "value": "type" + }, + { + "type": "HTMLWhitespace", + "range": [ + 232, + 233 + ], + "loc": { + "start": { + "line": 14, + "column": 4 + }, + "end": { + "line": 14, + "column": 5 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 233, + 236 + ], + "loc": { + "start": { + "line": 14, + "column": 5 + }, + "end": { + "line": 14, + "column": 8 + } + }, + "value": "Foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 236, + 237 + ], + "loc": { + "start": { + "line": 14, + "column": 8 + }, + "end": { + "line": 14, + "column": 9 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 237, + 238 + ], + "loc": { + "start": { + "line": 14, + "column": 9 + }, + "end": { + "line": 14, + "column": 10 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 238, + 239 + ], + "loc": { + "start": { + "line": 14, + "column": 10 + }, + "end": { + "line": 14, + "column": 11 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 239, + 245 + ], + "loc": { + "start": { + "line": 14, + "column": 11 + }, + "end": { + "line": 14, + "column": 17 + } + }, + "value": "number" + }, + { + "type": "HTMLWhitespace", + "range": [ + 245, + 246 + ], + "loc": { + "start": { + "line": 14, + "column": 17 + }, + "end": { + "line": 14, + "column": 18 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 246, + 247 + ], + "loc": { + "start": { + "line": 14, + "column": 18 + }, + "end": { + "line": 14, + "column": 19 + } + }, + "value": "|" + }, + { + "type": "HTMLWhitespace", + "range": [ + 247, + 248 + ], + "loc": { + "start": { + "line": 14, + "column": 19 + }, + "end": { + "line": 14, + "column": 20 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 248, + 254 + ], + "loc": { + "start": { + "line": 14, + "column": 20 + }, + "end": { + "line": 14, + "column": 26 + } + }, + "value": "string" + }, + { + "type": "HTMLWhitespace", + "range": [ + 254, + 255 + ], + "loc": { + "start": { + "line": 14, + "column": 26 + }, + "end": { + "line": 15, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 255, + 260 + ], + "loc": { + "start": { + "line": 15, + "column": 0 + }, + "end": { + "line": 15, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 260, + 261 + ], + "loc": { + "start": { + "line": 15, + "column": 5 + }, + "end": { + "line": 15, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 261, + 262 + ], + "loc": { + "start": { + "line": 15, + "column": 6 + }, + "end": { + "line": 15, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 262, + 263 + ], + "loc": { + "start": { + "line": 15, + "column": 7 + }, + "end": { + "line": 15, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 263, + 264 + ], + "loc": { + "start": { + "line": 15, + "column": 8 + }, + "end": { + "line": 15, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 264, + 265 + ], + "loc": { + "start": { + "line": 15, + "column": 9 + }, + "end": { + "line": 15, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 265, + 284 + ], + "loc": { + "start": { + "line": 15, + "column": 10 + }, + "end": { + "line": 15, + "column": 29 + } + }, + "value": "defineProps<{foo:T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 284, + 285 + ], + "loc": { + "start": { + "line": 15, + "column": 29 + }, + "end": { + "line": 15, + "column": 30 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 285, + 289 + ], + "loc": { + "start": { + "line": 15, + "column": 30 + }, + "end": { + "line": 15, + "column": 34 + } + }, + "value": "bar:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 289, + 290 + ], + "loc": { + "start": { + "line": 15, + "column": 34 + }, + "end": { + "line": 15, + "column": 35 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 290, + 295 + ], + "loc": { + "start": { + "line": 15, + "column": 35 + }, + "end": { + "line": 15, + "column": 40 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 295, + 296 + ], + "loc": { + "start": { + "line": 15, + "column": 40 + }, + "end": { + "line": 16, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 296, + 301 + ], + "loc": { + "start": { + "line": 16, + "column": 0 + }, + "end": { + "line": 16, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 301, + 302 + ], + "loc": { + "start": { + "line": 16, + "column": 5 + }, + "end": { + "line": 16, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 302, + 305 + ], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 9 + } + }, + "value": "foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 305, + 306 + ], + "loc": { + "start": { + "line": 16, + "column": 9 + }, + "end": { + "line": 16, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 306, + 307 + ], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 307, + 308 + ], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 308, + 313 + ], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 17 + } + }, + "value": "p.foo" + }, + { + "type": "HTMLWhitespace", + "range": [ + 313, + 314 + ], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 17, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 314, + 330 + ], + "loc": { + "start": { + "line": 17, + "column": 0 + }, + "end": { + "line": 17, + "column": 16 + } + }, + "value": "console.log(foo)" + }, + { + "type": "HTMLWhitespace", + "range": [ + 330, + 331 + ], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 18, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 331, + 339 + ], + "loc": { + "start": { + "line": 18, + "column": 0 + }, + "end": { + "line": 18, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 339, + 340 + ], + "loc": { + "start": { + "line": 18, + "column": 8 + }, + "end": { + "line": 18, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 340, + 341 + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 19, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 341, + 350 + ], + "loc": { + "start": { + "line": 19, + "column": 0 + }, + "end": { + "line": 19, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 350, + 351 + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 351, + 352 + ], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 20, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 352, + 354 + ], + "loc": { + "start": { + "line": 20, + "column": 0 + }, + "end": { + "line": 20, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 354, + 357 + ], + "loc": { + "start": { + "line": 20, + "column": 2 + }, + "end": { + "line": 20, + "column": 5 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 357, + 359 + ], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 7 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 359, + 360 + ], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 21, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 360, + 370 + ], + "loc": { + "start": { + "line": 21, + "column": 0 + }, + "end": { + "line": 21, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 370, + 371 + ], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [ + { + "type": "Line", + "value": " Comments", + "range": [ + 38, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " = ", + "range": [ + 62, + 69 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Line", + "value": " Comments", + "range": [ + 88, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + { + "type": "Block", + "value": " extends ", + "range": [ + 104, + 117 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 17 + } + } + }, + { + "type": "Block", + "value": " = ", + "range": [ + 151, + 158 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 13 + } + } + }, + { + "type": "Line", + "value": " =", + "range": [ + 173, + 177 + ], + "loc": { + "start": { + "line": 9, + "column": 14 + }, + "end": { + "line": 9, + "column": 18 + } + } + } + ], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-6-with-default/parser-options.json b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/parser-options.json new file mode 100644 index 00000000..0ead30e9 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/parser-options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "parser": { + "ts": "@typescript-eslint/parser" + } +} diff --git a/test/fixtures/document-fragment/vue3.3-generic-6-with-default/source.vue b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/source.vue new file mode 100644 index 00000000..a0ad29c8 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/source.vue @@ -0,0 +1,21 @@ + + \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-6-with-default/token-ranges.json b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/token-ranges.json new file mode 100644 index 00000000..38d59219 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/token-ranges.json @@ -0,0 +1,86 @@ +[ + "", + "=", + "Record", + "<", + "string", + ",", + "number", + ">", + "\"", + ">", + "\n", + "type", + " ", + "Foo", + " ", + "=", + " ", + "number", + " ", + "|", + " ", + "string", + "\n", + "const", + " ", + "p", + " ", + "=", + " ", + "defineProps<{foo:T,", + " ", + "bar:", + " ", + "U}>()", + "\n", + "const", + " ", + "foo", + " ", + "=", + " ", + "p.foo", + "\n", + "console.log(foo)", + "\n", + "", + "\n", + "", + "\n", + "{{", + "foo", + "}}", + "\n", + "", + "// Comments", + "/* = */", + "// Comments", + "/* extends */", + "/* = */", + "// =" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-6-with-default/tree.json b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/tree.json new file mode 100644 index 00000000..2147714f --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-6-with-default/tree.json @@ -0,0 +1,226 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n", + "children": [ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file From d79bcad8fba6f9e8cc4f7282a130a2a34f646267 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Tue, 23 Jan 2024 08:28:09 +0900 Subject: [PATCH 11/36] 9.4.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f6f5defc..b055e3f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-eslint-parser", - "version": "9.4.1", + "version": "9.4.2", "description": "The ESLint custom parser for `.vue` files.", "engines": { "node": "^14.17.0 || >=16.0.0" From dbeb73ba8186a3f9e23d47da0d98baeb718f5c01 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Sat, 24 Feb 2024 18:00:24 +0900 Subject: [PATCH 12/36] chore: fix type annotation --- src/script/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/script/index.ts b/src/script/index.ts index a0e620cb..b05b2c6d 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -32,7 +32,6 @@ import type { VSlotScopeExpression, OffsetRange, VGenericExpression, - ESLintClassExpression, } from "../ast" import { ParseError } from "../ast" import { debug } from "../common/debug" @@ -1288,8 +1287,8 @@ export function parseGenericExpression( const { ast } = result const statement = ast.body[0] as ESLintExpressionStatement const rawExpression = statement.expression as ESLintUnaryExpression - const classDecl = rawExpression.argument as ESLintClassExpression - const typeParameters = (classDecl as TSESTree.ClassExpression) + const classDecl = rawExpression.argument as ESLintFunctionExpression + const typeParameters = (classDecl as TSESTree.FunctionExpression) .typeParameters return typeParameters?.params } From ae61e8d4ec3f63d848fb8689572f8c3c9118a624 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 4 Mar 2024 15:42:52 +0900 Subject: [PATCH 13/36] fix: ESLintArrowFunctionExpression.body typing (#225) --- src/ast/nodes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ast/nodes.ts b/src/ast/nodes.ts index 090f8573..5ebf7039 100644 --- a/src/ast/nodes.ts +++ b/src/ast/nodes.ts @@ -486,7 +486,7 @@ export interface ESLintArrowFunctionExpression extends HasLocation, HasParent { generator: boolean id: ESLintIdentifier | null params: ESLintPattern[] - body: ESLintBlockStatement + body: ESLintBlockStatement | ESLintExpression } export interface ESLintSequenceExpression extends HasLocation, HasParent { From 79ecf1e80afe92ab67e588d2ee44e14cd78cc1a2 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sat, 1 Jun 2024 10:00:17 +0900 Subject: [PATCH 14/36] Fix wrong AST for asycn function in v-on (#227) * Fix wrong AST for asycn function in v-on * chore: add comment * chore: fix comment --- src/script/index.ts | 11 +- .../ast.json | 829 ++++++++++++++++ .../source.vue | 3 + .../token-ranges.json | 26 + .../tree.json | 96 ++ .../v-on-async-function-expression/ast.json | 909 ++++++++++++++++++ .../v-on-async-function-expression/source.vue | 3 + .../token-ranges.json | 28 + .../v-on-async-function-expression/tree.json | 108 +++ 9 files changed, 2011 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/ast.json create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/source.vue create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/tree.json create mode 100644 test/fixtures/ast/v-on-async-function-expression/ast.json create mode 100644 test/fixtures/ast/v-on-async-function-expression/source.vue create mode 100644 test/fixtures/ast/v-on-async-function-expression/token-ranges.json create mode 100644 test/fixtures/ast/v-on-async-function-expression/tree.json diff --git a/src/script/index.ts b/src/script/index.ts index b05b2c6d..262c4bd3 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -75,8 +75,15 @@ const PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u const DUMMY_PARENT: any = {} // Like Vue, it judges whether it is a function expression or not. -// https://github.com/vuejs/vue/blob/0948d999f2fddf9f90991956493f976273c5da1f/src/compiler/codegen/events.js#L3 -const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/u +// https://github.com/vuejs/core/blob/fef2acb2049fce3407dff17fe8af1836b97dfd73/packages/compiler-core/src/transforms/vOn.ts#L19 +const IS_FUNCTION_EXPRESSION = + /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u +// ^^^^^^^ omit paren argument ^^^^^^^^ function keyword +// ^^^^^ <--- async keyword (optional) ---> ^^^^^ +// ^^------^^ arguments with parens ^^^^^^ named function (optional) +// ^^^^^^^^^ return types (optional) +// ^^ arrow ^^ opening paren + const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/ast.json b/test/fixtures/ast/v-on-async-arrow-function-expression/ast.json new file mode 100644 index 00000000..17fa8149 --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/ast.json @@ -0,0 +1,829 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 77 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 31, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 31, + 54 + ], + "id": null, + "expression": true, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "AwaitExpression", + "start": 43, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 43, + 54 + ], + "argument": { + "type": "CallExpression", + "start": 49, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 49, + 54 + ], + "callee": { + "type": "Identifier", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 49, + 52 + ], + "name": "act" + }, + "arguments": [], + "optional": false + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 49, + 52 + ], + "name": "act" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 56, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 54 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 66, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "async", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 31, + 36 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 37, + 38 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 38, + 39 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "range": [ + 40, + 42 + ] + }, + { + "type": "Identifier", + "value": "await", + "start": 43, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "range": [ + 43, + 48 + ] + }, + { + "type": "Identifier", + "value": "act", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 49, + 52 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 52, + 53 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 53, + 54 + ] + }, + { + "type": "Punctuator", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 66, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/source.vue b/test/fixtures/ast/v-on-async-arrow-function-expression/source.vue new file mode 100644 index 00000000..9cdad449 --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json b/test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json new file mode 100644 index 00000000..032294ca --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json @@ -0,0 +1,26 @@ +[ + "", + "\n ", + "", + "await", + "act", + "(", + ")", + "\"", + ">", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/tree.json b/test/fixtures/ast/v-on-async-arrow-function-expression/tree.json new file mode 100644 index 00000000..d272edfa --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/tree.json @@ -0,0 +1,96 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-function-expression/ast.json b/test/fixtures/ast/v-on-async-function-expression/ast.json new file mode 100644 index 00000000..447b74bf --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/ast.json @@ -0,0 +1,909 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 86 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "expression": { + "type": "FunctionExpression", + "start": 31, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 52 + } + }, + "range": [ + 31, + 63 + ], + "id": null, + "expression": false, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 48, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 52 + } + }, + "range": [ + 48, + 63 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 50, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 50, + 61 + ], + "expression": { + "type": "AwaitExpression", + "start": 50, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 50, + 61 + ], + "argument": { + "type": "CallExpression", + "start": 56, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 56, + 61 + ], + "callee": { + "type": "Identifier", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 56, + 59 + ], + "name": "act" + }, + "arguments": [], + "optional": false + } + } + } + ] + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 56, + 59 + ], + "name": "act" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 65, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 63 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 63 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 75, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "async", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 31, + 36 + ] + }, + { + "type": "Keyword", + "value": "function", + "start": 37, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "range": [ + 37, + 45 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "range": [ + 45, + 46 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "range": [ + 46, + 47 + ] + }, + { + "type": "Punctuator", + "value": "{", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 48, + 49 + ] + }, + { + "type": "Identifier", + "value": "await", + "start": 50, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "range": [ + 50, + 55 + ] + }, + { + "type": "Identifier", + "value": "act", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 56, + 59 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 59, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 59, + 60 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 60, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 60, + 61 + ] + }, + { + "type": "Punctuator", + "value": "}", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 2, + "column": 52 + } + }, + "range": [ + 62, + 63 + ] + }, + { + "type": "Punctuator", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 52 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 65, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 63 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 75, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-function-expression/source.vue b/test/fixtures/ast/v-on-async-function-expression/source.vue new file mode 100644 index 00000000..fb86873b --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-async-function-expression/token-ranges.json b/test/fixtures/ast/v-on-async-function-expression/token-ranges.json new file mode 100644 index 00000000..77fdd025 --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/token-ranges.json @@ -0,0 +1,28 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-function-expression/tree.json b/test/fixtures/ast/v-on-async-function-expression/tree.json new file mode 100644 index 00000000..5fdf6e87 --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/tree.json @@ -0,0 +1,108 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file From c7b5fbf8032b936a575a309e87a3d69b9288b758 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sat, 1 Jun 2024 10:09:25 +0900 Subject: [PATCH 15/36] Fixed parsing error when arrow function type in generics (#234) * Fixed parsing error when arrow function type in generics * macos-latest to macos-12 --- .github/workflows/CI.yml | 2 +- src/script/generic.ts | 7 + .../ast/vue3.3-generic-7-with-arrow/ast.json | 2226 +++++++++++ .../parser-options.json | 6 + .../vue3.3-generic-7-with-arrow/source.vue | 11 + .../token-ranges.json | 88 + .../ast/vue3.3-generic-7-with-arrow/tree.json | 89 + .../document-fragment.json | 3364 +++++++++++++++++ .../parser-options.json | 6 + .../vue3.3-generic-7-with-arrow/source.vue | 11 + .../token-ranges.json | 69 + .../vue3.3-generic-7-with-arrow/tree.json | 257 ++ 12 files changed, 6135 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/ast/vue3.3-generic-7-with-arrow/ast.json create mode 100644 test/fixtures/ast/vue3.3-generic-7-with-arrow/parser-options.json create mode 100644 test/fixtures/ast/vue3.3-generic-7-with-arrow/source.vue create mode 100644 test/fixtures/ast/vue3.3-generic-7-with-arrow/token-ranges.json create mode 100644 test/fixtures/ast/vue3.3-generic-7-with-arrow/tree.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/document-fragment.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/parser-options.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/source.vue create mode 100644 test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/token-ranges.json create mode 100644 test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/tree.json diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a4f21980..ffe41eed 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -39,7 +39,7 @@ jobs: os: windows-latest - eslint: 7 node: 16 - os: macos-latest + os: macos-12 # On old Node.js versions - eslint: 7 node: 14 diff --git a/src/script/generic.ts b/src/script/generic.ts index 0fa1eded..822c26c0 100644 --- a/src/script/generic.ts +++ b/src/script/generic.ts @@ -133,9 +133,15 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) { continue } } else if (rawParam[index] === "=") { + if (rawParam[index + 1] === ">") { + // Arrow function type + index += 2 + continue + } return rawParam.slice(startIndex, index) } if (rawParam.startsWith("//", index)) { + // Skip line comment const lfIndex = rawParam.indexOf("\n", index) if (lfIndex >= 0) { index = lfIndex + 1 @@ -144,6 +150,7 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) { return "unknown" } if (rawParam.startsWith("/*", index)) { + // Skip block comment const endIndex = rawParam.indexOf("*/", index) if (endIndex >= 0) { index = endIndex + 2 diff --git a/test/fixtures/ast/vue3.3-generic-7-with-arrow/ast.json b/test/fixtures/ast/vue3.3-generic-7-with-arrow/ast.json new file mode 100644 index 00000000..a08b871e --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-7-with-arrow/ast.json @@ -0,0 +1,2226 @@ +{ + "type": "Program", + "body": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "defineProps", + "range": [ + 113, + 124 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 21 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 113, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "range": [ + 124, + 138 + ], + "params": [ + { + "type": "TSTypeLiteral", + "members": [ + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "t", + "range": [ + 126, + 127 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 24 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 5, + "column": 24 + }, + "end": { + "line": 5, + "column": 27 + } + }, + "range": [ + 127, + 130 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "T", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 27 + } + } + }, + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 27 + } + } + } + }, + "range": [ + 126, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 23 + }, + "end": { + "line": 5, + "column": 28 + } + } + }, + { + "type": "TSPropertySignature", + "computed": false, + "key": { + "type": "Identifier", + "name": "u", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + "typeAnnotation": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 5, + "column": 33 + } + }, + "range": [ + 133, + 136 + ], + "typeAnnotation": { + "type": "TSTypeReference", + "typeName": { + "type": "Identifier", + "name": "U", + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + "range": [ + 135, + 136 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 33 + } + } + } + }, + "range": [ + 132, + 136 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 33 + } + } + } + ], + "range": [ + 125, + 137 + ], + "loc": { + "start": { + "line": 5, + "column": 22 + }, + "end": { + "line": 5, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 5, + "column": 21 + }, + "end": { + "line": 5, + "column": 35 + } + } + } + }, + "range": [ + 109, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 37 + } + } + } + ], + "kind": "const", + "range": [ + 103, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 37 + } + } + } + ], + "sourceType": "module", + "range": [ + 103, + 141 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "tokens": [ + { + "type": "Punctuator", + "range": [ + 0, + 102 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "" + } + ], + "comments": [], + "templateBody": { + "type": "VElement", + "range": [ + 152, + 194 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 152, + 162 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 162, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 163, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "property": { + "type": "Identifier", + "name": "t", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 165, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 165, + 170 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 173, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + "property": { + "type": "Identifier", + "name": "u", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 175, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 175, + 180 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 183, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 38, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 49, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 52, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 65, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 76, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 91, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 33 + } + } + }, + { + "type": "String", + "value": "'abc'", + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 113, + 128 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "value": "defineProps<{t:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 129, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 28 + } + }, + "value": "T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 28 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 132, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "value": "u:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 32 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 135, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 5, + "column": 37 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 141, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 152 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 152, + 161 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 161, + 162 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 162, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 163, + 165 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "p", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "t", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 170, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 173, + 175 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "u", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 178, + 179 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 179, + 180 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 180, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 183, + 193 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 193, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-7-with-arrow/parser-options.json b/test/fixtures/ast/vue3.3-generic-7-with-arrow/parser-options.json new file mode 100644 index 00000000..0ead30e9 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-7-with-arrow/parser-options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "parser": { + "ts": "@typescript-eslint/parser" + } +} diff --git a/test/fixtures/ast/vue3.3-generic-7-with-arrow/source.vue b/test/fixtures/ast/vue3.3-generic-7-with-arrow/source.vue new file mode 100644 index 00000000..d1a84af7 --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-7-with-arrow/source.vue @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-7-with-arrow/token-ranges.json b/test/fixtures/ast/vue3.3-generic-7-with-arrow/token-ranges.json new file mode 100644 index 00000000..6ae5ff6d --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-7-with-arrow/token-ranges.json @@ -0,0 +1,88 @@ +[ + "", + "", + "string", + ",", + "U", + "extends", + "(", + ")", + "=>", + "string", + "=", + "(", + ")", + "=>", + "'abc'", + "\"", + ">", + "\n", + "const", + " ", + "p", + " ", + "=", + " ", + "defineProps<{t:", + " ", + "T,", + " ", + "u:", + " ", + "U}>()", + "\n", + "", + "\n\n", + "", + "\n", + "{{", + "p", + ".", + "t", + "(", + ")", + "}}", + "\n", + "{{", + "p", + ".", + "u", + "(", + ")", + "}}", + "\n", + "" +] \ No newline at end of file diff --git a/test/fixtures/ast/vue3.3-generic-7-with-arrow/tree.json b/test/fixtures/ast/vue3.3-generic-7-with-arrow/tree.json new file mode 100644 index 00000000..bd27ee7b --- /dev/null +++ b/test/fixtures/ast/vue3.3-generic-7-with-arrow/tree.json @@ -0,0 +1,89 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/document-fragment.json b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/document-fragment.json new file mode 100644 index 00000000..c6cf8e44 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/document-fragment.json @@ -0,0 +1,3364 @@ +{ + "type": "VDocumentFragment", + "range": [ + 0, + 194 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "children": [ + { + "type": "VElement", + "range": [ + 0, + 150 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "name": "script", + "rawName": "script", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 102 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 8, + 13 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "name": "setup", + "rawName": "setup" + }, + "value": null + }, + { + "type": "VAttribute", + "range": [ + 14, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "directive": false, + "key": { + "type": "VIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": "lang", + "rawName": "lang" + }, + "value": { + "type": "VLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + } + }, + { + "type": "VAttribute", + "range": [ + 24, + 101 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "name": "generic", + "rawName": "generic" + }, + "argument": null, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 32, + 101 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "expression": { + "type": "VGenericExpression", + "range": [ + 36, + 99 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + "constraint": { + "type": "TSFunctionType", + "params": [], + "range": [ + 46, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "returnType": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "range": [ + 49, + 58 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 52, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 24 + } + } + } + } + }, + "in": false, + "out": false, + "const": false, + "range": [ + 36, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "U", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + "constraint": { + "type": "TSFunctionType", + "params": [], + "range": [ + 73, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "returnType": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "range": [ + 76, + 85 + ], + "typeAnnotation": { + "type": "TSStringKeyword", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 25 + } + } + } + } + }, + "default": { + "type": "TSFunctionType", + "params": [], + "range": [ + 88, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "returnType": { + "type": "TSTypeAnnotation", + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 39 + } + }, + "range": [ + 91, + 99 + ], + "typeAnnotation": { + "type": "TSLiteralType", + "literal": { + "type": "Literal", + "value": "abc", + "raw": "'abc'", + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 39 + } + } + }, + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 39 + } + } + } + } + }, + "in": false, + "out": false, + "const": false, + "range": [ + 62, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 39 + } + } + } + ], + "rawParams": [ + "T extends () => string", + "U extends () => string = () => 'abc'" + ] + }, + "references": [] + } + } + ] + }, + "children": [ + { + "type": "VText", + "range": [ + 102, + 141 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\nconst p = defineProps<{t: T, u: U}>()\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 141, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + "variables": [ + { + "id": { + "type": "Identifier", + "name": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + "kind": "generic" + }, + { + "id": { + "type": "Identifier", + "name": "U", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + "kind": "generic" + } + ] + }, + { + "type": "VText", + "range": [ + 150, + 152 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "VElement", + "range": [ + 152, + 194 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 152, + 162 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 162, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 163, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "property": { + "type": "Identifier", + "name": "t", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 165, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 165, + 170 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionContainer", + "range": [ + 173, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "expression": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + "property": { + "type": "Identifier", + "name": "u", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "computed": false, + "optional": false, + "range": [ + 175, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + "arguments": [], + "optional": false, + "range": [ + 175, + 180 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "name": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + "mode": "r", + "isValueReference": true, + "isTypeReference": false + } + ] + }, + { + "type": "VText", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 183, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 38, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 49, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 52, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 65, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 76, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 91, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 33 + } + } + }, + { + "type": "String", + "value": "'abc'", + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 113, + 128 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "value": "defineProps<{t:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 129, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 28 + } + }, + "value": "T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 28 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 132, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "value": "u:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 32 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 135, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 5, + "column": 37 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 141, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 152 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 152, + 161 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 161, + 162 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 162, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 163, + 165 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "p", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "t", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 170, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 173, + 175 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "u", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 178, + 179 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 179, + 180 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 180, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 183, + 193 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 193, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [], + "errors": [] + } + ], + "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": "HTMLIdentifier", + "range": [ + 14, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "value": "lang" + }, + { + "type": "HTMLAssociation", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 19, + 23 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "value": "ts" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 31 + ], + "loc": { + "start": { + "column": 24, + "line": 1 + }, + "end": { + "column": 31, + "line": 1 + } + }, + "value": "generic" + }, + { + "type": "HTMLAssociation", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "T", + "range": [ + 36, + 37 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 38, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 49, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 52, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ",", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "U", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 3 + } + } + }, + { + "type": "Keyword", + "value": "extends", + "range": [ + 65, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 76, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "string", + "range": [ + 79, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 91, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 33 + } + } + }, + { + "type": "String", + "value": "'abc'", + "range": [ + 94, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 3, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 5, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLRawText", + "range": [ + 103, + 108 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "value": "const" + }, + { + "type": "HTMLWhitespace", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 109, + 110 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 7 + } + }, + "value": "p" + }, + { + "type": "HTMLWhitespace", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 8 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 9 + } + }, + "value": "=" + }, + { + "type": "HTMLWhitespace", + "range": [ + 112, + 113 + ], + "loc": { + "start": { + "line": 5, + "column": 9 + }, + "end": { + "line": 5, + "column": 10 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 113, + 128 + ], + "loc": { + "start": { + "line": 5, + "column": 10 + }, + "end": { + "line": 5, + "column": 25 + } + }, + "value": "defineProps<{t:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 5, + "column": 25 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 129, + 131 + ], + "loc": { + "start": { + "line": 5, + "column": 26 + }, + "end": { + "line": 5, + "column": 28 + } + }, + "value": "T," + }, + { + "type": "HTMLWhitespace", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 5, + "column": 28 + }, + "end": { + "line": 5, + "column": 29 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 132, + 134 + ], + "loc": { + "start": { + "line": 5, + "column": 29 + }, + "end": { + "line": 5, + "column": 31 + } + }, + "value": "u:" + }, + { + "type": "HTMLWhitespace", + "range": [ + 134, + 135 + ], + "loc": { + "start": { + "line": 5, + "column": 31 + }, + "end": { + "line": 5, + "column": 32 + } + }, + "value": " " + }, + { + "type": "HTMLRawText", + "range": [ + 135, + 140 + ], + "loc": { + "start": { + "line": 5, + "column": 32 + }, + "end": { + "line": 5, + "column": 37 + } + }, + "value": "U}>()" + }, + { + "type": "HTMLWhitespace", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 5, + "column": 37 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 141, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 8 + } + }, + "value": "script" + }, + { + "type": "HTMLTagClose", + "range": [ + 149, + 150 + ], + "loc": { + "start": { + "line": 6, + "column": 8 + }, + "end": { + "line": 6, + "column": 9 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 150, + 152 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + }, + "value": "\n\n" + }, + { + "type": "HTMLTagOpen", + "range": [ + 152, + 161 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 161, + 162 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 162, + 163 + ], + "loc": { + "start": { + "line": 8, + "column": 10 + }, + "end": { + "line": 9, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 163, + 165 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "p", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 9, + "column": 2 + }, + "end": { + "line": 9, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 166, + 167 + ], + "loc": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "t", + "range": [ + 167, + 168 + ], + "loc": { + "start": { + "line": 9, + "column": 4 + }, + "end": { + "line": 9, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 168, + 169 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 169, + 170 + ], + "loc": { + "start": { + "line": 9, + "column": 6 + }, + "end": { + "line": 9, + "column": 7 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 170, + 172 + ], + "loc": { + "start": { + "line": 9, + "column": 7 + }, + "end": { + "line": 9, + "column": 9 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 172, + 173 + ], + "loc": { + "start": { + "line": 9, + "column": 9 + }, + "end": { + "line": 10, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "VExpressionStart", + "range": [ + 173, + 175 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 2 + } + }, + "value": "{{" + }, + { + "type": "Identifier", + "value": "p", + "range": [ + 175, + 176 + ], + "loc": { + "start": { + "line": 10, + "column": 2 + }, + "end": { + "line": 10, + "column": 3 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 176, + 177 + ], + "loc": { + "start": { + "line": 10, + "column": 3 + }, + "end": { + "line": 10, + "column": 4 + } + } + }, + { + "type": "Identifier", + "value": "u", + "range": [ + 177, + 178 + ], + "loc": { + "start": { + "line": 10, + "column": 4 + }, + "end": { + "line": 10, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 178, + 179 + ], + "loc": { + "start": { + "line": 10, + "column": 5 + }, + "end": { + "line": 10, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 179, + 180 + ], + "loc": { + "start": { + "line": 10, + "column": 6 + }, + "end": { + "line": 10, + "column": 7 + } + } + }, + { + "type": "VExpressionEnd", + "range": [ + 180, + 182 + ], + "loc": { + "start": { + "line": 10, + "column": 7 + }, + "end": { + "line": 10, + "column": 9 + } + }, + "value": "}}" + }, + { + "type": "HTMLWhitespace", + "range": [ + 182, + 183 + ], + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 11, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 183, + 193 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 193, + 194 + ], + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 11, + "column": 11 + } + }, + "value": "" + } + ], + "comments": [], + "errors": [] +} \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/parser-options.json b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/parser-options.json new file mode 100644 index 00000000..0ead30e9 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/parser-options.json @@ -0,0 +1,6 @@ +{ + "sourceType": "module", + "parser": { + "ts": "@typescript-eslint/parser" + } +} diff --git a/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/source.vue b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/source.vue new file mode 100644 index 00000000..d1a84af7 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/source.vue @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/token-ranges.json b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/token-ranges.json new file mode 100644 index 00000000..19b7461d --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/token-ranges.json @@ -0,0 +1,69 @@ +[ + "", + "string", + ",", + "U", + "extends", + "(", + ")", + "=>", + "string", + "=", + "(", + ")", + "=>", + "'abc'", + "\"", + ">", + "\n", + "const", + " ", + "p", + " ", + "=", + " ", + "defineProps<{t:", + " ", + "T,", + " ", + "u:", + " ", + "U}>()", + "\n", + "", + "\n\n", + "", + "\n", + "{{", + "p", + ".", + "t", + "(", + ")", + "}}", + "\n", + "{{", + "p", + ".", + "u", + "(", + ")", + "}}", + "\n", + "" +] \ No newline at end of file diff --git a/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/tree.json b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/tree.json new file mode 100644 index 00000000..8a3067f7 --- /dev/null +++ b/test/fixtures/document-fragment/vue3.3-generic-7-with-arrow/tree.json @@ -0,0 +1,257 @@ +[ + { + "type": "VDocumentFragment", + "text": "\n\n", + "children": [ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + }, + { + "type": "VText", + "text": "\n\n", + "children": [] + }, + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } + ] + } +] \ No newline at end of file From b0e0ccc6d302bb40c5cb496528536bd355ee5151 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sat, 1 Jun 2024 10:11:42 +0900 Subject: [PATCH 16/36] 9.4.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b055e3f3..12f2dfb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-eslint-parser", - "version": "9.4.2", + "version": "9.4.3", "description": "The ESLint custom parser for `.vue` files.", "engines": { "node": "^14.17.0 || >=16.0.0" From d1d2540b44c08e479ce64be984912aef418ece6c Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Wed, 29 Jan 2025 13:21:45 +0900 Subject: [PATCH 17/36] Drop support old eslint and node (#242) * Drop support old eslint and node * fix * update * update * fix --- .eslintignore | 10 - .eslintrc.yml | 878 --------- .github/workflows/CI.yml | 52 +- .gitmodules | 3 - .vscode/settings.json | 11 +- README.md | 9 +- eslint.config.mjs | 803 +++++++++ package.json | 57 +- scripts/ci-install-eslint.js | 20 +- scripts/update-fixtures-ast.js | 3 +- scripts/update-fixtures-document-fragment.js | 4 +- src/common/ast-utils.ts | 2 +- src/common/error-utils.ts | 2 +- src/common/eslint-scope.ts | 46 +- src/common/espree.ts | 72 +- src/common/fix-locations.ts | 4 +- src/common/lines-and-columns.ts | 2 +- src/common/linter-require.ts | 26 - src/common/location-calculator.ts | 2 +- src/common/parser-object.ts | 2 +- src/common/parser-options.ts | 6 +- src/common/token-utils.ts | 2 +- src/external/node-event-generator.ts | 201 ++- .../cursors/backward-token-comment-cursor.ts | 30 +- .../cursors/backward-token-cursor.ts | 18 +- src/external/token-store/cursors/cursor.ts | 12 +- .../token-store/cursors/decorative-cursor.ts | 4 +- .../token-store/cursors/filter-cursor.ts | 8 +- .../cursors/forward-token-comment-cursor.ts | 35 +- .../cursors/forward-token-cursor.ts | 20 +- src/external/token-store/cursors/index.ts | 60 +- .../token-store/cursors/limit-cursor.ts | 6 +- .../cursors/padded-token-cursor.ts | 12 +- .../token-store/cursors/skip-cursor.ts | 6 +- src/external/token-store/index.ts | 338 +++- src/external/token-store/utils.ts | 22 +- src/html/custom-tokenizer.ts | 2 +- src/html/intermediate-tokenizer.ts | 4 +- src/html/parser.ts | 6 +- src/html/tokenizer.ts | 16 +- src/html/util/unicode.ts | 56 +- src/index.ts | 13 +- src/parser-services.ts | 15 +- src/script-setup/index.ts | 11 +- src/script-setup/parser-options.ts | 11 +- src/script-setup/scope-analyzer.ts | 4 +- src/script/generic.ts | 2 +- src/script/index.ts | 16 +- src/script/scope-analyzer.ts | 8 +- src/sfc/custom-block/index.ts | 4 +- src/style/index.ts | 8 +- src/style/tokenizer.ts | 2 +- src/template/index.ts | 8 +- test/ast.js | 138 +- test/core-rules.js | 239 --- test/define-custom-blocks-visitor.js | 622 ++++--- test/define-document-visitor.js | 71 +- test/document-fragment.js | 2 +- test/espree.js | 133 -- test/fixtures/ast/address-component/ast.json | 2 +- .../ast/attributes-linebreak/ast.json | 2 +- test/fixtures/ast/attributes/ast.json | 2 +- test/fixtures/ast/auto-closing-dt-dd/ast.json | 2 +- test/fixtures/ast/auto-closing-p/ast.json | 2 +- test/fixtures/ast/bogus-comments/ast.json | 2 +- test/fixtures/ast/cdata/ast.json | 2 +- test/fixtures/ast/comments-2/ast.json | 2 +- test/fixtures/ast/comments-3/ast.json | 2 +- test/fixtures/ast/comments/ast.json | 2 +- .../ast/custom-template-tokenizer/ast.json | 2 +- test/fixtures/ast/custom-thead/ast.json | 2 +- .../ast/define-model06-with-ts/ast.json | 312 ++-- .../ast/define-model06-with-ts/scope.json | 628 +++++-- .../ast/define-model07-with-ts/ast.json | 467 ++--- .../ast/define-model07-with-ts/scope.json | 628 +++++-- .../ast.json | 1252 ++++++------- .../scope.json | 808 ++++++--- test/fixtures/ast/define-slots01/ast.json | 644 +++---- test/fixtures/ast/define-slots01/scope.json | 628 +++++-- .../directive-argument-and-modifiers/ast.json | 2 +- .../fixtures/ast/directive-arguments/ast.json | 2 +- .../ast/directive-empty-value/ast.json | 2 +- test/fixtures/ast/directive-error-1/ast.json | 2 +- test/fixtures/ast/directive-error-2/ast.json | 2 +- test/fixtures/ast/directive-error-3/ast.json | 2 +- test/fixtures/ast/directive-error-4/ast.json | 2 +- .../fixtures/ast/directive-modifiers/ast.json | 2 +- .../ast/directive-shorthands/ast.json | 2 +- test/fixtures/ast/directives/ast.json | 2 +- .../ast/dynamic-argument-dot/ast.json | 2 +- .../ast/dynamic-argument-error-1/ast.json | 2 +- .../ast/dynamic-argument-error-2/ast.json | 2 +- .../ast/dynamic-argument-error-4/ast.json | 2 +- .../ast/dynamic-argument-error-5/ast.json | 2 +- .../ast/dynamic-argument-expr/ast.json | 2 +- .../ast/dynamic-argument-v-bind/ast.json | 2 +- .../ast/dynamic-argument-v-on/ast.json | 2 +- .../ast/dynamic-argument-v-slot/ast.json | 2 +- test/fixtures/ast/elements/ast.json | 2 +- test/fixtures/ast/empty-script-only/ast.json | 2 +- .../fixtures/ast/empty-template-only/ast.json | 2 +- test/fixtures/ast/empty/ast.json | 2 +- test/fixtures/ast/end-of-line01/ast.json | 2 +- test/fixtures/ast/end-of-line02/ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../ast/error-duplicate-attribute/ast.json | 2 +- .../error-end-tag-with-attributes/ast.json | 2 +- .../ast.json | 2 +- .../ast/error-eof-before-tag-name-2/ast.json | 2 +- .../ast/error-eof-before-tag-name/ast.json | 2 +- test/fixtures/ast/error-eof-in-cdata/ast.json | 2 +- .../ast/error-eof-in-comment-2/ast.json | 2 +- .../ast/error-eof-in-comment-3/ast.json | 2 +- .../ast/error-eof-in-comment-4/ast.json | 2 +- .../ast/error-eof-in-comment-5/ast.json | 2 +- .../ast/error-eof-in-comment/ast.json | 2 +- test/fixtures/ast/error-eof-in-tag-2/ast.json | 2 +- test/fixtures/ast/error-eof-in-tag-3/ast.json | 2 +- test/fixtures/ast/error-eof-in-tag-4/ast.json | 2 +- test/fixtures/ast/error-eof-in-tag-5/ast.json | 2 +- test/fixtures/ast/error-eof-in-tag-6/ast.json | 2 +- test/fixtures/ast/error-eof-in-tag-7/ast.json | 2 +- test/fixtures/ast/error-eof-in-tag/ast.json | 2 +- .../ast.json | 2 +- .../fixtures/ast/error-message-empty/ast.json | 2 +- .../ast/error-message-outside/ast.json | 2 +- .../ast/error-missing-end-tag-name/ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../error-null-character-reference/ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../error-unexpected-solidus-in-tag/ast.json | 2 +- .../ast.json | 2 +- .../error-v-on-function-expression/ast.json | 2 +- .../ast/error-x-invalid-end-tag/ast.json | 2 +- .../ast/error-x-invalid-namespace/ast.json | 2 +- .../ast/expression-container-only/ast.json | 2 +- test/fixtures/ast/filter-empty/ast.json | 2 +- test/fixtures/ast/filters-2/ast.json | 2 +- test/fixtures/ast/filters-3/ast.json | 2 +- test/fixtures/ast/filters-4/ast.json | 2 +- test/fixtures/ast/filters-error-2/ast.json | 2 +- test/fixtures/ast/filters-error/ast.json | 2 +- .../ast/filters-opt-filter-off/ast.json | 2 +- .../ast/filters-opt-filter-on/ast.json | 2 +- test/fixtures/ast/filters/ast.json | 2 +- .../fixtures/ast/foreignobject-lower/ast.json | 2 +- test/fixtures/ast/foreignobject/ast.json | 2 +- test/fixtures/ast/hole-in-array/ast.json | 2 +- .../html-entities-in-static-places/ast.json | 2 +- .../ast/html-entities-lone-amp/ast.json | 2 +- .../ast/html-entities-mapping/ast.json | 2 +- .../ast/html-entities-numeric/ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- test/fixtures/ast/html-entities/ast.json | 2 +- test/fixtures/ast/input-component/ast.json | 2 +- test/fixtures/ast/link-component/ast.json | 2 +- test/fixtures/ast/math/ast.json | 2 +- .../fixtures/ast/multiple-scripts-11/ast.json | 6 +- test/fixtures/ast/multiple-scripts-2/ast.json | 6 +- test/fixtures/ast/multiple-scripts-5/ast.json | 3 +- test/fixtures/ast/multiple-scripts-7/ast.json | 6 +- test/fixtures/ast/multiple-scripts-8/ast.json | 6 +- .../multiple-scripts-with-export02/ast.json | 9 +- .../multiple-scripts-with-export03/ast.json | 18 +- .../multiple-scripts-with-export04/ast.json | 3 +- .../ast/multiple-scripts-with-ts/ast.json | 380 ++-- .../ast.json | 2 +- test/fixtures/ast/mustache-errors/ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- .../ast.json | 2 +- test/fixtures/ast/mustache-in-lt-gt/ast.json | 2 +- .../ast.json | 2 +- .../fixtures/ast/mustache-not-closed/ast.json | 8 +- .../fixtures/ast/mustache-with-space/ast.json | 2 +- test/fixtures/ast/mustache/ast.json | 2 +- test/fixtures/ast/no-filters/ast.json | 2 +- .../ast/not-closing-elements/ast.json | 2 +- .../parser-option-multiple-parsers-1/ast.json | 634 +++---- .../services.json | 4 +- .../parser-option-multiple-parsers-3/ast.json | 316 ++-- .../services.json | 4 +- .../ast.json | 338 ++-- .../services.json | 4 +- test/fixtures/ast/pug/ast.json | 2 +- test/fixtures/ast/raw-names/ast.json | 2 +- test/fixtures/ast/rawtext/ast.json | 2 +- .../ast/script-setup-example01/ast.json | 6 +- .../ast/script-setup-example05/ast.json | 6 +- .../ast/script-setup-example06/ast.json | 6 +- .../ast/script-setup-example07/ast.json | 3 +- .../ast/script-setup-example09/ast.json | 3 +- .../ast/self-closing-elements/ast.json | 2 +- test/fixtures/ast/slot-scope-default/ast.json | 2 +- .../ast/slot-scope-destructuring/ast.json | 2 +- .../ast/slot-scope-multi-parameters/ast.json | 2 +- .../ast/slot-scope-rest-parameter/ast.json | 2 +- test/fixtures/ast/slot-scope/ast.json | 2 +- .../ast/svg-attrs-camel-case/ast.json | 2 +- test/fixtures/ast/svg-attrs-colon/ast.json | 2 +- test/fixtures/ast/svg-namespace/ast.json | 2 +- test/fixtures/ast/svg-upper/ast.json | 2 +- test/fixtures/ast/table/ast.json | 2 +- .../text-and-expression-container/ast.json | 2 +- test/fixtures/ast/text/ast.json | 2 +- test/fixtures/ast/textarea/ast.json | 2 +- .../ast.json | 369 ++-- .../scope.json | 506 ++++-- .../services.json | 4 +- .../ast/v-bind-prop-shorthand/ast.json | 2 +- .../scope.json | 24 +- .../scope.json | 24 +- .../ast/v-bind-sequence-expression/ast.json | 2 +- .../ast/v-bind-spread-element/ast.json | 2 +- .../parser-options.json | 3 +- .../ast/v-for-directives-error/ast.json | 2 +- .../ast/v-for-directives-index/ast.json | 2 +- .../ast.json | 2 +- .../parser-options.json | 3 +- .../parser-options.json | 3 +- test/fixtures/ast/v-for-directives/ast.json | 2 +- .../v-on-arrow-function-expression.1/ast.json | 2 +- .../v-on-arrow-function-expression.2/ast.json | 2 +- .../ast.json | 2 +- .../v-on-async-function-expression/ast.json | 2 +- .../ast/v-on-function-expression/ast.json | 2 +- .../ast/v-on-multiple-statements/ast.json | 2 +- .../ast/v-on-object-expression/ast.json | 2 +- test/fixtures/ast/v-on-simple-path.1/ast.json | 2 +- test/fixtures/ast/v-on-simple-path.2/ast.json | 2 +- test/fixtures/ast/v-on-simple-path.3/ast.json | 2 +- test/fixtures/ast/v-on-simple-path.4/ast.json | 2 +- test/fixtures/ast/v-pre/ast.json | 2 +- .../ast/v-slot-default-shorthand/ast.json | 2 +- test/fixtures/ast/v-slot-default/ast.json | 2 +- .../ast/v-slot-named-shorthand/ast.json | 2 +- test/fixtures/ast/v-slot-named/ast.json | 2 +- test/fixtures/ast/vue3.3-generic-1/ast.json | 369 ++-- test/fixtures/ast/vue3.3-generic-1/scope.json | 554 ++++-- test/fixtures/ast/vue3.3-generic-2/ast.json | 1000 ++++++----- test/fixtures/ast/vue3.3-generic-2/scope.json | 808 ++++++--- test/fixtures/ast/vue3.3-generic-3/ast.json | 1191 +++++++------ test/fixtures/ast/vue3.3-generic-3/scope.json | 832 ++++++--- .../ast/vue3.3-generic-4-with-spaces/ast.json | 1217 +++++++------ .../ast/vue3.3-generic-5-with-spaces/ast.json | 1343 +++++++------- .../vue3.3-generic-6-with-default/ast.json | 1573 +++++++++-------- .../ast/vue3.3-generic-7-with-arrow/ast.json | 1104 ++++++------ .../document-fragment.json | 9 +- .../document-fragment.json | 6 +- .../style-variables01/document-fragment.json | 3 +- .../style-variables02/document-fragment.json | 6 +- .../style-variables05/document-fragment.json | 9 +- .../vue3.3-generic-1/document-fragment.json | 132 +- .../vue3.3-generic-2/document-fragment.json | 260 +-- .../vue3.3-generic-2/tree.json | 10 +- .../vue3.3-generic-3/document-fragment.json | 474 ++--- .../vue3.3-generic-3/tree.json | 20 +- .../document-fragment.json | 534 +++--- .../vue3.3-generic-4-with-spaces/tree.json | 20 +- .../document-fragment.json | 842 ++++----- .../vue3.3-generic-5-with-spaces/tree.json | 30 +- .../document-fragment.json | 1386 ++++++++------- .../vue3.3-generic-6-with-default/tree.json | 40 +- .../document-fragment.json | 1350 +++++++------- .../vue3.3-generic-7-with-arrow/tree.json | 20 +- test/fixtures/eslint | 1 - test/index.js | 371 ++-- test/integrations.js | 16 +- test/lib/eslint-compat.js | 3 - test/parser-options.js | 53 +- 279 files changed, 15381 insertions(+), 12756 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.yml create mode 100644 eslint.config.mjs delete mode 100644 src/common/linter-require.ts delete mode 100644 test/core-rules.js delete mode 100644 test/espree.js delete mode 160000 test/fixtures/eslint diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 537f1533..00000000 --- a/.eslintignore +++ /dev/null @@ -1,10 +0,0 @@ -/.nyc_output -/.temp -/coverage -node_modules -/src/external -/src/html/util -/test/fixtures -/test/temp -/index.d.ts -/index.js diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 9a375797..00000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,878 +0,0 @@ -plugins: - - prettier -extends: - - plugin:node-dependencies/recommended - - plugin:jsonc/recommended-with-jsonc -globals: - root: off -parserOptions: - ecmaFeatures: - globalReturn: false - sourceType: module - ecmaVersion: 2020 - loggerFn: false - project: tsconfig.json -rules: - prettier/prettier: - - error - - tabWidth: 4 - semi: false - trailingComma: all - - usePrettierrc: false -overrides: - - files: "*.json" - rules: - prettier/prettier: - - error - - tabWidth: 2 - semi: false - trailingComma: all - - usePrettierrc: false - - files: "**/*.ts" - plugins: - - "@typescript-eslint" - - eslint-comments - - node - parser: "@typescript-eslint/parser" - rules: - prettier/prettier: - - error - - tabWidth: 4 - semi: false - trailingComma: all - parser: typescript - - usePrettierrc: false - "@typescript-eslint/consistent-type-imports": error - no-duplicate-imports: off - "@typescript-eslint/no-duplicate-imports": error - "@typescript-eslint/no-var-requires": off - node/no-unsupported-features/es-syntax: - - off - - ignores: - - modules - - dynamicImport - node/no-extraneous-import: - - error - node/file-extension-in-import: - - error - - always - - .js: never - .ts: never - .tsx: never - node/no-missing-import: - - error - node/no-unpublished-import: - - error - node/exports-style: - - error - - module.exports - node/no-callback-literal: - - off - node/no-deprecated-api: - - error - node/no-exports-assign: - - error - node/no-extraneous-require: - - error - node/no-missing-require: - - error - node/no-unpublished-bin: - - error - node/no-unpublished-require: - - error - node/no-unsupported-features/es-builtins: - - error - node/no-unsupported-features/node-builtins: - - error - node/prefer-global/buffer: - - error - node/prefer-global/console: - - error - node/prefer-global/process: - - error - node/prefer-global/text-decoder: - - off - node/prefer-global/text-encoder: - - off - node/prefer-global/url-search-params: - - off - node/prefer-global/url: - - off - node/prefer-promises/dns: - - off - node/prefer-promises/fs: - - off - node/process-exit-as-throw: - - error - node/shebang: - - error - "@typescript-eslint/adjacent-overload-signatures": - - error - "@typescript-eslint/array-type": - - error - "@typescript-eslint/await-thenable": - - error - "@typescript-eslint/ban-ts-comment": - - error - "@typescript-eslint/consistent-type-assertions": - - error - "@typescript-eslint/explicit-member-accessibility": - - error - "@typescript-eslint/no-array-constructor": - - error - "@typescript-eslint/no-empty-interface": - - error - "@typescript-eslint/no-extraneous-class": - - error - "@typescript-eslint/no-floating-promises": - - error - "@typescript-eslint/no-for-in-array": - - error - "@typescript-eslint/no-inferrable-types": - - error - "@typescript-eslint/no-misused-new": - - error - "@typescript-eslint/no-misused-promises": - - error - "@typescript-eslint/no-parameter-properties": - - error - "@typescript-eslint/no-require-imports": - - error - "@typescript-eslint/no-this-alias": - - error - - allowDestructuring: true - "@typescript-eslint/no-unnecessary-qualifier": - - error - "@typescript-eslint/no-unnecessary-type-arguments": - - error - "@typescript-eslint/no-unnecessary-type-assertion": - - error - "@typescript-eslint/prefer-function-type": - - off - "@typescript-eslint/prefer-includes": - - error - "@typescript-eslint/prefer-namespace-keyword": - - error - "@typescript-eslint/prefer-readonly": - - off - "@typescript-eslint/prefer-regexp-exec": - - error - "@typescript-eslint/prefer-string-starts-ends-with": - - error - "@typescript-eslint/restrict-plus-operands": - - error - "@typescript-eslint/require-array-sort-compare": - - error - "@typescript-eslint/triple-slash-reference": - - error - "@typescript-eslint/unbound-method": - - off - - ignoreStatic: true - "@typescript-eslint/unified-signatures": - - off - camelcase: - - off - no-empty-function: - - off - "@typescript-eslint/no-empty-function": - - error - no-useless-constructor: - - off - "@typescript-eslint/no-useless-constructor": - - error - require-await: - - off - "@typescript-eslint/require-await": - - error - func-style: - - off - - declaration - init-declarations: - - off - lines-between-class-members: - - off - no-dupe-class-members: - - off - no-invalid-this: - - off - no-loop-func: - - off - no-redeclare: - - off - - builtinGlobals: true - no-undef: - - off - - typeof: true - no-unused-vars: - - off - - args: all - argsIgnorePattern: "^_(?:[^_].*)?$" - caughtErrors: all - vars: all - varsIgnorePattern: "^_(?:[^_].*)?$" - no-use-before-define: - - off - - nofunc - one-var: - - off - - initialized: never - uninitialized: always - "@typescript-eslint/ban-types": - - off - "@typescript-eslint/brace-style": - - off - "@typescript-eslint/consistent-type-definitions": - - off - "@typescript-eslint/explicit-function-return-type": - - off - "@typescript-eslint/func-call-spacing": - - off - "@typescript-eslint/generic-type-naming": - - off - "@typescript-eslint/indent": - - off - "@typescript-eslint/member-delimiter-style": - - off - "@typescript-eslint/member-ordering": - - off - "@typescript-eslint/no-explicit-any": - - off - "@typescript-eslint/no-extra-parens": - - off - "@typescript-eslint/no-magic-numbers": - - off - "@typescript-eslint/no-namespace": - - off - "@typescript-eslint/no-non-null-assertion": - - off - "@typescript-eslint/no-type-alias": - - off - "@typescript-eslint/no-unnecessary-condition": - - off - "@typescript-eslint/no-unused-vars": - - off - "@typescript-eslint/no-use-before-define": - - off - "@typescript-eslint/prefer-for-of": - - off - "@typescript-eslint/promise-function-async": - - off - "@typescript-eslint/quotes": - - off - "@typescript-eslint/semi": - - off - "@typescript-eslint/strict-boolean-expressions": - - off - "@typescript-eslint/type-annotation-spacing": - - off - "@typescript-eslint/typedef": - - off - arrow-body-style: - - error - constructor-super: - - error - default-param-last: - - error - no-class-assign: - - error - no-const-assign: - - error - no-import-assign: - - error - no-new-symbol: - - error - no-template-curly-in-string: - - error - no-this-before-super: - - error - no-useless-computed-key: - - error - no-useless-rename: - - error - no-var: - - error - object-shorthand: - - error - - always - - avoidExplicitReturnArrows: true - prefer-arrow-callback: - - error - prefer-const: - - error - prefer-numeric-literals: - - error - prefer-rest-params: - - error - prefer-spread: - - error - prefer-template: - - error - require-unicode-regexp: - - error - require-yield: - - error - symbol-description: - - error - class-methods-use-this: - - warn - arrow-parens: - - off - arrow-spacing: - - off - generator-star-spacing: - - off - no-confusing-arrow: - - off - rest-spread-spacing: - - off - template-curly-spacing: - - off - yield-star-spacing: - - off - no-inner-declarations: - - off - - functions - no-restricted-imports: - - off - prefer-destructuring: - - off - sort-imports: - - off - accessor-pairs: - - error - - enforceForClassMembers: true - getWithoutSet: false - setWithoutGet: true - array-callback-return: - - error - consistent-return: - - error - curly: - - error - default-case: - - error - dot-notation: - - error - eqeqeq: - - error - - always - - "null": ignore - for-direction: - - error - getter-return: - - error - linebreak-style: - - error - - unix - max-statements-per-line: - - error - - max: 1 - multiline-comment-style: - - error - - separate-lines - new-cap: - - error - no-alert: - - error - no-array-constructor: - - error - no-async-promise-executor: - - error - no-caller: - - error - no-case-declarations: - - error - no-compare-neg-zero: - - error - no-cond-assign: - - error - no-constant-condition: - - error - no-control-regex: - - error - no-debugger: - - error - no-delete-var: - - error - no-div-regex: - - error - no-dupe-args: - - error - no-dupe-keys: - - error - no-duplicate-case: - - error - no-else-return: - - error - no-empty: - - error - no-empty-character-class: - - error - no-empty-pattern: - - error - no-eval: - - error - no-ex-assign: - - error - no-extend-native: - - error - no-extra-bind: - - error - no-extra-boolean-cast: - - error - no-extra-label: - - error - no-fallthrough: - - error - no-func-assign: - - error - no-global-assign: - - error - no-implicit-coercion: - - error - no-implicit-globals: - - error - no-implied-eval: - - error - no-invalid-regexp: - - error - no-irregular-whitespace: - - error - - skipComments: false - skipRegExps: false - skipStrings: false - skipTemplates: false - no-iterator: - - error - no-label-var: - - error - no-lone-blocks: - - error - no-lonely-if: - - error - no-misleading-character-class: - - error - no-mixed-operators: - - error - - groups: - - - - "&" - - "|" - - ^ - - "~" - - << - - ">>" - - ">>>" - - - - "&&" - - "||" - allowSamePrecedence: true - no-new: - - error - no-new-object: - - error - no-new-require: - - error - no-new-wrappers: - - error - no-obj-calls: - - error - no-octal: - - error - no-octal-escape: - - error - no-param-reassign: - - error - - props: false - no-process-env: - - error - no-process-exit: - - error - no-prototype-builtins: - - error - no-regex-spaces: - - error - no-restricted-properties: - - error - - property: __count__ - - property: __noSuchMethod__ - - property: __parent__ - - property: __defineGetter__ - - property: __defineSetter__ - - property: __lookupGetter__ - - property: __lookupSetter__ - no-return-assign: - - error - no-return-await: - - error - no-script-url: - - error - no-self-assign: - - error - - props: true - no-self-compare: - - error - no-sequences: - - error - "@typescript-eslint/no-shadow": - - error - - builtinGlobals: true - hoist: functions - no-shadow-restricted-names: - - error - no-sparse-arrays: - - error - no-tabs: - - error - no-throw-literal: - - error - no-unexpected-multiline: - - error - no-unmodified-loop-condition: - - error - no-unneeded-ternary: - - error - no-unreachable: - - error - no-unsafe-finally: - - error - no-unsafe-negation: - - error - - enforceForOrderingRelations: true - no-unused-expressions: - - error - no-unused-labels: - - error - no-useless-call: - - error - no-useless-catch: - - error - no-useless-concat: - - error - no-useless-escape: - - error - no-useless-return: - - error - no-void: - - error - no-with: - - error - padding-line-between-statements: - - error - - blankLine: always - next: "*" - prev: directive - - blankLine: always - next: function - prev: "*" - - blankLine: always - next: "*" - prev: function - prefer-promise-reject-errors: - - error - prefer-regex-literals: - - error - quotes: - - error - - double - - avoidEscape: true - radix: - - error - require-atomic-updates: - - error - spaced-comment: - - error - - always - - block: - balanced: true - markers: - - eslint - - eslint-env - - eslint-disable - - eslint-enable - - exported - - globals - - istanbul - line: - exceptions: - - "-" - - = - markers: - - eslint-disable-line - - eslint-disable-next-line - - istanbul - - "TODO:" - - "FIXME:" - strict: - - error - - global - use-isnan: - - error - - enforceForIndexOf: true - enforceForSwitchCase: true - valid-typeof: - - error - - requireStringLiterals: true - yoda: - - error - - never - - exceptRange: true - onlyEquality: false - complexity: - - warn - - max: 16 - max-nested-callbacks: - - warn - - max: 4 - max-params: - - warn - - max: 8 - no-console: - - warn - - allow: - - assert - - error - array-bracket-newline: - - off - array-bracket-spacing: - - off - array-element-newline: - - off - block-spacing: - - off - brace-style: - - off - comma-dangle: - - off - comma-spacing: - - off - comma-style: - - off - computed-property-spacing: - - off - dot-location: - - off - eol-last: - - off - func-call-spacing: - - off - function-call-argument-newline: - - off - function-paren-newline: - - off - implicit-arrow-linebreak: - - off - indent: - - off - jsx-quotes: - - off - key-spacing: - - off - keyword-spacing: - - off - multiline-ternary: - - off - new-parens: - - off - newline-per-chained-call: - - off - no-extra-parens: - - off - no-extra-semi: - - off - no-floating-decimal: - - off - no-mixed-spaces-and-tabs: - - off - no-multi-spaces: - - off - no-multiple-empty-lines: - - off - no-trailing-spaces: - - off - no-whitespace-before-property: - - off - nonblock-statement-body-position: - - off - object-curly-newline: - - off - object-curly-spacing: - - off - object-property-newline: - - off - one-var-declaration-per-line: - - off - operator-linebreak: - - off - padded-blocks: - - off - quote-props: - - off - semi: - - off - semi-spacing: - - off - semi-style: - - off - space-before-blocks: - - off - space-before-function-paren: - - off - space-in-parens: - - off - space-infix-ops: - - off - space-unary-ops: - - off - switch-colon-spacing: - - off - template-tag-spacing: - - off - unicode-bom: - - off - wrap-iife: - - off - wrap-regex: - - off - block-scoped-var: - - off - callback-return: - - off - capitalized-comments: - - off - consistent-this: - - off - func-name-matching: - - off - func-names: - - off - global-require: - - off - guard-for-in: - - off - handle-callback-err: - - off - id-blacklist: - - off - id-length: - - off - id-match: - - off - line-comment-position: - - off - lines-around-comment: - - off - max-classes-per-file: - - off - max-depth: - - off - max-len: - - off - max-lines: - - off - max-lines-per-function: - - off - max-statements: - - off - no-await-in-loop: - - off - no-bitwise: - - off - no-buffer-constructor: - - off - no-continue: - - off - no-eq-null: - - off - no-inline-comments: - - off - no-labels: - - off - no-magic-numbers: - - off - no-mixed-requires: - - off - no-multi-assign: - - off - no-multi-str: - - off - no-negated-condition: - - off - no-nested-ternary: - - off - no-new-func: - - off - no-path-concat: - - off - no-plusplus: - - off - no-proto: - - off - no-restricted-globals: - - off - no-restricted-modules: - - off - no-restricted-syntax: - - off - no-sync: - - off - no-ternary: - - off - no-undef-init: - - off - no-undefined: - - off - no-underscore-dangle: - - off - no-warning-comments: - - off - operator-assignment: - - off - prefer-named-capture-group: - - off - prefer-object-spread: - - off - sort-keys: - - off - sort-vars: - - off - vars-on-top: - - off - eslint-comments/disable-enable-pair: - - error - eslint-comments/no-aggregating-enable: - - error - eslint-comments/no-duplicate-disable: - - error - eslint-comments/no-restricted-disable: - - off - eslint-comments/no-unlimited-disable: - - error - eslint-comments/no-unused-disable: - - error - eslint-comments/no-unused-enable: - - error - eslint-comments/no-use: - - error - - allow: - - eslint-disable - - eslint-disable-line - - eslint-disable-next-line - - eslint-enable - - eslint-env - - globals - - files: "typings/**" - rules: - node/no-missing-import: - - error - - allowModules: - - estree - - files: package.json - rules: - "@mysticatea/prettier": off -settings: - node: - tryExtensions: - - .ts - - .js - - .json diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ffe41eed..2e31fdae 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,15 +13,15 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Checkout submodules run: git submodule update --init - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 'lts/*' - name: Install Packages - run: npm install && cd test/fixtures/eslint && npm install + run: npm install - name: Lint run: npm run -s lint @@ -29,42 +29,34 @@ jobs: name: Test strategy: matrix: - eslint: [7, 8] - node: [16, 17] + eslint: [9] + node: [18, 20, 21, 'lts/*'] os: [ubuntu-latest] include: # On other platforms - - eslint: 7 - node: 16 + - eslint: 9 + node: 'lts/*' os: windows-latest - - eslint: 7 - node: 16 - os: macos-12 - # On old Node.js versions - - eslint: 7 - node: 14 - os: ubuntu-latest + - eslint: 9 + node: 'lts/*' + os: macos-latest # On old ESLint versions - - eslint: 6 - node: 16 - os: ubuntu-latest - # On the minimum supported ESLint/Node.js version - - eslint: 6 - node: 14 + - eslint: 8 + node: 'lts/*' os: ubuntu-latest runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Checkout submodules run: git submodule update --init - name: Install Node.js v${{ matrix.node }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - name: Install Packages - run: npm install --legacy-peer-deps + run: npm install -f - name: Install ESLint v${{ matrix.eslint }} run: node scripts/ci-install-eslint ${{ matrix.eslint }} - name: Build @@ -77,17 +69,17 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Checkout submodules run: git submodule update --init - - name: Install Node.js v16 - uses: actions/setup-node@v3 + - name: Install Node.js + uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 'lts/*' - name: Install Packages run: npm install - - name: Install ESLint v8 - run: node scripts/ci-install-eslint 8.12.0 + - name: Install ESLint v9 + run: node scripts/ci-install-eslint 9 - name: Build run: npm run -s build - name: Test diff --git a/.gitmodules b/.gitmodules index 45ed6b45..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "test/fixtures/eslint"] - path = test/fixtures/eslint - url = https://github.com/eslint/eslint.git diff --git a/.vscode/settings.json b/.vscode/settings.json index 72446f43..7ff99747 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,12 @@ { - "typescript.tsdk": "node_modules/typescript/lib" + "typescript.tsdk": "node_modules/typescript/lib", + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + "vue", + "json", + "jsonc" + ] } diff --git a/README.md b/README.md index c0f76f2f..3a2146e1 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,6 @@ This parser allows us to lint the `