Skip to content

Commit 9be40ab

Browse files
authored
fix(get-function-name-with-kind): fix default exported function name (mysticatea#26)
1 parent 7f91b72 commit 9be40ab

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/get-function-name-with-kind.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export function getFunctionNameWithKind(node, sourceCode) {
8383
parent.left.type === "Identifier"
8484
) {
8585
tokens.push(`'${parent.left.name}'`)
86+
} else if (
87+
parent.type === "ExportDefaultDeclaration" &&
88+
parent.declaration === node
89+
) {
90+
tokens.push("'default'")
8691
}
8792

8893
return tokens.join(" ")

test/get-function-name-with-kind.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ describe("The 'getFunctionNameWithKind' function", () => {
6464
"class A { static async foo() {} }": "static async method 'foo'",
6565
"class A { static get foo() {} }": "static getter 'foo'",
6666
"class A { static set foo(a) {} }": "static setter 'foo'",
67+
"export default async function* foo() {}":
68+
"async generator function 'foo'",
69+
"export default async function* () {}":
70+
"async generator function 'default'",
71+
"export default async () => {}": "async arrow function 'default'",
6772

6873
...(semver.gte(eslint.Linter.version, "8.0.0")
6974
? {
@@ -142,6 +147,7 @@ describe("The 'getFunctionNameWithKind' function", () => {
142147
ecmaVersion: semver.gte(eslint.Linter.version, "8.0.0")
143148
? 2022
144149
: 2020,
150+
sourceType: "module",
145151
},
146152
})
147153

@@ -171,6 +177,7 @@ describe("The 'getFunctionNameWithKind' function", () => {
171177
ecmaVersion: semver.gte(eslint.Linter.version, "8.0.0")
172178
? 2022
173179
: 2020,
180+
sourceType: "module",
174181
},
175182
})
176183

0 commit comments

Comments
 (0)