From f29df4b16f8f5da11302cf9bc004f70006c936ce Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 16 Dec 2025 18:13:33 -0800 Subject: [PATCH] fix else if --- meson.build | 2 +- src/ant.c | 10 +++++- tests/test_numeric_separators.cjs | 58 +++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/test_numeric_separators.cjs diff --git a/meson.build b/meson.build index 3f12197..e45623d 100644 --- a/meson.build +++ b/meson.build @@ -74,7 +74,7 @@ endif build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() version_conf = configuration_data() -version_conf.set('ANT_VERSION', '0.0.8.26') +version_conf.set('ANT_VERSION', '0.0.8.27') version_conf.set('ANT_GIT_HASH', git_hash) version_conf.set('ANT_BUILD_DATE', build_date) diff --git a/src/ant.c b/src/ant.c index 859c47c..2115908 100644 --- a/src/ant.c +++ b/src/ant.c @@ -5626,8 +5626,16 @@ static jsval_t js_func_decl_async(struct js *js) { static jsval_t js_block_or_stmt(struct js *js) { if (next(js) == TOK_LBRACE) return js_block(js, !(js->flags & F_NOEXEC)); + uint8_t stmt_tok = js->tok; jsval_t res = resolveprop(js, js_stmt(js)); - js->consumed = 0; + bool is_block_stmt = ( + stmt_tok == TOK_FUNC || stmt_tok == TOK_CLASS || + stmt_tok == TOK_IF || stmt_tok == TOK_WHILE || + stmt_tok == TOK_DO || stmt_tok == TOK_FOR || + stmt_tok == TOK_SWITCH || stmt_tok == TOK_TRY || + stmt_tok == TOK_LBRACE || stmt_tok == TOK_ASYNC + ); + if (!is_block_stmt) js->consumed = 0; return res; } diff --git a/tests/test_numeric_separators.cjs b/tests/test_numeric_separators.cjs new file mode 100644 index 0000000..d39423f --- /dev/null +++ b/tests/test_numeric_separators.cjs @@ -0,0 +1,58 @@ +console.log('=== Numeric Separator Tests ===\n'); + +// Test 1: Decimal separators +console.log('Test 1: Decimal separators'); +console.log('1_000:', 1_000); +console.log('1_000_000:', 1_000_000); +console.log('86_400_000:', 86_400_000); +console.log('1_000 === 1000:', 1_000 === 1000 ? 'PASS' : 'FAIL'); +console.log('1_000_000 === 1000000:', 1_000_000 === 1000000 ? 'PASS' : 'FAIL'); +console.log('86_400_000 === 86400000:', 86_400_000 === 86400000 ? 'PASS' : 'FAIL'); + +// Test 2: Hexadecimal separators +console.log('\nTest 2: Hexadecimal separators'); +console.log('0xFF_FF:', 0xFF_FF); +console.log('0xDE_AD_BE_EF:', 0xDE_AD_BE_EF); +console.log('0xFF_AA_BB:', 0xFF_AA_BB); +console.log('0xFF_FF === 65535:', 0xFF_FF === 65535 ? 'PASS' : 'FAIL'); +console.log('0xDE_AD_BE_EF === 3735928559:', 0xDE_AD_BE_EF === 3735928559 ? 'PASS' : 'FAIL'); + +// Test 3: Binary separators +console.log('\nTest 3: Binary separators'); +console.log('0b1010_1010:', 0b1010_1010); +console.log('0b1111_0000_1111_0000:', 0b1111_0000_1111_0000); +console.log('0b1010_1010 === 170:', 0b1010_1010 === 170 ? 'PASS' : 'FAIL'); +console.log('0b1111_0000_1111_0000 === 61680:', 0b1111_0000_1111_0000 === 61680 ? 'PASS' : 'FAIL'); + +// Test 4: Octal separators +console.log('\nTest 4: Octal separators'); +console.log('0o77_00:', 0o77_00); +console.log('0o123_456:', 0o123_456); +console.log('0o77_00 === 4032:', 0o77_00 === 4032 ? 'PASS' : 'FAIL'); +console.log('0o123_456 === 42798:', 0o123_456 === 42798 ? 'PASS' : 'FAIL'); + +// Test 5: Floating point separators +console.log('\nTest 5: Floating point separators'); +console.log('1_000.5:', 1_000.5); +console.log('1_000.123_456:', 1_000.123_456); +console.log('1_000.5 === 1000.5:', 1_000.5 === 1000.5 ? 'PASS' : 'FAIL'); +console.log('1_000.123_456 === 1000.123456:', 1_000.123_456 === 1000.123456 ? 'PASS' : 'FAIL'); + +// Test 6: Mixed expressions +console.log('\nTest 6: Mixed expressions'); +const sum = 1_000 + 2_000 + 3_000; +console.log('1_000 + 2_000 + 3_000 =', sum); +console.log('Sum === 6000:', sum === 6000 ? 'PASS' : 'FAIL'); + +const product = 10_00 * 10_0; +console.log('10_00 * 10_0 =', product); +console.log('Product === 100000:', product === 100000 ? 'PASS' : 'FAIL'); + +// Test 7: Comparison with regular literals +console.log('\nTest 7: Comparison with regular literals'); +console.log('1_2_3_4_5 === 12345:', 1_2_3_4_5 === 12345 ? 'PASS' : 'FAIL'); +console.log('0xA_B_C === 0xABC:', 0xA_B_C === 0xABC ? 'PASS' : 'FAIL'); +console.log('0b1_0_1_0 === 0b1010:', 0b1_0_1_0 === 0b1010 ? 'PASS' : 'FAIL'); +console.log('0o7_7_7 === 0o777:', 0o7_7_7 === 0o777 ? 'PASS' : 'FAIL'); + +console.log('\n=== All numeric separator tests completed ==='); -- 2.51.2