( output: Sourcemap, body: Node, resolve: (specifier: string) => string = String )
| 185 | } |
| 186 | |
| 187 | function rewriteImportDeclarations( |
| 188 | output: Sourcemap, |
| 189 | body: Node, |
| 190 | resolve: (specifier: string) => string = String |
| 191 | ): void { |
| 192 | const declarations: ImportDeclaration[] = []; |
| 193 | |
| 194 | simple(body, { |
| 195 | ImportDeclaration(node) { |
| 196 | if (isStringLiteral(node.source)) { |
| 197 | declarations.push(node); |
| 198 | } |
| 199 | } |
| 200 | }); |
| 201 | |
| 202 | const specifiers: string[] = []; |
| 203 | const imports: string[] = []; |
| 204 | for (const node of declarations) { |
| 205 | output.delete(node.start, node.end + +(output.input[node.end] === "\n")); |
| 206 | specifiers.push(rewriteImportSpecifiers(node)); |
| 207 | imports.push(`import(${annotatePath(resolve(getStringLiteralValue(node.source as StringLiteral)))})`); |
| 208 | } |
| 209 | if (declarations.length > 1) { |
| 210 | output.insertLeft(0, `const [${specifiers.join(", ")}] = await Promise.all([${imports.join(", ")}]);\n`); |
| 211 | } else if (declarations.length === 1) { |
| 212 | output.insertLeft(0, `const ${specifiers[0]} = await ${imports[0]};\n`); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | function rewriteImportSpecifiers(node: ImportDeclaration): string { |
| 217 | return node.specifiers.some(isNotNamespaceSpecifier) |
no test coverage detected