microsoft / microsoft/TypeScript
Assignment to constant variables imported from ES6 modules allowed
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il problema con i tre file originalFunction.js, patchFunction.js e run.js usando tsc con allowJs abilitato, target es5 o es6 e module commonjs. Confronta il patchFunction.js emesso con l'output mostrato ed eseguilo con Node; il lavoro è completato quando l'assegnazione al binding importato genera il TypeError previsto invece di sostituire la funzione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100