ember-polyfills / ember-angle-bracket-invocation-polyfill

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Super Weird Bug

jherdman opened this issue · comments

Bear with me on this, but if you want to jump to the fun bits, here's the sample app https://github.com/jherdman/angle-bracket-bug

The gist is this:

<select>
  {{#each availableOptions as |option|}}
    <option>{{option}}</option>
  {{else}}
    <option>I'm not listing options</option>
  {{/each}}
</select>

(Obviously I'm defining availableOptions as an array of values)

Results in this:

screen shot 2018-06-13 at 4 39 21 pm

The problem goes away if I change the yielded param's name, e.g. option to opt.

👋 - I suspect that things are working appropriately here.

This situation is specifically discussed in this section of the RFC. Here is a small snippet:

Notably, based on the rules laied out above, the following is perfectly legal:

{{!-- DON'T DO THIS --}}

{{#let (component "my-div") as |div|}}
  {{!-- here, <div /> referes to the local variable, not the HTML tag! --}}
  <div id="my-div" class="lol" />
{{/let}}

From a programming language's perspective, the semantics here is quite clear. A local variable is allowed to override ("shadow") another varible on the outer scope (the "global" scope, in this case), similar to what is possible in JavaScript:

let console = {
  log() {
    alert("I win!");
  }
};
console.log("Hello!"); // shows alert dialog instead of logging to the console

While this is semantically unambigious, it is obviously very confusing to the human reader, and we don't recommend anyone actually doing this.

A previous version of this RFC recommended statically disallowing these cases. However, after giving it more thoughts, we realized it should not be the programming language's job to dictate what are considered "good" programming patterns. By statically disallowing arbitrary expressions, it actually makes it more difficult to learn and understand the underlying programming model.

You and me both!