You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// The entire runnable example is here: // https://github.com/fatso83/sinon-swc-bug/tree/swc-special-handling-mockfunction_toBeMocked(){return"I am the original function";}exportlettoBeMocked=_toBeMockedexportconstmock={gettoBeMocked(){returntoBeMocked;},settoBeMocked(mock){toBeMocked=mock;}}
export const mock = {
get toBeMocked(){ return toBeMocked; },
set toBeMocked(mock){ toBeMocked = mock; }
}
should be pretty much unaltered when compiled to ES5 with ESM exports. Probably something like this
function _toBeMocked() {
return "I am the original function";
}
export var toBeMocked = _toBeMocked;
export var mock = {
get toBeMocked () {
return toBeMocked;
},
set toBeMocked (mock){
toBeMocked = mock;
}
};
Actual behavior
The export is called _$mock instead of mock
function _toBeMocked() {
return "I am the original function";
}
export var toBeMocked = _toBeMocked;
export var _$mock = {
get toBeMocked () {
return toBeMocked;
},
set toBeMocked (mock){
toBeMocked = mock;
}
};
kdy1
changed the title
An export named mock is transpiled to _$mock when transpiling to ES5 (_not_ running Jest)
ES2015::block_scoping renames exports
Oct 19, 2023
fatso83
added a commit
to fatso83/sinon-swc-bug
that referenced
this issue
Oct 19, 2023
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
I was writing a how-to on using a new Sinon feature for auto-cleanup of stubs injected using accessors when I discovered it did not work when I exposed accessors on an exported object called 'mock'.
Basically, if I write something like this:
it will be transpiled to this by SWC, which is very different from
tsc
:Somehow 'mock' gets turned into
_$mock
.To run this example, just do
This is not a typescript issue, btw, as the playground shows the issue with a minimal example
Input code
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.3.94-nightly-20231016.1&code=H4sIAAAAAAAAA1WNQQrCMBBF93OKT1cteIPixp0LzyAlTmuwnZF0CkLJ3ZuIWrP9vP9ev4gzr4Kr6Ykv6h58qxusBAS2JQiqM7oJdmdo8IOXbkT%2FOVUtRSJ%2BPTUYRjbsDhz%2FjT%2FIqcyGKY0JyBFgKH51s37D%2B9giHt7sXLLZk%2FiimrfEU9wALRrz29oAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BAWdSIifrKJVBTl7iUE0maH3xsz8jooBbNoeKq1PMsQkYX4nEsi2Sf8lARIOxTNJia49XaWvRrRCtVoOxpIyBOluiX3hoMNQajjLXPGmzH%2FC3VwkUnkCu4o%2BsnSVTc0JbjwXmrZDkk50qF%2FwA%2FqsvNjMPLqm4kXGrYvhlQioBQBAAA%3D
SWC Info output
Expected behavior
This code:
should be pretty much unaltered when compiled to ES5 with ESM exports. Probably something like this
Actual behavior
The export is called
_$mock
instead ofmock
Version
1.3.94
Additional context
Originally posted as question on the Q&A.
Just play with the playground. It will show in any combination using ES5 as the target
The text was updated successfully, but these errors were encountered: