Skip to content

Commit 28070da

Browse files
NullVoxPopuliclaude
andcommitted
Add rfc931: 'native' option to preserve template() output
Adds an `rfc931` option controlling how the RFC 931 `template()` API (from `@ember/template-compiler`) is emitted: - "polyfilled" (default): existing behavior — lower `template()` to `precompileTemplate`/`createTemplateFactory` + `setComponentTemplate` + `templateOnly`, for runtimes without native `template()` support. - "native": preserve the `template()` call for runtimes that implement `@ember/template-compiler` natively (Ember 6+). AST transforms still run, and the implicit `eval` form is normalized into the explicit `scope` form. This only affects `targetFormat: 'hbs'`. With `targetFormat: 'wire'` the template is fully compiled to the standard wire format, which already runs on native runtimes, so `native` has no effect there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e95b0cd commit 28070da

3 files changed

Lines changed: 431 additions & 3 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ import hbs from 'ember-cli-htmlbars-inline-precompile';
2626
import hbs from 'htmlbars-inline-precompile';
2727
```
2828

29+
It also understands the `template()` API from [RFC 931](https://rfcs.emberjs.com/id/0931-template-compiler-api/):
30+
31+
```js
32+
import { template } from '@ember/template-compiler';
33+
```
34+
35+
By default, `template()` is **polyfilled**: it is lowered to the older
36+
`precompileTemplate` / `setComponentTemplate` / `templateOnly` primitives so the
37+
output runs on Ember versions that don't natively understand `template()`. If
38+
you are targeting a runtime that implements `@ember/template-compiler` natively
39+
(Ember 6+), pass `rfc931: 'native'` to keep the `template()` call in the output
40+
instead. See the `rfc931` option below.
41+
2942
## Common Options
3043

3144
This package has both a Node implementation and a portable implementation that works in browsers.
@@ -86,6 +99,23 @@ interface Options {
8699
// Optional list of custom transforms to apply to the handlebars AST before
87100
// compilation. See `type Transform` below.
88101
transforms?: Transform[];
102+
103+
// Controls how the RFC 931 `template()` API (imported from
104+
// `@ember/template-compiler`) is emitted.
105+
//
106+
// "polyfilled": The default. `template()` calls are lowered to the older,
107+
// widely-supported primitives (`precompileTemplate` / `createTemplateFactory`
108+
// plus `setComponentTemplate` and `templateOnly`). Use this to target Ember
109+
// versions that do not natively understand `template()`.
110+
//
111+
// "native": `template()` calls are preserved in the output for runtimes that
112+
// implement `@ember/template-compiler` natively (Ember 6+). AST transforms
113+
// still run, and the implicit `eval` form is normalized into the explicit
114+
// `scope` form. This only affects `targetFormat: 'hbs'`; with
115+
// `targetFormat: 'wire'` the template is fully compiled to the standard wire
116+
// format (which already runs on native runtimes), so this option has no
117+
// effect there.
118+
rfc931?: 'polyfilled' | 'native';
89119
}
90120

91121
// The legal legacy module names. These are the only ones that are supported,

0 commit comments

Comments
 (0)