-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.js
51 lines (43 loc) · 1.26 KB
/
application.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Route from '@ember/routing/route';
import { setComponentTemplate } from '@ember/component';
import _templateOnlyComponent from '@ember/component/template-only';
import { compileTemplate as _compile } from '@ember/template-compilation';
const code = `
<ul>
{{#each (array
(hash href='https://emberjs.com' text='Ember home page')
(hash href='https://github.com/nullvoxpopuli' text='My GitHub')
(hash href='https://twitter.com/nullvoxpopuli' text='My Twitter')
) as |site|}}
<li>
<a href={{site.href}} target="_blank">{{site.text}}</a>
</li>
{{/each}}
</ul>
`;
export default class ApplicationRoute extends Route {
async model() {
const foo = toComponent(
compileTemplate(code, { moduleName: 'repro-foo' }),
'repro-foo'
);
return { foo };
}
}
function toComponent(template, name) {
// https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/runtime/lib/component/template-only.ts#L83
return setComponentTemplate(template, _templateOnlyComponent(name));
}
function compileTemplate(text, { moduleName }) {
let compiled = _compile(text, {
strictMode: false,
moduleName,
locals: [],
isProduction: false,
meta: {},
plugins: {
ast: [],
},
});
return compiled;
}