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

Do not use Object.getOwnPropertyDescriptors when target is set to anything lower than es2017 #4071

Open
cyan-2048 opened this issue Feb 11, 2025 · 1 comment

Comments

@cyan-2048
Copy link

related issue #2631

Object.getOwnPropertyDescriptors is an es2017 static method (source: 1, 2)

However esbuild uses this method even if you set the target to es6.

hyrious.me/esbuild-repl/?version=0.25.0

Input:

const a = {a: "a"};
const b = {b: "b"}
const c = {...a,...b, c: "c"};

Output:

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" });
@cyan-2048 cyan-2048 changed the title Do not use Object.getOwnPropertyDescriptors when targetting anything lower than es2017 Do not use Object.getOwnPropertyDescriptors when target is set to anything lower than es2017 Feb 11, 2025
@cyan-2048
Copy link
Author

this has bothered me for a while actually, since you can't even polyfill it by importing npm packages if building with esbuild/vite, because these runtime functions are added before anything else. adding a banner is unfavorable as this runtime function is not always present in the chunked file.

as a result, I have resorted to creating a separate file for my polyfills, and also building it with esbuild separately.

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