Skip to content

Accept the source as a string in applyTransform - #762

Open
i098 wants to merge 1 commit into
meta:mainfrom
i098:fix-apply-transform-string-input
Open

i098 wants to merge 1 commit into
meta:mainfrom
i098:fix-apply-transform-string-input

Conversation

@i098

@i098 i098 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The README documents applyTransform with the source as a plain string:

const output = applyTransform(transform, transformOptions, 'input');

That call throws, because the string reaches the transform as the file argument and file.source is undefined:

TypeError: Received an unexpected value [object Undefined]
    at fromAST (src/core.js:70:9)

defineInlineTest and runTest wrap the source in a file object before they call the transform; applyTransform does not.

Fix

applyTransform now wraps a string input in { source: input }. Callers that already pass a { path, source } object behave as before, so the README example works as written and needs no change.

Verification

A new test in src/__tests__/testUtils-test.js calls applyTransform with a string. It fails on main with the error above and passes with this change. Full suite:

$ jest --bail
Test Suites: 19 passed, 19 total
Tests:       1 skipped, 222 passed, 223 total

A patch changeset is included.

Closes #448

I am new to open source, and this pull request was made with AI assistance.

@changeset-bot

changeset-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2b49b7f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jscodeshift Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 1, 2026

Copy link
Copy Markdown

@i098 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed label Nov 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/jscodeshift@762.tgz

commit: 2b49b7f

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ApplyTransform test util requires input to be manually wrapped in a file object

1 participant