Skip to content

Commit

Permalink
refactor: move out tool to own repo and utilize
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Apr 28, 2022
1 parent 5b86bcc commit 086ef92
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 296 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"devDependencies": {
"@es-joy/escodegen": "^3.5.1",
"@es-joy/js2ts-assistant": "^0.1.0",
"@es-joy/jsdoc-eslint-parser": "^0.16.0",
"@es-joy/jsdoccomment": "^0.29.0",
"@rollup/plugin-commonjs": "^17.1.0",
Expand Down Expand Up @@ -82,7 +83,7 @@
"pretest": "npm run build",
"prepublishOnly": "npm run update-version && npm run build",
"sync-docs": "node sync-docs.js",
"js-for-ts": "node tools/intermediate-js-for-ts.js",
"js-for-ts": "node tools/js-for-ts.js",
"generate-release": "eslint-generate-release",
"generate-alpharelease": "eslint-generate-prerelease alpha",
"generate-betarelease": "eslint-generate-prerelease beta",
Expand Down
295 changes: 0 additions & 295 deletions tools/intermediate-js-for-ts.js

This file was deleted.

62 changes: 62 additions & 0 deletions tools/js-for-ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import js2tsAssistant from "@es-joy/js2ts-assistant";

await js2tsAssistant({
customClassHandling({
ast, builders, superClassName
}) {

// Since we're not tracking types as in using a
// proper TS transformer (like `ttypescript`?),
// we hack this one for now
if (superClassName === "Parser") {

// Make import available
ast.body.unshift(
builders.importDeclaration(
[
builders.importNamespaceSpecifier(
builders.identifier("acorn")
)
],
builders.literal("acorn"),
"value"
)
);
return "acorn.Parser";
}
return null;
},
customParamHandling({
tag, identifier, typeCast
}) {

// Hack in some needed type casts
if (tag.name === "opts") {
identifier.jsdoc = typeCast({
typeLines: [
{
type: "JsdocTypeLine",
initial: "",
delimiter: "",
postDelimiter: "",
rawType: "acorn.Options"
}
],
rawType: "acorn.Options"
});
} else if (tag.name === "code") {
identifier.jsdoc = typeCast({
typeLines: [
{
type: "JsdocTypeLine",
initial: "",
delimiter: "",
postDelimiter: "",
rawType: "string"
}
],
rawType: "string"
});
}
}
});

0 comments on commit 086ef92

Please sign in to comment.