Skip to content

Commit

Permalink
Merge pull request #198 from samchon/v3.2
Browse files Browse the repository at this point in the history
Fix #197 - no superfluous property inspection when `undefined` value comes
  • Loading branch information
samchon authored Sep 19, 2022
2 parents fccd66e + 921a001 commit b942b33
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "3.2.6",
"version": "3.2.7",
"description": "Runtime type checkers and 5x faster JSON.stringify() function",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/programmers/internal/check_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function check_object(
) => (
halter: (expr: ts.CallExpression) => ts.Expression,
) => (
wrapper?: (expr: ts.CallExpression) => ts.Expression,
wrapper?: (expr: ts.Expression) => ts.Expression,
) => (entries: IExpressionEntry[]) => ts.Expression;

export function check_object(equals: true | false) {
Expand All @@ -37,7 +37,7 @@ export function check_object(equals: true | false) {
};
}

type Wrapper = (expr: ts.CallExpression) => ts.Expression;
type Wrapper = (expr: ts.Expression) => ts.Expression;
const reduce = (assert: boolean) => (expressions: ts.Expression[]) =>
assert
? expressions.reduce((x, y) => ts.factory.createLogicalAnd(x, y))
Expand Down
83 changes: 43 additions & 40 deletions src/programmers/internal/check_properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { check_everything } from "./check_everything";
export const check_properties =
(assert: boolean) =>
(halter: (exp: ts.CallExpression) => ts.Expression) =>
(wrapper?: (exp: ts.CallExpression) => ts.Expression) =>
(wrapper?: (exp: ts.Expression) => ts.Expression) =>
(entries: IExpressionEntry[]): ts.Expression => {
const func = wrapper ? "entries" : "keys";
const criteria = ts.factory.createCallExpression(
IdentifierFactory.join(
ts.factory.createCallExpression(
ts.factory.createIdentifier(`Object.${func}`),
ts.factory.createIdentifier("Object.entries"),
undefined,
[ts.factory.createIdentifier("input")],
),
Expand All @@ -29,55 +28,59 @@ export const check_properties =
};

const check_property =
(wrapper?: (exp: ts.CallExpression) => ts.Expression) =>
(wrapper?: (exp: ts.Expression) => ts.Expression) =>
(entries: IExpressionEntry[]) =>
ts.factory.createArrowFunction(
undefined,
undefined,
[
wrapper === undefined
? IdentifierFactory.parameter("key")
: IdentifierFactory.parameter(
ts.factory.createArrayBindingPattern([
ts.factory.createBindingElement(
undefined,
undefined,
"key",
),
ts.factory.createBindingElement(
undefined,
undefined,
"value",
),
]),
),
IdentifierFactory.parameter(
ts.factory.createArrayBindingPattern([
ts.factory.createBindingElement(
undefined,
undefined,
"key",
),
ts.factory.createBindingElement(
undefined,
undefined,
"value",
),
]),
),
],
undefined,
undefined,
(wrapper || ((elem) => elem))(
ts.factory.createCallExpression(
IdentifierFactory.join(
ts.factory.createArrayLiteralExpression(
entries.map((entry) =>
ts.factory.createStringLiteral(entry.key),
),
),
"some",
ts.factory.createLogicalOr(
ts.factory.createStrictEquality(
ts.factory.createIdentifier("undefined"),
ts.factory.createIdentifier("value"),
),
undefined,
[
ts.factory.createArrowFunction(
undefined,
undefined,
[IdentifierFactory.parameter("prop")],
undefined,
undefined,
ts.factory.createStrictEquality(
ts.factory.createIdentifier("key"),
ts.factory.createIdentifier("prop"),
ts.factory.createCallExpression(
IdentifierFactory.join(
ts.factory.createArrayLiteralExpression(
entries.map((entry) =>
ts.factory.createStringLiteral(entry.key),
),
),
"some",
),
],
undefined,
[
ts.factory.createArrowFunction(
undefined,
undefined,
[IdentifierFactory.parameter("prop")],
undefined,
undefined,
ts.factory.createStrictEquality(
ts.factory.createIdentifier("key"),
ts.factory.createIdentifier("prop"),
),
),
],
),
),
),
);

0 comments on commit b942b33

Please sign in to comment.