1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
1
import { template } from '@ember/template-compiler/runtime' ;
3
2
import { RenderingTestCase , defineSimpleModifier , moduleFor } from 'internal-test-helpers' ;
4
3
import GlimmerishComponent from '../../utils/glimmerish-component' ;
@@ -21,6 +20,8 @@ moduleFor(
21
20
} ,
22
21
} ) ;
23
22
23
+ hide ( Foo ) ;
24
+
24
25
return template ( '<Foo />' , {
25
26
eval ( ) {
26
27
return eval ( arguments [ 0 ] ) ;
@@ -36,6 +37,8 @@ moduleFor(
36
37
await this . renderComponentModule ( ( ) => {
37
38
let foo = ( ) => 'Hello, world!' ;
38
39
40
+ hide ( foo ) ;
41
+
39
42
return template ( '{{foo}}' , {
40
43
eval ( ) {
41
44
return eval ( arguments [ 0 ] ) ;
@@ -50,6 +53,9 @@ moduleFor(
50
53
async '@test Can use a custom modifier in scope' ( ) {
51
54
await this . renderComponentModule ( ( ) => {
52
55
let foo = defineSimpleModifier ( ( element : Element ) => ( element . innerHTML = 'Hello, world!' ) ) ;
56
+
57
+ hide ( foo ) ;
58
+
53
59
return template ( '<div {{foo}}></div>' , {
54
60
eval ( ) {
55
61
return eval ( arguments [ 0 ] ) ;
@@ -69,6 +75,8 @@ moduleFor(
69
75
} ,
70
76
} ) ;
71
77
78
+ hide ( each ) ;
79
+
72
80
return template ( `{{#each}}Hello, world!{{/each}}` , {
73
81
eval ( ) {
74
82
return eval ( arguments [ 0 ] ) ;
@@ -84,6 +92,8 @@ moduleFor(
84
92
await this . renderComponentModule ( ( ) => {
85
93
let value = 'Hello, world!' ;
86
94
95
+ hide ( value ) ;
96
+
87
97
return template ( `{{value}}` , {
88
98
eval ( ) {
89
99
return eval ( arguments [ 0 ] ) ;
@@ -186,12 +196,16 @@ moduleFor(
186
196
await this . renderComponentModule ( ( ) => {
187
197
let foo = ( v : string ) => v ;
188
198
199
+ hide ( foo ) ;
200
+
189
201
let Foo = template ( '{{@value}}' , {
190
202
eval ( ) {
191
203
return eval ( arguments [ 0 ] ) ;
192
204
} ,
193
205
} ) ;
194
206
207
+ hide ( Foo ) ;
208
+
195
209
return template ( '<Foo @value={{helper foo "Hello, world!"}}/>' , {
196
210
eval ( ) {
197
211
return eval ( arguments [ 0 ] ) ;
@@ -208,12 +222,16 @@ moduleFor(
208
222
( element : Element , [ text ] : [ string ] ) => ( element . innerHTML = text )
209
223
) ;
210
224
225
+ hide ( foo ) ;
226
+
211
227
let Foo = template ( '<div {{@value}}></div>' , {
212
228
eval ( ) {
213
229
return eval ( arguments [ 0 ] ) ;
214
230
} ,
215
231
} ) ;
216
232
233
+ hide ( Foo ) ;
234
+
217
235
return template ( '<Foo @value={{modifier foo "Hello, world!"}}/>' , {
218
236
eval ( ) {
219
237
return eval ( arguments [ 0 ] ) ;
@@ -232,6 +250,8 @@ moduleFor(
232
250
async '@test Can use Input' ( ) {
233
251
const { Input } = await import ( '@ember/component' ) ;
234
252
253
+ hide ( Input ) ;
254
+
235
255
await this . renderComponentModule ( ( ) => {
236
256
return template ( '<Input/>' , {
237
257
eval ( ) {
@@ -253,6 +273,8 @@ moduleFor(
253
273
async '@test Can use Textarea' ( ) {
254
274
const { Textarea } = await import ( '@ember/component' ) ;
255
275
276
+ hide ( Textarea ) ;
277
+
256
278
await this . renderComponentModule ( ( ) => {
257
279
return template ( '<Textarea/>' , {
258
280
eval ( ) {
@@ -273,6 +295,8 @@ moduleFor(
273
295
async '@test Can use hash' ( ) {
274
296
const { hash } = await import ( '@glimmer/runtime' ) ;
275
297
298
+ hide ( hash ) ;
299
+
276
300
await this . renderComponentModule ( ( ) => {
277
301
return template ( '{{#let (hash value="Hello, world!") as |hash|}}{{hash.value}}{{/let}}' , {
278
302
eval ( ) {
@@ -288,6 +312,8 @@ moduleFor(
288
312
async '@test Can use array' ( ) {
289
313
const { array } = await import ( '@glimmer/runtime' ) ;
290
314
315
+ hide ( array ) ;
316
+
291
317
await this . renderComponentModule ( ( ) => {
292
318
return template ( '{{#each (array "Hello, world!") as |value|}}{{value}}{{/each}}' , {
293
319
eval ( ) {
@@ -302,6 +328,8 @@ moduleFor(
302
328
async '@test Can use concat' ( ) {
303
329
const { concat } = await import ( '@glimmer/runtime' ) ;
304
330
331
+ hide ( concat ) ;
332
+
305
333
await this . renderComponentModule ( ( ) => {
306
334
return template ( '{{(concat "Hello" ", " "world!")}}' , {
307
335
eval ( ) {
@@ -317,6 +345,9 @@ moduleFor(
317
345
async '@test Can use get' ( ) {
318
346
const { hash, get } = await import ( '@glimmer/runtime' ) ;
319
347
348
+ hide ( hash ) ;
349
+ hide ( get ) ;
350
+
320
351
await this . renderComponentModule ( ( ) => {
321
352
return template (
322
353
'{{#let (hash value="Hello, world!") as |hash|}}{{(get hash "value")}}{{/let}}' ,
@@ -340,6 +371,8 @@ moduleFor(
340
371
assert . equal ( value , 123 ) ;
341
372
} ;
342
373
374
+ hide ( handleClick ) ;
375
+
343
376
return template ( '<button {{on "click" (fn handleClick 123)}}>Click</button>' , {
344
377
eval ( ) {
345
378
return eval ( arguments [ 0 ] ) ;
@@ -371,6 +404,8 @@ moduleFor(
371
404
bar : 'BAR' ,
372
405
} ;
373
406
407
+ hide ( obj ) ;
408
+
374
409
await this . renderComponentModule ( ( ) => {
375
410
return template ( '{{#each-in obj as |k v|}}[{{k}}:{{v}}]{{/each-in}}' , {
376
411
eval ( ) {
@@ -391,6 +426,8 @@ moduleFor(
391
426
392
427
const getElement = ( id : string ) => document . querySelector ( `#${ id } ` ) ! ;
393
428
429
+ hide ( getElement ) ;
430
+
394
431
await this . renderComponentModule ( ( ) => {
395
432
return template (
396
433
'{{#in-element (getElement "in-element-test")}}before{{/in-element}}after' ,
@@ -407,3 +444,17 @@ moduleFor(
407
444
}
408
445
}
409
446
) ;
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