13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*
16
-
16
+ * @emails react-core
17
17
*/
18
18
19
19
/*jshint evil:true, unused:false*/
@@ -59,48 +59,34 @@ describe('react jsx', function() {
59
59
} ;
60
60
61
61
it ( 'should convert simple tags' , function ( ) {
62
- var code = [
63
- '/**@jsx React.DOM*/' ,
64
- 'var x = <div></div>;'
65
- ] . join ( '\n' ) ;
66
- var result = [
67
- '/**@jsx React.DOM*/' ,
68
- 'var x = React.createElement(React.DOM.div, null);'
69
- ] . join ( '\n' ) ;
62
+ var code = 'var x = <div></div>;' ;
63
+ var result = 'var x = React.createElement("div", null);' ;
70
64
71
65
expect ( transform ( code ) . code ) . toEqual ( result ) ;
72
66
} ) ;
73
67
74
68
it ( 'should convert simple text' , function ( ) {
75
- var code = [
76
- '/**@jsx React.DOM*/\n' +
77
- 'var x = <div>text</div>;'
78
- ] . join ( '\n' ) ;
79
- var result = [
80
- '/**@jsx React.DOM*/' ,
81
- 'var x = React.createElement(React.DOM.div, null, "text");'
82
- ] . join ( '\n' ) ;
69
+ var code = 'var x = <div>text</div>;' ;
70
+ var result = 'var x = React.createElement("div", null, "text");' ;
83
71
84
72
expect ( transform ( code ) . code ) . toEqual ( result ) ;
85
73
} ) ;
86
74
87
75
it ( 'should have correct comma in nested children' , function ( ) {
88
76
var code = [
89
- '/**@jsx React.DOM*/' ,
90
77
'var x = <div>' ,
91
78
' <div><br /></div>' ,
92
79
' <Component>{foo}<br />{bar}</Component>' ,
93
80
' <br />' ,
94
81
'</div>;'
95
82
] . join ( '\n' ) ;
96
83
var result = [
97
- '/**@jsx React.DOM*/' ,
98
- 'var x = React.createElement(React.DOM.div, null, ' ,
99
- ' React.createElement(React.DOM.div, null, ' +
100
- 'React.createElement(React.DOM.br, null)), ' ,
84
+ 'var x = React.createElement("div", null, ' ,
85
+ ' React.createElement("div", null, ' +
86
+ 'React.createElement("br", null)), ' ,
101
87
' React.createElement(Component, null, foo, ' +
102
- 'React.createElement(React.DOM.br , null), bar), ' ,
103
- ' React.createElement(React.DOM.br , null)' ,
88
+ 'React.createElement("br" , null), bar), ' ,
89
+ ' React.createElement("br" , null)' ,
104
90
');'
105
91
] . join ( '\n' ) ;
106
92
@@ -110,14 +96,12 @@ describe('react jsx', function() {
110
96
it ( 'should avoid wrapping in extra parens if not needed' , function ( ) {
111
97
// Try with a single composite child, wrapped in a div.
112
98
var code = [
113
- '/**@jsx React.DOM*/' ,
114
99
'var x = <div>' ,
115
100
' <Component />' ,
116
101
'</div>;'
117
102
] . join ( '\n' ) ;
118
103
var result = [
119
- '/**@jsx React.DOM*/' ,
120
- 'var x = React.createElement(React.DOM.div, null, ' ,
104
+ 'var x = React.createElement("div", null, ' ,
121
105
' React.createElement(Component, null)' ,
122
106
');'
123
107
] . join ( '\n' ) ;
@@ -126,28 +110,24 @@ describe('react jsx', function() {
126
110
127
111
// Try with a single interpolated child, wrapped in a div.
128
112
code = [
129
- '/**@jsx React.DOM*/' ,
130
113
'var x = <div>' ,
131
114
' {this.props.children}' ,
132
115
'</div>;'
133
116
] . join ( '\n' ) ;
134
117
result = [
135
- '/**@jsx React.DOM*/' ,
136
- 'var x = React.createElement(React.DOM.div, null, ' ,
118
+ 'var x = React.createElement("div", null, ' ,
137
119
' this.props.children' ,
138
120
');'
139
121
] . join ( '\n' ) ;
140
122
expect ( transform ( code ) . code ) . toEqual ( result ) ;
141
123
142
124
// Try with a single interpolated child, wrapped in a composite.
143
125
code = [
144
- '/**@jsx React.DOM*/' ,
145
126
'var x = <Composite>' ,
146
127
' {this.props.children}' ,
147
128
'</Composite>;'
148
129
] . join ( '\n' ) ;
149
130
result = [
150
- '/**@jsx React.DOM*/' ,
151
131
'var x = React.createElement(Composite, null, ' ,
152
132
' this.props.children' ,
153
133
');'
@@ -156,13 +136,11 @@ describe('react jsx', function() {
156
136
157
137
// Try with a single composite child, wrapped in a composite.
158
138
code = [
159
- '/**@jsx React.DOM*/' ,
160
139
'var x = <Composite>' ,
161
140
' <Composite2 />' ,
162
141
'</Composite>;'
163
142
] . join ( '\n' ) ;
164
143
result = [
165
- '/**@jsx React.DOM*/' ,
166
144
'var x = React.createElement(Composite, null, ' ,
167
145
' React.createElement(Composite2, null)' ,
168
146
');'
@@ -172,7 +150,6 @@ describe('react jsx', function() {
172
150
173
151
it ( 'should insert commas after expressions before whitespace' , function ( ) {
174
152
var code = [
175
- '/**@jsx React.DOM*/' ,
176
153
'var x =' ,
177
154
' <div' ,
178
155
' attr1={' ,
@@ -192,9 +169,8 @@ describe('react jsx', function() {
192
169
' </div>;'
193
170
] . join ( '\n' ) ;
194
171
var result = [
195
- '/**@jsx React.DOM*/' ,
196
172
'var x =' ,
197
- ' React.createElement(React.DOM. div, {' ,
173
+ ' React.createElement(" div" , {' ,
198
174
' attr1: ' ,
199
175
' "foo" + "bar", ' ,
200
176
' ' ,
@@ -217,9 +193,6 @@ describe('react jsx', function() {
217
193
218
194
it ( 'should properly handle comments adjacent to children' , function ( ) {
219
195
var code = [
220
- '/**' ,
221
- ' * @jsx React.DOM' ,
222
- ' */' ,
223
196
'var x = (' ,
224
197
' <div>' ,
225
198
' {/* A comment at the beginning */}' ,
@@ -235,18 +208,15 @@ describe('react jsx', function() {
235
208
');'
236
209
] . join ( '\n' ) ;
237
210
var result = [
238
- '/**' ,
239
- ' * @jsx React.DOM' ,
240
- ' */' ,
241
211
'var x = (' ,
242
- ' React.createElement(React.DOM. div, null, ' ,
212
+ ' React.createElement(" div" , null, ' ,
243
213
' /* A comment at the beginning */' ,
244
214
' /* A second comment at the beginning */' ,
245
- ' React.createElement(React.DOM. span, null' ,
215
+ ' React.createElement(" span" , null' ,
246
216
' /* A nested comment */' ,
247
217
' ), ' ,
248
218
' /* A sandwiched comment */' ,
249
- ' React.createElement(React.DOM.br , null)' ,
219
+ ' React.createElement("br" , null)' ,
250
220
' /* A comment at the end */' ,
251
221
' /* A second comment at the end */' ,
252
222
' )' ,
@@ -258,9 +228,6 @@ describe('react jsx', function() {
258
228
259
229
it ( 'should properly handle comments between props' , function ( ) {
260
230
var code = [
261
- '/**' ,
262
- ' * @jsx React.DOM' ,
263
- ' */' ,
264
231
'var x = (' ,
265
232
' <div' ,
266
233
' /* a multi-line' ,
@@ -273,15 +240,12 @@ describe('react jsx', function() {
273
240
');'
274
241
] . join ( '\n' ) ;
275
242
var result = [
276
- '/**' ,
277
- ' * @jsx React.DOM' ,
278
- ' */' ,
279
243
'var x = (' ,
280
- ' React.createElement(React.DOM. div, {' ,
244
+ ' React.createElement(" div" , {' ,
281
245
' /* a multi-line' ,
282
246
' comment */' ,
283
247
' attr1: "foo"}, ' ,
284
- ' React.createElement(React.DOM. span, {// a double-slash comment' ,
248
+ ' React.createElement(" span" , {// a double-slash comment' ,
285
249
' attr2: "bar"}' ,
286
250
' )' ,
287
251
' )' ,
@@ -293,43 +257,35 @@ describe('react jsx', function() {
293
257
294
258
it ( 'should not strip tags with a single child of ' , function ( ) {
295
259
var code = [
296
- '/**' ,
297
- ' * @jsx React.DOM' ,
298
- ' */' ,
299
260
'<div> </div>;'
300
261
] . join ( '\n' ) ;
301
262
var result = [
302
- '/**' ,
303
- ' * @jsx React.DOM' ,
304
- ' */' ,
305
- 'React.createElement(React.DOM.div, null, "\u00A0");'
263
+ 'React.createElement("div", null, "\u00A0");'
306
264
] . join ( '\n' ) ;
307
265
308
266
expect ( transform ( code ) . code ) . toBe ( result ) ;
309
267
} ) ;
310
268
311
269
it ( 'should not strip even coupled with other whitespace' , function ( ) {
312
270
var code = [
313
- '/**' ,
314
- ' * @jsx React.DOM' ,
315
- ' */' ,
316
271
'<div> </div>;'
317
272
] . join ( '\n' ) ;
318
273
var result = [
319
- '/**' ,
320
- ' * @jsx React.DOM' ,
321
- ' */' ,
322
- 'React.createElement(React.DOM.div, null, "\u00A0 ");'
274
+ 'React.createElement("div", null, "\u00A0 ");'
323
275
] . join ( '\n' ) ;
324
276
325
277
expect ( transform ( code ) . code ) . toBe ( result ) ;
326
278
} ) ;
327
279
328
280
it ( 'should handle hasOwnProperty correctly' , function ( ) {
329
281
var code = '<hasOwnProperty>testing</hasOwnProperty>;' ;
330
- var result = 'React.createElement(hasOwnProperty, null, "testing");' ;
282
+ // var result = 'React.createElement(" hasOwnProperty" , null, "testing");';
331
283
332
- expect ( transform ( code ) . code ) . toBe ( result ) ;
284
+ // expect(transform(code).code).toBe(result);
285
+
286
+ // This is currently not supported, and will generate a string tag in
287
+ // a follow up.
288
+ expect ( ( ) => transform ( code ) ) . toThrow ( ) ;
333
289
} ) ;
334
290
335
291
it ( 'should allow constructor as prop' , function ( ) {
@@ -347,29 +303,15 @@ describe('react jsx', function() {
347
303
} ) ;
348
304
349
305
it ( 'should allow deeper JS namespacing' , function ( ) {
350
- var code = [
351
- '/**' ,
352
- ' * @jsx React.DOM' ,
353
- ' */' ,
354
- '<Namespace.DeepNamespace.Component />;'
355
- ] . join ( '\n' ) ;
356
- var result = [
357
- '/**' ,
358
- ' * @jsx React.DOM' ,
359
- ' */' ,
360
- 'React.createElement(Namespace.DeepNamespace.Component, null);'
361
- ] . join ( '\n' ) ;
306
+ var code = '<Namespace.DeepNamespace.Component />;' ;
307
+ var result =
308
+ 'React.createElement(Namespace.DeepNamespace.Component, null);' ;
362
309
363
310
expect ( transform ( code ) . code ) . toBe ( result ) ;
364
311
} ) ;
365
312
366
313
it ( 'should disallow XML namespacing' , function ( ) {
367
- var code = [
368
- '/**' ,
369
- ' * @jsx React.DOM' ,
370
- ' */' ,
371
- '<Namespace:Component />;'
372
- ] . join ( '\n' ) ;
314
+ var code = '<Namespace:Component />;' ;
373
315
374
316
expect ( ( ) => transform ( code ) ) . toThrow ( ) ;
375
317
} ) ;
@@ -399,18 +341,8 @@ describe('react jsx', function() {
399
341
} ) ;
400
342
401
343
it ( 'should transform known hyphenated tags' , function ( ) {
402
- var code = [
403
- '/**' ,
404
- ' * @jsx React.DOM' ,
405
- ' */' ,
406
- '<font-face />;'
407
- ] . join ( '\n' ) ;
408
- var result = [
409
- '/**' ,
410
- ' * @jsx React.DOM' ,
411
- ' */' ,
412
- 'React.createElement(React.DOM[\'font-face\'], null);'
413
- ] . join ( '\n' ) ;
344
+ var code = '<font-face />;' ;
345
+ var result = 'React.createElement("font-face", null);' ;
414
346
415
347
expect ( transform ( code ) . code ) . toBe ( result ) ;
416
348
} ) ;
@@ -422,12 +354,7 @@ describe('react jsx', function() {
422
354
} ) ;
423
355
424
356
it ( 'should throw for unknown hyphenated tags' , function ( ) {
425
- var code = [
426
- '/**' ,
427
- ' * @jsx React.DOM' ,
428
- ' */' ,
429
- '<x-component />;'
430
- ] . join ( '\n' ) ;
357
+ var code = '<x-component />;' ;
431
358
432
359
expect ( ( ) => transform ( code ) ) . toThrow ( ) ;
433
360
} ) ;
0 commit comments