* The value of the `export default` statement whose value starts at `at`, in * comment-stripped code: the name a declaration or a binding gives it, * `'anonymous'` for a function, class or arrow function without one, or null * for any other expression.
(code: string, at: number)
| 175 | * for any other expression. |
| 176 | */ |
| 177 | function readDefaultExport(code: string, at: number): { name: string; nameAt: number; declared: boolean } | 'anonymous' | null { |
| 178 | const rest = code.slice(at, at + 2048); |
| 179 | const decl = DEFAULT_DECLARATION_RE.exec(rest); |
| 180 | if (decl) { |
| 181 | const name = decl[1] ?? decl[2]; |
| 182 | return name ? { name, nameAt: at + decl[0].length - name.length, declared: true } : 'anonymous'; |
| 183 | } |
| 184 | const arrow = DEFAULT_ARROW_RE.exec(rest); |
| 185 | if (arrow) { |
| 186 | if (!arrow[0].endsWith('(')) return 'anonymous'; |
| 187 | // A parenthesized list is an arrow function's parameters when `=>` or a |
| 188 | // return type (`(…): JSX.Element =>`) follows it; otherwise it is an |
| 189 | // expression (`(Foo)`). |
| 190 | let depth = 0; |
| 191 | for (let i = arrow[0].length - 1; i < rest.length; i++) { |
| 192 | if (rest[i] === '(') depth++; |
| 193 | else if (rest[i] === ')' && --depth === 0) return /^\s*(?:=>|:)/.test(rest.slice(i + 1)) ? 'anonymous' : null; |
| 194 | } |
| 195 | return null; |
| 196 | } |
| 197 | const binding = DEFAULT_BINDING_RE.exec(rest); |
| 198 | return binding ? { name: binding[1]!, nameAt: at, declared: false } : null; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * What `filePath`'s own `export default` statement exports. The statement |
no test coverage detected