Skip to content

[compiler][snap] Fixes to relative path resolution; compile subcommand#462

Closed
everettbu wants to merge 1 commit into
mainfrom
more-snap-improvements-2
Closed

[compiler][snap] Fixes to relative path resolution; compile subcommand#462
everettbu wants to merge 1 commit into
mainfrom
more-snap-improvements-2

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35688
Original author: josephsavona


More snap improvements for use with agents:

  • yarn snap compile [--debug] <path> for compiling any file, optionally with debug logs
  • yarn snap minimize <path> now accepts path as a positional param for consistency w 'compile' command
  • Both compile/minimize commands properly handle paths relative to the compiler/ directory. When using yarn snap the current working directory is compiler/packages/snap, but you're generally running it from the compiler directory so this matches expectations of callers better.

More snap improvements for use with agents:
* `yarn snap compile [--debug] <path>` for compiling any file, optionally with debug logs
* `yarn snap minimize <path>` now accepts path as a positional param for consistency w 'compile' command
* Both compile/minimize commands properly handle paths relative to the compiler/ directory. When using `yarn snap` the current working directory is compiler/packages/snap, but you're generally running it from the compiler directory so this matches expectations of callers better.
@everettbu everettbu added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 3, 2026
@greptile-apps

greptile-apps Bot commented Feb 3, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

This PR adds new yarn snap compile [--debug] <path> support for compiling arbitrary files (not just fixtures), updates yarn snap minimize to accept the path positionally, and adjusts path resolution so snap commands work when invoked from the compiler directory while the snap package’s CWD is compiler/packages/snap.

Implementation-wise, snap’s path constants are split into PROJECT_ROOT, BABEL_PLUGIN_ROOT, and BABEL_PLUGIN_SRC, and the runner/watch/worker/minimize code now uses these for requiring the built compiler and locating fixtures/tsconfig/build output.

One functional issue was introduced in the new CLI flows: both compile and minimize derive firstLine via input.substring(0, input.indexOf('\n')), which yields an empty string when the input file is a single line (no trailing newline), causing language/sourceType/config parsing to misbehave.

Confidence Score: 4/5

  • This PR is largely safe to merge, with one notable functional edge-case in the new compile/minimize CLI paths.
  • Most changes are straightforward wiring/documentation and path constant refactors. The main risk is the firstLine extraction bug that breaks single-line input files for the new subcommands (and minimize path parsing), which is likely to be hit when creating minimal repros.
  • compiler/packages/snap/src/runner.ts

Important Files Changed

Filename Overview
compiler/.claude/agents/investigate-error.md Docs update: mentions new yarn snap compile -d <path> option alongside existing debug fixture workflow.
compiler/CLAUDE.md Docs: adds sections for compiling arbitrary files and minimizing test cases using new snap subcommands.
compiler/docs/DEVELOPMENT_GUIDE.md Docs: adds instructions for yarn snap compile and yarn snap minimize with positional path argument.
compiler/packages/babel-plugin-react-compiler/docs/passes/README.md Docs: extends snap command examples to include new compile/minimize subcommands.
compiler/packages/snap/src/constants.ts Refactors root constants: introduces PROJECT_ROOT and splits BABEL_PLUGIN_ROOT/BABEL_PLUGIN_SRC; updates fixtures path to use plugin root.
compiler/packages/snap/src/minimize.ts Updates compiler plugin import path constant from PROJECT_SRC to BABEL_PLUGIN_SRC; otherwise unchanged minimization logic.
compiler/packages/snap/src/runner-watch.ts Adjusts TS watch/build working directory to BABEL_PLUGIN_ROOT to align with new path resolution constants.
compiler/packages/snap/src/runner-worker.ts Switches compiler plugin require path to BABEL_PLUGIN_SRC and removes an unused import.
compiler/packages/snap/src/runner.ts Adds snap compile subcommand and makes minimize take positional path; updates relative path resolution via PROJECT_ROOT/BABEL_PLUGIN_ROOT. Bug: first-line extraction breaks for single-line files.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

9 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps

greptile-apps Bot commented Feb 3, 2026

Copy link
Copy Markdown
Additional Comments (1)

compiler/packages/snap/src/runner.ts
Single-line input bug

firstLine is computed as input.substring(0, input.indexOf('\n')). If the file has no newline, indexOf returns -1 and substring returns '', so parseLanguage(firstLine), parseSourceType(firstLine), and parseConfigPragmaForTests(firstLine, ...) run with an empty string. This breaks snap minimize/snap compile for valid one-line repro files. Also appears in the compile subcommand at runner.ts:224-229.

Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/snap/src/runner.ts
Line: 171:176

Comment:
**Single-line input bug**

`firstLine` is computed as `input.substring(0, input.indexOf('\n'))`. If the file has no newline, `indexOf` returns `-1` and `substring` returns `''`, so `parseLanguage(firstLine)`, `parseSourceType(firstLine)`, and `parseConfigPragmaForTests(firstLine, ...)` run with an empty string. This breaks `snap minimize`/`snap compile` for valid one-line repro files. Also appears in the compile subcommand at runner.ts:224-229.

How can I resolve this? If you propose a fix, please make it concise.

@everettbu

Copy link
Copy Markdown
Author

Upstream PR was closed or merged. Code is synced via branch mirror.

@everettbu everettbu closed this Feb 4, 2026
@everettbu
everettbu deleted the more-snap-improvements-2 branch February 4, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants