microsoft / microsoft/TypeScript

ES6 module immediately exported var clash with local "exports" variable

Đang mở
#33,043 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Bug Domain: ES Modules Help Wanted
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ả

TypeScript Version: 3.5.1 (playground), 3.5.3

Search Terms:
es6 module exports object scope declare declaration overwrite

Code

export const a = 1
function b () {
    const exports = 2
    console.log(a)
}
b()

Expected behavior:
output from babel with es2015 preset
https://babeljs.io/repl#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=KYDwDg9gTgLgBAYwgOwM7wIZwLxwIwBQAZgK7IIwCWKcARnABQCUcA3gXJ4iunKJLFQ44AJg5ckaCABtgAOmkQA5gwxMCAXwK1mQA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=false&presets=es2015&prettier=false&targets=&version=7.5.5&externalPlugins=

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.a = void 0;
var a = 1;
exports.a = a;

function b() {
  var exports = 2;
  console.log(a);
}

b();

Actual behavior:
console.log is referencing the local exports.a instead of the global const a

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a = 1;
function b() {
    var exports = 2;
    console.log(exports.a);
}
b();

However, if I split the export const into two, it will work.

const a = 1
export { a }

Playground Link:
http://www.typescriptlang.org/play/?target=1#code/KYDwDg9gTgLgBAYwgOwM7wIZwLxwIwCwAUAGYCuyCMAlinAEZwAUAlHAN7FzeIrpyhIsVDjgAmLjyRoIAG2AA6WRADmTDC2IBfYvVZA

Related Issues: can't find

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.

Hướng nghiên cứu

Tái hiện đoạn mã được cung cấp trong TypeScript playground và so sánh JavaScript được phát ra với đầu ra Babel được liên kết trong issue. Theo dõi cách xử lý một biến được export ngay lập tức và binding exports cục bộ lồng nhau; được coi là hoàn tất khi console.log được tạo vẫn tham chiếu đến giá trị ở cấp module thay vì binding cục bộ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

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.