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

transform-object-rest-spread does not follow complete spec, should use CreateDataProperty instead of Set (T7461) #4371

Closed
babel-bot opened this issue Jun 27, 2016 · 2 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Object Rest/Spread

Comments

@babel-bot
Copy link
Collaborator

Issue originally made by @pitaj

Bug information

  • Babel version: 6.9.1
  • Node version: 6.2.2
  • npm version: 3.9.5

Options

{
  plugins: ['transform-object-rest-spread', 'transform-es2015-destructuring']
}

Input code

const l = {
  a: 1,
  c: 3,
};

const k = {
  a: 0,
  b: 1,
  set c(val) { this._c = -6; },
  d: 3,
  e: 4,
  ...l,
};

assert.equals(k.c, 3);

Description

The spec for Object spread explicitly states that CreateDataProperty should be used instead of Set. Currently, the spread transform uses Object.assign, which uses Set.

This will cause instances where setters that exist on the target object will be triggered, even though that behavior is counter to spec. In cases where a setter is not detected within the surrounding object literal, _extends can be used. However, if a setter is detected, then a different function using Object.defineProperties should be used.

Alternatively, it could be specified that this transform does not fully comply with the specification, and setters within object literals should be avoided with this syntax.

@babel-bot
Copy link
Collaborator Author

Comment originally made by @loganfsmyth

I'm all for fixing this, but it does seem like this would likely have to wait for a future 7.x release.

@hzoo hzoo added area: experimental PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release PR: Spec Compliance 👓 A type of pull request used for our changelog categories labels Dec 14, 2016
@hzoo hzoo added es-proposal and removed PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release area: experimental labels Aug 31, 2017
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Object Rest/Spread
Projects
None yet
Development

No branches or pull requests

3 participants