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
202ea6fb
Unverified
Commit
202ea6fb
authored
May 15, 2020
by
Joe Haddad
Committed by
GitHub
May 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support eliminating memoized functions (#12953)
parent
7edc815a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
next-ssg-transform.ts
packages/next/build/babel/plugins/next-ssg-transform.ts
+14
-2
babel-plugin-next-ssg-transform.test.js
test/unit/babel-plugin-next-ssg-transform.test.js
+17
-0
No files found.
packages/next/build/babel/plugins/next-ssg-transform.ts
View file @
202ea6fb
import
{
NodePath
,
PluginObj
,
types
as
BabelTypes
}
from
'@babel/core'
import
{
SERVER_PROPS_SSG_CONFLICT
}
from
'../../../lib/constants'
import
{
STATIC_PROPS_ID
,
SERVER_PROPS_ID
,
STATIC_PROPS_ID
,
}
from
'../../../next-server/lib/constants'
export
const
EXPORT_NAME_GET_STATIC_PROPS
=
'getStaticProps'
...
...
@@ -134,7 +134,19 @@ export default function nextTransformSsg({
ident
:
NodePath
<
BabelTypes
.
Identifier
>
):
boolean
{
const
b
=
ident
.
scope
.
getBinding
(
ident
.
node
.
name
)
return
b
!=
null
&&
b
.
referenced
if
(
b
?.
referenced
)
{
// Functions can reference themselves, so we need to check if there's a
// binding outside the function scope or not.
if
(
b
.
path
.
type
===
'FunctionDeclaration'
)
{
return
!
b
.
constantViolations
.
concat
(
b
.
referencePaths
)
// Check that every reference is contained within the function:
.
every
(
ref
=>
ref
.
findParent
(
p
=>
p
===
b
.
path
))
}
return
true
}
return
false
}
function
markFunction
(
...
...
test/unit/babel-plugin-next-ssg-transform.test.js
View file @
202ea6fb
...
...
@@ -439,5 +439,22 @@ describe('babel plugin (next-ssg-transform)', () => {
`"export var __N_SSG=true;export{default}from'a';"`
)
})
it
(
'should support babel-style memoized function'
,
()
=>
{
const
output
=
babel
(
trim
`
function fn() {
fn = function () {};
return fn.apply(this, arguments);
}
export function getStaticProps() {
fn;
}
export default function Home() { return <div />; }
`
)
expect
(
output
).
toMatchInlineSnapshot
(
`"export var __N_SSG=true;export default function Home(){return __jsx(\\"div\\",null);}"`
)
})
})
})
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