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

Is there a way to change rename order when exist duplicate names? #3975

Closed
supperchong opened this issue Feb 26, 2021 · 4 comments · Fixed by #3977
Closed

Is there a way to change rename order when exist duplicate names? #3975

supperchong opened this issue Feb 26, 2021 · 4 comments · Fixed by #3977

Comments

@supperchong
Copy link

Feature Use Case

//a.js

function add(a,b){
    return a+b
}
export {add}

//main.js

import * as a from './a'
function add(){
    return  a.add(1,2)
}
console.log(add())

// bundle out,js

function add(a,b){
    return a+b
}

function add$1(){ // the name changed
    return  add(1,2)
}
console.log(add$1());
//# sourceMappingURL=out.js.map

When there are duplicate names, it will rename the variable from inner module to outer.
Is there a way to reverse the rename order? or add a custom config to support that?
// expect out.js

function add$1(a,b){ //expect to chang the name
    return a+b
}

function add(){  
    return  add$1(1,2)
}
console.log(add());
//# sourceMappingURL=out.js.map

Feature Proposal

@lukastaegert
Copy link
Member

lukastaegert commented Feb 26, 2021

This is not possible and I am not sure it is useful to make it configurable as this may raise expectations that names could be predictable, which I want to avoid. But if I understand you correctly, you think it is better that e.g. names in entry points should be retained as opposed names in dependencies. The rationale would be that could further down the execution order is more likely to be written by the user.

So from this perspective, we could just change the order in which we deconflict variables to use reverse execution order instead of execution order. Do you agree?

@supperchong
Copy link
Author

supperchong commented Feb 26, 2021

@lukastaegert yeah. Thanks for reply. That's just what I need. I want to retain names in entry points as it may do additional things with the same name in dependencies.
The situation is that bundling the code for executing in a coding website. And the function with predetermined name will be calling. So the predetermined name in entry points have to be retained.

we could just change the order in which we deconflict variables to use reverse execution order instead of execution order

Could you give an example?

@lukastaegert
Copy link
Member

lukastaegert commented Feb 26, 2021

I created a fix in #3977. This is the situation without the fix:

https://rollupjs.org/repl/?version=2.39.1&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMj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M0FmYWxzZSU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlMjJmb3JtYXQlMjIlM0ElMjJlcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

@supperchong
Copy link
Author

Perfect, thanks very much!

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

Successfully merging a pull request may close this issue.

2 participants