MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

import aliases

+150 -15
+1 -1
include/ant.h
··· 88 88 void js_setup_import_meta(struct js *js, const char *filename); 89 89 90 90 typedef jsval_t (*ant_library_init_fn)(struct js *js); 91 - void ant_register_library(const char *name, ant_library_init_fn init_fn); 91 + void ant_register_library(ant_library_init_fn init_fn, const char *name, ...); 92 92 93 93 typedef jsval_t (*js_getter_fn)(struct js *js, jsval_t obj, const char *key, size_t key_len); 94 94
+1 -1
meson.build
··· 74 74 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 75 75 76 76 version_conf = configuration_data() 77 - version_conf.set('ANT_VERSION', '0.0.8.24') 77 + version_conf.set('ANT_VERSION', '0.0.8.25') 78 78 version_conf.set('ANT_GIT_HASH', git_hash) 79 79 version_conf.set('ANT_BUILD_DATE', build_date) 80 80
+16 -8
src/ant.c
··· 169 169 if (protected_brk < 0x2000) protected_brk = 0x2000; 170 170 } 171 171 172 - void ant_register_library(const char *name, ant_library_init_fn init_fn) { 173 - ant_library_t *lib = (ant_library_t *)ANT_GC_MALLOC(sizeof(ant_library_t)); 174 - if (!lib) return; 175 - 176 - strncpy(lib->name, name, sizeof(lib->name) - 1); 177 - lib->name[sizeof(lib->name) - 1] = '\0'; 178 - lib->init_fn = init_fn; 172 + void ant_register_library(ant_library_init_fn init_fn, const char *name, ...) { 173 + va_list args; 174 + const char *alias = name; 179 175 180 - HASH_ADD_STR(library_registry, name, lib); 176 + va_start(args, name); 177 + while (alias != NULL) { 178 + ant_library_t *lib = (ant_library_t *)ANT_GC_MALLOC(sizeof(ant_library_t)); 179 + if (!lib) break; 180 + 181 + strncpy(lib->name, alias, sizeof(lib->name) - 1); 182 + lib->name[sizeof(lib->name) - 1] = '\0'; 183 + lib->init_fn = init_fn; 184 + 185 + HASH_ADD_STR(library_registry, name, lib); 186 + alias = va_arg(args, const char *); 187 + } 188 + va_end(args); 181 189 } 182 190 183 191 static ant_library_t* find_library(const char *specifier, size_t spec_len) {
+6 -5
src/main.c
··· 185 185 init_process_module(); 186 186 init_events_module(); 187 187 init_performance_module(); 188 + 189 + ant_register_library(shell_library, "ant:shell", NULL); 190 + ant_register_library(ffi_library, "ant:ffi", NULL); 188 191 189 - ant_register_library("ant:fs", fs_library); 190 - ant_register_library("ant:shell", shell_library); 191 - ant_register_library("ant:path", path_library); 192 - ant_register_library("ant:ffi", ffi_library); 193 - ant_register_library("node:crypto", crypto_library); 192 + ant_register_library(path_library, "ant:path", "node:path", NULL); 193 + ant_register_library(fs_library, "ant:fs", "node:fs", NULL); 194 + ant_register_library(crypto_library, "ant:crypto", "node:crypto", NULL); 194 195 195 196 if (eval->count > 0) eval_code(js, eval, print); 196 197 else if (repl_mode) ant_repl_run(); else {
+126
tests/test_asi.cjs
··· 1 + // Test: Automatic Semicolon Insertion (ASI) 2 + // Tests that statements work correctly without explicit semicolons 3 + 4 + console.log('=== ASI Tests ===') 5 + 6 + // Test 1: const without semicolons 7 + console.log('\nTest 1: const ASI') 8 + const a = 1 9 + const b = 2 10 + const c = a + b 11 + console.log('const a + b:', c) 12 + 13 + // Test 2: let without semicolons 14 + console.log('\nTest 2: let ASI') 15 + let x = 10 16 + let y = 20 17 + let z = x * y 18 + console.log('let x * y:', z) 19 + 20 + // Test 3: else if without semicolons 21 + console.log('\nTest 3: else if ASI') 22 + let val = 50 23 + if (val < 25) { 24 + console.log('less than 25') 25 + } else if (val < 75) { 26 + console.log('between 25 and 75') 27 + } else { 28 + console.log('75 or more') 29 + } 30 + 31 + // Test 4: Chained else if without semicolons 32 + console.log('\nTest 4: Chained else if ASI') 33 + let grade = 85 34 + let letter 35 + if (grade >= 90) { 36 + letter = 'A' 37 + } else if (grade >= 80) { 38 + letter = 'B' 39 + } else if (grade >= 70) { 40 + letter = 'C' 41 + } else if (grade >= 60) { 42 + letter = 'D' 43 + } else { 44 + letter = 'F' 45 + } 46 + console.log('Grade:', letter) 47 + 48 + // Test 5: Mixed const/let without semicolons 49 + console.log('\nTest 5: Mixed declarations ASI') 50 + const PI = 3.14159 51 + let radius = 5 52 + let area = PI * radius * radius 53 + console.log('Circle area:', area) 54 + 55 + // Test 6: Dynamic import without semicolons (expression) 56 + console.log('\nTest 6: Dynamic import ASI') 57 + async function testImport() { 58 + const mod = await import('./export-test.js') 59 + mod.hello('asi') 60 + } 61 + 62 + // Test 7: Nested if/else if without semicolons 63 + console.log('\nTest 7: Nested conditionals ASI') 64 + let outer = true 65 + let inner = false 66 + if (outer) { 67 + if (inner) { 68 + console.log('both true') 69 + } else if (!inner) { 70 + console.log('outer true, inner false') 71 + } 72 + } else if (!outer) { 73 + console.log('outer false') 74 + } 75 + 76 + // Test 8: Return statements without semicolons 77 + console.log('\nTest 8: Return ASI') 78 + function add(a, b) { 79 + return a + b 80 + } 81 + function multiply(a, b) { 82 + return a * b 83 + } 84 + console.log('add(3, 4):', add(3, 4)) 85 + console.log('multiply(3, 4):', multiply(3, 4)) 86 + 87 + // Test 9: Object/array literals with const/let 88 + console.log('\nTest 9: Object/array ASI') 89 + const obj = { name: 'test', value: 42 } 90 + let arr = [1, 2, 3] 91 + console.log('obj.name:', obj.name) 92 + console.log('arr[1]:', arr[1]) 93 + 94 + // Test 10: Arrow functions without semicolons 95 + console.log('\nTest 10: Arrow function ASI') 96 + const double = x => x * 2 97 + const triple = x => x * 3 98 + console.log('double(5):', double(5)) 99 + console.log('triple(5):', triple(5)) 100 + 101 + // Test 11: for loop with let (ASI in body) 102 + console.log('\nTest 11: for loop ASI') 103 + let sum = 0 104 + for (let i = 0; i < 5; i++) { 105 + sum = sum + i 106 + } 107 + console.log('sum:', sum) 108 + 109 + // Test 12: while with else if pattern 110 + console.log('\nTest 12: while + else if ASI') 111 + let counter = 0 112 + while (counter < 3) { 113 + if (counter === 0) { 114 + console.log('zero') 115 + } else if (counter === 1) { 116 + console.log('one') 117 + } else if (counter === 2) { 118 + console.log('two') 119 + } 120 + counter = counter + 1 121 + } 122 + 123 + // Run async test 124 + testImport() 125 + 126 + console.log('\n=== All ASI tests completed ===')