microsoft / microsoft/TypeScript
Assignment to constant variables imported from ES6 modules allowed
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el problema con los tres archivos originalFunction.js, patchFunction.js y run.js usando tsc con allowJs habilitado, target es5 o es6 y module commonjs. Compara el patchFunction.js generado con la salida mostrada y ejecútalo con Node; se considera hecho cuando la asignación al binding importado lanza el TypeError esperado en lugar de reemplazar la función.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100