Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c4c739

Browse files
committed
test(minifier): cleanup some tests in substitute_alternate_syntax (#8768)
1 parent 79d5481 commit 0c4c739

File tree

1 file changed

+16
-145
lines changed

1 file changed

+16
-145
lines changed

crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs

Lines changed: 16 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,59 +1232,6 @@ mod test {
12321232
test_same("new Int8Array(0, a)");
12331233
}
12341234

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-
12881235
#[test]
12891236
#[ignore]
12901237
fn test_string_array_splitting() {
@@ -1316,23 +1263,7 @@ mod test {
13161263

13171264
#[test]
13181265
#[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() {
13361267
test("((function(){}).bind())()", "((function(){}))()");
13371268
test("((function(){}).bind(a))()", "((function(){})).call(a)");
13381269
test("((function(){}).bind(a,b))()", "((function(){})).call(a,b)");
@@ -1346,94 +1277,34 @@ mod test {
13461277
test_same("(f.bind(a))()");
13471278
test_same("(f.bind())(a)");
13481279
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)");
14091280
}
14101281

1282+
// FIXME: the cases commented out can be implemented
14111283
#[test]
1412-
#[ignore]
14131284
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)");
14191298
test_same("(a / b) * (c % d)");
14201299
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");
14231301
}
14241302

14251303
#[test]
14261304
fn nullish_coalesce() {
14271305
test("a ?? (b ?? c);", "(a ?? b) ?? c");
14281306
}
14291307

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-
14371308
#[test]
14381309
fn test_fold_arrow_function_return() {
14391310
test("const foo = () => { return 'baz' }", "const foo = () => 'baz'");

0 commit comments

Comments
 (0)