Do not use Object.getOwnPropertyDescriptors when target is set to anything lower than es2017
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
related issue #2631
`Object.getOwnPropertyDescriptors` is an es2017 static method (source: [1](https://www.npmjs.com/package/object.getownpropertydescriptors), [2](https://github.com/tc39/ecma262/pull/582))
However esbuild uses this method even if you set the target to es6.
[hyrious.me/esbuild-repl/?version=0.25.0](https://hyrious.me/esbuild-repl/?version=0.25.0&t=const+a+%3D+%7Ba%3A+%22a%22%7D%3B%0Aconst+b+%3D+%7Bb%3A+%22b%22%7D%0Aconst+c+%3D+%7B...a%2C...b%2C+c%3A+%22c%22%7D%3B&o=--target%3Des6)
Input:
```JS
const a = {a: "a"};
const b = {b: "b"}
const c = {...a,...b, c: "c"};
```
Output:
```JS
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a2, b2) => {
for (var prop in b2 || (b2 = {}))
if (__hasOwnProp.call(b2, prop))
__defNormalProp(a2, prop, b2[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b2)) {
if (__propIsEnum.call(b2, prop))
__defNormalProp(a2, prop, b2[prop]);
}
return a2;
};
var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
const a = { a: "a" };
const b = { b: "b" };
const c = __spreadProps(__spreadValues(__spreadValues({}, a), b), { c: "c" });
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the linked esbuild REPL case with target es6 and inspect the object-spread lowering that emits __getOwnPropDescs. Verify the completed change preserves the shown spread behavior while avoiding Object.getOwnPropertyDescriptors for targets below es2017.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100