Skip to content

Conversation

@josephsavona
Copy link
Member

@josephsavona josephsavona commented Jan 31, 2026

Snap now supports subcommands 'test' (default) and 'minimize`. The minimize subcommand attempts to minimize a single failing input fixture by incrementally simplifying the ast so long as the same error occurs. I spot-checked it and it seemed to work pretty well. This is intended for use in a new subagent designed for investigating bugs — fixture simplification is an important part of the process and we can automate this rather than light tokens on fire.

Example Input:

function Component(props) {
  const x = [];
  let result;
  for (let i = 0; i < 10; i++) {
    if (cond) {
      try {
        result = {key: bar([props.cond && props.foo])};
      } catch (e) {
        console.log(e);
      }
    }
  }
  x.push(result);
  return <Stringify x={x} />;
}

Command output:

$ yarn snap minimize --path .../input.js
Minimizing: .../input.js

Minimizing................

--- Minimized Code ---
function Component(props) {
  try {
    props && props;
  } catch (e) {}
}

Reduced from 16 lines to 5 lines

This demonstrates things like:

  • Removing one statement at at time
  • Replacing if/else with the test, consequent, or alternate. Similar for other control-flow statements including try/catch
  • Removing individual array/object expression properties
  • Replacing single-value array/object with the value
  • Replacing control-flow expression (logical, consequent) w the test or left/right values
  • Removing call arguments
  • Replacing calls with a single argument with the argument
  • Replacing calls with multiple arguments with an array of the arguments
  • Replacing optional member/call with non-optional versions
  • Replacing member expression with the object. If computed, also try replacing w the key
  • And a bunch more strategies, see the code

@meta-cla meta-cla bot added the CLA Signed label Jan 31, 2026
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jan 31, 2026
@josephsavona josephsavona force-pushed the worktree-2026-01-30-14-40-20-error-binary-search2 branch from 2296859 to 98b2073 Compare January 31, 2026 07:33

This comment was marked as spam.

This comment was marked as spam.

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