Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 import bindings should be immutable #202

Closed
kzc opened this issue Jun 27, 2020 · 1 comment
Closed

ES6 import bindings should be immutable #202

kzc opened this issue Jun 27, 2020 · 1 comment

Comments

@kzc
Copy link
Contributor

kzc commented Jun 27, 2020

https://2ality.com/2015/07/es6-module-exports.html#es6-modules-export-immutable-bindings

//------ lib.js ------
export let mutableValue = 3;
export function incMutableValue() {
    mutableValue++;
}
//------ main1.js ------
import { mutableValue, incMutableValue } from './lib';

// The imported value is live
console.log(mutableValue); // 3
incMutableValue();
console.log(mutableValue); // 4

// The imported value can’t be changed
mutableValue++; // TypeError in NodeJS, compile error in tsc and rollup

esbuild incorrectly results in no error:

$ esbuild --version
0.5.13

$ esbuild main1.js --bundle | node
3
4

$ echo $?
0
@evanw
Copy link
Owner

evanw commented Jun 27, 2020

Ah yes, thanks for the reminder. I should make this a compile error. I think this should be pretty straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants