Issue compiling glimmer expressions in Ember 3.0 - 3.2

Hi there,

I’m currently working on writing the polyfill for the new {{#let helper coming in Ember 3.2 (see this issue for more info).

Since let uses an AST transform, we have to be careful about how we polyfill across different version, and currently I can’t find a way to polyfill it in 3.0 and 3.1.

Prior versions of let relied on a function called compileList from @glimmer/runtime, while the official version of let in 3.2 relies on a method called compileParams that lives on the the OpCodeBuilder itself.

However, in 3.0 and 3.1, neither of those options exist and after a decent amount of source diving I haven’t been able to find a replacement.

You can see the code for the polyfill here. So far the tests are only failing for Ember 3.0 specifically.

So, my question is, what can I use to compile glimmer expressions in Ember 3.0 and 3.1, and also was it expected that this functionality would drop out of 3.0 but reappear in 3.2?

Maybe I’m misunderstanding something but I don’t see any AST transforms in that repo. You’re extending the compiler itself, which seems like the hard-mode way to achieve this feature.

It’s easier to make this kind of thing work across glimmer versions using AST transforms. Here is a search on emberobserver for places where addons are registering AST transforms.

You only need the AST transform to rewrite things that are impossible for normal components to do into things that they can, and then implement the rest as a normal component. Like

{{#let a b c as |d e f|}}
   {{d}}
{{/let}}

Could rewrite to

{{#-polyfill-let a b c as |values|}}
  {{values.v0}}
{{/-polyfill-let}}

And the -polyfill-let component can use positionalParams to get the list of inputs, and yield out a POJO with all of those values on it.

The only subtlety is ensuring that values is a free variable (you need to check that it’s not in use, and mangle the name until you get one that isn’t).

Ah, ok, I guess I didn’t understand the difference between “AST Transform” and “extending the compiler”.

The reason I’m going the “extend the compiler” route is because this is how several core team members have been directing the ember-let addon for the last year or so, but it’s not clear why they initially went that direction instead of just registering a helper (which is how ember-let began).

I can try re-implementing let as a helper for the polyfill though.

Nevermind, I know why they moved away from the helper approach. With the introduction of glimmer 2, helpers can’t yield anymore so they moved to the macro approach.

Swapping a helper invocation for a component + AST plugin seems like it might be harder than the current approach (which works in all but one version of Ember). Just need to track down where this functionality went in 3.0