@@ -1232,59 +1232,6 @@ mod test {
1232
1232
test_same ( "new Int8Array(0, a)" ) ;
1233
1233
}
1234
1234
1235
- #[ test]
1236
- #[ ignore]
1237
- fn test_split_comma_expressions ( ) {
1238
- // Don't try to split in expressions.
1239
- test_same ( "while (foo(), !0) boo()" ) ;
1240
- test_same ( "var a = (foo(), !0);" ) ;
1241
- test_same ( "a = (foo(), !0);" ) ;
1242
-
1243
- // Don't try to split COMMA under LABELs.
1244
- test_same ( "a:a(),b()" ) ;
1245
- test ( "1, 2, 3, 4" , "1; 2; 3; 4" ) ;
1246
- test ( "x = 1, 2, 3" , "x = 1; 2; 3" ) ;
1247
- test_same ( "x = (1, 2, 3)" ) ;
1248
- test ( "1, (2, 3), 4" , "1; 2; 3; 4" ) ;
1249
- test ( "(x=2), foo()" , "x=2; foo()" ) ;
1250
- test ( "foo(), boo();" , "foo(); boo()" ) ;
1251
- test ( "(a(), b()), (c(), d());" , "a(); b(); c(); d()" ) ;
1252
- test ( "a(); b(); (c(), d());" , "a(); b(); c(); d();" ) ;
1253
- test ( "foo(), true" , "foo();true" ) ;
1254
- test_same ( "foo();true" ) ;
1255
- test ( "function x(){foo(), !0}" , "function x(){foo(); !0}" ) ;
1256
- test_same ( "function x(){foo(); !0}" ) ;
1257
- }
1258
-
1259
- #[ test]
1260
- fn test_comma1 ( ) {
1261
- test_same ( "x, y" ) ;
1262
- }
1263
-
1264
- #[ test]
1265
- fn test_comma2 ( ) {
1266
- test ( "a, a()" , "a, a()" ) ;
1267
- test ( "a, a?.()" , "a, a?.()" ) ;
1268
- }
1269
-
1270
- #[ test]
1271
- fn test_comma3 ( ) {
1272
- test ( "x, a(), b()" , "x, a(), b()" ) ;
1273
- test ( "x, a?.(), b?.()" , "x, a?.(), b?.()" ) ;
1274
- }
1275
-
1276
- #[ test]
1277
- fn test_comma4 ( ) {
1278
- test ( "a(), b()" , "a(), b()" ) ;
1279
- test ( "a?.(), b?.()" , "a?.(), b?.()" ) ;
1280
- }
1281
-
1282
- #[ test]
1283
- fn test_comma5 ( ) {
1284
- test ( "a(), b(), 1" , "a(), b(), 1" ) ;
1285
- test ( "a?.(), b?.(), 1" , "a?.(), b?.(), 1" ) ;
1286
- }
1287
-
1288
1235
#[ test]
1289
1236
#[ ignore]
1290
1237
fn test_string_array_splitting ( ) {
@@ -1316,23 +1263,7 @@ mod test {
1316
1263
1317
1264
#[ test]
1318
1265
#[ ignore]
1319
- fn test_bind_to_call1 ( ) {
1320
- test ( "(goog.bind(f))()" , "f()" ) ;
1321
- test ( "(goog.bind(f,a))()" , "f.call(a)" ) ;
1322
- test ( "(goog.bind(f,a,b))()" , "f.call(a,b)" ) ;
1323
-
1324
- test ( "(goog.bind(f))(a)" , "f(a)" ) ;
1325
- test ( "(goog.bind(f,a))(b)" , "f.call(a,b)" ) ;
1326
- test ( "(goog.bind(f,a,b))(c)" , "f.call(a,b,c)" ) ;
1327
-
1328
- test ( "(goog.partial(f))()" , "f()" ) ;
1329
- test ( "(goog.partial(f,a))()" , "f(a)" ) ;
1330
- test ( "(goog.partial(f,a,b))()" , "f(a,b)" ) ;
1331
-
1332
- test ( "(goog.partial(f))(a)" , "f(a)" ) ;
1333
- test ( "(goog.partial(f,a))(b)" , "f(a,b)" ) ;
1334
- test ( "(goog.partial(f,a,b))(c)" , "f(a,b,c)" ) ;
1335
-
1266
+ fn test_bind_to_call ( ) {
1336
1267
test ( "((function(){}).bind())()" , "((function(){}))()" ) ;
1337
1268
test ( "((function(){}).bind(a))()" , "((function(){})).call(a)" ) ;
1338
1269
test ( "((function(){}).bind(a,b))()" , "((function(){})).call(a,b)" ) ;
@@ -1346,94 +1277,34 @@ mod test {
1346
1277
test_same ( "(f.bind(a))()" ) ;
1347
1278
test_same ( "(f.bind())(a)" ) ;
1348
1279
test_same ( "(f.bind(a))(b)" ) ;
1349
-
1350
- // Don't rewrite if the bind isn't the immediate call target
1351
- test_same ( "(goog.bind(f)).call(g)" ) ;
1352
- }
1353
-
1354
- #[ test]
1355
- #[ ignore]
1356
- fn test_bind_to_call2 ( ) {
1357
- test ( "(goog$bind(f))()" , "f()" ) ;
1358
- test ( "(goog$bind(f,a))()" , "f.call(a)" ) ;
1359
- test ( "(goog$bind(f,a,b))()" , "f.call(a,b)" ) ;
1360
-
1361
- test ( "(goog$bind(f))(a)" , "f(a)" ) ;
1362
- test ( "(goog$bind(f,a))(b)" , "f.call(a,b)" ) ;
1363
- test ( "(goog$bind(f,a,b))(c)" , "f.call(a,b,c)" ) ;
1364
-
1365
- test ( "(goog$partial(f))()" , "f()" ) ;
1366
- test ( "(goog$partial(f,a))()" , "f(a)" ) ;
1367
- test ( "(goog$partial(f,a,b))()" , "f(a,b)" ) ;
1368
-
1369
- test ( "(goog$partial(f))(a)" , "f(a)" ) ;
1370
- test ( "(goog$partial(f,a))(b)" , "f(a,b)" ) ;
1371
- test ( "(goog$partial(f,a,b))(c)" , "f(a,b,c)" ) ;
1372
- // Don't rewrite if the bind isn't the immediate call target
1373
- test_same ( "(goog$bind(f)).call(g)" ) ;
1374
- }
1375
-
1376
- #[ test]
1377
- #[ ignore]
1378
- fn test_bind_to_call3 ( ) {
1379
- // TODO(johnlenz): The code generator wraps free calls with (0,...) to
1380
- // prevent leaking "this", but the parser doesn't unfold it, making a
1381
- // AST comparison fail. For now do a string comparison to validate the
1382
- // correct code is in fact generated.
1383
- // The FREE call wrapping should be moved out of the code generator
1384
- // and into a denormalizing pass.
1385
- // disableCompareAsTree();
1386
- // retraverseOnChange = true;
1387
- // late = false;
1388
-
1389
- test ( "(goog.bind(f.m))()" , "(0,f.m)()" ) ;
1390
- test ( "(goog.bind(f.m,a))()" , "f.m.call(a)" ) ;
1391
-
1392
- test ( "(goog.bind(f.m))(a)" , "(0,f.m)(a)" ) ;
1393
- test ( "(goog.bind(f.m,a))(b)" , "f.m.call(a,b)" ) ;
1394
-
1395
- test ( "(goog.partial(f.m))()" , "(0,f.m)()" ) ;
1396
- test ( "(goog.partial(f.m,a))()" , "(0,f.m)(a)" ) ;
1397
-
1398
- test ( "(goog.partial(f.m))(a)" , "(0,f.m)(a)" ) ;
1399
- test ( "(goog.partial(f.m,a))(b)" , "(0,f.m)(a,b)" ) ;
1400
-
1401
- // Without using type information we don't know "f" is a function.
1402
- test_same ( "f.m.bind()()" ) ;
1403
- test_same ( "f.m.bind(a)()" ) ;
1404
- test_same ( "f.m.bind()(a)" ) ;
1405
- test_same ( "f.m.bind(a)(b)" ) ;
1406
-
1407
- // Don't rewrite if the bind isn't the immediate call target
1408
- test_same ( "goog.bind(f.m).call(g)" ) ;
1409
1280
}
1410
1281
1282
+ // FIXME: the cases commented out can be implemented
1411
1283
#[ test]
1412
- #[ ignore]
1413
1284
fn test_rotate_associative_operators ( ) {
1414
- test ( "a || (b || c); a * (b * c); a | (b | c)" , "(a || b) || c; (a * b) * c; (a | b) | c" ) ;
1415
- test_same ( "a % (b % c); a / (b / c); a - (b - c);" ) ;
1416
- test ( "a * (b % c);" , "b % c * a" ) ;
1417
- test ( "a * b * (c / d)" , "c / d * b * a" ) ;
1418
- test ( "(a + b) * (c % d)" , "c % d * (a + b)" ) ;
1285
+ test ( "a || (b || c)" , "(a || b) || c" ) ;
1286
+ // float multiplication is not always associative
1287
+ // <https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-numeric-types-number-multiply>
1288
+ test_same ( "a * (b * c)" ) ;
1289
+ // test("a | (b | c)", "(a | b) | c");
1290
+ test_same ( "a % (b % c)" ) ;
1291
+ test_same ( "a / (b / c)" ) ;
1292
+ test_same ( "a - (b - c);" ) ;
1293
+ // test("a * (b % c);", "b % c * a");
1294
+ // test("a * (b / c);", "b / c * a");
1295
+ // cannot transform to `c / d * a * b`
1296
+ test_same ( "a * b * (c / d)" ) ;
1297
+ // test("(a + b) * (c % d)", "c % d * (a + b)");
1419
1298
test_same ( "(a / b) * (c % d)" ) ;
1420
1299
test_same ( "(c = 5) * (c % d)" ) ;
1421
- test ( "(a + b) * c * (d % e)" , "d % e * c * (a + b)" ) ;
1422
- test ( "!a * c * (d % e)" , "d % e * c * !a" ) ;
1300
+ // test("!a * c * (d % e)", "d % e * c * !a");
1423
1301
}
1424
1302
1425
1303
#[ test]
1426
1304
fn nullish_coalesce ( ) {
1427
1305
test ( "a ?? (b ?? c);" , "(a ?? b) ?? c" ) ;
1428
1306
}
1429
1307
1430
- #[ test]
1431
- #[ ignore]
1432
- fn test_no_rotate_infinite_loop ( ) {
1433
- test ( "1/x * (y/1 * (1/z))" , "1/x * (y/1) * (1/z)" ) ;
1434
- test_same ( "1/x * (y/1) * (1/z)" ) ;
1435
- }
1436
-
1437
1308
#[ test]
1438
1309
fn test_fold_arrow_function_return ( ) {
1439
1310
test ( "const foo = () => { return 'baz' }" , "const foo = () => 'baz'" ) ;
0 commit comments