( _: string, typeOnly: string | undefined, imports: string, module: string, )
| 245 | }); |
| 246 | |
| 247 | const getRunnableImport = ( |
| 248 | _: string, |
| 249 | typeOnly: string | undefined, |
| 250 | imports: string, |
| 251 | module: string, |
| 252 | ): string => { |
| 253 | if (typeOnly != null) { |
| 254 | return ''; |
| 255 | } |
| 256 | const moduleExpression = `modules[\`${module}\`]`; |
| 257 | const trimmedImports = imports.trim(); |
| 258 | const defaultAndNamedImports = trimmedImports.match(/^(\w+),\s*({.*})$/s); |
| 259 | if (defaultAndNamedImports != null) { |
| 260 | return ( |
| 261 | `const ${defaultAndNamedImports[1]} = ` + |
| 262 | `${moduleExpression}.default ?? ${moduleExpression};\n` + |
| 263 | `const ${defaultAndNamedImports[2].replace(/\bas\b/g, ':')} = ` + |
| 264 | `${moduleExpression};` |
| 265 | ); |
| 266 | } |
| 267 | if (trimmedImports.startsWith('{')) { |
| 268 | // eslint-disable-next-line max-len |
| 269 | return `const ${trimmedImports.replace(/\bas\b/g, ':')} = ${moduleExpression};`; |
| 270 | } |
| 271 | if (trimmedImports.startsWith('* as ')) { |
| 272 | return `const ${trimmedImports.slice(5)} = ${moduleExpression};`; |
| 273 | } |
| 274 | // eslint-disable-next-line max-len |
| 275 | return `const ${trimmedImports} = ${moduleExpression}.default ?? ${moduleExpression};`; |
| 276 | }; |
| 277 | |
| 278 | const replaceRunnableImports = (source: string): string => |
| 279 | source.replace( |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…