(codeLine)
| 249 | |
| 250 | // Converts static import statement to dynamic import statement |
| 251 | const toDynamicImport = (codeLine) => { |
| 252 | let dynamicImportStatement = ''; |
| 253 | const ast = acornParse(codeLine, { __proto__: null, sourceType: 'module', ecmaVersion: 'latest' }); |
| 254 | acornWalk.ancestor(ast, { |
| 255 | ImportDeclaration(node) { |
| 256 | const awaitDynamicImport = `await import(${JSONStringify(node.source.value)});`; |
| 257 | if (node.specifiers.length === 0) { |
| 258 | dynamicImportStatement += awaitDynamicImport; |
| 259 | } else if (node.specifiers.length === 1 && node.specifiers[0].type === 'ImportNamespaceSpecifier') { |
| 260 | dynamicImportStatement += `const ${node.specifiers[0].local.name} = ${awaitDynamicImport}`; |
| 261 | } else { |
| 262 | const importNames = ArrayPrototypeJoin(ArrayPrototypeMap(node.specifiers, ({ local, imported }) => |
| 263 | (local.name === imported?.name ? local.name : `${imported?.name ?? 'default'}: ${local.name}`), |
| 264 | ), ', '); |
| 265 | dynamicImportStatement += `const { ${importNames} } = ${awaitDynamicImport}`; |
| 266 | } |
| 267 | }, |
| 268 | }); |
| 269 | return dynamicImportStatement; |
| 270 | }; |
| 271 | |
| 272 | class Recoverable extends SyntaxError { |
| 273 | constructor(err) { |
no outgoing calls
no test coverage detected
searching dependent graphs…