Rename import as prefix to real source name

This commit is contained in:
Sam Nolan 2022-09-21 13:40:15 +10:00
parent 2458762acd
commit b7d634de86

View File

@ -14,6 +14,8 @@ type SquiggleArgs = {
onChange?: (expr: SqValue | undefined, sourceName: string) => void; onChange?: (expr: SqValue | undefined, sourceName: string) => void;
}; };
const importSourceName = (sourceName: string) => "imports-" + sourceName;
export const useSquiggle = (args: SquiggleArgs) => { export const useSquiggle = (args: SquiggleArgs) => {
const autogenName = useMemo(() => uuidv4(), []); const autogenName = useMemo(() => uuidv4(), []);
@ -43,8 +45,8 @@ export const useSquiggle = (args: SquiggleArgs) => {
} }
if (args.jsImports && Object.keys(args.jsImports).length) { if (args.jsImports && Object.keys(args.jsImports).length) {
const importsSource = jsImportsToSquiggleCode(args.jsImports); const importsSource = jsImportsToSquiggleCode(args.jsImports);
project.setSource("imports", importsSource); project.setSource(importSourceName(sourceName), importsSource);
includes.push("imports"); includes.push(importSourceName(sourceName));
} }
project.setContinues(sourceName, includes); project.setContinues(sourceName, includes);
project.run(sourceName); project.run(sourceName);
@ -68,6 +70,8 @@ export const useSquiggle = (args: SquiggleArgs) => {
useEffect(() => { useEffect(() => {
return () => { return () => {
if (!args.sourceName) args.project.clean(result.sourceName); if (!args.sourceName) args.project.clean(result.sourceName);
if (args.project.getSource(importSourceName(result.sourceName)))
args.project.clean(result.sourceName);
}; };
}); });