Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
os: windows-latest
- eslint: 7
node: 16
os: macos-latest
os: macos-12
# On old Node.js versions
- eslint: 7
node: 14
Expand Down
7 changes: 7 additions & 0 deletions src/script/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) {
continue
}
} else if (rawParam[index] === "=") {
if (rawParam[index + 1] === ">") {
// Arrow function type
index += 2
continue
}
return rawParam.slice(startIndex, index)
}
if (rawParam.startsWith("//", index)) {
// Skip line comment
const lfIndex = rawParam.indexOf("\n", index)
if (lfIndex >= 0) {
index = lfIndex + 1
Expand All @@ -144,6 +150,7 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) {
return "unknown"
}
if (rawParam.startsWith("/*", index)) {
// Skip block comment
const endIndex = rawParam.indexOf("*/", index)
if (endIndex >= 0) {
index = endIndex + 2
Expand Down
2,226 changes: 2,226 additions & 0 deletions test/fixtures/ast/vue3.3-generic-7-with-arrow/ast.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sourceType": "module",
"parser": {
"ts": "@typescript-eslint/parser"
}
}
11 changes: 11 additions & 0 deletions test/fixtures/ast/vue3.3-generic-7-with-arrow/source.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts" generic="
T extends () => string,
U extends () => string = () => 'abc'
">
const p = defineProps<{t: T, u: U}>()
</script>

<template>
{{p.t()}}
{{p.u()}}
</template>
88 changes: 88 additions & 0 deletions test/fixtures/ast/vue3.3-generic-7-with-arrow/token-ranges.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[
"<script setup lang=\"ts\" generic=\"\n T extends () => string,\n U extends () => string = () => 'abc'\n\">",
"const",
"p",
"=",
"defineProps",
"<",
"{",
"t",
":",
"T",
",",
"u",
":",
"U",
"}",
">",
"(",
")",
"</script>",
"<script",
"setup",
"lang",
"=",
"\"ts\"",
"generic",
"=",
"\"",
"T",
"extends",
"(",
")",
"=>",
"string",
",",
"U",
"extends",
"(",
")",
"=>",
"string",
"=",
"(",
")",
"=>",
"'abc'",
"\"",
">",
"\n",
"const",
" ",
"p",
" ",
"=",
" ",
"defineProps<{t:",
" ",
"T,",
" ",
"u:",
" ",
"U}>()",
"\n",
"</script",
">",
"\n\n",
"<template",
">",
"\n",
"{{",
"p",
".",
"t",
"(",
")",
"}}",
"\n",
"{{",
"p",
".",
"u",
"(",
")",
"}}",
"\n",
"</template",
">"
]
89 changes: 89 additions & 0 deletions test/fixtures/ast/vue3.3-generic-7-with-arrow/tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[
{
"type": "VElement",
"text": "<template>\n{{p.t()}}\n{{p.u()}}\n</template>",
"children": [
{
"type": "VStartTag",
"text": "<template>",
"children": []
},
{
"type": "VText",
"text": "\n",
"children": []
},
{
"type": "VExpressionContainer",
"text": "{{p.t()}}",
"children": [
{
"type": "CallExpression",
"text": "p.t()",
"children": [
{
"type": "MemberExpression",
"text": "p.t",
"children": [
{
"type": "Identifier",
"text": "p",
"children": []
},
{
"type": "Identifier",
"text": "t",
"children": []
}
]
}
]
}
]
},
{
"type": "VText",
"text": "\n",
"children": []
},
{
"type": "VExpressionContainer",
"text": "{{p.u()}}",
"children": [
{
"type": "CallExpression",
"text": "p.u()",
"children": [
{
"type": "MemberExpression",
"text": "p.u",
"children": [
{
"type": "Identifier",
"text": "p",
"children": []
},
{
"type": "Identifier",
"text": "u",
"children": []
}
]
}
]
}
]
},
{
"type": "VText",
"text": "\n",
"children": []
},
{
"type": "VEndTag",
"text": "</template>",
"children": []
}
]
}
]
Loading