New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter's default value is removed when it's not supposed to #4516
Parameter's default value is removed when it's not supposed to #4516
Comments
Up. Version 2.75.3 does not fix it. |
Sorry for this. Fix at #4518 |
I think this is not completely fixed yet. I'm trying to build a minimal test case, but meanwhile I have a module including a function with the signature: |
Well, that is the whole point of default parameter tree-shaking. The question is just if it is missing in a situation where it is definitely making a difference. |
I've just tested with version 2.75.4 and this issue is still reproducible: vitejs/vite#8395 (comment) Its is basically something like this: function foo() {
const bar = (options = {}) => {
console.log(options);
}
return bar;
}
foo()(); // console.logs "undefined" |
Yes, sorry, I just ran into the issue before even reading up on the feature itself! In my case I could narrow it down to the use of export function uniq(array, into = [], memo = new Set()) { /* ... */ } import { uniq } from './util'
export function x() {
try {
return uniq([])
} catch {
return []
}
} Yields a While a usage like: export function y() {
return uniq([])
} Includes all of them. In my own code base there must be a third case which I haven't been able to isolate yet, where only the default value of the second parameter is dropped. |
Oh darn. First, thanks so much for spotting these. It seems this feature that I initially thought was "not too complicated" is a pesky can of worms that is more brittle than any optimization I created before. I think at this point, I will keep the test cases (and create more regression tests for the things mentioned above), but roll back the feature until I am feeling adventurous again. |
Rollup Version
2.75.0+
Operating System (or Browser)
macOS Monterey
Node Version (if applicable)
16.14.0
Link To Reproduction
https://replit.com/@jindrahm/ParamDefaultBug?v=1
Expected Behaviour
The following code should remain basically untouched after bundling by rollup.
Actual Behaviour
But it generates this code which throws an error because rollup removed the
options
param default value so it cannot access thecountdown
property ofundefined
.The text was updated successfully, but these errors were encountered: