Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break change from ts.factory.createNumericLiteral(). #863

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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": "5.2.5",
"version": "5.2.6",
"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": "5.2.5",
"version": "5.2.6",
"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.2.5"
"typia": "5.2.6"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.3.0"
Expand Down
8 changes: 8 additions & 0 deletions src/factories/ExpressionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import ts from "typescript";
import { RandomGenerator } from "../utils/RandomGenerator";

export namespace ExpressionFactory {
export const number = (value: number) =>
value < 0
? ts.factory.createPrefixUnaryExpression(
ts.SyntaxKind.MinusToken,
ts.factory.createNumericLiteral(Math.abs(value)),
)
: ts.factory.createNumericLiteral(value);

export const bigint = (value: number | bigint) =>
ts.factory.createCallExpression(
ts.factory.createIdentifier("BigInt"),
Expand Down
8 changes: 4 additions & 4 deletions src/programmers/CheckerProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ export namespace CheckerProgrammer {
IdentifierFactory.access(input)("slice"),
undefined,
[
ts.factory.createNumericLiteral(
ExpressionFactory.number(
tuple.elements.length - 1,
),
],
Expand Down Expand Up @@ -809,7 +809,7 @@ export namespace CheckerProgrammer {
expression:
ts.factory.createStrictEquality(
arrayLength,
ts.factory.createNumericLiteral(
ExpressionFactory.number(
tuple.elements.length,
),
),
Expand All @@ -820,7 +820,7 @@ export namespace CheckerProgrammer {
combined: false,
expression: ts.factory.createLogicalAnd(
ts.factory.createLessThanEquals(
ts.factory.createNumericLiteral(
ExpressionFactory.number(
tuple.elements.filter(
(t) =>
t.optional === false,
Expand All @@ -829,7 +829,7 @@ export namespace CheckerProgrammer {
arrayLength,
),
ts.factory.createGreaterThanEquals(
ts.factory.createNumericLiteral(
ExpressionFactory.number(
tuple.elements.length,
),
arrayLength,
Expand Down
33 changes: 16 additions & 17 deletions src/programmers/RandomProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export namespace RandomProgrammer {
IdentifierFactory.parameter(
"_depth",
TypeFactory.keyword("number"),
ts.factory.createNumericLiteral(0),
ExpressionFactory.number(0),
),
],
TypeFactory.keyword("any"),
Expand Down Expand Up @@ -163,7 +163,7 @@ export namespace RandomProgrammer {
IdentifierFactory.parameter(
"_depth",
TypeFactory.keyword("number"),
ts.factory.createNumericLiteral(0),
ExpressionFactory.number(0),
),
],
TypeFactory.keyword("any"),
Expand Down Expand Up @@ -204,7 +204,7 @@ export namespace RandomProgrammer {
IdentifierFactory.parameter(
"_depth",
TypeFactory.keyword("number"),
ts.factory.createNumericLiteral(0),
ExpressionFactory.number(0),
),
],
TypeFactory.keyword("any"),
Expand Down Expand Up @@ -312,7 +312,7 @@ export namespace RandomProgrammer {
typeof value === "boolean"
? ts.factory.createIdentifier(value.toString())
: typeof value === "number"
? ts.factory.createNumericLiteral(value)
? ExpressionFactory.number(value)
: typeof value === "string"
? ts.factory.createStringLiteral(value)
: ExpressionFactory.bigint(Number(value));
Expand Down Expand Up @@ -346,16 +346,15 @@ export namespace RandomProgrammer {
return random_custom(COALESCE(importer))("number")(tags)(
RandomRanger.number({
type,
transform: (value) =>
ts.factory.createNumericLiteral(value),
transform: (value) => ExpressionFactory.number(value),
setter: (args) =>
ts.factory.createCallExpression(
type !== "double" || multiply !== undefined
? COALESCE(importer)("integer")
: COALESCE(importer)("number"),
undefined,
args.map((val) =>
ts.factory.createNumericLiteral(val),
ExpressionFactory.number(val),
),
),
})({
Expand Down Expand Up @@ -469,10 +468,10 @@ export namespace RandomProgrammer {
ts.factory.createTrue(),
explore.recursive
? ts.factory.createAdd(
ts.factory.createNumericLiteral(1),
ExpressionFactory.number(1),
ts.factory.createIdentifier("_depth"),
)
: ts.factory.createNumericLiteral(0),
: ExpressionFactory.number(0),
],
),
);
Expand All @@ -485,7 +484,7 @@ export namespace RandomProgrammer {
ts.factory.createLogicalAnd(
ts.factory.createIdentifier("_recursive"),
ts.factory.createLessThan(
ts.factory.createNumericLiteral(5),
ExpressionFactory.number(5),
ts.factory.createIdentifier("_depth"),
),
),
Expand All @@ -512,10 +511,10 @@ export namespace RandomProgrammer {
ts.factory.createTrue(),
explore.recursive
? ts.factory.createAdd(
ts.factory.createNumericLiteral(1),
ExpressionFactory.number(1),
ts.factory.createIdentifier("_depth"),
)
: ts.factory.createNumericLiteral(0),
: ExpressionFactory.number(0),
],
)
: RandomJoiner.tuple(decode(importer)(explore))(
Expand All @@ -540,7 +539,7 @@ export namespace RandomProgrammer {
ts.factory.createIdentifier("_recursive"),
undefined,
ts.factory.createAdd(
ts.factory.createNumericLiteral(1),
ExpressionFactory.number(1),
ts.factory.createIdentifier("_depth"),
),
undefined,
Expand Down Expand Up @@ -716,7 +715,7 @@ export namespace RandomProgrammer {
const literal =
type === "BigInt64Array" || type === "BigUint64Array"
? ExpressionFactory.bigint
: ts.factory.createNumericLiteral;
: ExpressionFactory.number;
return ts.factory.createNewExpression(
ts.factory.createIdentifier(type),
[],
Expand Down Expand Up @@ -812,10 +811,10 @@ export namespace RandomProgrammer {
),
undefined,
[
ts.factory.createNumericLiteral(
ExpressionFactory.number(
0,
),
ts.factory.createNumericLiteral(
ExpressionFactory.number(
255,
),
],
Expand All @@ -826,7 +825,7 @@ export namespace RandomProgrammer {
),
],
),
ts.factory.createNumericLiteral(0),
ExpressionFactory.number(0),
],
),
),
Expand Down
3 changes: 2 additions & 1 deletion src/programmers/ValidateProgrammer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ts from "typescript";

import { ExpressionFactory } from "../factories/ExpressionFactory";
import { IdentifierFactory } from "../factories/IdentifierFactory";
import { StatementFactory } from "../factories/StatementFactory";
import { TypeFactory } from "../factories/TypeFactory";
Expand Down Expand Up @@ -176,7 +177,7 @@ export namespace ValidateProgrammer {
StatementFactory.constant(
"success",
ts.factory.createStrictEquality(
ts.factory.createNumericLiteral(0),
ExpressionFactory.number(0),
ts.factory.createIdentifier("errors.length"),
),
),
Expand Down
10 changes: 4 additions & 6 deletions src/programmers/helpers/RandomJoiner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ts from "typescript";

import { ExpressionFactory } from "../../factories/ExpressionFactory";
import { StatementFactory } from "../../factories/StatementFactory";
import { TypeFactory } from "../../factories/TypeFactory";

Expand Down Expand Up @@ -36,7 +37,7 @@ export namespace RandomJoiner {
if (explore.recursive === false) return generator;
return ts.factory.createConditionalExpression(
ts.factory.createGreaterThanEquals(
ts.factory.createNumericLiteral(5),
ExpressionFactory.number(5),
ts.factory.createIdentifier("_depth"),
),
undefined,
Expand Down Expand Up @@ -99,7 +100,7 @@ export namespace RandomJoiner {
? [
ts.factory.createIfStatement(
ts.factory.createGreaterThanEquals(
ts.factory.createNumericLiteral(5),
ExpressionFactory.number(5),
ts.factory.createIdentifier("_depth"),
),
ts.factory.createBlock(properties, true),
Expand Down Expand Up @@ -137,10 +138,7 @@ export namespace RandomJoiner {
ts.factory.createCallExpression(
coalesce("integer"),
undefined,
[
ts.factory.createNumericLiteral(0),
ts.factory.createNumericLiteral(3),
],
[ExpressionFactory.number(0), ExpressionFactory.number(3)],
),
]);
}
Expand Down
6 changes: 4 additions & 2 deletions src/programmers/helpers/RandomRanger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ts from "typescript";

import { ExpressionFactory } from "../../factories/ExpressionFactory";

import { IMetadataTypeTag } from "../../schemas/metadata/IMetadataTypeTag";

export namespace RandomRanger {
Expand Down Expand Up @@ -30,8 +32,8 @@ export namespace RandomRanger {
coalesce("integer"),
undefined,
[
ts.factory.createNumericLiteral(props.minimum),
ts.factory.createNumericLiteral(props.maximum),
ExpressionFactory.number(props.minimum),
ExpressionFactory.number(props.maximum),
],
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/programmers/http/HttpHeadersProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export namespace HttpHeadersProgrammer {
const access = IdentifierFactory.access(output)(key);
return ts.factory.createIfStatement(
ts.factory.createStrictEquality(
ts.factory.createNumericLiteral(0),
ExpressionFactory.number(0),
IdentifierFactory.access(access)("length"),
),
ts.factory.createExpressionStatement(
Expand Down
7 changes: 4 additions & 3 deletions src/programmers/internal/check_dynamic_properties.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ts from "typescript";

import { ExpressionFactory } from "../../factories/ExpressionFactory";
import { IdentifierFactory } from "../../factories/IdentifierFactory";
import { StatementFactory } from "../../factories/StatementFactory";

Expand Down Expand Up @@ -35,7 +36,7 @@ export const check_dynamic_properties =
? props.undefined === true ||
regular.every((r) => r.meta.isRequired())
? ts.factory.createStrictEquality(
ts.factory.createNumericLiteral(
ExpressionFactory.number(
regular.filter((r) => r.meta.isRequired()).length,
),
length,
Expand All @@ -45,11 +46,11 @@ export const check_dynamic_properties =
[],
[
length,
ts.factory.createNumericLiteral(
ExpressionFactory.number(
regular.filter((r) => r.meta.isRequired())
.length,
),
ts.factory.createNumericLiteral(regular.length),
ExpressionFactory.number(regular.length),
],
)
: null;
Expand Down
7 changes: 4 additions & 3 deletions src/programmers/internal/check_union_array_like.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ts from "typescript";

import { ExpressionFactory } from "../../factories/ExpressionFactory";
import { IdentifierFactory } from "../../factories/IdentifierFactory";
import { StatementFactory } from "../../factories/StatementFactory";
import { TypeFactory } from "../../factories/TypeFactory";
Expand Down Expand Up @@ -159,7 +160,7 @@ export const check_union_array_like =
StatementFactory.constant("top", accessor.front(input)),
ts.factory.createIfStatement(
ts.factory.createStrictEquality(
ts.factory.createNumericLiteral(0),
ExpressionFactory.number(0),
accessor.size(input),
),
ts.isReturnStatement(props.empty)
Expand Down Expand Up @@ -198,7 +199,7 @@ export const check_union_array_like =
),
ts.factory.createIfStatement(
ts.factory.createStrictEquality(
ts.factory.createNumericLiteral(1),
ExpressionFactory.number(1),
ts.factory.createIdentifier("passed.length"),
),
ts.factory.createReturnStatement(
Expand All @@ -215,7 +216,7 @@ export const check_union_array_like =
),
ts.factory.createIfStatement(
ts.factory.createLessThan(
ts.factory.createNumericLiteral(1),
ExpressionFactory.number(1),
ts.factory.createIdentifier("passed.length"),
),
iterate("pred")(ts.factory.createIdentifier("passed"))(
Expand Down
6 changes: 1 addition & 5 deletions src/programmers/json/JsonStringifyProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,7 @@ export namespace JsonStringifyProgrammer {
ts.factory.createCallExpression(
IdentifierFactory.access(input)("slice"),
undefined,
[
ts.factory.createNumericLiteral(
tuple.elements.length - 1,
),
],
[ExpressionFactory.number(tuple.elements.length - 1)],
),
wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
{
Expand Down
6 changes: 1 addition & 5 deletions src/programmers/misc/MiscCloneProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,7 @@ export namespace MiscCloneProgrammer {
ts.factory.createCallExpression(
IdentifierFactory.access(input)("slice"),
undefined,
[
ts.factory.createNumericLiteral(
tuple.elements.length - 1,
),
],
[ExpressionFactory.number(tuple.elements.length - 1)],
),
wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
{
Expand Down
2 changes: 1 addition & 1 deletion src/programmers/misc/MiscLiteralsProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export namespace MiscLiteralsProgrammer {
? ts.factory.createTrue()
: ts.factory.createFalse()
: typeof v === "number"
? ts.factory.createNumericLiteral(v)
? ExpressionFactory.number(v)
: typeof v === "bigint"
? ExpressionFactory.bigint(Number(v))
: ts.factory.createStringLiteral(v),
Expand Down
6 changes: 1 addition & 5 deletions src/programmers/misc/MiscPruneProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ export namespace MiscPruneProgrammer {
ts.factory.createCallExpression(
IdentifierFactory.access(input)("slice"),
undefined,
[
ts.factory.createNumericLiteral(
tuple.elements.length - 1,
),
],
[ExpressionFactory.number(tuple.elements.length - 1)],
),
wrap_metadata_rest_tuple(tuple.elements.at(-1)!.rest!),
{
Expand Down
Loading
Loading