-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/minifier): Check for conditional usages while inlining (#2459)
swc_ecma_minifier: - `hoist_props`: Check for `used_in_cond` before inlining.
- Loading branch information
Showing
27 changed files
with
193 additions
and
112 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
55 changes: 55 additions & 0 deletions
55
ecmascript/minifier/tests/compress/fixture/issues/react/hooks/5/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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
|
||
|
||
const CONST_1 = 'const1'; | ||
const CONST_2 = 'const2'; | ||
|
||
function useHook1() { | ||
const [v1, v1_set] = useState(undefined); | ||
|
||
useEffect(() => { | ||
if ( | ||
GLOBALS.get(CONST_1) && | ||
GLOBALS.get(CONST_2) | ||
) { | ||
v1_set(true); | ||
} else { | ||
v1_set(false); | ||
} | ||
}, []); | ||
|
||
return v1; | ||
} | ||
|
||
|
||
function useHook2() { | ||
const [a1, a1_set] = useState({}); | ||
useEffect(() => { | ||
a1_set( | ||
JSON.parse(GLOBALS.get(CONST1) || '{}') , | ||
); | ||
}, []); | ||
return a1; | ||
} | ||
|
||
|
||
|
||
export function HeaderCTA() { | ||
const varB = useHook2(); | ||
const varA = useHook1(); | ||
|
||
// Loading... | ||
if (varA === undefined) { | ||
return null; | ||
} | ||
|
||
if (varA) { | ||
return ( | ||
use(varB.field) | ||
); | ||
} | ||
|
||
return ( | ||
pure() | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
ecmascript/minifier/tests/compress/fixture/issues/react/hooks/5/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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function HeaderCTA() { | ||
const varB = function() { | ||
const [a1, a1_set] = useState({ | ||
}); | ||
return useEffect(()=>{ | ||
a1_set(JSON.parse(GLOBALS.get(CONST1) || "{}")); | ||
}, []), a1; | ||
}(), varA = function() { | ||
const [v1, v1_set] = useState(void 0); | ||
return useEffect(()=>{ | ||
GLOBALS.get("const1") && GLOBALS.get("const2") ? v1_set(!0) : v1_set(!1); | ||
}, []), v1; | ||
}(); | ||
return void 0 === varA ? null : varA ? use(varB.field) : pure(); | ||
} |
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
tests/tsc-references/es6/for-ofStatements/for-of32/input.ts/es5.2.minified/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
14 changes: 7 additions & 7 deletions
14
tests/tsc-references/es6/for-ofStatements/for-of37/input.ts/es5.2.minified/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
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
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
Oops, something went wrong.