rm some any

This commit is contained in:
Olivier Gagnon
2022-07-15 23:34:27 -04:00
parent 59e55de9ca
commit 5b8eea66d4
10 changed files with 80 additions and 62 deletions
+26 -20
View File
@@ -12,6 +12,9 @@ import { Script } from "./Script/Script";
import { areImportsEquals } from "./Terminal/DirectoryHelpers";
import { IPlayer } from "./PersonObjects/IPlayer";
// Acorn type def is straight up incomplete so we have to fill with our own.
export type Node = any;
// Makes a blob that contains the code of a given script.
function makeScriptBlob(code: string): Blob {
return new Blob([code], { type: "text/javascript" });
@@ -144,36 +147,39 @@ function _getScriptUrls(script: Script, scripts: Script[], seen: Script[]): Scri
// Where the blob URL contains the script content.
// Parse the code into an ast tree
const ast: any = parse(script.code, { sourceType: "module", ecmaVersion: "latest", ranges: true });
const importNodes: Array<any> = [];
const ast = parse(script.code, { sourceType: "module", ecmaVersion: "latest", ranges: true });
interface importNode {
filename: string;
start: number;
end: number;
}
const importNodes: importNode[] = [];
// Walk the nodes of this tree and find any import declaration statements.
walk.simple(ast, {
ImportDeclaration(node: any) {
ImportDeclaration(node: Node) {
// Push this import onto the stack to replace
if (!node.source) return;
importNodes.push({
filename: node.source.value,
start: node.source.range[0] + 1,
end: node.source.range[1] - 1,
});
},
ExportNamedDeclaration(node: any) {
if (node.source) {
importNodes.push({
filename: node.source.value,
start: node.source.range[0] + 1,
end: node.source.range[1] - 1,
});
}
ExportNamedDeclaration(node: Node) {
if (!node.source) return;
importNodes.push({
filename: node.source.value,
start: node.source.range[0] + 1,
end: node.source.range[1] - 1,
});
},
ExportAllDeclaration(node: any) {
if (node.source) {
importNodes.push({
filename: node.source.value,
start: node.source.range[0] + 1,
end: node.source.range[1] - 1,
});
}
ExportAllDeclaration(node: Node) {
if (!node.source) return;
importNodes.push({
filename: node.source.value,
start: node.source.range[0] + 1,
end: node.source.range[1] - 1,
});
},
});
// Sort the nodes from last start index to first. This replaces the last import with a blob first,