Inconsistent behavior between transformed code and native code
littlee opened this issue · 0 comments
(async () => {
let obj = {};
setTimeout(() => {
console.log('timeout');
obj = {};
}, 1000);
obj['a'] = await new Promise((resolve) => {
setTimeout(() => {
console.log('resolved');
resolve('a');
}, 1000);
});
obj['b'] = 'b';
console.log('what is obj:', JSON.stringify(obj));
})();
when transformed with babel-transform-regenerator
, the final value of obj
is {a:'a',b:'b'}
link : https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=BQQwzgngdgxgBMAlHAvAPjgbwFBzgGwFMAXOAewCMArVLAXwG5c4wSAVASwFtCyBXYsCSoMOPHhhkoYMkQB0-MgHNgAcmLdeA1Yibjy1WpkbM6AGjgBGAAy3d2ZpSoBtVSFUBdWiADuIDqRQhD5wAAoATmRcHKxC4YQy-ABuhMjoWMx4rMScPPyCwuli-nCS0rKECspq8YkpACY6eiW1silq7vb65la21l1wdANOrhSetKpjTMxliZWKKqo-ABYgpDEGVABcqhYAUgDKAPIAcnJgxOEcUEocAGYQwE6I9kNIDEA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&evaluate=true&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=react%2Cstage-2&prettier=false&targets=&version=7.25.6&externalPlugins=%40babel%2Fplugin-transform-regenerator%407.24.7&assumptions=%7B%7D
when babel-transform-regenerator
plugin removed, the final value of obj
is {b:'b'}
link: https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=BQQwzgngdgxgBMAlHAvAPjgbwFBzgGwFMAXOAewCMArVLAXwG5c4wSAVASwFtCyBXYsCSoMOPHhhkoYMkQB0-MgHNgAcmLdeA1Yibjy1WpkbM6AGjgBGAAy3d2ZpSoBtVSFUBdWiADuIDqRQhD5wAAoATmRcHKxC4YQy-ABuhMjoWMx4rMScPPyCwuli-nCS0rKECspq8YkpACY6eiW1silq7vb65la21l1wdANOrhSetKpjTMxliZWKKqo-ABYgpDEGVABcqhYAUgDKAPIAcnJgxOEcUEocAGYQwE6I9kNIDEA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&evaluate=true&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=react%2Cstage-2&prettier=false&targets=&version=7.25.6&externalPlugins=&assumptions=%7B%7D