Skip to content

fix(native): prevent json.isStringify helper mismatch#1997

Merged
samchon merged 4 commits into
masterfrom
fix/1966-json-is-stringify-large-union
Jul 3, 2026
Merged

fix(native): prevent json.isStringify helper mismatch#1997
samchon merged 4 commits into
masterfrom
fix/1966-json-is-stringify-large-union

Conversation

@samchon

@samchon samchon commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Scope json.isStringify serializer branch-check helpers to the JSON stringify metadata collection.
  • Add a transform/runtime regression for toJSON() object-union branches that previously emitted missing _io* helper references.
  • Bump typia to 13.0.0-rc.2 because native source changed.

Root Cause

json.isStringify validates with the regular checker collection, then serializes through the JSON stringify collection. When a type defines toJSON(), the JSON metadata graph can contain object-union branches that the outer validator never generated. The validated serializer was still using the default _i checker helper namespace, so generated serializer helpers could reference validator helpers that did not exist.

Changed Behavior

Validated JSON stringify now emits and references checker helpers under its own stringify-local namespace for serializer branch selection. This keeps helper generation tied to the metadata collection that actually needs those helpers instead of relying on the outer validator collection.

Validation

  • pnpm format
  • git diff --cached --check
  • go test ./cmd/ttsc-typia -run TestJsonIsStringifyScopedCheckerTransform -count=1
  • go test ./core/programmers/json ./cmd/ttsc-typia -count=1
  • pnpm test:go:native

Local Limitations

  • Full pnpm test was not run locally; CI should cover the broader package/test matrix.

Fixes #1966

Copilot AI review requested due to automatic review settings July 3, 2026 13:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Validated JSON stringify can traverse a JSON metadata graph that differs from the outer runtime validator, especially when toJSON returns object unions. The serializer now emits and references its own checker helper namespace for branch selection, so generated _su helpers do not depend on validator-only _io helpers.

Constraint: Native source ships in the typia npm package, so the package version is bumped.
Rejected: Patch generated JavaScript output | codegen must consistently own helper scopes.
Rejected: Reuse outer validator helpers | regular and JSON metadata collections can diverge.
Confidence: high
Scope-risk: narrow
Directive: Keep validated stringify checker helpers scoped to the stringify metadata collection.
Tested: pnpm format
Tested: git diff --cached --check
Tested: go test ./cmd/ttsc-typia -run TestJsonIsStringifyScopedCheckerTransform -count=1
Tested: go test ./core/programmers/json ./cmd/ttsc-typia -count=1
Tested: pnpm test:go:native
Not-tested: Full pnpm test
@samchon samchon force-pushed the fix/1966-json-is-stringify-large-union branch from c68aac7 to cf642b1 Compare July 3, 2026 13:42
samchon added 3 commits July 3, 2026 22:48
The Prefix option is now used by both plain.classify and validated JSON stringify. The comments now describe the caller-owned helper namespace rule instead of a single historical caller.

Constraint: Follow-up from self-review of PR #1997.
Confidence: high
Scope-risk: narrow
Tested: pnpm format
Tested: git diff --check
Tested: go test ./core/programmers/json ./cmd/ttsc-typia -count=1
Not-tested: Full pnpm test
The regression fixture now puts the JSON-only toJSON object union inside a recursive serializer helper and asserts that validated stringify emits its scoped _si helpers before executing both union branches.

Constraint: Follow-up from exhaustive self-review of PR #1997.

Confidence: high

Scope-risk: narrow

Tested: gofmt packages/typia/native/cmd/ttsc-typia/json_is_stringify_scoped_checker_transform_test.go

Tested: go test ./core/programmers/json ./cmd/ttsc-typia -count=1

Not-tested: Full pnpm test
The scoped checker regression test should follow the cmd/ttsc-typia fixture style used by neighboring transform tests, while still passing the repository's format-go script.

Constraint: Self-review found the prior gofmt-only indentation diverged from nearby test files.

Confidence: high

Scope-risk: narrow

Tested: pnpm run format:go

Tested: go test ./core/programmers/json ./cmd/ttsc-typia -count=1

Not-tested: Full pnpm test
@samchon samchon merged commit 28c27ab into master Jul 3, 2026
19 of 21 checks passed
@samchon samchon deleted the fix/1966-json-is-stringify-large-union branch July 3, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typia.json.isStringify: invalid JS file is simply created silently and without errors during the build process

2 participants