forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Babel & next-swc: Fix exporting page config with AsExpression (vercel…
…#32702) fixes vercel#20626 No changes needed in next-swc, see comments from @kdy1 below. Co-authored-by: JJ Kasper <[email protected]>
- Loading branch information
Showing
3 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test/production/typescript-basic/app/pages/page-config.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Link from 'next/link' | ||
import { PageConfig } from 'next' | ||
|
||
export const config: PageConfig = { | ||
unstable_runtimeJS: false, | ||
} | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<p>hello world</p> | ||
<Link href="/another"> | ||
<a>to /another</a> | ||
</Link> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-env jest */ | ||
import { transformSync } from '@babel/core' | ||
|
||
const babel = (code) => | ||
transformSync(code, { | ||
filename: 'page.tsx', | ||
presets: ['@babel/preset-typescript'], | ||
plugins: [require('next/dist/build/babel/plugins/next-page-config')], | ||
babelrc: false, | ||
configFile: false, | ||
sourceType: 'module', | ||
compact: true, | ||
caller: { | ||
name: 'tests', | ||
isDev: false, | ||
}, | ||
} as any).code | ||
|
||
describe('babel plugin (next-page-config)', () => { | ||
test('export config with type annotation', () => { | ||
const output = babel('export const config: PageConfig = {};') | ||
|
||
expect(output).toMatch(`export const config={};`) | ||
}) | ||
|
||
test('export config with AsExpression', () => { | ||
const output = babel('export const config = {} as PageConfig;') | ||
|
||
expect(output).toMatch('export const config={};') | ||
}) | ||
|
||
test('amp enabled', () => { | ||
jest.spyOn(Date, 'now').mockReturnValue(1234) | ||
const output = babel(` | ||
export const config = { amp: true } | ||
function About(props) { | ||
return <h3>My AMP About Page!</h3> | ||
} | ||
export default About`) | ||
|
||
expect(output).toMatch( | ||
'const __NEXT_DROP_CLIENT_FILE__="__NEXT_DROP_CLIENT_FILE__ 1234";' | ||
) | ||
}) | ||
|
||
test('amp hybrid enabled', () => { | ||
const output = babel(` | ||
export const config = { amp: 'hybrid' } | ||
function About(props) { | ||
return <h3>My AMP About Page!</h3> | ||
} | ||
export default About`) | ||
|
||
expect(output).toMatch( | ||
"export const config={amp:'hybrid'};function About(props){return<h3>My AMP About Page!</h3>;}export default About;" | ||
) | ||
}) | ||
}) |