Skip to content

Commit

Permalink
fix(get-function-name-with-kind): fix default exported function name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 28, 2022
1 parent 7f91b72 commit 9be40ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/get-function-name-with-kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export function getFunctionNameWithKind(node, sourceCode) {
parent.left.type === "Identifier"
) {
tokens.push(`'${parent.left.name}'`)
} else if (
parent.type === "ExportDefaultDeclaration" &&
parent.declaration === node
) {
tokens.push("'default'")
}

return tokens.join(" ")
Expand Down
7 changes: 7 additions & 0 deletions test/get-function-name-with-kind.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe("The 'getFunctionNameWithKind' function", () => {
"class A { static async foo() {} }": "static async method 'foo'",
"class A { static get foo() {} }": "static getter 'foo'",
"class A { static set foo(a) {} }": "static setter 'foo'",
"export default async function* foo() {}":
"async generator function 'foo'",
"export default async function* () {}":
"async generator function 'default'",
"export default async () => {}": "async arrow function 'default'",

...(semver.gte(eslint.Linter.version, "8.0.0")
? {
Expand Down Expand Up @@ -142,6 +147,7 @@ describe("The 'getFunctionNameWithKind' function", () => {
ecmaVersion: semver.gte(eslint.Linter.version, "8.0.0")
? 2022
: 2020,
sourceType: "module",
},
})

Expand Down Expand Up @@ -171,6 +177,7 @@ describe("The 'getFunctionNameWithKind' function", () => {
ecmaVersion: semver.gte(eslint.Linter.version, "8.0.0")
? 2022
: 2020,
sourceType: "module",
},
})

Expand Down

0 comments on commit 9be40ab

Please sign in to comment.