Closed kostia closed 5 years ago
I added a test-case for it: https://github.com/asapach/babel-plugin-rewire-exports/compare/master...apepper:issue_13_bugreport
I've tried your original example and I get the following exports - spam
, eggs
, rewire$spam
, rewire$eggs
, restore
:
var spam = _spam,
eggs = _eggs;
function _spam() {
return {
eggs() {
eggs();
}
};
}
export { spam };
function _eggs() {}
export { eggs };
export function rewire$spam($stub) {
spam = $stub;
}
export function rewire$eggs($stub) {
eggs = $stub;
}
export function restore() {
spam = _spam;
eggs = _eggs;
}
Your original example doesn't have restore
as an export, which is suspicious.
And your other example - spam
, broken
, ok
, rewire$spam
, rewire$broken
, rewire$ok
, restore
:
var spam = _spam,
broken = _broken,
ok = _ok;
function _spam() {
return {
ok,
broken() {
broken();
}
};
}
export { spam };
function _broken() {
return true;
}
export { broken };
function _ok() {
return false;
}
export { ok };
export function rewire$spam($stub) {
spam = $stub;
}
export function rewire$broken($stub) {
broken = $stub;
}
export function rewire$ok($stub) {
ok = $stub;
}
export function restore() {
spam = _spam;
broken = _broken;
ok = _ok;
}
So I'm unable to reproduce the issue :sweat:. Do you have a more complete example? Maybe a small repo with a repro case?
I added a package-lock.json
to https://github.com/asapach/babel-plugin-rewire-exports/compare/master...apepper:issue_13_bugreport to better reproduce the error.
I'm using max osx with node version 11.14.0
.
OK, I think I got it: you have to transpile it down to ES5:
exports.rewire$_eggs2 = rewire$_eggs2;
var _eggs2 = _eggs;
exports.eggs = _eggs2;
function _spam() {
return {
eggs: function eggs() {
_eggs2();
}
};
}
Thanks a lot! 👍
Following code gets "rewired" with wrong name for
eggs
:The exports then look weird:
Any ideas how to fix that?