Constant/variable shadowing #120
Replies: 2 comments 1 reply
-
I think the one potential downside to this is "safety". Someone might use But I think the benefits are generally stronger here. It just may be good to keep an option like |
Beta Was this translation helpful? Give feedback.
-
Another option for compilation that we've discussed is adding braced blocks, like this output: const response = await fetch(...)
const body = await response.json()
const shop = body.shop
console.log(response.status)
{
const response = await fetch(...)
const shop = body.json()
const products = body.products
console.log(response.status)
} (or maybe one braced block for each overriding The nice thing here is that we don't have to rename used variables (which might be an issue e.g. when writing the object literal Ideally we'd be able to support getting values from the previous scope. For example, consider this input: i := 0
process i
i := i + 1
process i With variable renaming as in the original post, this is straightforward to compile: the third line becomes const i = 0
process(i)
const i2 = i // give the current value of i another name
{
const i = i2
process(i)
} It occurs to me that this might have some weird interaction with garbage collection, as the let i = 0
process(i)
const i2 = new WeakRef(i)
{
const i = i2.deref()
process(i)
} |
Beta Was this translation helpful? Give feedback.
-
What?
Civet:
Output:
Why?
const
s. In the end, you'll really be creating different variables. Much better/safer than reassigning/mutating alet
variable.Relevant links
Beta Was this translation helpful? Give feedback.
All reactions