Skip to content

Commit 086ef92

Browse files
committed
refactor: move out tool to own repo and utilize
1 parent 5b86bcc commit 086ef92

File tree

3 files changed

+64
-296
lines changed

3 files changed

+64
-296
lines changed

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
},
4040
"devDependencies": {
4141
"@es-joy/escodegen": "^3.5.1",
42+
"@es-joy/js2ts-assistant": "^0.1.0",
4243
"@es-joy/jsdoc-eslint-parser": "^0.16.0",
4344
"@es-joy/jsdoccomment": "^0.29.0",
4445
"@rollup/plugin-commonjs": "^17.1.0",
@@ -82,7 +83,7 @@
8283
"pretest": "npm run build",
8384
"prepublishOnly": "npm run update-version && npm run build",
8485
"sync-docs": "node sync-docs.js",
85-
"js-for-ts": "node tools/intermediate-js-for-ts.js",
86+
"js-for-ts": "node tools/js-for-ts.js",
8687
"generate-release": "eslint-generate-release",
8788
"generate-alpharelease": "eslint-generate-prerelease alpha",
8889
"generate-betarelease": "eslint-generate-prerelease beta",

Diff for: tools/intermediate-js-for-ts.js

-295
This file was deleted.

Diff for: tools/js-for-ts.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import js2tsAssistant from "@es-joy/js2ts-assistant";
2+
3+
await js2tsAssistant({
4+
customClassHandling({
5+
ast, builders, superClassName
6+
}) {
7+
8+
// Since we're not tracking types as in using a
9+
// proper TS transformer (like `ttypescript`?),
10+
// we hack this one for now
11+
if (superClassName === "Parser") {
12+
13+
// Make import available
14+
ast.body.unshift(
15+
builders.importDeclaration(
16+
[
17+
builders.importNamespaceSpecifier(
18+
builders.identifier("acorn")
19+
)
20+
],
21+
builders.literal("acorn"),
22+
"value"
23+
)
24+
);
25+
return "acorn.Parser";
26+
}
27+
return null;
28+
},
29+
customParamHandling({
30+
tag, identifier, typeCast
31+
}) {
32+
33+
// Hack in some needed type casts
34+
if (tag.name === "opts") {
35+
identifier.jsdoc = typeCast({
36+
typeLines: [
37+
{
38+
type: "JsdocTypeLine",
39+
initial: "",
40+
delimiter: "",
41+
postDelimiter: "",
42+
rawType: "acorn.Options"
43+
}
44+
],
45+
rawType: "acorn.Options"
46+
});
47+
} else if (tag.name === "code") {
48+
identifier.jsdoc = typeCast({
49+
typeLines: [
50+
{
51+
type: "JsdocTypeLine",
52+
initial: "",
53+
delimiter: "",
54+
postDelimiter: "",
55+
rawType: "string"
56+
}
57+
],
58+
rawType: "string"
59+
});
60+
}
61+
}
62+
});

0 commit comments

Comments
 (0)