Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
415d7fd7
Unverified
Commit
415d7fd7
authored
Nov 13, 2020
by
Joe Haddad
Committed by
GitHub
Nov 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respect next/babel user provided runtime option (#19136)
parent
8ff52136
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
5 deletions
+34
-5
preset.ts
packages/next/build/babel/preset.ts
+6
-5
next-babel.unit.test.js
test/unit/next-babel.unit.test.js
+28
-0
No files found.
packages/next/build/babel/preset.ts
View file @
415d7fd7
...
...
@@ -67,9 +67,10 @@ module.exports = (
const
supportsESM
=
api
.
caller
(
supportsStaticESM
)
const
isServer
=
api
.
caller
((
caller
:
any
)
=>
!!
caller
&&
caller
.
isServer
)
const
isModern
=
api
.
caller
((
caller
:
any
)
=>
!!
caller
&&
caller
.
isModern
)
const
hasJsxRuntime
=
Boolean
(
api
.
caller
((
caller
:
any
)
=>
!!
caller
&&
caller
.
hasJsxRuntime
)
)
const
useJsxRuntime
=
options
[
'preset-react'
]?.
runtime
===
'automatic'
||
(
Boolean
(
api
.
caller
((
caller
:
any
)
=>
!!
caller
&&
caller
.
hasJsxRuntime
))
&&
options
[
'preset-react'
]?.
runtime
!==
'classic'
)
const
isLaxModern
=
isModern
||
...
...
@@ -122,7 +123,7 @@ module.exports = (
// This adds @babel/plugin-transform-react-jsx-source and
// @babel/plugin-transform-react-jsx-self automatically in development
development
:
isDevelopment
||
isTest
,
...(
has
JsxRuntime
?
{
runtime
:
'automatic'
}
:
{
pragma
:
'__jsx'
}),
...(
use
JsxRuntime
?
{
runtime
:
'automatic'
}
:
{
pragma
:
'__jsx'
}),
...
options
[
'preset-react'
],
},
],
...
...
@@ -132,7 +133,7 @@ module.exports = (
],
],
plugins
:
[
!
has
JsxRuntime
&&
[
!
use
JsxRuntime
&&
[
require
(
'./plugins/jsx-pragma'
),
{
// This produces the following injected import for modules containing JSX:
...
...
test/unit/next-babel.unit.test.js
View file @
415d7fd7
...
...
@@ -191,4 +191,32 @@ describe('next/babel', () => {
`
)
})
})
describe
(
'respect preset-react runtime'
,
()
=>
{
it
(
'should allow forcing on automatic mode'
,
()
=>
{
const
code
=
trim
`const a = ()=><a href="/">home</a>`
const
output
=
babel
(
code
,
true
,
{
'preset-react'
:
{
runtime
:
'automatic'
,
},
})
expect
(
output
).
toMatchInlineSnapshot
(
`"import{jsx as _jsx}from\\"react/jsx-runtime\\";var a=function a(){return/*#__PURE__*/_jsx(\\"a\\",{href:\\"/\\",children:\\"home\\"});};"`
)
})
it
(
'should allow forcing on classic mode'
,
()
=>
{
const
code
=
trim
`const a = ()=><a href="/">home</a>`
const
output
=
babel
(
code
,
true
,
{
'preset-react'
:
{
runtime
:
'classic'
,
},
})
expect
(
output
).
toMatchInlineSnapshot
(
`"import React from\\"react\\";var __jsx=React.createElement;var a=function a(){return __jsx(\\"a\\",{href:\\"/\\"},\\"home\\");};"`
)
})
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment