moduloze icon indicating copy to clipboard operation
moduloze copied to clipboard

bug: ESM named export identifier conflict

Open getify opened this issue 5 years ago • 4 comments

This kind of code:

var publicAPI = {
   something
};

module.exports.something = publicAPI.something;

function something() {}

...is transpiled to ESM format as:

var publicAPI = {
   something
};

export let {
   something   // <---- conflict
} = publicAPI;

function something() {}   // <---- conflict

The alternative named export form would have been:

let _exp1234 = publicAPI.something;
export { _exp1234 as something };

Need to check for this name conflict and use this alternate form if necessary.

getify avatar Nov 19 '20 04:11 getify

References:

https://github.com/getify/moduloze/blob/0ceb03a54223207c8d2a0611cb6caedb59e322f8/src/esm.js#L424-L477

https://github.com/getify/moduloze/blob/0ceb03a54223207c8d2a0611cb6caedb59e322f8/src/analysis.js#L643-L665

getify avatar Nov 19 '20 04:11 getify

So, if I understand it correctly, the esm.js already can handle both types of conversions.

But the analysis.js file is only using the "destructured-declaration-export".

A possible solution would be to add some code for checking the conflict and using the "named-declaration-export" bit ?

vipulbhj avatar Nov 19 '20 05:11 vipulbhj

@vipulbhj I believe that's the case, yes. I hope that's all it is.

getify avatar Nov 19 '20 12:11 getify

Will try to look into it. Thanks 😁

vipulbhj avatar Nov 19 '20 12:11 vipulbhj