sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.58k stars 208 forks source link

Scoping issues with default parameters #678

Open gabejohnson opened 7 years ago

gabejohnson commented 7 years ago
function foo(a = 1, b = a) { return a + b; }

should result in:

function foo(a_100 = 1, b_101 = a_100) {
  return a_100 + b_101;
}

but instead yields:

function foo(a_100 = 1, b_101 = a) { // note that 'a' has not been gensym'd
  return a_100 + b_101;
}

@disnet, is this an issue in TermExpander?

disnet commented 7 years ago

Yeah right around here it looks like the hygiene stuff isn't taking into account initializers.

It needs to apply the function scope in initializers.

Also, I think the current CloneReducer is potentially picking up too many bindings so that should be fixed too.