@@ -479,6 +479,45 @@ const tests = {
479
479
}
480
480
` ,
481
481
} ,
482
+ {
483
+ code : normalizeIndent `
484
+ function App() {
485
+ const text = use(Promise.resolve('A'));
486
+ return <Text text={text} />
487
+ }
488
+ ` ,
489
+ } ,
490
+ {
491
+ code : normalizeIndent `
492
+ function App() {
493
+ if (shouldShowText) {
494
+ const text = use(query);
495
+ return <Text text={text} />
496
+ }
497
+ return <Text text={shouldFetchBackupText ? use(backupQuery) : "Nothing to see here"} />
498
+ }
499
+ ` ,
500
+ } ,
501
+ {
502
+ code : normalizeIndent `
503
+ function App() {
504
+ let data = [];
505
+ for (const query of queries) {
506
+ const text = use(item);
507
+ data.push(text);
508
+ }
509
+ return <Child data={data} />
510
+ }
511
+ ` ,
512
+ } ,
513
+ {
514
+ code : normalizeIndent `
515
+ function App() {
516
+ const data = someCallback((x) => use(x));
517
+ return <Child data={data} />
518
+ }
519
+ ` ,
520
+ } ,
482
521
] ,
483
522
invalid : [
484
523
{
@@ -1058,6 +1097,58 @@ const tests = {
1058
1097
` ,
1059
1098
errors : [ asyncComponentHookError ( 'useState' ) ] ,
1060
1099
} ,
1100
+ {
1101
+ code : normalizeIndent `
1102
+ Hook.use();
1103
+ Hook._use();
1104
+ Hook.useState();
1105
+ Hook._useState();
1106
+ Hook.use42();
1107
+ Hook.useHook();
1108
+ Hook.use_hook();
1109
+ ` ,
1110
+ errors : [
1111
+ topLevelError ( 'Hook.use' ) ,
1112
+ topLevelError ( 'Hook.useState' ) ,
1113
+ topLevelError ( 'Hook.use42' ) ,
1114
+ topLevelError ( 'Hook.useHook' ) ,
1115
+ ] ,
1116
+ } ,
1117
+ {
1118
+ code : normalizeIndent `
1119
+ function notAComponent() {
1120
+ use(promise);
1121
+ }
1122
+ ` ,
1123
+ errors : [ functionError ( 'use' , 'notAComponent' ) ] ,
1124
+ } ,
1125
+ {
1126
+ code : normalizeIndent `
1127
+ const text = use(promise);
1128
+ function App() {
1129
+ return <Text text={text} />
1130
+ }
1131
+ ` ,
1132
+ errors : [ topLevelError ( 'use' ) ] ,
1133
+ } ,
1134
+ {
1135
+ code : normalizeIndent `
1136
+ class C {
1137
+ m() {
1138
+ use(promise);
1139
+ }
1140
+ }
1141
+ ` ,
1142
+ errors : [ classError ( 'use' ) ] ,
1143
+ } ,
1144
+ {
1145
+ code : normalizeIndent `
1146
+ async function AsyncComponent() {
1147
+ use();
1148
+ }
1149
+ ` ,
1150
+ errors : [ asyncComponentHookError ( 'use' ) ] ,
1151
+ } ,
1061
1152
] ,
1062
1153
} ;
1063
1154
@@ -1159,45 +1250,6 @@ if (__EXPERIMENTAL__) {
1159
1250
}
1160
1251
` ,
1161
1252
} ,
1162
- {
1163
- code : normalizeIndent `
1164
- function App() {
1165
- const text = use(Promise.resolve('A'));
1166
- return <Text text={text} />
1167
- }
1168
- ` ,
1169
- } ,
1170
- {
1171
- code : normalizeIndent `
1172
- function App() {
1173
- if (shouldShowText) {
1174
- const text = use(query);
1175
- return <Text text={text} />
1176
- }
1177
- return <Text text={shouldFetchBackupText ? use(backupQuery) : "Nothing to see here"} />
1178
- }
1179
- ` ,
1180
- } ,
1181
- {
1182
- code : normalizeIndent `
1183
- function App() {
1184
- let data = [];
1185
- for (const query of queries) {
1186
- const text = use(item);
1187
- data.push(text);
1188
- }
1189
- return <Child data={data} />
1190
- }
1191
- ` ,
1192
- } ,
1193
- {
1194
- code : normalizeIndent `
1195
- function App() {
1196
- const data = someCallback((x) => use(x));
1197
- return <Child data={data} />
1198
- }
1199
- ` ,
1200
- } ,
1201
1253
] ;
1202
1254
tests . invalid = [
1203
1255
...tests . invalid ,
@@ -1272,58 +1324,6 @@ if (__EXPERIMENTAL__) {
1272
1324
` ,
1273
1325
errors : [ useEffectEventError ( 'onClick' ) ] ,
1274
1326
} ,
1275
- {
1276
- code : normalizeIndent `
1277
- Hook.use();
1278
- Hook._use();
1279
- Hook.useState();
1280
- Hook._useState();
1281
- Hook.use42();
1282
- Hook.useHook();
1283
- Hook.use_hook();
1284
- ` ,
1285
- errors : [
1286
- topLevelError ( 'Hook.use' ) ,
1287
- topLevelError ( 'Hook.useState' ) ,
1288
- topLevelError ( 'Hook.use42' ) ,
1289
- topLevelError ( 'Hook.useHook' ) ,
1290
- ] ,
1291
- } ,
1292
- {
1293
- code : normalizeIndent `
1294
- function notAComponent() {
1295
- use(promise);
1296
- }
1297
- ` ,
1298
- errors : [ functionError ( 'use' , 'notAComponent' ) ] ,
1299
- } ,
1300
- {
1301
- code : normalizeIndent `
1302
- const text = use(promise);
1303
- function App() {
1304
- return <Text text={text} />
1305
- }
1306
- ` ,
1307
- errors : [ topLevelError ( 'use' ) ] ,
1308
- } ,
1309
- {
1310
- code : normalizeIndent `
1311
- class C {
1312
- m() {
1313
- use(promise);
1314
- }
1315
- }
1316
- ` ,
1317
- errors : [ classError ( 'use' ) ] ,
1318
- } ,
1319
- {
1320
- code : normalizeIndent `
1321
- async function AsyncComponent() {
1322
- use();
1323
- }
1324
- ` ,
1325
- errors : [ asyncComponentHookError ( 'use' ) ] ,
1326
- } ,
1327
1327
] ;
1328
1328
}
1329
1329
0 commit comments