-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify logic and add more thorough tests
- Loading branch information
Showing
3 changed files
with
46 additions
and
17 deletions.
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
33 changes: 30 additions & 3 deletions
33
...es/core/tests/fixture/ssg/getStaticProps/should-not-remove-import-used-in-render/input.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,9 +1,36 @@ | ||
import Component from '../' | ||
import { useState, useEffect } from 'react' | ||
import { Root, Children, AttributeValue, AttributeJSX, ValueInRender, ValueInEffect, UnusedInRender } from '../' | ||
|
||
export default function Test() { | ||
return <Component /> | ||
const [x, setX] = useState(ValueInRender.value) | ||
useEffect(() => { | ||
setX(ValueInEffect.value) | ||
}, []) | ||
|
||
return ( | ||
<Root x={x}> | ||
<div> | ||
<Children attr={AttributeValue} jsx={<AttributeJSX />} /> | ||
</div> | ||
</Root> | ||
) | ||
} | ||
|
||
export async function getStaticProps() { | ||
return { props: { name: Component.displayName } } | ||
return { | ||
props: { | ||
// simulate Component usage inside getStaticProps | ||
used: [ | ||
// these import references should not be removed | ||
Root.value, | ||
Children.value, | ||
AttributeValue.value, | ||
AttributeJSX.value, | ||
ValueInRender.value, | ||
ValueInEffect.value, | ||
// this import reference should be removed | ||
UnusedInRender.value, | ||
], | ||
} | ||
} | ||
} |
16 changes: 13 additions & 3 deletions
16
...s/core/tests/fixture/ssg/getStaticProps/should-not-remove-import-used-in-render/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,5 +1,15 @@ | ||
import Component from '../' | ||
export var __N_SSG = true | ||
import { useState, useEffect } from "react"; | ||
import { Root, Children, AttributeValue, AttributeJSX, ValueInRender, ValueInEffect } from "../"; | ||
export var __N_SSG = true; | ||
export default function Test() { | ||
return __jsx(Component, null) | ||
const [x, setX] = useState(ValueInRender.value); | ||
useEffect(() => { | ||
setX(ValueInEffect.value); | ||
}, []) | ||
return __jsx(Root, { | ||
x: x | ||
}, __jsx('div', null, __jsx(Children, { | ||
attr: AttributeValue, | ||
jsx: __jsx(AttributeJSX, null) | ||
}))); | ||
} |