Skip to content

Commit 5395bcd

Browse files
committed
Failing test
1 parent a0f05ab commit 5395bcd

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

packages/@ember/-internals/glimmer/tests/integration/components/runtime-template-compiler-implicit-test.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,65 @@
1+
import { tracked } from '@ember/-internals/metal';
12
import { template } from '@ember/template-compiler/runtime';
2-
import { RenderingTestCase, defineSimpleModifier, moduleFor } from 'internal-test-helpers';
3+
import { RenderingTestCase, defineSimpleModifier, moduleFor, runTask } from 'internal-test-helpers';
34
import GlimmerishComponent from '../../utils/glimmerish-component';
45
import { on } from '@ember/modifier/on';
56
import { fn } from '@ember/helper';
67

78
moduleFor(
89
'Strict Mode - Runtime Template Compiler (implicit)',
910
class extends RenderingTestCase {
11+
async '@test can have in-scope tracked data'(assert: Assert) {
12+
class State {
13+
@tracked str = `hello there`;
14+
15+
get component() {
16+
assert.step('get component');
17+
18+
let getStr = () => {
19+
assert.step('getStr()');
20+
return this.str;
21+
};
22+
23+
hide(getStr);
24+
25+
return template(`{{ (getStr) }}`, {
26+
eval() {
27+
return eval(arguments[0]);
28+
},
29+
});
30+
}
31+
}
32+
33+
let state = new State();
34+
35+
await this.renderComponentModule(() => {
36+
return template('<state.component />', {
37+
eval() {
38+
assert.step('eval');
39+
return eval(arguments[0]);
40+
},
41+
});
42+
});
43+
44+
this.assertHTML('hello there');
45+
this.assertStableRerender();
46+
assert.verifySteps([
47+
// for every value in the component, for eevry node traversed in the compiler
48+
'eval', // precompileJSON -> ... ElementNode -> ... -> lexicalScope -> isScope('state', ...)
49+
'eval', // "..."
50+
'eval', // "..."
51+
'eval', // creating the templateFactory
52+
'get component',
53+
'getStr()',
54+
]);
55+
56+
runTask(() => (state.str += '!'));
57+
58+
this.assertHTML('hello there!');
59+
this.assertStableRerender();
60+
assert.verifySteps(['getStr()']);
61+
}
62+
1063
async '@test Can use a component in scope'() {
1164
await this.renderComponentModule(() => {
1265
let Foo = template('Hello, world!', {

packages/@ember/template-compiler/lib/template.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,12 @@ export function template(
242242
const normalizedOptions = compileOptions(options);
243243
const component = normalizedOptions.component ?? templateOnly();
244244

245-
const source = glimmerPrecompile(templateString, normalizedOptions);
246-
const template = templateFactory(evaluate(`(${source})`) as SerializedTemplateWithLazyBlock);
245+
queueMicrotask(() => {
246+
const source = glimmerPrecompile(templateString, normalizedOptions);
247+
const template = templateFactory(evaluate(`(${source})`) as SerializedTemplateWithLazyBlock);
247248

248-
setComponentTemplate(template, component);
249+
setComponentTemplate(template, component);
250+
});
249251

250252
return component;
251253
}

0 commit comments

Comments
 (0)