* 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, an * object literal (named `default` by its owner, #3393), or null for any other
( code: string, at: number )
| 180 | * expression. |
| 181 | */ |
| 182 | function readDefaultExport( |
| 183 | code: string, |
| 184 | at: number |
| 185 | ): { name: string; nameAt: number; declared: boolean; object?: true } | 'anonymous' | null { |
| 186 | const rest = code.slice(at, at + 2048); |
| 187 | if (rest.startsWith('{')) return { name: 'default', nameAt: at, declared: true, object: true }; |
| 188 | const decl = DEFAULT_DECLARATION_RE.exec(rest); |
| 189 | if (decl) { |
| 190 | const name = decl[1] ?? decl[2]; |
| 191 | return name ? { name, nameAt: at + decl[0].length - name.length, declared: true } : 'anonymous'; |
| 192 | } |
| 193 | const arrow = DEFAULT_ARROW_RE.exec(rest); |
| 194 | if (arrow) { |
| 195 | if (!arrow[0].endsWith('(')) return 'anonymous'; |
| 196 | // A parenthesized list is an arrow function's parameters when `=>` or a |
| 197 | // return type (`(…): JSX.Element =>`) follows it; otherwise it is an |
| 198 | // expression (`(Foo)`). |
| 199 | let depth = 0; |
| 200 | for (let i = arrow[0].length - 1; i < rest.length; i++) { |
| 201 | if (rest[i] === '(') depth++; |
| 202 | else if (rest[i] === ')' && --depth === 0) return /^\s*(?:=>|:)/.test(rest.slice(i + 1)) ? 'anonymous' : null; |
| 203 | } |
| 204 | return null; |
| 205 | } |
| 206 | const binding = DEFAULT_BINDING_RE.exec(rest); |
| 207 | return binding ? { name: binding[1]!, nameAt: at, declared: false } : null; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * What `filePath`'s own `export default` statement exports. The statement |
no test coverage detected