Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.3.0-dev.20231120",
"version": "5.3.0-dev.20231122",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -97,7 +97,7 @@
"@types/nested-error-stacks": "^2.1.0",
"@types/node": "^18.15.12",
"@types/physical-cpu-count": "^2.0.0",
"@types/ts-expose-internals": "npm:[email protected].0-beta",
"@types/ts-expose-internals": "npm:[email protected].2",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "5.3.0-dev.20231120",
"version": "5.3.0-dev.20231122",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -72,7 +72,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.3.0-dev.20231120"
"typia": "5.3.0-dev.20231122"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.3.0"
Expand Down
44 changes: 39 additions & 5 deletions src/transformers/FileTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import ts from "typescript";

import { Singleton } from "../utils/Singleton";

import { IProject } from "./IProject";
import { NodeTransformer } from "./NodeTransformer";
import { TransformerError } from "./TransformerError";

export namespace FileTransformer {
export const transform =
(project: Omit<IProject, "context">) =>
(environments: Omit<IProject, "context">) =>
(context: ts.TransformationContext) =>
(file: ts.SourceFile): ts.SourceFile => {
if (file.isDeclarationFile) return file;

const project: IProject = {
...environments,
context,
};
checkJsDocParsingMode.get(project, file);

return ts.visitEachChild(
file,
(node) => iterate_node({ ...project, context })(context)(node),
(node) => iterate_node(project)(node),
context,
);
};

const iterate_node =
(project: IProject) =>
(context: ts.TransformationContext) =>
(node: ts.Node): ts.Node =>
ts.visitEachChild(
try_transform_node(project)(node) ?? node,
(child) => iterate_node(project)(context)(child),
context,
(child) => iterate_node(project)(child),
project.context,
);

const try_transform_node =
Expand Down Expand Up @@ -55,3 +63,29 @@ const isTransformerError = (error: any): error is TransformerError =>
error.constructor.name === "TransformerError" &&
typeof error.code === "string" &&
typeof error.message === "string";

const checkJsDocParsingMode = new Singleton(
(project: IProject, file: ts.SourceFile) => {
if (
typeof file.jsDocParsingMode === "number" &&
file.jsDocParsingMode !== 0
) {
project.extras.addDiagnostic(
ts.createDiagnosticForNode(file, {
code: `(typia setup)` as any,
key: "jsDocParsingMode",
category: ts.DiagnosticCategory.Warning,
message: [
`Run "npx typia setup" or "npx ts-patch install" command again.`,
``,
`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.`,
``,
`To solve this problem, run "npx typia setup" or "ts-patch install" command again to hack the TypeScript compiler to revive the JSDoc parsing.`,
``,
` - reference: https://github.com/microsoft/TypeScript/pull/55739`,
].join("\n"),
}),
);
}
},
);