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
e76fc186
Unverified
Commit
e76fc186
authored
Dec 05, 2019
by
Joe Haddad
Committed by
GitHub
Dec 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Scope Bindings for SSG (#9642)
parent
7a51b888
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
4 deletions
+51
-4
next-ssg-transform.ts
packages/next/build/babel/plugins/next-ssg-transform.ts
+15
-4
babel-plugin-next-ssg-transform.test.js
test/unit/babel-plugin-next-ssg-transform.test.js
+36
-0
No files found.
packages/next/build/babel/plugins/next-ssg-transform.ts
View file @
e76fc186
...
...
@@ -55,16 +55,27 @@ export default function nextTransformSsg({
name
===
EXPORT_NAME_GET_STATIC_PROPS
||
name
===
EXPORT_NAME_GET_STATIC_PATHS
)
{
path
.
remove
()
state
.
isPrerender
=
true
if
(
path
.
parent
.
type
!==
'ExportNamedDeclaration'
)
{
const
parent
=
path
.
parent
if
(
parent
.
type
!==
'ExportNamedDeclaration'
)
{
throw
new
Error
(
`invariant:
${
path
.
type
}
has unknown parent:
${
pa
th
.
pa
rent
.
type
}
`
`invariant:
${
path
.
type
}
has unknown parent:
${
parent
.
type
}
`
)
}
if
(
path
.
parent
.
specifiers
.
length
===
0
)
{
if
(
!
parent
.
source
)
{
const
localName
=
path
.
node
.
local
.
name
const
binding
=
path
.
scope
.
getBinding
(
localName
)
if
(
binding
)
{
binding
.
path
.
remove
()
}
}
path
.
remove
()
if
(
parent
.
specifiers
.
length
===
0
)
{
path
.
parentPath
.
remove
()
}
}
...
...
test/unit/babel-plugin-next-ssg-transform.test.js
View file @
e76fc186
...
...
@@ -187,5 +187,41 @@ describe('babel plugin (next-ssg-transform)', () => {
`"export const foo=2;const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__NEXT_SPR=true export default __NEXT_COMP;"`
)
})
it
(
'should remove re-exported variable declarations'
,
()
=>
{
const
output
=
babel
(
trim
`
const unstable_getStaticPaths = () => {
return []
}
export { unstable_getStaticPaths }
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 re-exported function declarations'
,
()
=>
{
const
output
=
babel
(
trim
`
function unstable_getStaticPaths() {
return []
}
export { unstable_getStaticPaths }
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;"`
)
})
})
})
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