New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Babel & next-swc: Fix exporting page config with AsExpression #32702
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93afebd
Fix asexpression for babel and swc
hanneslund cee2c1b
match -> .map()
hanneslund 8b7933a
Merge branch 'canary' of github.com:hanneslund/next.js into page-conf…
hanneslund 3882c69
Revert next-swc changes
hanneslund 31daa4f
Merge branch 'canary' into page-config-asexpression
ijjk c3d2804
Add integration test
ijjk d2f0321
Merge branch 'canary' into page-config-asexpression
ijjk File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ function About(props) { | |
return <h3>My AMP About Page!</h3> | ||
} | ||
|
||
export default About | ||
export default About |
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
11 changes: 11 additions & 0 deletions
11
packages/next-swc/crates/core/tests/fixture/page-config/amp-true-asexpression/input.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,11 @@ | ||
import type { PageConfig } from "next" | ||
|
||
export const config = { | ||
amp: true, | ||
} as PageConfig | ||
|
||
function About(props) { | ||
return <h3>My AMP About Page!</h3> | ||
} | ||
|
||
export default About |
1 change: 1 addition & 0 deletions
1
packages/next-swc/crates/core/tests/fixture/page-config/amp-true-asexpression/output.js
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 @@ | ||
const __NEXT_DROP_CLIENT_FILE__ = "__NEXT_DROP_CLIENT_FILE__ mock_timestamp"; |
11 changes: 11 additions & 0 deletions
11
packages/next-swc/crates/core/tests/fixture/page-config/amp-true-type-annotation/input.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,11 @@ | ||
import type { PageConfig } from "next" | ||
|
||
export const config: PageConfig = { | ||
amp: true, | ||
} | ||
|
||
function About(props) { | ||
return <h3>My AMP About Page!</h3> | ||
} | ||
|
||
export default About |
1 change: 1 addition & 0 deletions
1
packages/next-swc/crates/core/tests/fixture/page-config/amp-true-type-annotation/output.js
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 @@ | ||
const __NEXT_DROP_CLIENT_FILE__ = "__NEXT_DROP_CLIENT_FILE__ mock_timestamp"; |
6 changes: 4 additions & 2 deletions
6
...sts/fixture/page-config/amp-true/input.js → ...ts/fixture/page-config/amp-true/input.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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export const config = { amp: true } | ||
export const config = { | ||
amp: true, | ||
} | ||
|
||
function About(props) { | ||
return <h3>My AMP About Page!</h3> | ||
} | ||
|
||
export default About | ||
export default About |
2 changes: 1 addition & 1 deletion
2
packages/next-swc/crates/core/tests/fixture/page-config/amp-true/output.js
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 |
---|---|---|
@@ -1 +1 @@ | ||
const __NEXT_DROP_CLIENT_FILE__ = "__NEXT_DROP_CLIENT_FILE__ mock_timestamp"; | ||
const __NEXT_DROP_CLIENT_FILE__ = "__NEXT_DROP_CLIENT_FILE__ mock_timestamp"; |
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
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;" | ||
) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is redundant.
We use this pass with
swc
crate and the swc crate invokes custom passes after stripping typescript types.And this is a public API, because of the binary size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! I reverted the changes to next-swc.