File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " shadcn " : patch
3+ ---
4+
5+ fix transofmrRsc for handling use client
Original file line number Diff line number Diff line change 11import { Transformer } from "@/src/utils/transformers"
22import { SyntaxKind } from "ts-morph"
33
4+ const directiveRegex = / ^ [ " ' ] u s e c l i e n t [ " ' ] $ / g
5+
46export const transformRsc : Transformer = async ( { sourceFile, config } ) => {
57 if ( config . rsc ) {
68 return sourceFile
79 }
810
911 // Remove "use client" from the top of the file.
1012 const first = sourceFile . getFirstChildByKind ( SyntaxKind . ExpressionStatement )
11- if ( first ?. getText ( ) === `"use client"` ) {
13+ if ( first && directiveRegex . test ( first . getText ( ) ) ) {
1214 first . remove ( )
1315 }
1416
Original file line number Diff line number Diff line change @@ -29,3 +29,27 @@ import { Foo } from "bar"
2929"use client"
3030 "
3131` ;
32+
33+ exports [` transform rsc 5` ] = `
34+ "'use client'
35+
36+ import * as React from 'react'
37+ import { Foo } from 'bar'
38+ "
39+ ` ;
40+
41+ exports [` transform rsc 6` ] = `
42+ "import * as React from 'react'
43+ import { Foo } from 'bar'
44+ "
45+ ` ;
46+
47+ exports [` transform rsc 7` ] = `
48+ "'use foo'
49+
50+ import * as React from 'react'
51+ import { Foo } from 'bar'
52+
53+ 'use client'
54+ "
55+ ` ;
Original file line number Diff line number Diff line change @@ -62,4 +62,52 @@ import { Foo } from "bar"
6262 } ,
6363 } )
6464 ) . toMatchSnapshot ( )
65+
66+
67+ expect (
68+ await transform ( {
69+ filename : "test.ts" ,
70+ raw : `'use client'
71+
72+ import * as React from 'react'
73+ import { Foo } from 'bar'
74+ ` ,
75+ config : {
76+ tsx : true ,
77+ rsc : true ,
78+ } ,
79+ } )
80+ ) . toMatchSnapshot ( )
81+
82+ expect (
83+ await transform ( {
84+ filename : "test.ts" ,
85+ raw : `'use client'
86+
87+ import * as React from 'react'
88+ import { Foo } from 'bar'
89+ ` ,
90+ config : {
91+ tsx : true ,
92+ rsc : false ,
93+ } ,
94+ } )
95+ ) . toMatchSnapshot ( )
96+
97+ expect (
98+ await transform ( {
99+ filename : "test.ts" ,
100+ raw : `'use foo'
101+
102+ import * as React from 'react'
103+ import { Foo } from 'bar'
104+
105+ 'use client'
106+ ` ,
107+ config : {
108+ tsx : true ,
109+ rsc : false ,
110+ } ,
111+ } )
112+ ) . toMatchSnapshot ( )
65113} )
You can’t perform that action at this time.
0 commit comments