Skip to content

Spread operator in method shorthand in object literal is not emitted with "__assign" #17087

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

Closed
kobiburnley opened this issue Jul 11, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@kobiburnley
Copy link

kobiburnley commented Jul 11, 2017

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Link to playground

Code

const y = {
  prop: "ms"
}

const x = {
  ...y,
  fn(options) {
    return {
      timestamps: false,
      ...options
    }
  }
}

Emits to:

var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
var y = {
    prop: "ms"
};
var x = __assign({}, y, { fn: function (options) {
        return {
            timestamps: false,
            ...options
        };
    } });

Expected behavior:
"...options" will be emitted with "__assign"
Actual behavior:
"...options" is not emitted with "__assign"

@aminpaks
Copy link
Contributor

aminpaks commented Jul 11, 2017

I think it's supposed to be:

const y = {
  prop: "ms"
}

const x = {
  ...y,
  ...((options) => {
    return {
      timestamps: false,
      ...options
    }
  })({new: 'old',})
}

or

const y = {
  prop: "ms"
}

const x = {
  ...y,
  ...fn({}),
}

function fn(options) {
  return {
    timestamps: false,
    ...options
  }
}

@kobiburnley
Copy link
Author

The issue happens when using method shorthand in object literal

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Jul 26, 2017

This seems to happen when their is a spread in the directly enclosing literal only.

This works

const x = {
  fn() {
    return {
      ...{}
    };
  }
}

and this fails

const x = {
  ...{},
  fn() {
    return {
      ...{}
    };
  }
}

but this works

const x = {
  ...{},
  y: {
    fn() {
      return {
        ...{}
      };
    }
  }
}

@aluanhaddad
Copy link
Contributor

I just realized this is a dupe of #16765

@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 28, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 12, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Sep 12, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants