Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Inconsistent behavior between transformed code and native code #729

Open
@littlee

Description

@littlee
(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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions