1010 color : red;
1111 }
1212 </ style >
13+ < script src ="https://code.jquery.com/jquery-3.7.1.min.js " integrity ="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo= " crossorigin ="anonymous "> </ script >
1314</ head >
1415< body >
1516 < script >
17+
18+
19+ // make the tests actually run in the browser
20+ const inBrowser = true ;
21+ const test = `I'm a test string` ;
22+ const elm = /*html*/ `<div></div>` ;
23+ const deep = { test : /*html*/ `<div>going deep</div>` } ;
24+ const table = 'myTable' ;
25+ const myArray = [
26+ { txt : /*html*/ `<div>1</div>` } ,
27+ { txt : /*html*/ `<div>2</div>` } ,
28+ { txt : /*html*/ `<div>3</div>` }
29+ ] ;
30+
1631 /**
1732 source.css
1833 meta.embedded.block.html
1934 text.html.derivative
2035 */
2136 let variable = /*html*/ `
22- <div attr="${ test } asd${ test } ">Test</div>${ Window }
23- `
37+ <div attr="${ test } asd${ test } ">Test</div>${ elm }
38+ ` ;
2439
2540 variable = /*css*/ `
2641 .className {
2742 color: red;
2843 }
29- `
44+ ` ;
3045
31- variable = /*html*/ `<div attr="asdasd">Test</div>${ window } `
46+ variable = /*html*/ `<div attr="asdasd">Test</div>${ elm } ` ;
3247
3348 variable = //html
3449 `
35- <div>Test</div>${ Window }
36- `
50+ <div>Test</div>${ elm }
51+ ` ;
3752
3853 variable = /*html*/
3954 `
40- <div>Test</div>${ Window }
41- `
55+ <div>Test</div>${ elm }
56+ ` ;
57+
58+ if ( ! inBrowser ) {
59+
60+ // html` and similar will fail in the browser
61+ // this can only be used with a transpiler
62+
63+ const fn = ( param ) => param ;
64+
65+ const html = ( param ) => html `< div > Something</ div > ` ;
66+
67+ fn ( //html
68+ `<div>Something</div>${ elm } `
69+ ) ;
70+
71+ fn ( html `< div > OK</ div > ` ) ;
72+
73+ }
74+
4275
43- const fn = ( param ) => param ;
44- const html = ( param ) => html `< div > Something</ div > `
45- fn ( //html
46- `<div>Something</div>${ window } `
47- )
48- fn ( html `< div > OK</ div > ` )
4976
50- variable = /*svg*/ `<text x="${ test } 0" y="0">${ elmnt . txt } </text>`
77+ variable = /*svg*/ `<text x="${ test } 0" y="0">${ deep . test } </text>` ;
5178
5279 variable = /*SVG*/ `
5380 <svg viewBox="0 0 100 100">
5481 ${ myArray . reduce ( ( html , elmnt ) => html + /*svg*/ `<text x="${ test } 0" y="0">${ elmnt . txt } </text>` , '' ) }
55- </svg>`
82+ </svg>` ;
5683
57- variable = /*sql*/ `SELECT * FROM \`table\` WHERE 1=1`
84+ variable = /*sql*/ `SELECT * FROM \`table\` WHERE 1=1` ;
5885
5986 variable = /*sql*/
6087 `
6188 SELECT -- must have whitespace [\s ] after --
6289 *,
6390 --123, -- double negative is positive!
6491 FROM table--syntax error in mysql
65- `
92+ ` ;
6693
6794 variable = /*sql*/
6895 `
6996 SELECT * FROM ${ table }
7097 WHERE \`test\` NOT BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni'
7198 ORDER BY ProductName;
72- `
99+ ` ;
73100
74101 variable = /*XML*/
75102 `
79106 <loc>http://www.example.com/</loc>
80107 </url>
81108 </urlset>
82- `
109+ ` ;
83110
84111 variable = /*javascript*/
85112 `
86113 function hello(){
87114 console.log("Hello World!")
88115 }
89- `
116+ ` ;
90117
91118 variable = /*js*/
92119 `
93120 function hello(){
94121 console.log("Hello World!")
95122 }
96- `
123+ ` ;
97124
98125 variable = /*typescript*/ `
99126 function hello(name: string){
100127 console.log("Hello " + name + "!")
101- }`
128+ }` ;
102129
103130 variable = /*ts*/ `
104131 function hello(name: string){
105132 console.log("Hello " + name + "!")
106- }`
133+ }` ;
134+
135+ const $body = $ ( 'body' ) ;
136+
137+ $jQueryTest . appendTo ( $body ) ;
138+
139+
140+ // test jQuery
141+ const $jQueryTest = $ ( `
142+ <div>
143+ <h1>Test Header</h1>
144+ <p>${ test } </p>
145+ <p>${ deep . test } </p>
146+
147+ </div>
148+ ` ) ;
149+
150+ const $jQueryTest2 = $ ( `
151+ <div>
152+ <h1>Test Header 2</h1>
153+ <p>${ test } </p>
154+ <p>${ deep . test } </p>
155+
156+ </div>
157+ ` ) . appendTo ( $body ) ;
158+
159+
160+
161+
107162 </ script >
108163</ body >
109164</ html >
0 commit comments