8000 Fixed parsing error when arrow function type in generics (#234) · vuejs/vue-eslint-parser@c7b5fbf · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c7b5fbf

Browse files
authored
Fixed parsing error when arrow function type in generics (#234)
* Fixed parsing error when arrow function type in generics * macos-latest to macos-12
1 parent 79ecf1e commit c7b5fbf

File tree

12 files changed

+6135
-1
lines changed

12 files changed

+6135
-1
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
os: windows-latest
4040
- eslint: 7
4141
node: 16
42-
os: macos-latest
42+
os: macos-12
4343
# On old Node.js versions
4444
- eslint: 7
4545
node: 14

src/script/generic.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,15 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) {
133133
continue
134134
}
135135
} else if (rawParam[index] === "=") {
136+
if (rawParam[index + 1] === ">") {
137+
// Arrow function type
138+
index += 2
139+
continue
140+
}
136141
return rawParam.slice(startIndex, index)
137142
}
138143
if (rawParam.startsWith("//", index)) {
144+
// Skip line comment
139145
const lfIndex = rawParam.indexOf("\n", index)
140146
if (lfIndex >= 0) {
141147
index = lfIndex + 1
@@ -144,6 +150,7 @@ function getConstraint(node: TSESTree.TSTypeParameter, rawParam: string) {
144150
return "unknown"
145151
}
146152
if (rawParam.startsWith("/*", index)) {
153+
// Skip block comment
147154
const endIndex = rawParam.indexOf("*/", index)
148155
if (endIndex >= 0) {
149156
index = endIndex + 2

test/fixtures/ast/vue3.3-generic-7-with-arrow/ast.json

Lines changed: 2226 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sourceType": "module",
3+
"parser": {
4+
"ts": "@typescript-eslint/parser"
5+
}
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts" generic="
2+
T extends () => string,
3+
U extends () => string = () => 'abc'
4+
">
5+
const p = defineProps<{t: T, u: U}>()
6+
</script>
7+
8+
<template>
9+
{{p.t()}}
10+
{{p.u()}}
11+
</template>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
[
2+
"<script setup lang=\"ts\" generic=\"\n T extends () => string,\n U extends () => string = () => 'abc'\n\">",
3+
"const",
4+
"p",
5+
"=",
6+
"defineProps",
7+
"<",
8+
"{",
9+
"t",
10+
":",
11+
"T",
12+
",",
13+
"u",
14+
":",
15+
"U",
16+
"}",
17+
">",
18+
"(",
19+
")",
20+
"</script>",
21+
"<script",
22+
"setup",
23+
"lang",
24+
"=",
25+
"\"ts\"",
26+
"generic",
27+
"=",
28+
"\"",
29+
"T",
30+
"extends",
31+
"(",
32+
")",
33+
"=>",
34+
"string",
35+
",",
36+
"U",
37+
"extends",
38+
"(",
39+
")",
40+
"=>",
41+
"string",
42+
"=",
43+
"(",
44+
")",
45+
"=>",
46+
"'abc'",
47+
"\"",
48+
">",
49+
"\n",
50+
"const",
51+
" ",
52+
"p",
53+
" ",
54+
"=",
55+
" ",
56+
"defineProps<{t:",
57+
" ",
58+
"T,",
59+
" ",
60+
"u:",
61+
" ",
62+
"U}>()",
63+
"\n",
64+
"</script",
65+
">",
66+
"\n\n",
67+
"<template",
68+
">",
69+
"\n",
70+
"{{",
71+
"p",
72+
".",
73+
"t",
74+
"(",
75+
")",
76+
"}}",
77+
"\n",
78+
"{{",
79+
"p",
80+
".",
81+
"u",
82+
"(",
83+
")",
84+
"}}",
85+
"\n",
86+
"</template",
87+
">"
88+
]
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
[
2+
{
3+
"type": "VElement",
4+
"text": "<template>\n{{p.t()}}\n{{p.u()}}\n</template>",
5+
"children": [
6+
{
7+
"type": "VStartTag",
8+
"text": "<template>",
9+
"children": []
10+
},
11+
{
12+
"type": "VText",
13+
"text": "\n",
14+
"children": []
15+
},
16+
{
17+
"type": "VExpressionContainer",
18+
"text": "{{p.t()}}",
19+
"children": [
20+
{
21+
"type": "CallExpression",
22+
"text": "p.t()",
23+
"children": [
24+
{
25+
"type": "MemberExpression",
26+
"text": "p.t",
27+
"children": [
28+
{
29+
"type": "Identifier",
30+
"text": "p",
31+
"children": []
32+
},
33+
{
34+
"type": "Identifier",
35+
"text": "t",
36+
"children": []
37+
}
38+
]
39+
}
40+
]
41+
}
42+
]
43+
},
44+
{
45+
"type": "VText",
46+
"text": "\n",
47+
"children": []
48+
},
49+
{
50+
"type": "VExpressionContainer",
51+
"text": "{{p.u()}}",
52+
"children": [
53+
{
54+
"type": "CallExpression",
55+
"text": "p.u()",
56+
"children": [
57+
{
58+
"type": "MemberExpression",
59+
"text": "p.u",
60+
"children": [
61+
{
62+
"type": "Identifier",
63+
"text": "p",
64+
"children": []
65+
},
66+
{
67+
"type": "Identifier",
68+
"text": "u",
69+
"children": []
70+
}
71+
]
72+
}
73+
]
74+
}
75+
]
76+
},
77+
{
78+
"type": "VText",
79+
"text": "\n",
80+
"children": []
81+
},
82+
{
83+
"type": "VEndTag",
84+
"text": "</template>",
85+
"children": []
86+
}
87+
]
88+
}
89+
]

0 commit comments

Comments
 (0)
0