microsoft / microsoft/TypeScript
Assignment to constant variables imported from ES6 modules allowed
Chưa có ai nhận issue này.
- 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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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