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

The spread operator helper not copy the getter function. #1259

Closed
underfin opened this issue May 7, 2021 · 1 comment
Closed

The spread operator helper not copy the getter function. #1259

underfin opened this issue May 7, 2021 · 1 comment

Comments

@underfin
Copy link

underfin commented May 7, 2021

Description

The spread operator will output code which has __objSpread helper, but this helper behavior is not equal the native spread oprator. The getter funtion is lost. The original issue is vitejs/vite#3247

Input

const  value = { ...{},  get data() { return 1 } } 
console.log(value)

Output

(() => {
  var __defProp = Object.defineProperty;
  var __hasOwnProp = Object.prototype.hasOwnProperty;
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
  var __defNormalProp = (obj, key, value2) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value: value2}) : obj[key] = value2;
  var __objSpread = (a, b) => {
    for (var prop in b || (b = {}))
      if (__hasOwnProp.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    if (__getOwnPropSymbols)
      for (var prop of __getOwnPropSymbols(b)) {
        if (__propIsEnum.call(b, prop))
          __defNormalProp(a, prop, b[prop]);
      }
    return a;
  };

  // src/main.ts
  var value = __objSpread(__objSpread({}, {}), {get data() {
    return 1;
  }});
  console.log(value);
})();
@evanw
Copy link
Owner

evanw commented May 7, 2021

Thanks for the report. I can reproduce the issue. It looks like the TypeScript compiler (which esbuild's transform is modeled after) has the same issue, so that's why this is happening: microsoft/TypeScript#24799. I should be able to fix this.

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

2 participants