microsoft / microsoft/TypeScript
Assignment to constant variables imported from ES6 modules allowed
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mit den drei Dateien originalFunction.js, patchFunction.js und run.js mithilfe von tsc mit aktiviertem allowJs, target es5 oder es6 und module commonjs. Vergleiche die ausgegebene patchFunction.js mit der gezeigten Ausgabe und führe sie unter Node aus; erledigt ist es, wenn die Zuweisung an die importierte Bindung den erwarteten TypeError auslöst, anstatt die Funktion zu ersetzen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100