microsoft / microsoft/TypeScript

Array destructuring is transpiled with `__read` helper even when asking for no transpilation and no inline helper functions.

Đang mở
#43,541 11 bình luận 0 reaction 1 người được giao Xem trên GitHub

@rbuckton đang làm issue này rồi.

Từ ngày 6/4/2021.

Bug Domain: JS Emit Rescheduled
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

Bug Report

🔎 Search Terms

array destructuring
downLevelIteration
importHelpers
ESNEXT
CommonJS

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about importHelpers
⏯ Playground Link

Playground link with relevant code

Note: I'm not sure how to reliably get the target option to encode into the URL; you may need to set the target manually to ESNext (or any other value >= ES2015)

💻 Code
declare function foo(): any;

export const [A, V] = foo();
🙁 Actual behavior

The __read transpilation helper was injected into the output JS, even though I specified that I didn't want transpilation (through target=ESNEXT). Additionally, the transpilation helper was injected inline even though I specified the importHelpers=true option.

"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.V = exports.A = void 0;
_a = __read(foo(), 2), exports.A = _a[0], exports.V = _a[1];
🙂 Expected behavior

I was expecting output that leveraged the target=ESNEXT setting to include the array destructuring in the output code, like:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.V = exports.A = void 0;
const [A, V] = foo();
exports.A = A;
exports.V = V;

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.