Skip to content

Commit 75c59cb

Browse files
committed
Cleanup
1 parent 86bb572 commit 75c59cb

10 files changed

Lines changed: 350 additions & 51 deletions

File tree

packages/@glimmer-workspace/integration-tests/test/keywords/gt-runtime-test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class KeywordGtRuntime extends RenderTest {
2020
this.assertHTML('yes');
2121
}
2222

23+
@test
24+
'explicit scope (shadowed)'() {
25+
const compiled = template('{{if (gt a b) "yes" "no"}}', {
26+
strictMode: true,
27+
scope: () => ({ gt: () => false, a: 3, b: 2 }),
28+
});
29+
this.renderComponent(compiled);
30+
this.assertHTML('no');
31+
}
32+
2333
@test
2434
'implicit scope (eval)'() {
2535
let a = 3;
@@ -39,14 +49,14 @@ class KeywordGtRuntime extends RenderTest {
3949
@test
4050
'no eval and no scope'() {
4151
class Foo extends GlimmerishComponent {
42-
a = 3;
43-
b = 2;
4452
static {
4553
template('{{if (gt this.a this.b) "yes" "no"}}', {
4654
strictMode: true,
4755
component: this,
4856
});
4957
}
58+
a = 3;
59+
b = 2;
5060
}
5161
this.renderComponent(Foo);
5262
this.assertHTML('yes');

packages/@glimmer-workspace/integration-tests/test/keywords/gt-test.ts

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,64 @@ import { DEBUG } from '@glimmer/env';
22
import { jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';
33

44
import { template } from '@ember/template-compiler';
5-
import { gt } from '@ember/helper';
65

76
class KeywordGt extends RenderTest {
87
static suiteName = 'keyword helper: gt';
98

9+
@test
10+
'explicit scope'() {
11+
let a = 3;
12+
let b = 2;
13+
14+
const compiled = template('{{gt a b}}', {
15+
strictMode: true,
16+
scope: () => ({ a, b }),
17+
});
18+
19+
this.renderComponent(compiled);
20+
this.assertHTML('true');
21+
}
22+
23+
@test
24+
'explicit scope (shadowed)'() {
25+
let a = 3;
26+
let b = 2;
27+
let gt = () => 'surprise';
28+
const compiled = template('{{gt a b}}', {
29+
strictMode: true,
30+
scope: () => ({ gt, a, b }),
31+
});
32+
33+
this.renderComponent(compiled);
34+
this.assertHTML('surprise');
35+
}
36+
37+
@test
38+
'implicit scope (eval)'() {
39+
let a = 3;
40+
let b = 2;
41+
42+
hide(a);
43+
hide(b);
44+
45+
const compiled = template('{{if (gt a b) "yes" "no"}}', {
46+
strictMode: true,
47+
eval() {
48+
return eval(arguments[0]);
49+
},
50+
});
51+
52+
this.renderComponent(compiled);
53+
this.assertHTML('yes');
54+
}
55+
1056
@test
1157
'returns true when first arg is greater'() {
1258
let a = 3;
1359
let b = 2;
1460
const compiled = template('{{if (gt a b) "yes" "no"}}', {
1561
strictMode: true,
16-
scope: () => ({ gt, a, b }),
62+
scope: () => ({ a, b }),
1763
});
1864
this.renderComponent(compiled);
1965
this.assertHTML('yes');
@@ -25,7 +71,7 @@ class KeywordGt extends RenderTest {
2571
let b = 2;
2672
const compiled = template('{{if (gt a b) "yes" "no"}}', {
2773
strictMode: true,
28-
scope: () => ({ gt, a, b }),
74+
scope: () => ({ a, b }),
2975
});
3076
this.renderComponent(compiled);
3177
this.assertHTML('no');
@@ -37,7 +83,7 @@ class KeywordGt extends RenderTest {
3783
let b = 2;
3884
const compiled = template('{{if (gt a b) "yes" "no"}}', {
3985
strictMode: true,
40-
scope: () => ({ gt, a, b }),
86+
scope: () => ({ a, b }),
4187
});
4288
this.renderComponent(compiled);
4389
this.assertHTML('no');
@@ -48,7 +94,7 @@ class KeywordGt extends RenderTest {
4894
let a = 1;
4995
const compiled = template('{{gt a}}', {
5096
strictMode: true,
51-
scope: () => ({ gt, a }),
97+
scope: () => ({ a }),
5298
});
5399

54100
assert.throws(() => {
@@ -58,3 +104,7 @@ class KeywordGt extends RenderTest {
58104
}
59105

60106
jitSuite(KeywordGt);
107+
108+
const hide = (variable: unknown) => {
109+
new Function(`return (${JSON.stringify(variable)});`);
110+
};

packages/@glimmer-workspace/integration-tests/test/keywords/gte-runtime-test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,51 @@ class KeywordGteRuntime extends RenderTest {
2020
this.assertHTML('yes');
2121
}
2222

23+
@test
24+
'explicit scope (shadowed)'() {
25+
const compiled = template('{{if (gte a b) "yes" "no"}}', {
26+
strictMode: true,
27+
scope: () => ({ gte: () => false, a: 2, b: 2 }),
28+
});
29+
this.renderComponent(compiled);
30+
this.assertHTML('no');
31+
}
32+
33+
@test
34+
'implicit scope (eval)'() {
35+
let a = 2;
36+
let b = 2;
37+
hide(a);
38+
hide(b);
39+
const compiled = template('{{if (gte a b) "yes" "no"}}', {
40+
strictMode: true,
41+
eval() {
42+
return eval(arguments[0]);
43+
},
44+
});
45+
this.renderComponent(compiled);
46+
this.assertHTML('yes');
47+
}
48+
2349
@test
2450
'no eval and no scope'() {
2551
class Foo extends GlimmerishComponent {
26-
a = 2;
27-
b = 2;
2852
static {
2953
template('{{if (gte this.a this.b) "yes" "no"}}', {
3054
strictMode: true,
3155
component: this,
3256
});
3357
}
58+
a = 2;
59+
b = 2;
3460
}
3561
this.renderComponent(Foo);
3662
this.assertHTML('yes');
3763
}
3864
}
3965

4066
jitSuite(KeywordGteRuntime);
67+
68+
const hide = (variable: unknown) => {
69+
new Function(`return (${JSON.stringify(variable)});`);
70+
};

packages/@glimmer-workspace/integration-tests/test/keywords/gte-test.ts

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,64 @@ import { DEBUG } from '@glimmer/env';
22
import { jitSuite, RenderTest, test } from '@glimmer-workspace/integration-tests';
33

44
import { template } from '@ember/template-compiler';
5-
import { gte } from '@ember/helper';
65

76
class KeywordGte extends RenderTest {
87
static suiteName = 'keyword helper: gte';
98

9+
@test
10+
'explicit scope'() {
11+
let a = 2;
12+
let b = 2;
13+
14+
const compiled = template('{{gte a b}}', {
15+
strictMode: true,
16+
scope: () => ({ a, b }),
17+
});
18+
19+
this.renderComponent(compiled);
20+
this.assertHTML('true');
21+
}
22+
23+
@test
24+
'explicit scope (shadowed)'() {
25+
let a = 3;
26+
let b = 2;
27+
let gte = () => 'surprise';
28+
const compiled = template('{{gte a b}}', {
29+
strictMode: true,
30+
scope: () => ({ gte, a, b }),
31+
});
32+
33+
this.renderComponent(compiled);
34+
this.assertHTML('surprise');
35+
}
36+
37+
@test
38+
'implicit scope (eval)'() {
39+
let a = 2;
40+
let b = 2;
41+
42+
hide(a);
43+
hide(b);
44+
45+
const compiled = template('{{if (gte a b) "yes" "no"}}', {
46+
strictMode: true,
47+
eval() {
48+
return eval(arguments[0]);
49+
},
50+
});
51+
52+
this.renderComponent(compiled);
53+
this.assertHTML('yes');
54+
}
55+
1056
@test
1157
'returns true when first arg is greater'() {
1258
let a = 3;
1359
let b = 2;
1460
const compiled = template('{{if (gte a b) "yes" "no"}}', {
1561
strictMode: true,
16-
scope: () => ({ gte, a, b }),
62+
scope: () => ({ a, b }),
1763
});
1864
this.renderComponent(compiled);
1965
this.assertHTML('yes');
@@ -25,7 +71,7 @@ class KeywordGte extends RenderTest {
2571
let b = 2;
2672
const compiled = template('{{if (gte a b) "yes" "no"}}', {
2773
strictMode: true,
28-
scope: () => ({ gte, a, b }),
74+
scope: () => ({ a, b }),
2975
});
3076
this.renderComponent(compiled);
3177
this.assertHTML('yes');
@@ -37,7 +83,7 @@ class KeywordGte extends RenderTest {
3783
let b = 2;
3884
const compiled = template('{{if (gte a b) "yes" "no"}}', {
3985
strictMode: true,
40-
scope: () => ({ gte, a, b }),
86+
scope: () => ({ a, b }),
4187
});
4288
this.renderComponent(compiled);
4389
this.assertHTML('no');
@@ -48,7 +94,7 @@ class KeywordGte extends RenderTest {
4894
let a = 1;
4995
const compiled = template('{{gte a}}', {
5096
strictMode: true,
51-
scope: () => ({ gte, a }),
97+
scope: () => ({ a }),
5298
});
5399

54100
assert.throws(() => {
@@ -58,3 +104,7 @@ class KeywordGte extends RenderTest {
58104
}
59105

60106
jitSuite(KeywordGte);
107+
108+
const hide = (variable: unknown) => {
109+
new Function(`return (${JSON.stringify(variable)});`);
110+
};

packages/@glimmer-workspace/integration-tests/test/keywords/lt-runtime-test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class KeywordLtRuntime extends RenderTest {
2020
this.assertHTML('yes');
2121
}
2222

23+
@test
24+
'explicit scope (shadowed)'() {
25+
const compiled = template('{{if (lt a b) "yes" "no"}}', {
26+
strictMode: true,
27+
scope: () => ({ lt: () => false, a: 1, b: 2 }),
28+
});
29+
this.renderComponent(compiled);
30+
this.assertHTML('no');
31+
}
32+
2333
@test
2434
'implicit scope (eval)'() {
2535
let a = 1;
@@ -39,14 +49,14 @@ class KeywordLtRuntime extends RenderTest {
3949
@test
4050
'no eval and no scope'() {
4151
class Foo extends GlimmerishComponent {
42-
a = 1;
43-
b = 2;
4452
static {
4553
template('{{if (lt this.a this.b) "yes" "no"}}', {
4654
strictMode: true,
4755
component: this,
4856
});
4957
}
58+
a = 1;
59+
b = 2;
5060
}
5161
this.renderComponent(Foo);
5262
this.assertHTML('yes');

0 commit comments

Comments
 (0)