MCPcopy
hub / github.com/1weiho/open-slide / planAssetImport

Function planAssetImport

packages/core/src/editing/edit-ops.ts:1088–1105  ·  view source on GitHub ↗
(
  ast: t.File,
  assetPath: string,
)

Source from the content-addressed store, hash-verified

1086};
1087
1088export 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
1107function planAssetAttr(
1108 ast: t.File,

Callers 2

planAssetAttrFunction · 0.85
planReplacePlaceholderFunction · 0.85

Calls 3

safeAssetIdentifierFunction · 0.85
findImportsFunction · 0.70

Tested by

no test coverage detected