Skip to content

Commit 38930ae

Browse files
committed
Avoid variable stripping
1 parent 1580b97 commit 38930ae

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
21
import { template } from '@ember/template-compiler/runtime';
32
import { RenderingTestCase, defineSimpleModifier, moduleFor } from 'internal-test-helpers';
43
import GlimmerishComponent from '../../utils/glimmerish-component';
@@ -21,6 +20,8 @@ moduleFor(
2120
},
2221
});
2322

23+
hide(Foo);
24+
2425
return template('<Foo />', {
2526
eval() {
2627
return eval(arguments[0]);
@@ -36,6 +37,8 @@ moduleFor(
3637
await this.renderComponentModule(() => {
3738
let foo = () => 'Hello, world!';
3839

40+
hide(foo);
41+
3942
return template('{{foo}}', {
4043
eval() {
4144
return eval(arguments[0]);
@@ -50,6 +53,9 @@ moduleFor(
5053
async '@test Can use a custom modifier in scope'() {
5154
await this.renderComponentModule(() => {
5255
let foo = defineSimpleModifier((element: Element) => (element.innerHTML = 'Hello, world!'));
56+
57+
hide(foo);
58+
5359
return template('<div {{foo}}></div>', {
5460
eval() {
5561
return eval(arguments[0]);
@@ -69,6 +75,8 @@ moduleFor(
6975
},
7076
});
7177

78+
hide(each);
79+
7280
return template(`{{#each}}Hello, world!{{/each}}`, {
7381
eval() {
7482
return eval(arguments[0]);
@@ -84,6 +92,8 @@ moduleFor(
8492
await this.renderComponentModule(() => {
8593
let value = 'Hello, world!';
8694

95+
hide(value);
96+
8797
return template(`{{value}}`, {
8898
eval() {
8999
return eval(arguments[0]);
@@ -186,12 +196,16 @@ moduleFor(
186196
await this.renderComponentModule(() => {
187197
let foo = (v: string) => v;
188198

199+
hide(foo);
200+
189201
let Foo = template('{{@value}}', {
190202
eval() {
191203
return eval(arguments[0]);
192204
},
193205
});
194206

207+
hide(Foo);
208+
195209
return template('<Foo @value={{helper foo "Hello, world!"}}/>', {
196210
eval() {
197211
return eval(arguments[0]);
@@ -208,12 +222,16 @@ moduleFor(
208222
(element: Element, [text]: [string]) => (element.innerHTML = text)
209223
);
210224

225+
hide(foo);
226+
211227
let Foo = template('<div {{@value}}></div>', {
212228
eval() {
213229
return eval(arguments[0]);
214230
},
215231
});
216232

233+
hide(Foo);
234+
217235
return template('<Foo @value={{modifier foo "Hello, world!"}}/>', {
218236
eval() {
219237
return eval(arguments[0]);
@@ -232,6 +250,8 @@ moduleFor(
232250
async '@test Can use Input'() {
233251
const { Input } = await import('@ember/component');
234252

253+
hide(Input);
254+
235255
await this.renderComponentModule(() => {
236256
return template('<Input/>', {
237257
eval() {
@@ -253,6 +273,8 @@ moduleFor(
253273
async '@test Can use Textarea'() {
254274
const { Textarea } = await import('@ember/component');
255275

276+
hide(Textarea);
277+
256278
await this.renderComponentModule(() => {
257279
return template('<Textarea/>', {
258280
eval() {
@@ -273,6 +295,8 @@ moduleFor(
273295
async '@test Can use hash'() {
274296
const { hash } = await import('@glimmer/runtime');
275297

298+
hide(hash);
299+
276300
await this.renderComponentModule(() => {
277301
return template('{{#let (hash value="Hello, world!") as |hash|}}{{hash.value}}{{/let}}', {
278302
eval() {
@@ -288,6 +312,8 @@ moduleFor(
288312
async '@test Can use array'() {
289313
const { array } = await import('@glimmer/runtime');
290314

315+
hide(array);
316+
291317
await this.renderComponentModule(() => {
292318
return template('{{#each (array "Hello, world!") as |value|}}{{value}}{{/each}}', {
293319
eval() {
@@ -302,6 +328,8 @@ moduleFor(
302328
async '@test Can use concat'() {
303329
const { concat } = await import('@glimmer/runtime');
304330

331+
hide(concat);
332+
305333
await this.renderComponentModule(() => {
306334
return template('{{(concat "Hello" ", " "world!")}}', {
307335
eval() {
@@ -317,6 +345,9 @@ moduleFor(
317345
async '@test Can use get'() {
318346
const { hash, get } = await import('@glimmer/runtime');
319347

348+
hide(hash);
349+
hide(get);
350+
320351
await this.renderComponentModule(() => {
321352
return template(
322353
'{{#let (hash value="Hello, world!") as |hash|}}{{(get hash "value")}}{{/let}}',
@@ -340,6 +371,8 @@ moduleFor(
340371
assert.equal(value, 123);
341372
};
342373

374+
hide(handleClick);
375+
343376
return template('<button {{on "click" (fn handleClick 123)}}>Click</button>', {
344377
eval() {
345378
return eval(arguments[0]);
@@ -371,6 +404,8 @@ moduleFor(
371404
bar: 'BAR',
372405
};
373406

407+
hide(obj);
408+
374409
await this.renderComponentModule(() => {
375410
return template('{{#each-in obj as |k v|}}[{{k}}:{{v}}]{{/each-in}}', {
376411
eval() {
@@ -391,6 +426,8 @@ moduleFor(
391426

392427
const getElement = (id: string) => document.querySelector(`#${id}`)!;
393428

429+
hide(getElement);
430+
394431
await this.renderComponentModule(() => {
395432
return template(
396433
'{{#in-element (getElement "in-element-test")}}before{{/in-element}}after',
@@ -407,3 +444,17 @@ moduleFor(
407444
}
408445
}
409446
);
447+
448+
/**
449+
* This function is used to hide a variable from the transpiler, so that it
450+
* doesn't get removed as "unused". It does not actually do anything with the
451+
* variable, it just makes it be part of an expression that the transpiler
452+
* won't remove.
453+
*
454+
* It's a bit of a hack, but it's necessary for testing.
455+
*
456+
* @param variable The variable to hide.
457+
*/
458+
const hide = (variable: unknown) => {
459+
new Function(`return (${JSON.stringify(variable)});`);
460+
};

0 commit comments

Comments
 (0)