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

Enforce immutability #5364

Closed
nschurmann opened this issue Jul 22, 2021 · 2 comments
Closed

Enforce immutability #5364

nschurmann opened this issue Jul 22, 2021 · 2 comments

Comments

@nschurmann
Copy link

Is there a way to enforce immutability? I know that the team chose to use var instead of scoped variables like const and let, but it would be nice for the compiler to detect if there has been a re-assignation and show an error at compile time to prevent it.

@GeoffreyBooth
Copy link
Collaborator

I think #4985 is the main issue discussing supporting const. Basically it’s not supported currently, but there are ways that support could be added (like via new syntax such as := instead of =); however there’s debate as to whether this violates the spirit of CoffeeScript where one of the original tenets was that you shouldn’t need to think about whether a variable is being declared versus assigned.

@nschurmann
Copy link
Author

The way I see this that may not violate the "const" assignment is that we keep using var, however, internally coffeescript could have a reference of all the variables that have been declared, if the variable has more than one assignment then show a warning or error during compilation. IMO I don't care if I'm using var, let or const, I just don't want to assign a value to a variable more than once. So I see it as a feature of coffeescript rather than a transpilation option.

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