Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior between transformed code and native code #729

Open
littlee opened this issue Sep 1, 2024 · 0 comments
Open

Inconsistent behavior between transformed code and native code #729

littlee opened this issue Sep 1, 2024 · 0 comments

Comments

@littlee
Copy link

littlee commented Sep 1, 2024

(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant