fix(codemod): handle static z.extend(Schema, {...}) form#1530
fix(codemod): handle static z.extend(Schema, {...}) form#1530uttam12331 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThe PR adds support for the static namespace form 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The zod-to-valibot codemod only handled the method form
Foo.extend({...})but not the static namespace formz.extend(Foo, {...}).When the transformer encountered
z.extend(Foo, { bar: z.string() })it treated the namespace identifier itself as the base schema and the first argument as the extension, producing garbled output instead ofv.object({ ...Foo.entries, bar: v.string() }).Root cause: The import rewrite transforms
z.extend(Foo, {...})intov.extend(Foo, {...}). The chain walker then hitsv.extendas a method call withtransformedExp === null, so it falls through totoValibotMethodExpwithschemaExp = j.identifier('v')(the namespace) andargs = [Foo, {...}]— both wrong.Fix: In the
isZodMethodNamebranch of the chain walker, detect whenpropertyName === 'extend',transformedExp === null(nothing built yet, so we are on the namespace), and exactly 2 arguments are present. In that case extractargs[0]as the base schema expression andargs[1]as the extension, matching the shape expected bytransformExtend.Adds a test fixture (
object-extend-static) covering both a schema-reference base and an inline-object base.Closes #1502
Summary by CodeRabbit
extendconversions so the generated output now uses the correct base schema and extension values.