diff --git a/src/script/index.ts b/src/script/index.ts index 7be03681..50010618 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -46,6 +46,11 @@ import { const ALIAS_PARENS = /^(\s*)\(([\s\S]+)\)(\s*(?:in|of)\b[\s\S]+)$/u const DUMMY_PARENT: any = {} +// Like Vue, it judges whether it is a function expression or not. +// https://github.com/vuejs/vue/blob/0948d999f2fddf9f90991956493f976273c5da1f/src/compiler/codegen/events.js#L3 +const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/u +const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u + /** * The interface of ESLint custom parsers. */ @@ -807,6 +812,24 @@ export function parseVOnExpression( code: string, locationCalculator: LocationCalculator, parserOptions: any, +): ExpressionParseResult { + if (IS_FUNCTION_EXPRESSION.test(code) || IS_SIMPLE_PATH.test(code)) { + return parseExpressionBody(code, locationCalculator, parserOptions) + } + return parseVOnExpressionBody(code, locationCalculator, parserOptions) +} + +/** + * Parse the source code of inline scripts. + * @param code The source code of inline scripts. + * @param locationCalculator The location calculator for the inline script. + * @param parserOptions The parser options. + * @returns The result of parsing. + */ +function parseVOnExpressionBody( + code: string, + locationCalculator: LocationCalculator, + parserOptions: any, ): ExpressionParseResult { debug('[script] parse v-on expression: "void function($event){%s}"', code) diff --git a/test/fixtures/ast/error-v-on-function-expression/ast.json b/test/fixtures/ast/error-v-on-function-expression/ast.json new file mode 100644 index 00000000..bf7e0cd9 --- /dev/null +++ b/test/fixtures/ast/error-v-on-function-expression/ast.json @@ -0,0 +1,503 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 73 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "expression": null, + "references": [] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 52, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 50 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 62, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "HTMLLiteral", + "range": [ + 30, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "value": "function() { err( }" + }, + { + "type": "HTMLTagClose", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 52, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 62, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [ + { + "message": "Unexpected token }", + "index": 49, + "lineNumber": 2, + "column": 38 + } + ] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/error-v-on-function-expression/source.vue b/test/fixtures/ast/error-v-on-function-expression/source.vue new file mode 100644 index 00000000..82a8a957 --- /dev/null +++ b/test/fixtures/ast/error-v-on-function-expression/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/error-v-on-function-expression/token-ranges.json b/test/fixtures/ast/error-v-on-function-expression/token-ranges.json new file mode 100644 index 00000000..9eb022c2 --- /dev/null +++ b/test/fixtures/ast/error-v-on-function-expression/token-ranges.json @@ -0,0 +1,16 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/error-v-on-function-expression/tree.json b/test/fixtures/ast/error-v-on-function-expression/tree.json new file mode 100644 index 00000000..1747a052 --- /dev/null +++ b/test/fixtures/ast/error-v-on-function-expression/tree.json @@ -0,0 +1,61 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-arrow-function-expression.1/ast.json b/test/fixtures/ast/v-on-arrow-function-expression.1/ast.json new file mode 100644 index 00000000..0a6cb994 --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.1/ast.json @@ -0,0 +1,721 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 65 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 31, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "range": [ + 31, + 42 + ], + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "CallExpression", + "start": 37, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "range": [ + 37, + 42 + ], + "callee": { + "type": "Identifier", + "start": 37, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 37, + 40 + ], + "name": "act" + }, + "arguments": [] + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 37, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 37, + 40 + ], + "name": "act" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 44, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 42 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 54, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Punctuator", + "value": "(", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 31, + 32 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "range": [ + 32, + 33 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 34, + 36 + ] + }, + { + "type": "Identifier", + "value": "act", + "start": 37, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 37, + 40 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "range": [ + 40, + 41 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "range": [ + 41, + 42 + ] + }, + { + "type": "Punctuator", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 44, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 54, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-arrow-function-expression.1/source.vue b/test/fixtures/ast/v-on-arrow-function-expression.1/source.vue new file mode 100644 index 00000000..6306dab3 --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.1/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-arrow-function-expression.1/token-ranges.json b/test/fixtures/ast/v-on-arrow-function-expression.1/token-ranges.json new file mode 100644 index 00000000..35660111 --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.1/token-ranges.json @@ -0,0 +1,23 @@ +[ + "", + "\n ", + "", + "act", + "(", + ")", + "\"", + ">", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-arrow-function-expression.1/tree.json b/test/fixtures/ast/v-on-arrow-function-expression.1/tree.json new file mode 100644 index 00000000..b765189c --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.1/tree.json @@ -0,0 +1,79 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-arrow-function-expression.2/ast.json b/test/fixtures/ast/v-on-arrow-function-expression.2/ast.json new file mode 100644 index 00000000..b18a0d5a --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.2/ast.json @@ -0,0 +1,722 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 64 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 31, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "range": [ + 31, + 41 + ], + "id": null, + "expression": true, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 31, + 32 + ], + "name": "e" + } + ], + "body": { + "type": "CallExpression", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "range": [ + 36, + 41 + ], + "callee": { + "type": "Identifier", + "start": 36, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 36, + 39 + ], + "name": "act" + }, + "arguments": [] + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 36, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 36, + 39 + ], + "name": "act" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 43, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 41 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 53, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "e", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "range": [ + 31, + 32 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "range": [ + 33, + 35 + ] + }, + { + "type": "Identifier", + "value": "act", + "start": 36, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 36, + 39 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 39, + 40 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "range": [ + 40, + 41 + ] + }, + { + "type": "Punctuator", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 43, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 53, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-arrow-function-expression.2/source.vue b/test/fixtures/ast/v-on-arrow-function-expression.2/source.vue new file mode 100644 index 00000000..9b6a0735 --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.2/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-arrow-function-expression.2/token-ranges.json b/test/fixtures/ast/v-on-arrow-function-expression.2/token-ranges.json new file mode 100644 index 00000000..a73ca1ee --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.2/token-ranges.json @@ -0,0 +1,22 @@ +[ + "", + "\n ", + "", + "act", + "(", + ")", + "\"", + ">", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-arrow-function-expression.2/tree.json b/test/fixtures/ast/v-on-arrow-function-expression.2/tree.json new file mode 100644 index 00000000..08202878 --- /dev/null +++ b/test/fixtures/ast/v-on-arrow-function-expression.2/tree.json @@ -0,0 +1,84 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-function-expression/ast.json b/test/fixtures/ast/v-on-function-expression/ast.json new file mode 100644 index 00000000..58484adb --- /dev/null +++ b/test/fixtures/ast/v-on-function-expression/ast.json @@ -0,0 +1,801 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 74 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 51 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "expression": { + "type": "FunctionExpression", + "start": 31, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 31, + 51 + ], + "id": null, + "expression": false, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 42, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 42, + 51 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 44, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 44, + 49 + ], + "expression": { + "type": "CallExpression", + "start": 44, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 44, + 49 + ], + "callee": { + "type": "Identifier", + "start": 44, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "range": [ + 44, + 47 + ], + "name": "act" + }, + "arguments": [] + } + } + ] + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 44, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "range": [ + 44, + 47 + ], + "name": "act" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 53, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 51 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 63, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Keyword", + "value": "function", + "start": 31, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 31, + 39 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "range": [ + 39, + 40 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "range": [ + 40, + 41 + ] + }, + { + "type": "Punctuator", + "value": "{", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "range": [ + 42, + 43 + ] + }, + { + "type": "Identifier", + "value": "act", + "start": 44, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "range": [ + 44, + 47 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 36 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "range": [ + 47, + 48 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 48, + 49 + ] + }, + { + "type": "Punctuator", + "value": "}", + "start": 50, + "end": 51, + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 40 + } + }, + "range": [ + 50, + 51 + ] + }, + { + "type": "Punctuator", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 53, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 50 + }, + "end": { + "line": 2, + "column": 51 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 63, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-function-expression/source.vue b/test/fixtures/ast/v-on-function-expression/source.vue new file mode 100644 index 00000000..32d06fd1 --- /dev/null +++ b/test/fixtures/ast/v-on-function-expression/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-function-expression/token-ranges.json b/test/fixtures/ast/v-on-function-expression/token-ranges.json new file mode 100644 index 00000000..15b2c455 --- /dev/null +++ b/test/fixtures/ast/v-on-function-expression/token-ranges.json @@ -0,0 +1,25 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-function-expression/tree.json b/test/fixtures/ast/v-on-function-expression/tree.json new file mode 100644 index 00000000..d8b48493 --- /dev/null +++ b/test/fixtures/ast/v-on-function-expression/tree.json @@ -0,0 +1,91 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.1/ast.json b/test/fixtures/ast/v-on-simple-path.1/ast.json new file mode 100644 index 00000000..081e2e77 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.1/ast.json @@ -0,0 +1,577 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 57 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "expression": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ], + "name": "foo" + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ], + "name": "foo" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 36, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 34 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 46, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "foo", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ] + }, + { + "type": "Punctuator", + "range": [ + 34, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 35, + 36 + ], + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 36, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 44, + 45 + ], + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 45, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 46, + 56 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.1/source.vue b/test/fixtures/ast/v-on-simple-path.1/source.vue new file mode 100644 index 00000000..720524e9 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.1/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-simple-path.1/token-ranges.json b/test/fixtures/ast/v-on-simple-path.1/token-ranges.json new file mode 100644 index 00000000..b152d5fb --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.1/token-ranges.json @@ -0,0 +1,18 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.1/tree.json b/test/fixtures/ast/v-on-simple-path.1/tree.json new file mode 100644 index 00000000..63dcfe8a --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.1/tree.json @@ -0,0 +1,67 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.2/ast.json b/test/fixtures/ast/v-on-simple-path.2/ast.json new file mode 100644 index 00000000..31e71851 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.2/ast.json @@ -0,0 +1,657 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 61 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "expression": { + "type": "MemberExpression", + "start": 31, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 31, + 38 + ], + "object": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ], + "name": "foo" + }, + "property": { + "type": "Identifier", + "start": 35, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 35, + 38 + ], + "name": "bar" + }, + "computed": false + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ], + "name": "foo" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 40, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 38 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 50, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "foo", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ] + }, + { + "type": "Punctuator", + "value": ".", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "range": [ + 34, + 35 + ] + }, + { + "type": "Identifier", + "value": "bar", + "start": 35, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 35, + 38 + ] + }, + { + "type": "Punctuator", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 40, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 50, + 60 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.2/source.vue b/test/fixtures/ast/v-on-simple-path.2/source.vue new file mode 100644 index 00000000..6ace14dc --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.2/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-simple-path.2/token-ranges.json b/test/fixtures/ast/v-on-simple-path.2/token-ranges.json new file mode 100644 index 00000000..3c0c3eb7 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.2/token-ranges.json @@ -0,0 +1,20 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.2/tree.json b/test/fixtures/ast/v-on-simple-path.2/tree.json new file mode 100644 index 00000000..c1edc11e --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.2/tree.json @@ -0,0 +1,78 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.3/ast.json b/test/fixtures/ast/v-on-simple-path.3/ast.json new file mode 100644 index 00000000..f424c254 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.3/ast.json @@ -0,0 +1,977 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 103 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 91 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 82 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 31, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 31, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 38, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "expression": { + "type": "MemberExpression", + "start": 39, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "range": [ + 39, + 49 + ], + "object": { + "type": "Identifier", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "range": [ + 39, + 42 + ], + "name": "foo" + }, + "property": { + "type": "Literal", + "start": 43, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "range": [ + 43, + 48 + ], + "value": "bar", + "raw": "'bar'" + }, + "computed": true + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "range": [ + 39, + 42 + ], + "name": "foo" + }, + "mode": "r" + } + ] + } + }, + { + "type": "VAttribute", + "range": [ + 59, + 76 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 59, + 67 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "name": "on", + "argument": "keydown", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "keydown", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 68, + 76 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "expression": { + "type": "MemberExpression", + "start": 69, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "range": [ + 69, + 75 + ], + "object": { + "type": "Identifier", + "start": 69, + "end": 72, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 21 + } + }, + "range": [ + 69, + 72 + ], + "name": "foo" + }, + "property": { + "type": "Literal", + "start": 73, + "end": 74, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "range": [ + 73, + 74 + ], + "value": 0, + "raw": "0" + }, + "computed": true + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 69, + "end": 72, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 21 + } + }, + "range": [ + 69, + 72 + ], + "name": "foo" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 82, + 91 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 14 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 92, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 31, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "foo", + "start": 39, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "range": [ + 39, + 42 + ] + }, + { + "type": "Punctuator", + "value": "[", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "range": [ + 42, + 43 + ] + }, + { + "type": "String", + "value": "'bar'", + "start": 43, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 25 + } + }, + "range": [ + 43, + 48 + ] + }, + { + "type": "Punctuator", + "value": "]", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 26 + } + }, + "range": [ + 48, + 49 + ] + }, + { + "type": "Punctuator", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + }, + "value": "\"" + }, + { + "type": "HTMLIdentifier", + "range": [ + 59, + 67 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 16 + } + }, + "value": "@keydown" + }, + { + "type": "HTMLAssociation", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "foo", + "start": 69, + "end": 72, + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 21 + } + }, + "range": [ + 69, + 72 + ] + }, + { + "type": "Punctuator", + "value": "[", + "start": 72, + "end": 73, + "loc": { + "start": { + "line": 4, + "column": 21 + }, + "end": { + "line": 4, + "column": 22 + } + }, + "range": [ + 72, + 73 + ] + }, + { + "type": "Numeric", + "value": "0", + "start": 73, + "end": 74, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 4, + "column": 23 + } + }, + "range": [ + 73, + 74 + ] + }, + { + "type": "Punctuator", + "value": "]", + "start": 74, + "end": 75, + "loc": { + "start": { + "line": 4, + "column": 23 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "range": [ + 74, + 75 + ] + }, + { + "type": "Punctuator", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 4, + "column": 24 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 82, + 90 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 13 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 14 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 92, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 102, + 103 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 103, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.3/source.vue b/test/fixtures/ast/v-on-simple-path.3/source.vue new file mode 100644 index 00000000..cc83915b --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.3/source.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/ast/v-on-simple-path.3/token-ranges.json b/test/fixtures/ast/v-on-simple-path.3/token-ranges.json new file mode 100644 index 00000000..51f40d47 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.3/token-ranges.json @@ -0,0 +1,29 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.3/tree.json b/test/fixtures/ast/v-on-simple-path.3/tree.json new file mode 100644 index 00000000..aaad636d --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.3/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/v-on-simple-path.4/ast.json b/test/fixtures/ast/v-on-simple-path.4/ast.json new file mode 100644 index 00000000..7f70ef7a --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.4/ast.json @@ -0,0 +1,700 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 62 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": "on", + "argument": "click", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "on", + "argument": "click", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "expression": { + "type": "MemberExpression", + "start": 31, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 31, + 39 + ], + "object": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ], + "name": "foo" + }, + "property": { + "type": "Identifier", + "start": 35, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 35, + 38 + ], + "name": "bar" + }, + "computed": true + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ], + "name": "foo" + }, + "mode": "r" + }, + { + "id": { + "type": "Identifier", + "start": 35, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 35, + 38 + ], + "name": "bar" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 41, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 39 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 51, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "HTMLIdentifier", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "value": "@click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "foo", + "start": 31, + "end": 34, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "range": [ + 31, + 34 + ] + }, + { + "type": "Punctuator", + "value": "[", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "range": [ + 34, + 35 + ] + }, + { + "type": "Identifier", + "value": "bar", + "start": 35, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 24 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 35, + 38 + ] + }, + { + "type": "Punctuator", + "value": "]", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 38, + 39 + ] + }, + { + "type": "Punctuator", + "range": [ + 39, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 41, + 49 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 49, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 39 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 51, + 61 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.4/source.vue b/test/fixtures/ast/v-on-simple-path.4/source.vue new file mode 100644 index 00000000..561289e5 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.4/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-simple-path.4/token-ranges.json b/test/fixtures/ast/v-on-simple-path.4/token-ranges.json new file mode 100644 index 00000000..72e86b41 --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.4/token-ranges.json @@ -0,0 +1,21 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-simple-path.4/tree.json b/test/fixtures/ast/v-on-simple-path.4/tree.json new file mode 100644 index 00000000..50378ecc --- /dev/null +++ b/test/fixtures/ast/v-on-simple-path.4/tree.json @@ -0,0 +1,78 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file