escope icon indicating copy to clipboard operation
escope copied to clipboard

ES6 default parameters cause two write references

Open bakkot opened this issue 10 years ago • 2 comments

(@michaelficarra)

See for example this test: https://github.com/estools/escope/blob/f237eefd4bfadfcf397e451219c3079e9bc3bb81/test/es6-destructuring-assignments.coffee#L340-L346

Note that there are two references with name c and isWrite() true: that is, two write references to c. This despite the fact that c will be written precisely once by the sample code. This is especially confusing if you're looking at const-correctness.

Is this intentional? If so, what's the reasoning behind it?

bakkot avatar Jul 07 '15 02:07 bakkot

Ping @mysticatea, author of https://github.com/estools/escope/commit/23bb40b835b01e14e086c98f24d746427c91d502 which added the referenced tests.

michaelficarra avatar Jul 07 '15 02:07 michaelficarra

escope has been making a writable reference for variable initializers, so I treated default parameters and default values of destructuring as same as that. Currently, references for initializers, default parameters, and default values are have a property init as true.

(Thanks @michaelficarra)

mysticatea avatar Jul 07 '15 03:07 mysticatea