镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Object rest issue with computed property names #12228

Description

@rbuckton

TypeScript Version: 2.2.0-dev.20161114

When emitting Object Rest in --target es5 with a binding or assignment pattern containing a computed property name, we emit "undefined" instead of the value of the computed property name converted to a string. As a result, the e.indexOf(p) check results in a false negative in the __rest helper. NOTE: we must ensure the value of the computed property we pass to __rest is converted to a string otherwise e.indexOf(p) will still result in a false negative.

Also, !e.indexOf(p) is wrong, see #12227 for details.

Code

const x = 1;
const { [x]: a, ...b } = { 1: "a", 2: "b" };

Expected emit:

var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !~e.indexOf(p))
        t[p] = s[p];
    return t;
};
var x = 1;
var _a = { 1: "a", 2: "b" }, _b = x, a = _a[_b], b = __rest(_a, [_b + ""]);

Actual emit:

var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && !e.indexOf(p))
        t[p] = s[p];
    return t;
};
var x = 1;
var _a = { 1: "a", 2: "b" }, _b = x, a = _a[_b], b = __rest(_a, ["undefined"]);

Activity

  1. added this to the milestone on Nov 14, 2016
  2. sandersn commented on Nov 15, 2016

    @sandersn
    Member

    Fix is up at #12248

  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions