From aa2de99765b03c706921cd0843fd219d48fb88a0 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sun, 31 Dec 2023 08:42:01 +0900 Subject: [PATCH] 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