tc39 / proposal-do-expressions

Proposal for `do` expressions
MIT License
1.11k stars 14 forks source link

So, what's the plan for var/hoisting? #2

Closed domenic closed 7 years ago

domenic commented 7 years ago

Thought it'd be worth opening a tracking issue for this problem, which I believe is fairly well-known. Looking forward to hearing what the solution is (I have no idea myself).

allenwb commented 7 years ago

why should it be any different from a Block. Alternative the semantics of preexisting constructs within micro contexts just adds spec/implementation complexity and make a language harder to learn and use.

dherman commented 7 years ago

Do you mean whether vars hoist outside of a do block?

The purpose of do-expressions is to minimize friction (aka refactoring hazards, aka inequivalences) for fine-grained refactoring (aka TCP). For example:

function f() {
  let tmp;
  {
    var result = foo();
    tmp = bar(result);
  }
  baz(tmp);
  return result;
}

can be refactored to:

function f() {
  baz(do {
    var result = foo();
    bar(result)
  });
  return result;
}
dherman commented 7 years ago

just adds spec/implementation complexity and make a language harder to learn and use.

Agreed.

dherman commented 7 years ago

In short: the plan is that vars are allowed inside of do-expressions and hoist to the nearest enclosing function/module/script, as per usual.

domenic commented 7 years ago

Great, this might be something to add to the readme then, as I thought it was something of a controversy... @ajklein