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
@swc/helpers unexpectedly merges two different code paths.
Input code
function*test(){while(!False()){// execute this linewhile(!False()){// execute this linebreak;}// execute this lineif(False()){// NOT execute this linebreak;}// execute this lineyield"correct";return;}// NOT execute this lineyield"wrong";return;}functionFalse(){returnfalse;}for(constresultoftest()){console.log(result);}
functiontest(){return__generator(this,function(_a){switch(_a.label){case0:
if(!!False())return[3/*break*/,2];// execute this line// >>>>> >>>>>while(!False()){// execute this linebreak;}// execute this lineif(False()){// NOT execute this linereturn[3/*break*/,2];}// execute this linereturn[4/*yield*/,"correct"];case1:
// execute this line_a.sent();return[2/*return*/];case2:
// NOT execute this linereturn[4/*yield*/,"wrong"];case3:
// NOT execute this line_a.sent();return[2/*return*/];}});}
swc:
functiontest(){return_ts_generator(this,function(_state){switch(_state.label){case0:
if(!!False())return[3,2];// execute this line// >>>>> >>>>>while(!False()){// execute this linereturn[3,2];}// execute this lineif(False()){// NOT execute this linereturn[3,2];}// execute this linereturn[4,"correct"];case1:
_state.sent();return[2];case2:
// NOT execute this linereturn[4,"wrong"];case3:
_state.sent();return[2];}});}
Describe the bug
@swc/helpers unexpectedly merges two different code paths.
Input code
Config
Playground link (or link to the minimal reproduction)
https://play.swc.rs/?version=1.6.5&code=H4sIAAAAAAAAA42RPQ7CMAyFd07x6JQy0AOwM8LCBSA4bUSUSImjghB3p%2Flhg4gt8Xvfs2WraCVrZzdgCix6PFfAPGlDEOv92QQSfSkCwwC6k4xM4EkHGG0pCz%2F8DQK4eDrfdvnzaqdrBfEt%2BXA8%2FZfejn9oMld00nlPkrsCeeLobXpnvNGt4rN3dszwB11AVZeLOn6evuhQqVRczkNIZwMvWoiG4VS9RiGS5gxtjRtFcfQJfANPEoyouwEAAA%3D%3D&config=H4sIAAAAAAAAA1WPSw7DIAwF9zkF8rrbdtE79BCIOhERP9mOVBTl7oUE0maH3xszsA5KwcwGnmotxzIkTYx0ziXhHER%2FSgKSE7IhmwRuvRWu1agd4x5tRwOiaUKpW8j3hoOLkbHjLfM22DH%2FC030iZD5ClZUh8nhVTc0Jfj4XvayfaQ%2B9tA%2F4Ad12XkxWH71TaEFh%2B0LYuVI0xQBAAA%3D
SWC Info output
Operating System:
Platform: darwin
Arch: x64
Machine Type: x86_64
Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64
CPU: (16 cores)
Models: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Expected behavior
The two
break
should not be merged together and yields "correct"Actual behavior
Two
break
are merged, innerbreak
directly breaks twowhile
loops and yields "wrong"Version
@swc/helpers: 0.5.11
Additional context
You can also play with https://github.com/yf-yang/swc-ts-generator-bug, but maybe the playground is enough.
The text was updated successfully, but these errors were encountered: