Skip to content
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

Tree-shaking of parameter defaults too aggressive #4514

Closed
Swatinem opened this issue May 29, 2022 · 2 comments · Fixed by #4515
Closed

Tree-shaking of parameter defaults too aggressive #4514

Swatinem opened this issue May 29, 2022 · 2 comments · Fixed by #4515
Assignees

Comments

@Swatinem
Copy link
Contributor

Rollup Version

2.75

Operating System (or Browser)

any

Node Version (if applicable)

No response

Link To Reproduction

https://rollupjs.org/repl/?version=2.75.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmZ1bmN0aW9uJTIwQSgpJTIwJTdCJTdEJTVDbmZ1bmN0aW9uJTIwYShfMSUyMCUzRCUyMEEpJTIwJTdCcmV0dXJuJTIwJTVCXzElNUQlN0QlNUNuZnVuY3Rpb24lMjB0eXBlUXVlcnkoXzIlMjAlM0QlMjB0eXBlUXVlcnklMkMlMjBfMyUyMCUzRCUyMGEpJTIwJTdCcmV0dXJuJTIwJTVCXzIlMkNfMyU1RCU3RCU1Q25leHBvcnQlMjAlN0J0eXBlUXVlcnklN0QlMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

Expected Behaviour

In rollup-plugin-dts, I synthesize a fake AST for typescript definitions.

As an example, I turn the following TS code:

interface A {}
declare const a: A;
export declare function typeQuery(): typeof a;

Into a synthetic AST representing something like:

function A() {}
function a(_1 = A) {return [_1]}
function typeQuery(_2 = typeQuery, _3 = a) {return [_2,_3]}
export {typeQuery}

For various reasons, I use parameters and defaults to link between items and make sure that referenced things are being retained.

In particular, looking at the synthetic AST, I would expect that A is retained because I could "in theory" get a reference to it by doing a typeQuery()[1]()[0].

Actual Behaviour

As reported in Swatinem/rollup-plugin-dts#208, the recent changes in #4510 broke this use-case.

As the REPL shows, the synthetic example is being reduced to:

function a(_1) {return [_1]}
function typeQuery(_2 = typeQuery, _3 = a) {return [_2,_3]}

export { typeQuery };

That seems to be wrong, as I can no longer get to A by doing typeQuery()[1]()[0].

@Swatinem
Copy link
Contributor Author

Amazing responsiveness as always ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants