Skip to content

Commit

Permalink
modify parseDefaultExportName so it does not grab an HOC, but the fir… (
Browse files Browse the repository at this point in the history
#4359)

* modify parseDefaultExportName so it does not grab an HOC, but the first Argument it takes. presumably the actual component

* created changeset
  • Loading branch information
bezalel6 authored Jul 30, 2024
1 parent e1055f7 commit d53da39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-boats-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"blitz": patch
---

Improved parsing of default export names to handle higher-order components (HOCs) in the `parseDefaultExportName` function.
7 changes: 4 additions & 3 deletions packages/blitz/src/cli/utils/routes-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,13 @@ const pascalCase = (value: string): string => {
return val.substr(0, 1).toUpperCase() + val.substr(1)
}
export function parseDefaultExportName(contents: string): string | null {
const result = contents.match(/export\s+default(?:\s+(?:const|let|class|var|function))?\s+(\w+)/)
const result = contents.match(/export\s+default(?:\s+(const|let|class|var|function))?\s+(\w+)(?:\(([a-zA-Z_$][a-zA-Z0-9_$]*\b).*\))?/)
if (!result) {
return null
}

return result[1] ?? null
const [,declaration,compOrHOCName,comp] = result
if(declaration||!comp) return compOrHOCName ?? null;
return comp ?? null
}
export async function generateManifest() {
const config = await loadConfig(process.cwd())
Expand Down

0 comments on commit d53da39

Please sign in to comment.