Skip to content

Tree-shaking of parameter defaults too aggressive #4514

@Swatinem

Description

@Swatinem

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].

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions