Skip to content

Commit

Permalink
Small optimizations
Browse files Browse the repository at this point in the history
* Ignore "any" when writing types from tsc
* replace mapToObj with Object.fromEntries (since ES6).
  • Loading branch information
max-leuthaeuser committed Apr 11, 2023
1 parent 044d6c1 commit 044551d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
12 changes: 2 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function createTsc(srcFiles) {
} else {
typeStr = safeTypeWithContextToString(typeChecker.getTypeAtLocation(node), node);
}
seenTypes.set(node.getStart(), typeStr);
if (typeStr !== "any") seenTypes.set(node.getStart(), typeStr);
tsc.forEachChild(node, addType);
}

Expand Down Expand Up @@ -283,14 +283,6 @@ const getCircularReplacer = () => {
};
};

function mapToObj(map) {
let obj = Object.create(null);
for (let [k, v] of map) {
obj[k.toString()] = v;
}
return obj;
}

/**
* Write AST data to a json file
*/
Expand All @@ -316,7 +308,7 @@ const writeTypesFile = (file, seenTypes, options) => {
fs.mkdirSync(path.dirname(outTypeFile), {recursive: true});
fs.writeFileSync(
outTypeFile,
JSON.stringify(mapToObj(seenTypes))
JSON.stringify(Object.fromEntries(seenTypes), undefined, " ")
);
console.log("Converted types for", relativePath, "to", outTypeFile);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@joernio/astgen",
"version": "2.21.0",
"version": "2.22.0",
"description": "Generate JS/TS AST in json format with Babel",
"exports": "./index.js",
"keywords": [
Expand Down

0 comments on commit 044551d

Please sign in to comment.