ember-cli / babel-plugin-htmlbars-inline-precompile

Babel plugin to replace tagged template strings with precompiled HTMLBars templates
9 stars 21 forks source link

Inline HBS Reform #462

Closed ef4 closed 3 years ago

ef4 commented 3 years ago

This accompanies https://github.com/embroider-build/embroider/pull/893 and similar PRs to ember-cli-htmlbars and ember-template-imports will be forthcoming.

This is a radical simplification of this plugin, along with a full port to typescript. The main reason we can simplify is that we're dropping support for Ember versions that need modules-api-polyfill (a source of much pain and complexity when it comes to composing babel plugins).

I have confirmed that other consumers of template compilation like Embroider and ember-template-imports can use their own standalone babel plugins that compose nicely with this one, so they can emit precompileTemplate, and this plugin will handle that with one shared implementation.

Along with this, I'd prefer to rename this package @ember/template-compilation, because that's its public API:

import { precompileTemplate } from '@ember/template-compilation';

The older patterns like import { hbs } from 'ember-cli-htmlbars' are still available, but are understood to be sugar for precompile, because precompile is a superset of all the rest and it should be understood as the foundational primitive for all template compilation in Ember. Even standalone .hbs files are conceptually sugar for export default precompileTemplate(...). The actual rename will presumably need an RFC.

This cuts all the special ember-template-imports support from this plugin, since it doesn't belong here and was only entangled due to the cruft we have removed. I'll have a PR to ember-template-imports porting its code back into there.

In the process of porting to typescript, several real edge case crashes were found, like not handling spread elements within the options we parse.

There was also a whole dance of registerRefs that was having no effect at all, perhaps it was only needed on older babel versions.

pzuraq commented 3 years ago

There was also a whole dance of registerRefs that was having no effect at all, perhaps it was only needed on older babel versions

I believe this was necessary for when this plugin had to layer cleanly on top of/before the Ember modules polyfill. There ended up being so many edge cases there that we had to just ship modules, or it wouldn't fully work đŸ™ƒ

ef4 commented 3 years ago

This branch is instead becoming a separate repo:

https://github.com/emberjs/babel-plugin-ember-template-compilation