Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Fixed babel transform for request$
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanner-Scadden committed Mar 1, 2023
1 parent 670d680 commit ad6385e
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 183 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-carrots-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@prpc/vite': patch
---

Fixed babel transform for request$ in functions
21 changes: 11 additions & 10 deletions packages/vite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Plugin } from 'vite'
import { transform, type types } from '@babel/core'
import type { Plugin } from 'vite'

export function prpc(): Plugin {
return {
Expand Down Expand Up @@ -50,15 +50,16 @@ function transformpRPC$({ types: t }: { types: typeof types }) {
t.isIdentifier(callee, { name: 'mutation$' })
) {
const [serverFunction, key, zodSchema] = path.node.arguments
// @todo: fix this, it doesn't replace request$
serverFunction.body.body.forEach((body: any) => {
if (
body.expression &&
body.expression.object &&
body.expression.object.name === 'request$'
) {
body.expression.object.name = 'server$.request'
}

path.traverse({
Identifier(innerPath: any) {
if (
innerPath.node.name === 'request$' &&
innerPath.scope?.path?.listKey !== 'params'
) {
innerPath.node.name = 'server$.request'
}
},
})

if (zodSchema) {
Expand Down
Loading

1 comment on commit ad6385e

@vercel
Copy link

@vercel vercel bot commented on ad6385e Mar 1, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

prpc-docs – ./

prpc-docs-git-main-orjdev.vercel.app
prpc.vercel.app
prpc-docs-orjdev.vercel.app
prpc-docs.vercel.app

Please sign in to comment.