Skip to content

Commit

Permalink
Merge pull request #1198 from samchon/feature/generate
Browse files Browse the repository at this point in the history
Fix generaton mode's non-initialized `let` variable problem.
  • Loading branch information
samchon authored Aug 4, 2024
2 parents 253a1de + 5266e5e commit c792f72
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 35 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "../typia-6.7.1.tgz"
"typia": "../typia-6.7.2.tgz"
}
}
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "../typia-6.7.1.tgz"
"typia": "../typia-6.7.2.tgz"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "6.7.1",
"version": "6.7.2",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
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": "6.7.1",
"version": "6.7.2",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -63,7 +63,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "6.7.1"
"typia": "6.7.2"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.6.0"
Expand Down
4 changes: 3 additions & 1 deletion src/factories/StatementFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ts from "typescript";

import { TypeFactory } from "./TypeFactory";

export namespace StatementFactory {
export const mut = (name: string, initializer?: ts.Expression) =>
ts.factory.createVariableStatement(
Expand All @@ -9,7 +11,7 @@ export namespace StatementFactory {
ts.factory.createVariableDeclaration(
name,
undefined,
undefined,
initializer === undefined ? TypeFactory.keyword("any") : undefined,
initializer,
),
],
Expand Down
38 changes: 28 additions & 10 deletions src/programmers/misc/MiscAssertPruneProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,39 @@ export namespace MiscAssertPruneProgrammer {
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
AssertProgrammer.Guardian.parameter(props.init),
],
prune.arrow.type,
ts.factory.createTypeReferenceNode(
props.name ??
TypeFactory.getFullName(props.project.checker)(props.type),
),
undefined,
ts.factory.createCallExpression(
ts.factory.createIdentifier("__prune"),
undefined,
ts.factory.createBlock(
[
ts.factory.createCallExpression(
ts.factory.createIdentifier("__assert"),
undefined,
[
ts.factory.createExpressionStatement(
ts.factory.createBinaryExpression(
ts.factory.createIdentifier("input"),
AssertProgrammer.Guardian.identifier(),
],
ts.SyntaxKind.EqualsToken,
ts.factory.createCallExpression(
ts.factory.createIdentifier("__assert"),
undefined,
[
ts.factory.createIdentifier("input"),
AssertProgrammer.Guardian.identifier(),
],
),
),
),
ts.factory.createExpressionStatement(
ts.factory.createCallExpression(
ts.factory.createIdentifier("__prune"),
undefined,
[ts.factory.createIdentifier("input")],
),
),
ts.factory.createReturnStatement(
ts.factory.createIdentifier("input"),
),
],
true,
),
),
};
Expand Down
5 changes: 1 addition & 4 deletions src/programmers/misc/MiscIsPruneProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export namespace MiscIsPruneProgrammer {
undefined,
undefined,
[IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
ts.factory.createUnionTypeNode([
prune.arrow.type ?? TypeFactory.keyword("any"),
ts.factory.createTypeReferenceNode("null"),
]),
is.arrow.type,
undefined,
ts.factory.createBlock(
[
Expand Down
9 changes: 6 additions & 3 deletions src/programmers/misc/MiscValidatePruneProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export namespace MiscValidatePruneProgrammer {
undefined,
undefined,
[IdentifierFactory.parameter("input", TypeFactory.keyword("any"))],
ts.factory.createTypeReferenceNode("typia.IValidation", [
prune.arrow.type ?? TypeFactory.keyword("any"),
]),
ts.factory.createTypeReferenceNode(
`typia.IValidation<${
props.name ??
TypeFactory.getFullName(props.project.checker)(props.type)
}>`,
),
undefined,
ts.factory.createBlock(
[
Expand Down
7 changes: 6 additions & 1 deletion src/programmers/notations/NotationGeneralProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export namespace NotationGeneralProgrammer {
undefined,
undefined,
composed.parameters,
TypeFactory.keyword("void"),
ts.factory.createTypeReferenceNode(
returnType(props.rename)(
props.name ??
TypeFactory.getFullName(props.project.checker)(props.type),
),
),
undefined,
composed.body,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export namespace NotationValidateGeneralProgrammer {
),
),
ts.factory.createReturnStatement(
ts.factory.createIdentifier("result"),
ts.factory.createAsExpression(
ts.factory.createIdentifier("result"),
TypeFactory.keyword("any"),
),
),
],
true,
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/metadata/IMetadataConstantValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IMetadataTypeTag } from "./IMetadataTypeTag";

export interface IMetadataConstantValue<T extends Atomic.Type> {
value: T;
tags: IMetadataTypeTag[][] | undefined;
tags?: IMetadataTypeTag[][] | undefined;
description?: string | null;
jsDocTags?: IJsDocTagInfo[];
}
2 changes: 1 addition & 1 deletion src/schemas/metadata/IMetadataTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { IMetadataTypeTag } from "./IMetadataTypeTag";

export interface IMetadataTemplate {
row: IMetadata[];
tags: IMetadataTypeTag[][] | undefined;
tags?: IMetadataTypeTag[][] | undefined;
}
2 changes: 1 addition & 1 deletion test-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
"typescript": "^5.4.5"
},
"dependencies": {
"typia": "../typia-6.7.1.tgz"
"typia": "../typia-6.7.2.tgz"
}
}
2 changes: 2 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin-generated
generated
3 changes: 2 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"build": "rimraf bin && tsc",
"build_run": "npm run build",
"generate": "rimraf generated && rimraf bin-generated && node --max-old-space-size=8000 node_modules/typia/lib/executable/typia generate --input src --output generated --project tsconfig.generated.json && rimraf generated/features/functional* && rimraf generated/features/issues && node --max-old-space-size=8000 node_modules/typescript/bin/tsc --project tsconfig.generated.json",
"prepare": "ts-patch install",
"prettier": "prettier ./src/**/*.ts --write",
"setup": "node build/setup.js",
Expand Down Expand Up @@ -51,6 +52,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^3.0.0",
"uuid": "^9.0.1",
"typia": "../typia-6.7.1.tgz"
"typia": "../typia-6.7.2.tgz"
}
}
5 changes: 0 additions & 5 deletions test/tsconfig.actions.json

This file was deleted.

7 changes: 7 additions & 0 deletions test/tsconfig.generated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./bin-generated",
},
"include": ["generated"],
}
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"tgrid": "^1.0.3",
"tstl": "^3.0.0",
"typescript": "^5.5.4",
"typia": "^6.7.1"
"typia": "^6.7.2"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
Expand Down

0 comments on commit c792f72

Please sign in to comment.