From a210e33ad40cdb94995603db287b8aa02eb1d9c5 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Sat, 9 Mar 2024 18:49:13 +0900 Subject: [PATCH 1/3] Fix wrong AST for asycn function in v-on --- src/script/index.ts | 6 +- .../ast.json | 829 ++++++++++++++++ .../source.vue | 3 + .../token-ranges.json | 26 + .../tree.json | 96 ++ .../v-on-async-function-expression/ast.json | 909 ++++++++++++++++++ .../v-on-async-function-expression/source.vue | 3 + .../token-ranges.json | 28 + .../v-on-async-function-expression/tree.json | 108 +++ 9 files changed, 2006 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/ast.json create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/source.vue create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json create mode 100644 test/fixtures/ast/v-on-async-arrow-function-expression/tree.json create mode 100644 test/fixtures/ast/v-on-async-function-expression/ast.json create mode 100644 test/fixtures/ast/v-on-async-function-expression/source.vue create mode 100644 test/fixtures/ast/v-on-async-function-expression/token-ranges.json create mode 100644 test/fixtures/ast/v-on-async-function-expression/tree.json diff --git a/src/script/index.ts b/src/script/index.ts index b05b2c6..7deb083 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -75,8 +75,10 @@ const PARENS = /^(\s*\()([\s\S]*?)(\)\s*)$/u const DUMMY_PARENT: any = {} // Like Vue, it judges whether it is a function expression or not. -// https://github.com/vuejs/vue/blob/0948d999f2fddf9f90991956493f976273c5da1f/src/compiler/codegen/events.js#L3 -const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|\([^)]*?\))\s*=>|^function\s*\(/u +// https://github.com/vuejs/core/blob/fef2acb2049fce3407dff17fe8af1836b97dfd73/packages/compiler-core/src/transforms/vOn.ts#L19 +const IS_FUNCTION_EXPRESSION = + /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u + const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/ast.json b/test/fixtures/ast/v-on-async-arrow-function-expression/ast.json new file mode 100644 index 0000000..17fa814 --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/ast.json @@ -0,0 +1,829 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 77 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 31, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 31, + 54 + ], + "id": null, + "expression": true, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "AwaitExpression", + "start": 43, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 43, + 54 + ], + "argument": { + "type": "CallExpression", + "start": 49, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 49, + 54 + ], + "callee": { + "type": "Identifier", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 49, + 52 + ], + "name": "act" + }, + "arguments": [], + "optional": false + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 49, + 52 + ], + "name": "act" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 56, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 54 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 66, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "async", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 31, + 36 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + }, + "range": [ + 37, + 38 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + }, + "range": [ + 38, + 39 + ] + }, + { + "type": "Punctuator", + "value": "=>", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "range": [ + 40, + 42 + ] + }, + { + "type": "Identifier", + "value": "await", + "start": 43, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 2, + "column": 37 + } + }, + "range": [ + 43, + 48 + ] + }, + { + "type": "Identifier", + "value": "act", + "start": 49, + "end": 52, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 41 + } + }, + "range": [ + 49, + 52 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 2, + "column": 41 + }, + "end": { + "line": 2, + "column": 42 + } + }, + "range": [ + 52, + 53 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 53, + "end": 54, + "loc": { + "start": { + "line": 2, + "column": 42 + }, + "end": { + "line": 2, + "column": 43 + } + }, + "range": [ + 53, + 54 + ] + }, + { + "type": "Punctuator", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 55, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 44 + }, + "end": { + "line": 2, + "column": 45 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 56, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 66, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 77, + 78 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/source.vue b/test/fixtures/ast/v-on-async-arrow-function-expression/source.vue new file mode 100644 index 0000000..9cdad44 --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json b/test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json new file mode 100644 index 0000000..032294c --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/token-ranges.json @@ -0,0 +1,26 @@ +[ + "", + "\n ", + "", + "await", + "act", + "(", + ")", + "\"", + ">", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-arrow-function-expression/tree.json b/test/fixtures/ast/v-on-async-arrow-function-expression/tree.json new file mode 100644 index 0000000..d272edf --- /dev/null +++ b/test/fixtures/ast/v-on-async-arrow-function-expression/tree.json @@ -0,0 +1,96 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-function-expression/ast.json b/test/fixtures/ast/v-on-async-function-expression/ast.json new file mode 100644 index 0000000..447b74b --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/ast.json @@ -0,0 +1,909 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 86 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "name": "button", + "rawName": "button", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 23, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 23, + 29 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "name": { + "type": "VIdentifier", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "name": "on", + "rawName": "@" + }, + "argument": { + "type": "VIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "name": "click", + "rawName": "click" + }, + "modifiers": [] + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 30, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "expression": { + "type": "FunctionExpression", + "start": 31, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 52 + } + }, + "range": [ + 31, + 63 + ], + "id": null, + "expression": false, + "generator": false, + "async": true, + "params": [], + "body": { + "type": "BlockStatement", + "start": 48, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 52 + } + }, + "range": [ + 48, + 63 + ], + "body": [ + { + "type": "ExpressionStatement", + "start": 50, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 50, + 61 + ], + "expression": { + "type": "AwaitExpression", + "start": 50, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 50, + 61 + ], + "argument": { + "type": "CallExpression", + "start": 56, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 56, + 61 + ], + "callee": { + "type": "Identifier", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 56, + 59 + ], + "name": "act" + }, + "arguments": [], + "optional": false + } + } + } + ] + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 56, + 59 + ], + "name": "act" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 65, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 63 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 63 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 75, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "value": "button" + }, + { + "type": "Punctuator", + "range": [ + 23, + 24 + ], + "loc": { + "start": { + "column": 12, + "line": 2 + }, + "end": { + "column": 13, + "line": 2 + } + }, + "value": "@" + }, + { + "type": "HTMLIdentifier", + "range": [ + 24, + 29 + ], + "loc": { + "start": { + "column": 13, + "line": 2 + }, + "end": { + "column": 18, + "line": 2 + } + }, + "value": "click" + }, + { + "type": "HTMLAssociation", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "async", + "start": 31, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "range": [ + 31, + 36 + ] + }, + { + "type": "Keyword", + "value": "function", + "start": 37, + "end": 45, + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 34 + } + }, + "range": [ + 37, + 45 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 34 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "range": [ + 45, + 46 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 2, + "column": 35 + }, + "end": { + "line": 2, + "column": 36 + } + }, + "range": [ + 46, + 47 + ] + }, + { + "type": "Punctuator", + "value": "{", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 37 + }, + "end": { + "line": 2, + "column": 38 + } + }, + "range": [ + 48, + 49 + ] + }, + { + "type": "Identifier", + "value": "await", + "start": 50, + "end": 55, + "loc": { + "start": { + "line": 2, + "column": 39 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "range": [ + 50, + 55 + ] + }, + { + "type": "Identifier", + "value": "act", + "start": 56, + "end": 59, + "loc": { + "start": { + "line": 2, + "column": 45 + }, + "end": { + "line": 2, + "column": 48 + } + }, + "range": [ + 56, + 59 + ] + }, + { + "type": "Punctuator", + "value": "(", + "start": 59, + "end": 60, + "loc": { + "start": { + "line": 2, + "column": 48 + }, + "end": { + "line": 2, + "column": 49 + } + }, + "range": [ + 59, + 60 + ] + }, + { + "type": "Punctuator", + "value": ")", + "start": 60, + "end": 61, + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 2, + "column": 50 + } + }, + "range": [ + 60, + 61 + ] + }, + { + "type": "Punctuator", + "value": "}", + "start": 62, + "end": 63, + "loc": { + "start": { + "line": 2, + "column": 51 + }, + "end": { + "line": 2, + "column": 52 + } + }, + "range": [ + 62, + 63 + ] + }, + { + "type": "Punctuator", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 2, + "column": 52 + }, + "end": { + "line": 2, + "column": 53 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 64, + 65 + ], + "loc": { + "start": { + "line": 2, + "column": 53 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 65, + 73 + ], + "loc": { + "start": { + "line": 2, + "column": 54 + }, + "end": { + "line": 2, + "column": 62 + } + }, + "value": "button" + }, + { + "type": "HTMLTagClose", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 2, + "column": 62 + }, + "end": { + "line": 2, + "column": 63 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 63 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 75, + 85 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 4, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-function-expression/source.vue b/test/fixtures/ast/v-on-async-function-expression/source.vue new file mode 100644 index 0000000..fb86873 --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/source.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/ast/v-on-async-function-expression/token-ranges.json b/test/fixtures/ast/v-on-async-function-expression/token-ranges.json new file mode 100644 index 0000000..77fdd02 --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/token-ranges.json @@ -0,0 +1,28 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/v-on-async-function-expression/tree.json b/test/fixtures/ast/v-on-async-function-expression/tree.json new file mode 100644 index 0000000..5fdf6e8 --- /dev/null +++ b/test/fixtures/ast/v-on-async-function-expression/tree.json @@ -0,0 +1,108 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file From 3ce44ad296fa7b37d77a1ad5310524dc5ec68445 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Sat, 9 Mar 2024 19:18:07 +0900 Subject: [PATCH 2/3] chore: add comment --- src/script/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/script/index.ts b/src/script/index.ts index 7deb083..96c10c6 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -78,6 +78,11 @@ const DUMMY_PARENT: any = {} // https://github.com/vuejs/core/blob/fef2acb2049fce3407dff17fe8af1836b97dfd73/packages/compiler-core/src/transforms/vOn.ts#L19 const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u +// ^^^^^^^ omit paren argument ^^^^^^^^ function keyword +// ^^^^^ <--- async key word (optional) --> ^^^^^ +// ^^------^^ arguments with parens ^^^^^^ named function (optional) +// ^^^^^^^^^ return types (optional) +// ^^ arrow ^^ opening paren const IS_SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?'\]|\["[^"]*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/u From ce22a1ec1f5b9c04365134f387ffcaaaa6c0683c Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Sat, 9 Mar 2024 19:19:50 +0900 Subject: [PATCH 3/3] chore: fix comment --- src/script/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/script/index.ts b/src/script/index.ts index 96c10c6..262c4bd 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -79,7 +79,7 @@ const DUMMY_PARENT: any = {} const IS_FUNCTION_EXPRESSION = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/u // ^^^^^^^ omit paren argument ^^^^^^^^ function keyword -// ^^^^^ <--- async key word (optional) --> ^^^^^ +// ^^^^^ <--- async keyword (optional) ---> ^^^^^ // ^^------^^ arguments with parens ^^^^^^ named function (optional) // ^^^^^^^^^ return types (optional) // ^^ arrow ^^ opening paren