microsoft / microsoft/TypeScript

Assignment to constant variables imported from ES6 modules allowed

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

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

Bug Domain: ES Modules
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.7.5

Search Terms:

  • Assignment to constant variable in imported modules

Code

// originalFunction.js
let originalFunction = () => console.log('Original function executed! 🏁');
export {originalFunction};

// patchFunction.js
import {originalFunction} from "./originalFunction.js";
originalFunction = () => console.log('patched function 💥');

// run.js
import './patchFunction.js';
import {originalFunction} from './originalFunction.js';

originalFunction();

Expected behavior:
After tsc (with "allowJs": true, "target": "es5" or es6, "module": "commonjs") and running node run.js in output folder you should get Uncaught TypeError: Assignment to constant variable. at patchFunction.js:6

Just like you'd get with pure es6 in browser with this html (on same 3 original .js files):

<html >
<head></head>
<body>
<script type="module" src="originalFunction.js"></script>
<script type="module" src="patchFunction.js"></script>
<script type="module" src="run.js"></script>
</body>
</html>

Actual behavior:

Output is patched function 💥 because the code is transpiled in this manner:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var originalFunction_js_1 = require("./originalFunction.js");
originalFunction_js_1.originalFunction = function () {
    console.log('patched function 💥');
};

Playground Link:

Hard to get it on playground because it requires having separate files on filesystem and actually loading them by browser.

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 vấn đề với ba tệp originalFunction.js, patchFunction.js và run.js bằng cách sử dụng tsc với allowJs được bật, target là es5 hoặc es6 và module là commonjs. So sánh patchFunction.js được tạo ra với đầu ra đã cho và chạy nó trên Node; được xem là hoàn tất khi phép gán cho binding đã import ném ra TypeError như mong đợi thay vì thay thế hàm.

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
38/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.