babel-plugin-transform-commonjs
babel-plugin-transform-commonjs copied to clipboard
Issue declaring "keyword" at export
I have exports.super
and it's converting to export let super
which doesn't compile. Example here.
Any chance that rather then declaring each variable there can be one export?
export {
super: 'something'
}
Also I would love the ability to ignore throwing this error and keeping in those requires I can do something with them with another plugin after. This isn't a big deal as I can patch-package to stop it from throwing.
throw new Error(`Invalid require signature: ${path.toString()}`);
Thanks for reporting, I was able to reproduce the issue.
input:
exports.super = () => {};
output:
var module = {
exports: {}
};
var exports = module.exports;
exports.super = () => {};
export let super = exports.super;
export default module.exports;
The fix here, if I'm understanding correctly, is to filter out named exports when it's a reserved word. We already do this for invalid identifiers, we just need to expand this for reserved words.
@tbranyen if you filter it out then the module won't line up with the source.
Is it possible to do an exported object, and never define the variable ?
Like this:
export {
super: 'something'
}
@reggi the export name would still available on the default export, which is exactly what you're asking for here:
Is it possible to do an exported object, and never define the variable
The code you've shown:
export {
super: 'something'
}
is not valid JavaScript and will not work.
var module = {
exports: {}
};
var exports = module.exports;
exports.super = () => {};
export default module.exports;
Is how the output will look after I apply the patch.