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
7a51b888
Commit
7a51b888
authored
Dec 05, 2019
by
Joe Haddad
Committed by
JJ Kasper
Dec 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SSG Support for VariableDeclarations (#9641)
parent
a718df5f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
next-ssg-transform.ts
packages/next/build/babel/plugins/next-ssg-transform.ts
+24
-0
babel-plugin-next-ssg-transform.test.js
test/unit/babel-plugin-next-ssg-transform.test.js
+60
-0
No files found.
packages/next/build/babel/plugins/next-ssg-transform.ts
View file @
7a51b888
...
@@ -69,6 +69,30 @@ export default function nextTransformSsg({
...
@@ -69,6 +69,30 @@ export default function nextTransformSsg({
}
}
}
}
},
},
// export const unstable_getStaticPaths = () => {}
VariableDeclaration
(
path
)
{
if
(
path
.
parent
.
type
!==
'ExportNamedDeclaration'
)
{
return
}
path
.
node
.
declarations
=
path
.
node
.
declarations
.
filter
(
d
=>
{
const
name
=
d
.
id
.
type
===
'Identifier'
&&
d
.
id
.
name
const
isPrerender
=
name
===
EXPORT_NAME_GET_STATIC_PROPS
||
name
===
EXPORT_NAME_GET_STATIC_PATHS
if
(
isPrerender
)
{
state
.
isPrerender
=
true
}
return
!
isPrerender
})
if
(
path
.
node
.
declarations
.
length
===
0
)
{
path
.
parentPath
.
remove
()
}
},
})
})
},
},
exit
(
path
,
state
)
{
exit
(
path
,
state
)
{
...
...
test/unit/babel-plugin-next-ssg-transform.test.js
View file @
7a51b888
...
@@ -127,5 +127,65 @@ describe('babel plugin (next-ssg-transform)', () => {
...
@@ -127,5 +127,65 @@ describe('babel plugin (next-ssg-transform)', () => {
`"export function Noop(){}const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
`"export function Noop(){}const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
)
)
})
})
it
(
'should remove named export variable declarations'
,
()
=>
{
const
output
=
babel
(
trim
`
export const unstable_getStaticPaths = () => {
return []
}
export const unstable_getStaticProps = function() {
return { props: {} }
}
export default function Test() {
return <div />
}
`
)
expect
(
output
).
toMatchInlineSnapshot
(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
)
})
it
(
'should remove named export variable declarations (async)'
,
()
=>
{
const
output
=
babel
(
trim
`
export const unstable_getStaticPaths = async () => {
return []
}
export const unstable_getStaticProps = async function() {
return { props: {} }
}
export default function Test() {
return <div />
}
`
)
expect
(
output
).
toMatchInlineSnapshot
(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
)
})
it
(
'should not remove extra named export variable declarations'
,
()
=>
{
const
output
=
babel
(
trim
`
export const unstable_getStaticPaths = () => {
return []
}, foo = 2
export const unstable_getStaticProps = function() {
return { props: {} }
}
export default function Test() {
return <div />
}
`
)
expect
(
output
).
toMatchInlineSnapshot
(
`"export const foo=2;const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
)
})
})
})
})
})
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