Skip to content

fix: indent standalone blocks in tseynit - #2933

Open
huytdps13400 wants to merge 2 commits into
software-mansion:mainfrom
huytdps13400:fix/2894-tseynit-block-indent
Open

fix: indent standalone blocks in tseynit#2933
huytdps13400 wants to merge 2 commits into
software-mansion:mainfrom
huytdps13400:fix/2894-tseynit-block-indent

Conversation

@huytdps13400

@huytdps13400 huytdps13400 commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • indent standalone and nested block opening braces using the caller-provided indentation
  • omit only the first indentation prefix when a statement is rendered inline after if/else/for/while/for-of
  • avoid trimStart, so the stringifier never removes semantic or future formatter-owned whitespace
  • keep the focused nested-block regression and affected obfuscation snapshots

Closes #2894.

Verification

  • focused tseynit suite: 29/29 passed
  • unplugin-typegpu obfuscation suite: 24/24 passed
  • full source unit suite: 275 files; 2,853 passed, 2 skipped
  • full monorepo typecheck: 0 errors
  • full Oxlint/Prettier/Oxfmt style gate passed
  • git diff --check passed

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.

Pull request overview

This PR fixes indentation behavior in the tseynit AST-to-JS stringifier so that standalone/nested blocks respect the caller-provided indentation, while control-flow statements (if/else/for/while/for-of) still keep their bodies directly after the control syntax.

Changes:

  • Indent block opening braces using the provided indentation (fixes standalone/nested blocks starting at column 0).
  • Ensure control-flow bodies don’t gain extra leading indentation by trimming the stringified body prefix.
  • Add a targeted regression test and update affected obfuscation inline snapshots.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
packages/typegpu/src/shared/tseynit.ts Adjusts stringifyStatement block formatting and control-flow body rendering to preserve correct indentation.
packages/typegpu/tests/internal/tseynit.test.ts Adds a focused regression test covering standalone nested blocks + control-flow formatting expectations.
packages/unplugin-typegpu/test/obfuscation.test.ts Updates obfuscation snapshots to match the corrected block indentation output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

  • tseynit.ts — indent block opening braces. NODE.block now emits ${ident}{\n…\n${ident}}, so standalone blocks inherit the caller's indentation instead of starting at column 0.
  • Control-flow bodies trimmed. if/else, for, while, and for-of bodies call .trimStart() so the block { still hugs the ) — exactly the double-space failure mode the issue (#2894) flagged.
  • Regression + snapshot updates. New tseynit.test.ts case pins both cases (indented standalone block, inline if-body); the obfuscation snapshots reflect only the corrected { indent.

The fix matches the issue intent precisely, and the trimmed blast radius is worth noting: stringifyNode output feeds only error-message text (wgslGenerator.ts) and test snapshots — never emitted WGSL — so this is a formatting-only correction. I verified .trimStart() is safe across every statement type (each stringifies to a first line prefixed by exactly the indent), and nested standalone blocks inside a control-flow body still indent correctly.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@aleksanderkatan

Copy link
Copy Markdown
Member

Can we do this without trim?

@huytdps13400

Copy link
Copy Markdown
Author

Implemented without trimming in 214b4ebb.

stringifyStatement now accepts an omitInitialIndent flag. Control-flow bodies omit only their known first indentation prefix, while nested lines keep the caller-provided indentation unchanged. There is no trimStart left in the stringifier.

Focused verification: tseynit 29/29 and obfuscation 24/24. Full source verification: 275 files, 2,853 tests passed / 2 skipped; monorepo typecheck and full style gate pass.

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Reviewed changes

  • Replaced .trimStart() with a threaded omitInitialIndent parameter. stringifyStatement now takes a third argument and every statement type (expression, block, return, let, const, continue, break) returns via an initialIndent that is elided only for control-flow bodies (if/else, for, while, forOf). This is behaviorally byte-identical to the previously-approved .trimStart() version — the tseynit regression test and the obfuscation snapshots are unchanged in this commit.
  • Cleaner than trimming. Omitting the caller-owned indent at the source instead of post-hoc .trimStart() means the stringifier never strips whitespace it didn't itself add, which is more robust against future formatter-owned or semantic leading space.
  • Verified against the regression case. Traced if (true) { [3, 4]; } and the standalone nested { [1, 2]; } block through the new code path: the { of a control-flow body hugs the ) (no double space), while the standalone block opens indented and closes at ident. The inline snapshot matches exactly.

The refactor preserves the prior fix precisely while removing the whitespace-trim bluntness the earlier version carried.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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.

impr: Give correct indent to blocks in tseynit

3 participants