Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(get-function-name-with-kind): fix default exported function name #26

Merged
merged 1 commit into from
Nov 28, 2022
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
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'",
MichaelDeBoey marked this conversation as resolved.
Show resolved Hide resolved

...(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