Skip to content

Commit

Permalink
early return on own issues
Browse files Browse the repository at this point in the history
  • Loading branch information
selimb committed Jan 10, 2024
1 parent 2e7ab71 commit 83e8ea4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4264,8 +4264,10 @@ export class ZodEffects<

const effect = this._def.effect || null;

let hasIssue = false;
const checkCtx: RefinementCtx = {
addIssue: (arg: IssueData) => {
hasIssue = true;
addIssueToContext(ctx, arg);
if (arg.fatal) {
status.abort();
Expand All @@ -4282,7 +4284,7 @@ export class ZodEffects<

if (effect.type === "preprocess") {
const processed = effect.transform(ctx.data, checkCtx);
if (ctx.common.issues.length) {
if (hasIssue) {
return {
status: "dirty",
value: ctx.data,
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4264,8 +4264,10 @@ export class ZodEffects<

const effect = this._def.effect || null;

let hasIssue = false;
const checkCtx: RefinementCtx = {
addIssue: (arg: IssueData) => {
hasIssue = true;
addIssueToContext(ctx, arg);
if (arg.fatal) {
status.abort();
Expand All @@ -4282,7 +4284,7 @@ export class ZodEffects<

if (effect.type === "preprocess") {
const processed = effect.transform(ctx.data, checkCtx);
if (ctx.common.issues.length) {
if (hasIssue) {
return {
status: "dirty",
value: ctx.data,
Expand Down

0 comments on commit 83e8ea4

Please sign in to comment.