Skip to content

Commit

Permalink
fix: arrow function export in rsc client component (vercel#34105)
Browse files Browse the repository at this point in the history
The `export default xxx` statement is slightly different from estree when exporting an arrow function instead of identifier in swc.
We also need to capture arrow exports.
  • Loading branch information
huozhi authored and natew committed Feb 16, 2022
1 parent afaa46f commit 97a49c8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async function parseExportNamesInto(
switch (node.type) {
// TODO: support export * from module path
// case 'ExportAllDeclaration':
case 'ExportDefaultExpression':
case 'ExportDefaultDeclaration':
names.push('default')
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => 'client-default-export-arrow'
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as all from '../components/client-exports-all'
import * as allClient from '../components/client-exports-all.client'

// TODO: support export all declaration
export default function Page() {
const { a, b, c, d, e } = all
const { a: ac, b: bc, c: cc, d: dc, e: ec } = allClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { a, b, c, d, e } from '../components/client-exports'
import DefaultArrow from '../components/client-default-export-arrow.client'

export default function Page() {
return (
<div>
{a}
{b}
{c}
{d}
{e[0]}
<div id="named-exports">
{a}
{b}
{c}
{d}
{e[0]}
</div>
<div id="default-exports-arrow">
<DefaultArrow />
</div>
</div>
)
}
17 changes: 14 additions & 3 deletions test/integration/react-streaming-and-server-components/test/rsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ export default function (context) {
'/client-exports'
)
const $clientExports = cheerio.load(clientExportsHTML)
expect($clientExports('div[hidden] > div').text()).toBe('abcde')
expect($clientExports('div[hidden] > div > #named-exports').text()).toBe(
'abcde'
)
expect(
$clientExports('div[hidden] > div > #default-exports-arrow').text()
).toBe('client-default-export-arrow')

const browser = await webdriver(context.appPort, '/client-exports')
const text = await browser.waitForElementByCss('#__next').text()
expect(text).toBe('abcde')
const textNamedExports = await browser
.waitForElementByCss('#named-exports')
.text()
const textDefaultExportsArrow = await browser
.waitForElementByCss('#default-exports-arrow')
.text()
expect(textNamedExports).toBe('abcde')
expect(textDefaultExportsArrow).toBe('client-default-export-arrow')
})
}

0 comments on commit 97a49c8

Please sign in to comment.