Skip to content

Commit

Permalink
refactor: add changeImportLocation function
Browse files Browse the repository at this point in the history
add a changeImportLocation function in toFractalTree to avoid duplicated code
  • Loading branch information
AnatoleLucet committed May 23, 2020
1 parent 847003d commit 16fc061
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/index/generateTrees/toFractalTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export function toFractalTree(graph: Graph, entryPoints: string[]) {
return location;
};

const changeImportLocation = (
filePath: string,
newLocation: string
): void => {
tree[filePath] = newLocation;

treeSet.add(newLocation);
};

const fn = (filePath: string, folderPath: string, graph: Graph) => {
const basename = path.basename(filePath);

Expand All @@ -64,8 +73,7 @@ export function toFractalTree(graph: Graph, entryPoints: string[]) {
directoryName = path.basename(location, path.extname(location));

if (!isGlobal) {
tree[filePath] = location;
treeSet.add(location);
changeImportLocation(filePath, location);
}

const imports = graph[filePath];
Expand Down Expand Up @@ -118,8 +126,7 @@ export function toFractalTree(graph: Graph, entryPoints: string[]) {
: filename
);

tree[currentPath] = newFilePath;
treeSet.add(newFilePath);
changeImportLocation(currentPath, newFilePath);
});
}

Expand All @@ -143,8 +150,7 @@ export function toFractalTree(graph: Graph, entryPoints: string[]) {
testFile
);

tree[testFile] = location;
treeSet.add(location);
changeImportLocation(testFile, location);
}
}

Expand Down

0 comments on commit 16fc061

Please sign in to comment.