Skip to content

Commit 1a04d2a

Browse files
committed
Warning message when jsDocParsingMode is not hacked.
As TypeScript starts skipping parsing `JSDocComment`s since TypeScript v5.3 update but it is possible to revive the `JSDocComment`s' parsing, by hacking the `jsDocParsingMode` value of `tsc.js`, I've decided to print a warning message from `typia` when the `jsDocParsingMode` value is not hacked. Therefore, it is possible to running the `typia` as before even when the `jsDocParsingMode` is not hacked, and user can ignore the warning message if he (or she) does not use any comment tags or not generating JSON schema with description comments. - Related issue: microsoft/TypeScript#55739
1 parent 9da97d3 commit 1a04d2a

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typia",
3-
"version": "5.3.0-dev.20231120",
3+
"version": "5.3.0-dev.20231122",
44
"description": "Superfast runtime validators with only one line",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
@@ -97,7 +97,7 @@
9797
"@types/nested-error-stacks": "^2.1.0",
9898
"@types/node": "^18.15.12",
9999
"@types/physical-cpu-count": "^2.0.0",
100-
"@types/ts-expose-internals": "npm:[email protected].0-beta",
100+
"@types/ts-expose-internals": "npm:[email protected].2",
101101
"@types/uuid": "^8.3.4",
102102
"@typescript-eslint/eslint-plugin": "^5.59.11",
103103
"@typescript-eslint/parser": "^5.59.11",

packages/typescript-json/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-json",
3-
"version": "5.3.0-dev.20231120",
3+
"version": "5.3.0-dev.20231122",
44
"description": "Superfast runtime validators with only one line",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
@@ -72,7 +72,7 @@
7272
},
7373
"homepage": "https://typia.io",
7474
"dependencies": {
75-
"typia": "5.3.0-dev.20231120"
75+
"typia": "5.3.0-dev.20231122"
7676
},
7777
"peerDependencies": {
7878
"typescript": ">=4.8.0 <5.3.0"

src/transformers/FileTransformer.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
import ts from "typescript";
22

3+
import { Singleton } from "../utils/Singleton";
4+
35
import { IProject } from "./IProject";
46
import { NodeTransformer } from "./NodeTransformer";
57
import { TransformerError } from "./TransformerError";
68

79
export namespace FileTransformer {
810
export const transform =
9-
(project: Omit<IProject, "context">) =>
11+
(environments: Omit<IProject, "context">) =>
1012
(context: ts.TransformationContext) =>
1113
(file: ts.SourceFile): ts.SourceFile => {
1214
if (file.isDeclarationFile) return file;
15+
16+
const project: IProject = {
17+
...environments,
18+
context,
19+
};
20+
checkJsDocParsingMode.get(project, file);
21+
1322
return ts.visitEachChild(
1423
file,
15-
(node) => iterate_node({ ...project, context })(context)(node),
24+
(node) => iterate_node(project)(node),
1625
context,
1726
);
1827
};
1928

2029
const iterate_node =
2130
(project: IProject) =>
22-
(context: ts.TransformationContext) =>
2331
(node: ts.Node): ts.Node =>
2432
ts.visitEachChild(
2533
try_transform_node(project)(node) ?? node,
26-
(child) => iterate_node(project)(context)(child),
27-
context,
34+
(child) => iterate_node(project)(child),
35+
project.context,
2836
);
2937

3038
const try_transform_node =
@@ -55,3 +63,29 @@ const isTransformerError = (error: any): error is TransformerError =>
5563
error.constructor.name === "TransformerError" &&
5664
typeof error.code === "string" &&
5765
typeof error.message === "string";
66+
67+
const checkJsDocParsingMode = new Singleton(
68+
(project: IProject, file: ts.SourceFile) => {
69+
if (
70+
typeof file.jsDocParsingMode === "number" &&
71+
file.jsDocParsingMode !== 0
72+
) {
73+
project.extras.addDiagnostic(
74+
ts.createDiagnosticForNode(file, {
75+
code: `(typia setup)` as any,
76+
key: "jsDocParsingMode",
77+
category: ts.DiagnosticCategory.Warning,
78+
message: [
79+
`Run "npx typia setup" or "npx ts-patch install" command again.`,
80+
``,
81+
`Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments. Therefore, "typia" also cannot utilize those JSDoc comments, and it would damage some features of "typia" like "comment tags" or "JSON schema" generator.`,
82+
``,
83+
`To solve this problem, run "npx typia setup" or "ts-patch install" command again to hack the TypeScript compiler to revive the JSDoc parsing.`,
84+
``,
85+
` - reference: https://github.com/microsoft/TypeScript/pull/55739`,
86+
].join("\n"),
87+
}),
88+
);
89+
}
90+
},
91+
);

0 commit comments

Comments
 (0)