( ast: t.File, assetPath: string, )
| 1086 | }; |
| 1087 | |
| 1088 | export function planAssetImport( |
| 1089 | ast: t.File, |
| 1090 | assetPath: string, |
| 1091 | ): { identifier: string; importSplice: Splice | null } { |
| 1092 | const imports = findImports(ast); |
| 1093 | for (const imp of imports) { |
| 1094 | if (imp.source === assetPath && imp.defaultIdent) { |
| 1095 | return { identifier: imp.defaultIdent, importSplice: null }; |
| 1096 | } |
| 1097 | } |
| 1098 | const filename = assetPath.slice(assetPath.lastIndexOf('/') + 1); |
| 1099 | const identifier = safeAssetIdentifier(filename, collectTopLevelIdentifiers(ast)); |
| 1100 | const importStmt = `import ${identifier} from '${assetPath.replace(/'/g, "\\'")}';\n`; |
| 1101 | const last = imports[imports.length - 1]; |
| 1102 | const insertAt = last ? (last.node.end ?? 0) : 0; |
| 1103 | const prefix = last ? '\n' : ''; |
| 1104 | return { identifier, importSplice: { from: insertAt, to: insertAt, text: prefix + importStmt } }; |
| 1105 | } |
| 1106 | |
| 1107 | function planAssetAttr( |
| 1108 | ast: t.File, |
no test coverage detected