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.

add a typescript type stripper

+1255 -30
+1
.gitignore
··· 8 8 9 9 /build 10 10 /traces 11 + /src/strip/target 11 12 /javascript-zoo 12 13 13 14 /vendor/*/
+7 -4
examples/ffi/basic/printf.js examples/ffi/basic/printf.ts
··· 1 1 import { dlopen, suffix, FFIType } from 'ant:ffi'; 2 2 3 - let libcName; 3 + let libcName: string; 4 4 if (process.platform === 'darwin') { 5 5 libcName = `libSystem.${suffix}`; 6 6 } else if (process.platform === 'linux') { 7 7 libcName = `libc.${suffix}`; 8 8 } else if (process.platform === 'win32') { 9 9 libcName = `msvcrt.${suffix}`; 10 - } else { 11 - throw new Error(`Unsupported platform: ${process.platform}`); 10 + } else throw new Error(`Unsupported platform: ${process.platform}`); 11 + 12 + interface libC { 13 + putchar(c: number): number; 14 + printf(format: string, ...args: unknown[]): number; 12 15 } 13 16 14 - const libc = dlopen(libcName); 17 + const libc = dlopen<libC>(libcName); 15 18 16 19 libc.define('putchar', { 17 20 args: [FFIType.int],
+23 -4
meson.build
··· 81 81 'build_benchmarks=false' 82 82 ]).get_variable('libuv_dep') 83 83 84 + cargo = find_program('cargo', required: true) 85 + cp = find_program('cp', required: true) 86 + strip_include = include_directories('src/strip') 87 + 88 + oxc_lib = custom_target( 89 + 'oxc_strip', 90 + output: 'liboxc.a', 91 + command: [ 92 + 'sh', '-c', 93 + cargo.full_path() + ' build --release ' + 94 + '--manifest-path ' + meson.project_source_root() / 'src' / 'strip' / 'Cargo.toml' + ' ' + 95 + '--target-dir ' + meson.project_build_root() / 'oxc-target' + 96 + ' && ' + cp.full_path() + ' ' + meson.project_build_root() / 'oxc-target' / 'release' / 'liboxc.a' + ' @OUTPUT@' 97 + ], 98 + build_by_default: true 99 + ) 100 + 101 + oxc_dep = declare_dependency(link_with: oxc_lib) 102 + 84 103 git = find_program('git', required: false) 85 104 if git.found() 86 105 git_commit = run_command(git, 'rev-parse', '--short=10', 'HEAD', check: false) ··· 96 115 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 97 116 98 117 version_conf = configuration_data() 99 - version_conf.set('ANT_VERSION', '0.3.3.8') 118 + version_conf.set('ANT_VERSION', '0.3.3.9') 100 119 version_conf.set('ANT_GIT_HASH', git_hash) 101 120 version_conf.set('ANT_BUILD_DATE', build_date) 102 121 ··· 146 165 147 166 ant_deps = [ 148 167 libffi_dep, bdwgc_dep, uuid_dep, 149 - llhttp, pcre2_dep, libuv_dep, 168 + llhttp, pcre2_dep, libuv_dep, oxc_dep, 150 169 argtable3_dep, tlsuv_dep, libsodium_dep, 151 170 yyjson_dep, minicoro_dep, uuidv7_dep, 152 - openssl_dep, zlib_dep, uthash_dep 171 + openssl_dep, zlib_dep, uthash_dep, 153 172 ] 154 173 155 174 if host_machine.system() == 'darwin' ··· 159 178 executable( 160 179 'ant', 161 180 sources + [snapshot_h], 162 - include_directories: [include, build_include], 181 + include_directories: [include, build_include, strip_include], 163 182 dependencies: ant_deps 164 183 )
+30 -2
src/main.c
··· 1 + #include <oxc.h> 1 2 #include <stdio.h> 2 3 #include <stdlib.h> 3 4 #include <string.h> ··· 42 43 #include "modules/navigator.h" 43 44 #include "modules/child_process.h" 44 45 46 + 45 47 int js_result = EXIT_SUCCESS; 48 + 49 + static int is_typescript_file(const char *filename) { 50 + if (filename == NULL) return 0; 51 + size_t len = strlen(filename); 52 + if (len < 3) return 0; 53 + 54 + const char *ext = filename + len; 55 + while (ext > filename && *(ext - 1) != '.' && *(ext - 1) != '/') ext--; 56 + if (ext == filename || *(ext - 1) != '.') return 0; 57 + ext--; 58 + 59 + return (strcmp(ext, ".ts") == 0 || strcmp(ext, ".mts") == 0 || strcmp(ext, ".cts") == 0); 60 + } 46 61 47 62 static void eval_code(struct js *js, struct arg_str *eval, struct arg_lit *print) { 48 63 const char *script = eval->sval[0]; ··· 111 126 if (realpath(filename, abs_path) != NULL) { 112 127 use_path = abs_path; 113 128 } else use_path = filename; 129 + 130 + char *js_code = buffer; 131 + size_t js_len = len; 132 + 133 + if (is_typescript_file(filename)) { 134 + int result = OXC_strip_types(buffer, filename, buffer, len + 1); 135 + if (result < 0) { 136 + fprintf(stderr, "TypeScript error: strip failed (%d)\n", result); 137 + free(buffer); 138 + return EXIT_FAILURE; 139 + } 140 + js_len = (size_t)result; 141 + } 114 142 115 143 js_set_filename(js, use_path); 116 144 js_setup_import_meta(js, use_path); 117 145 js_mkscope(js); 118 146 119 - jsval_t result = js_eval(js, buffer, len); 120 - free(buffer); 147 + jsval_t result = js_eval(js, js_code, js_len); 148 + free(js_code); 121 149 122 150 if (js_type(result) == JS_ERR) { 123 151 fprintf(stderr, "%s\n", js_str(js, result));
+1007
src/strip/Cargo.lock
··· 1 + # This file is automatically @generated by Cargo. 2 + # It is not intended for manual editing. 3 + version = 4 4 + 5 + [[package]] 6 + name = "adler2" 7 + version = "2.0.1" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" 10 + 11 + [[package]] 12 + name = "allocator-api2" 13 + version = "0.2.21" 14 + source = "registry+https://github.com/rust-lang/crates.io-index" 15 + checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" 16 + 17 + [[package]] 18 + name = "autocfg" 19 + version = "1.5.0" 20 + source = "registry+https://github.com/rust-lang/crates.io-index" 21 + checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" 22 + 23 + [[package]] 24 + name = "base64" 25 + version = "0.22.1" 26 + source = "registry+https://github.com/rust-lang/crates.io-index" 27 + checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" 28 + 29 + [[package]] 30 + name = "base64-simd" 31 + version = "0.8.0" 32 + source = "registry+https://github.com/rust-lang/crates.io-index" 33 + checksum = "339abbe78e73178762e23bea9dfd08e697eb3f3301cd4be981c0f78ba5859195" 34 + dependencies = [ 35 + "outref", 36 + "vsimd", 37 + ] 38 + 39 + [[package]] 40 + name = "bitflags" 41 + version = "2.10.0" 42 + source = "registry+https://github.com/rust-lang/crates.io-index" 43 + checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" 44 + 45 + [[package]] 46 + name = "block-buffer" 47 + version = "0.10.4" 48 + source = "registry+https://github.com/rust-lang/crates.io-index" 49 + checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" 50 + dependencies = [ 51 + "generic-array", 52 + ] 53 + 54 + [[package]] 55 + name = "bumpalo" 56 + version = "3.19.1" 57 + source = "registry+https://github.com/rust-lang/crates.io-index" 58 + checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" 59 + dependencies = [ 60 + "allocator-api2", 61 + ] 62 + 63 + [[package]] 64 + name = "castaway" 65 + version = "0.2.4" 66 + source = "registry+https://github.com/rust-lang/crates.io-index" 67 + checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a" 68 + dependencies = [ 69 + "rustversion", 70 + ] 71 + 72 + [[package]] 73 + name = "cfg-if" 74 + version = "1.0.4" 75 + source = "registry+https://github.com/rust-lang/crates.io-index" 76 + checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" 77 + 78 + [[package]] 79 + name = "cobs" 80 + version = "0.3.0" 81 + source = "registry+https://github.com/rust-lang/crates.io-index" 82 + checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" 83 + dependencies = [ 84 + "thiserror", 85 + ] 86 + 87 + [[package]] 88 + name = "compact_str" 89 + version = "0.9.0" 90 + source = "registry+https://github.com/rust-lang/crates.io-index" 91 + checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a" 92 + dependencies = [ 93 + "castaway", 94 + "cfg-if", 95 + "itoa", 96 + "rustversion", 97 + "ryu", 98 + "static_assertions", 99 + ] 100 + 101 + [[package]] 102 + name = "cow-utils" 103 + version = "0.1.3" 104 + source = "registry+https://github.com/rust-lang/crates.io-index" 105 + checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79" 106 + 107 + [[package]] 108 + name = "cpufeatures" 109 + version = "0.2.17" 110 + source = "registry+https://github.com/rust-lang/crates.io-index" 111 + checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" 112 + dependencies = [ 113 + "libc", 114 + ] 115 + 116 + [[package]] 117 + name = "crc32fast" 118 + version = "1.5.0" 119 + source = "registry+https://github.com/rust-lang/crates.io-index" 120 + checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" 121 + dependencies = [ 122 + "cfg-if", 123 + ] 124 + 125 + [[package]] 126 + name = "crypto-common" 127 + version = "0.1.7" 128 + source = "registry+https://github.com/rust-lang/crates.io-index" 129 + checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" 130 + dependencies = [ 131 + "generic-array", 132 + "typenum", 133 + ] 134 + 135 + [[package]] 136 + name = "deranged" 137 + version = "0.5.5" 138 + source = "registry+https://github.com/rust-lang/crates.io-index" 139 + checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" 140 + dependencies = [ 141 + "powerfmt", 142 + ] 143 + 144 + [[package]] 145 + name = "digest" 146 + version = "0.10.7" 147 + source = "registry+https://github.com/rust-lang/crates.io-index" 148 + checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" 149 + dependencies = [ 150 + "block-buffer", 151 + "crypto-common", 152 + ] 153 + 154 + [[package]] 155 + name = "dragonbox_ecma" 156 + version = "0.0.5" 157 + source = "registry+https://github.com/rust-lang/crates.io-index" 158 + checksum = "d742b56656e8b14d63e7ea9806597b1849ae25412584c8adf78c0f67bd985e66" 159 + 160 + [[package]] 161 + name = "either" 162 + version = "1.15.0" 163 + source = "registry+https://github.com/rust-lang/crates.io-index" 164 + checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" 165 + 166 + [[package]] 167 + name = "embedded-io" 168 + version = "0.4.0" 169 + source = "registry+https://github.com/rust-lang/crates.io-index" 170 + checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" 171 + 172 + [[package]] 173 + name = "embedded-io" 174 + version = "0.6.1" 175 + source = "registry+https://github.com/rust-lang/crates.io-index" 176 + checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" 177 + 178 + [[package]] 179 + name = "equivalent" 180 + version = "1.0.2" 181 + source = "registry+https://github.com/rust-lang/crates.io-index" 182 + checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 183 + 184 + [[package]] 185 + name = "fastrand" 186 + version = "2.3.0" 187 + source = "registry+https://github.com/rust-lang/crates.io-index" 188 + checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" 189 + 190 + [[package]] 191 + name = "flate2" 192 + version = "1.1.5" 193 + source = "registry+https://github.com/rust-lang/crates.io-index" 194 + checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" 195 + dependencies = [ 196 + "crc32fast", 197 + "miniz_oxide", 198 + ] 199 + 200 + [[package]] 201 + name = "generic-array" 202 + version = "0.14.7" 203 + source = "registry+https://github.com/rust-lang/crates.io-index" 204 + checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" 205 + dependencies = [ 206 + "typenum", 207 + "version_check", 208 + ] 209 + 210 + [[package]] 211 + name = "hashbrown" 212 + version = "0.16.1" 213 + source = "registry+https://github.com/rust-lang/crates.io-index" 214 + checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" 215 + dependencies = [ 216 + "allocator-api2", 217 + ] 218 + 219 + [[package]] 220 + name = "indexmap" 221 + version = "2.13.0" 222 + source = "registry+https://github.com/rust-lang/crates.io-index" 223 + checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" 224 + dependencies = [ 225 + "equivalent", 226 + "hashbrown", 227 + ] 228 + 229 + [[package]] 230 + name = "itertools" 231 + version = "0.14.0" 232 + source = "registry+https://github.com/rust-lang/crates.io-index" 233 + checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" 234 + dependencies = [ 235 + "either", 236 + ] 237 + 238 + [[package]] 239 + name = "itoa" 240 + version = "1.0.17" 241 + source = "registry+https://github.com/rust-lang/crates.io-index" 242 + checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" 243 + 244 + [[package]] 245 + name = "json-escape-simd" 246 + version = "3.0.1" 247 + source = "registry+https://github.com/rust-lang/crates.io-index" 248 + checksum = "a3c2a6c0b4b5637c41719973ef40c6a1cf564f9db6958350de6193fbee9c23f5" 249 + 250 + [[package]] 251 + name = "libc" 252 + version = "0.2.180" 253 + source = "registry+https://github.com/rust-lang/crates.io-index" 254 + checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" 255 + 256 + [[package]] 257 + name = "memchr" 258 + version = "2.7.6" 259 + source = "registry+https://github.com/rust-lang/crates.io-index" 260 + checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" 261 + 262 + [[package]] 263 + name = "miniz_oxide" 264 + version = "0.8.9" 265 + source = "registry+https://github.com/rust-lang/crates.io-index" 266 + checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" 267 + dependencies = [ 268 + "adler2", 269 + "simd-adler32", 270 + ] 271 + 272 + [[package]] 273 + name = "nom" 274 + version = "8.0.0" 275 + source = "registry+https://github.com/rust-lang/crates.io-index" 276 + checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" 277 + dependencies = [ 278 + "memchr", 279 + ] 280 + 281 + [[package]] 282 + name = "nonmax" 283 + version = "0.5.5" 284 + source = "registry+https://github.com/rust-lang/crates.io-index" 285 + checksum = "610a5acd306ec67f907abe5567859a3c693fb9886eb1f012ab8f2a47bef3db51" 286 + 287 + [[package]] 288 + name = "num-bigint" 289 + version = "0.4.6" 290 + source = "registry+https://github.com/rust-lang/crates.io-index" 291 + checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" 292 + dependencies = [ 293 + "num-integer", 294 + "num-traits", 295 + ] 296 + 297 + [[package]] 298 + name = "num-conv" 299 + version = "0.1.0" 300 + source = "registry+https://github.com/rust-lang/crates.io-index" 301 + checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" 302 + 303 + [[package]] 304 + name = "num-integer" 305 + version = "0.1.46" 306 + source = "registry+https://github.com/rust-lang/crates.io-index" 307 + checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" 308 + dependencies = [ 309 + "num-traits", 310 + ] 311 + 312 + [[package]] 313 + name = "num-traits" 314 + version = "0.2.19" 315 + source = "registry+https://github.com/rust-lang/crates.io-index" 316 + checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" 317 + dependencies = [ 318 + "autocfg", 319 + ] 320 + 321 + [[package]] 322 + name = "outref" 323 + version = "0.5.2" 324 + source = "registry+https://github.com/rust-lang/crates.io-index" 325 + checksum = "1a80800c0488c3a21695ea981a54918fbb37abf04f4d0720c453632255e2ff0e" 326 + 327 + [[package]] 328 + name = "owo-colors" 329 + version = "4.2.3" 330 + source = "registry+https://github.com/rust-lang/crates.io-index" 331 + checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" 332 + 333 + [[package]] 334 + name = "oxc" 335 + version = "0.0.0" 336 + dependencies = [ 337 + "oxc_allocator", 338 + "oxc_codegen", 339 + "oxc_parser", 340 + "oxc_semantic", 341 + "oxc_span", 342 + "oxc_transformer", 343 + ] 344 + 345 + [[package]] 346 + name = "oxc-browserslist" 347 + version = "2.2.0" 348 + source = "registry+https://github.com/rust-lang/crates.io-index" 349 + checksum = "23d55ecaab3af16fee2d0195f2e7d26f27cab0044d0b6d74073514c7feee6beb" 350 + dependencies = [ 351 + "flate2", 352 + "nom", 353 + "postcard", 354 + "rustc-hash", 355 + "serde", 356 + "serde_json", 357 + "thiserror", 358 + "time", 359 + ] 360 + 361 + [[package]] 362 + name = "oxc-miette" 363 + version = "2.7.0" 364 + source = "registry+https://github.com/rust-lang/crates.io-index" 365 + checksum = "60a7ba54c704edefead1f44e9ef09c43e5cfae666bdc33516b066011f0e6ebf7" 366 + dependencies = [ 367 + "cfg-if", 368 + "owo-colors", 369 + "oxc-miette-derive", 370 + "textwrap", 371 + "thiserror", 372 + "unicode-segmentation", 373 + "unicode-width", 374 + ] 375 + 376 + [[package]] 377 + name = "oxc-miette-derive" 378 + version = "2.7.0" 379 + source = "registry+https://github.com/rust-lang/crates.io-index" 380 + checksum = "d4faecb54d0971f948fbc1918df69b26007e6f279a204793669542e1e8b75eb3" 381 + dependencies = [ 382 + "proc-macro2", 383 + "quote", 384 + "syn", 385 + ] 386 + 387 + [[package]] 388 + name = "oxc_allocator" 389 + version = "0.107.0" 390 + source = "registry+https://github.com/rust-lang/crates.io-index" 391 + checksum = "377063b29ba9762002f07bd4bc5cdd60373a4e3b094e15ea201eec07556d65ff" 392 + dependencies = [ 393 + "allocator-api2", 394 + "bumpalo", 395 + "hashbrown", 396 + "oxc_data_structures", 397 + "rustc-hash", 398 + ] 399 + 400 + [[package]] 401 + name = "oxc_ast" 402 + version = "0.107.0" 403 + source = "registry+https://github.com/rust-lang/crates.io-index" 404 + checksum = "ff4d2aed570578cfe5249d1e50736971b85c4eedc39f9777f735914e10d42dd7" 405 + dependencies = [ 406 + "bitflags", 407 + "oxc_allocator", 408 + "oxc_ast_macros", 409 + "oxc_data_structures", 410 + "oxc_diagnostics", 411 + "oxc_estree", 412 + "oxc_regular_expression", 413 + "oxc_span", 414 + "oxc_syntax", 415 + ] 416 + 417 + [[package]] 418 + name = "oxc_ast_macros" 419 + version = "0.107.0" 420 + source = "registry+https://github.com/rust-lang/crates.io-index" 421 + checksum = "d7d5f0089ba8705ef065f8acb371c3ab44e3a7fb90372cccac6788b677e763f1" 422 + dependencies = [ 423 + "phf", 424 + "proc-macro2", 425 + "quote", 426 + "syn", 427 + ] 428 + 429 + [[package]] 430 + name = "oxc_ast_visit" 431 + version = "0.107.0" 432 + source = "registry+https://github.com/rust-lang/crates.io-index" 433 + checksum = "45305537949b2471ce9afe251a2051af6ed2188492cd079b1d83b96caa6714b5" 434 + dependencies = [ 435 + "oxc_allocator", 436 + "oxc_ast", 437 + "oxc_span", 438 + "oxc_syntax", 439 + ] 440 + 441 + [[package]] 442 + name = "oxc_codegen" 443 + version = "0.107.0" 444 + source = "registry+https://github.com/rust-lang/crates.io-index" 445 + checksum = "bcf3d7a97d49d6557d315f7b806a246a6627aec4942b9bd50e670686be6d3b00" 446 + dependencies = [ 447 + "bitflags", 448 + "cow-utils", 449 + "dragonbox_ecma", 450 + "itoa", 451 + "oxc_allocator", 452 + "oxc_ast", 453 + "oxc_data_structures", 454 + "oxc_index", 455 + "oxc_semantic", 456 + "oxc_sourcemap", 457 + "oxc_span", 458 + "oxc_syntax", 459 + "rustc-hash", 460 + ] 461 + 462 + [[package]] 463 + name = "oxc_compat" 464 + version = "0.107.0" 465 + source = "registry+https://github.com/rust-lang/crates.io-index" 466 + checksum = "8d772c9461d67a0bd1b8177674f73d7d666f8120bab90bfc37383eace93bcd82" 467 + dependencies = [ 468 + "cow-utils", 469 + "oxc-browserslist", 470 + "oxc_syntax", 471 + "rustc-hash", 472 + "serde", 473 + ] 474 + 475 + [[package]] 476 + name = "oxc_data_structures" 477 + version = "0.107.0" 478 + source = "registry+https://github.com/rust-lang/crates.io-index" 479 + checksum = "b0264dbee1c186f744a433955a900a34f7a8bf6e4381d00100528d2b23043b21" 480 + dependencies = [ 481 + "ropey", 482 + ] 483 + 484 + [[package]] 485 + name = "oxc_diagnostics" 486 + version = "0.107.0" 487 + source = "registry+https://github.com/rust-lang/crates.io-index" 488 + checksum = "cd5d75130504c4b6792eba9a687349ec92cc7e220ddfc1cba35ef540c194b6ed" 489 + dependencies = [ 490 + "cow-utils", 491 + "oxc-miette", 492 + "percent-encoding", 493 + ] 494 + 495 + [[package]] 496 + name = "oxc_ecmascript" 497 + version = "0.107.0" 498 + source = "registry+https://github.com/rust-lang/crates.io-index" 499 + checksum = "12400e655a18fe9ba1359324d7a634964f62d9a151008a48671e46abd9b728e1" 500 + dependencies = [ 501 + "cow-utils", 502 + "num-bigint", 503 + "num-traits", 504 + "oxc_allocator", 505 + "oxc_ast", 506 + "oxc_span", 507 + "oxc_syntax", 508 + ] 509 + 510 + [[package]] 511 + name = "oxc_estree" 512 + version = "0.107.0" 513 + source = "registry+https://github.com/rust-lang/crates.io-index" 514 + checksum = "e2059abb4c194b588d128c1933b6c20fde1b443b053e51da818caed17c272f65" 515 + 516 + [[package]] 517 + name = "oxc_index" 518 + version = "4.1.0" 519 + source = "registry+https://github.com/rust-lang/crates.io-index" 520 + checksum = "eb3e6120999627ec9703025eab7c9f410ebb7e95557632a8902ca48210416c2b" 521 + dependencies = [ 522 + "nonmax", 523 + "serde", 524 + ] 525 + 526 + [[package]] 527 + name = "oxc_parser" 528 + version = "0.107.0" 529 + source = "registry+https://github.com/rust-lang/crates.io-index" 530 + checksum = "090741583620244210f9988d13e7ddec78d8c22b13f885eb8d31c6566528c943" 531 + dependencies = [ 532 + "bitflags", 533 + "cow-utils", 534 + "memchr", 535 + "num-bigint", 536 + "num-traits", 537 + "oxc_allocator", 538 + "oxc_ast", 539 + "oxc_data_structures", 540 + "oxc_diagnostics", 541 + "oxc_ecmascript", 542 + "oxc_regular_expression", 543 + "oxc_span", 544 + "oxc_syntax", 545 + "rustc-hash", 546 + "seq-macro", 547 + ] 548 + 549 + [[package]] 550 + name = "oxc_regular_expression" 551 + version = "0.107.0" 552 + source = "registry+https://github.com/rust-lang/crates.io-index" 553 + checksum = "47fe9458baea58cfe0d514b32a3258839f9cad1af738a92c1c55ccea97c5ceb7" 554 + dependencies = [ 555 + "bitflags", 556 + "oxc_allocator", 557 + "oxc_ast_macros", 558 + "oxc_diagnostics", 559 + "oxc_span", 560 + "phf", 561 + "rustc-hash", 562 + "unicode-id-start", 563 + ] 564 + 565 + [[package]] 566 + name = "oxc_semantic" 567 + version = "0.107.0" 568 + source = "registry+https://github.com/rust-lang/crates.io-index" 569 + checksum = "e425a107259ff3417682df38a9964491013de0080aecbaab7e43eb1f452b6de1" 570 + dependencies = [ 571 + "itertools", 572 + "memchr", 573 + "oxc_allocator", 574 + "oxc_ast", 575 + "oxc_ast_visit", 576 + "oxc_data_structures", 577 + "oxc_diagnostics", 578 + "oxc_ecmascript", 579 + "oxc_index", 580 + "oxc_span", 581 + "oxc_syntax", 582 + "rustc-hash", 583 + "self_cell", 584 + ] 585 + 586 + [[package]] 587 + name = "oxc_sourcemap" 588 + version = "6.0.1" 589 + source = "registry+https://github.com/rust-lang/crates.io-index" 590 + checksum = "36801dbbd025f2fa133367494e38eef75a53d334ae6746ba0c889fc4e76fa3a3" 591 + dependencies = [ 592 + "base64-simd", 593 + "json-escape-simd", 594 + "rustc-hash", 595 + "serde", 596 + "serde_json", 597 + ] 598 + 599 + [[package]] 600 + name = "oxc_span" 601 + version = "0.107.0" 602 + source = "registry+https://github.com/rust-lang/crates.io-index" 603 + checksum = "4eb492189296521cf459f4caaee8d7525c70341daf10083c53c962c13e4748ee" 604 + dependencies = [ 605 + "compact_str", 606 + "oxc-miette", 607 + "oxc_allocator", 608 + "oxc_ast_macros", 609 + "oxc_estree", 610 + ] 611 + 612 + [[package]] 613 + name = "oxc_syntax" 614 + version = "0.107.0" 615 + source = "registry+https://github.com/rust-lang/crates.io-index" 616 + checksum = "c09691f16fb7ed90acb442e88faca68751f2222dbed892122a9b50fc7d161c8d" 617 + dependencies = [ 618 + "bitflags", 619 + "cow-utils", 620 + "dragonbox_ecma", 621 + "nonmax", 622 + "oxc_allocator", 623 + "oxc_ast_macros", 624 + "oxc_data_structures", 625 + "oxc_estree", 626 + "oxc_index", 627 + "oxc_span", 628 + "phf", 629 + "unicode-id-start", 630 + ] 631 + 632 + [[package]] 633 + name = "oxc_transformer" 634 + version = "0.107.0" 635 + source = "registry+https://github.com/rust-lang/crates.io-index" 636 + checksum = "11b2b72d1e073c39b4993d7dfd71daeb7ea6fb445f5c8b445be6998022ee4f76" 637 + dependencies = [ 638 + "base64", 639 + "compact_str", 640 + "indexmap", 641 + "itoa", 642 + "memchr", 643 + "oxc_allocator", 644 + "oxc_ast", 645 + "oxc_ast_visit", 646 + "oxc_compat", 647 + "oxc_data_structures", 648 + "oxc_diagnostics", 649 + "oxc_ecmascript", 650 + "oxc_regular_expression", 651 + "oxc_semantic", 652 + "oxc_span", 653 + "oxc_syntax", 654 + "oxc_traverse", 655 + "rustc-hash", 656 + "serde", 657 + "serde_json", 658 + "sha1", 659 + ] 660 + 661 + [[package]] 662 + name = "oxc_traverse" 663 + version = "0.107.0" 664 + source = "registry+https://github.com/rust-lang/crates.io-index" 665 + checksum = "5dcaa9168b7ae1f7df2461e33210605bbe60dd2b638af08a7093310c232f1bda" 666 + dependencies = [ 667 + "itoa", 668 + "oxc_allocator", 669 + "oxc_ast", 670 + "oxc_ast_visit", 671 + "oxc_data_structures", 672 + "oxc_ecmascript", 673 + "oxc_semantic", 674 + "oxc_span", 675 + "oxc_syntax", 676 + "rustc-hash", 677 + ] 678 + 679 + [[package]] 680 + name = "percent-encoding" 681 + version = "2.3.2" 682 + source = "registry+https://github.com/rust-lang/crates.io-index" 683 + checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" 684 + 685 + [[package]] 686 + name = "phf" 687 + version = "0.13.1" 688 + source = "registry+https://github.com/rust-lang/crates.io-index" 689 + checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" 690 + dependencies = [ 691 + "phf_macros", 692 + "phf_shared", 693 + "serde", 694 + ] 695 + 696 + [[package]] 697 + name = "phf_generator" 698 + version = "0.13.1" 699 + source = "registry+https://github.com/rust-lang/crates.io-index" 700 + checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737" 701 + dependencies = [ 702 + "fastrand", 703 + "phf_shared", 704 + ] 705 + 706 + [[package]] 707 + name = "phf_macros" 708 + version = "0.13.1" 709 + source = "registry+https://github.com/rust-lang/crates.io-index" 710 + checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef" 711 + dependencies = [ 712 + "phf_generator", 713 + "phf_shared", 714 + "proc-macro2", 715 + "quote", 716 + "syn", 717 + ] 718 + 719 + [[package]] 720 + name = "phf_shared" 721 + version = "0.13.1" 722 + source = "registry+https://github.com/rust-lang/crates.io-index" 723 + checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" 724 + dependencies = [ 725 + "siphasher", 726 + ] 727 + 728 + [[package]] 729 + name = "postcard" 730 + version = "1.1.3" 731 + source = "registry+https://github.com/rust-lang/crates.io-index" 732 + checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" 733 + dependencies = [ 734 + "cobs", 735 + "embedded-io 0.4.0", 736 + "embedded-io 0.6.1", 737 + "serde", 738 + ] 739 + 740 + [[package]] 741 + name = "powerfmt" 742 + version = "0.2.0" 743 + source = "registry+https://github.com/rust-lang/crates.io-index" 744 + checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" 745 + 746 + [[package]] 747 + name = "proc-macro2" 748 + version = "1.0.105" 749 + source = "registry+https://github.com/rust-lang/crates.io-index" 750 + checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" 751 + dependencies = [ 752 + "unicode-ident", 753 + ] 754 + 755 + [[package]] 756 + name = "quote" 757 + version = "1.0.43" 758 + source = "registry+https://github.com/rust-lang/crates.io-index" 759 + checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" 760 + dependencies = [ 761 + "proc-macro2", 762 + ] 763 + 764 + [[package]] 765 + name = "ropey" 766 + version = "1.6.1" 767 + source = "registry+https://github.com/rust-lang/crates.io-index" 768 + checksum = "93411e420bcd1a75ddd1dc3caf18c23155eda2c090631a85af21ba19e97093b5" 769 + dependencies = [ 770 + "smallvec", 771 + "str_indices", 772 + ] 773 + 774 + [[package]] 775 + name = "rustc-hash" 776 + version = "2.1.1" 777 + source = "registry+https://github.com/rust-lang/crates.io-index" 778 + checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" 779 + 780 + [[package]] 781 + name = "rustversion" 782 + version = "1.0.22" 783 + source = "registry+https://github.com/rust-lang/crates.io-index" 784 + checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" 785 + 786 + [[package]] 787 + name = "ryu" 788 + version = "1.0.22" 789 + source = "registry+https://github.com/rust-lang/crates.io-index" 790 + checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" 791 + 792 + [[package]] 793 + name = "self_cell" 794 + version = "1.2.2" 795 + source = "registry+https://github.com/rust-lang/crates.io-index" 796 + checksum = "b12e76d157a900eb52e81bc6e9f3069344290341720e9178cde2407113ac8d89" 797 + 798 + [[package]] 799 + name = "seq-macro" 800 + version = "0.3.6" 801 + source = "registry+https://github.com/rust-lang/crates.io-index" 802 + checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc" 803 + 804 + [[package]] 805 + name = "serde" 806 + version = "1.0.228" 807 + source = "registry+https://github.com/rust-lang/crates.io-index" 808 + checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" 809 + dependencies = [ 810 + "serde_core", 811 + "serde_derive", 812 + ] 813 + 814 + [[package]] 815 + name = "serde_core" 816 + version = "1.0.228" 817 + source = "registry+https://github.com/rust-lang/crates.io-index" 818 + checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" 819 + dependencies = [ 820 + "serde_derive", 821 + ] 822 + 823 + [[package]] 824 + name = "serde_derive" 825 + version = "1.0.228" 826 + source = "registry+https://github.com/rust-lang/crates.io-index" 827 + checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" 828 + dependencies = [ 829 + "proc-macro2", 830 + "quote", 831 + "syn", 832 + ] 833 + 834 + [[package]] 835 + name = "serde_json" 836 + version = "1.0.149" 837 + source = "registry+https://github.com/rust-lang/crates.io-index" 838 + checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" 839 + dependencies = [ 840 + "itoa", 841 + "memchr", 842 + "serde", 843 + "serde_core", 844 + "zmij", 845 + ] 846 + 847 + [[package]] 848 + name = "sha1" 849 + version = "0.10.6" 850 + source = "registry+https://github.com/rust-lang/crates.io-index" 851 + checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" 852 + dependencies = [ 853 + "cfg-if", 854 + "cpufeatures", 855 + "digest", 856 + ] 857 + 858 + [[package]] 859 + name = "simd-adler32" 860 + version = "0.3.8" 861 + source = "registry+https://github.com/rust-lang/crates.io-index" 862 + checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" 863 + 864 + [[package]] 865 + name = "siphasher" 866 + version = "1.0.1" 867 + source = "registry+https://github.com/rust-lang/crates.io-index" 868 + checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" 869 + 870 + [[package]] 871 + name = "smallvec" 872 + version = "1.15.1" 873 + source = "registry+https://github.com/rust-lang/crates.io-index" 874 + checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" 875 + 876 + [[package]] 877 + name = "smawk" 878 + version = "0.3.2" 879 + source = "registry+https://github.com/rust-lang/crates.io-index" 880 + checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" 881 + 882 + [[package]] 883 + name = "static_assertions" 884 + version = "1.1.0" 885 + source = "registry+https://github.com/rust-lang/crates.io-index" 886 + checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 887 + 888 + [[package]] 889 + name = "str_indices" 890 + version = "0.4.4" 891 + source = "registry+https://github.com/rust-lang/crates.io-index" 892 + checksum = "d08889ec5408683408db66ad89e0e1f93dff55c73a4ccc71c427d5b277ee47e6" 893 + 894 + [[package]] 895 + name = "syn" 896 + version = "2.0.114" 897 + source = "registry+https://github.com/rust-lang/crates.io-index" 898 + checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" 899 + dependencies = [ 900 + "proc-macro2", 901 + "quote", 902 + "unicode-ident", 903 + ] 904 + 905 + [[package]] 906 + name = "textwrap" 907 + version = "0.16.2" 908 + source = "registry+https://github.com/rust-lang/crates.io-index" 909 + checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057" 910 + dependencies = [ 911 + "smawk", 912 + "unicode-linebreak", 913 + "unicode-width", 914 + ] 915 + 916 + [[package]] 917 + name = "thiserror" 918 + version = "2.0.17" 919 + source = "registry+https://github.com/rust-lang/crates.io-index" 920 + checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" 921 + dependencies = [ 922 + "thiserror-impl", 923 + ] 924 + 925 + [[package]] 926 + name = "thiserror-impl" 927 + version = "2.0.17" 928 + source = "registry+https://github.com/rust-lang/crates.io-index" 929 + checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" 930 + dependencies = [ 931 + "proc-macro2", 932 + "quote", 933 + "syn", 934 + ] 935 + 936 + [[package]] 937 + name = "time" 938 + version = "0.3.44" 939 + source = "registry+https://github.com/rust-lang/crates.io-index" 940 + checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" 941 + dependencies = [ 942 + "deranged", 943 + "num-conv", 944 + "powerfmt", 945 + "serde", 946 + "time-core", 947 + ] 948 + 949 + [[package]] 950 + name = "time-core" 951 + version = "0.1.6" 952 + source = "registry+https://github.com/rust-lang/crates.io-index" 953 + checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" 954 + 955 + [[package]] 956 + name = "typenum" 957 + version = "1.19.0" 958 + source = "registry+https://github.com/rust-lang/crates.io-index" 959 + checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" 960 + 961 + [[package]] 962 + name = "unicode-id-start" 963 + version = "1.4.0" 964 + source = "registry+https://github.com/rust-lang/crates.io-index" 965 + checksum = "81b79ad29b5e19de4260020f8919b443b2ef0277d242ce532ec7b7a2cc8b6007" 966 + 967 + [[package]] 968 + name = "unicode-ident" 969 + version = "1.0.22" 970 + source = "registry+https://github.com/rust-lang/crates.io-index" 971 + checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" 972 + 973 + [[package]] 974 + name = "unicode-linebreak" 975 + version = "0.1.5" 976 + source = "registry+https://github.com/rust-lang/crates.io-index" 977 + checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" 978 + 979 + [[package]] 980 + name = "unicode-segmentation" 981 + version = "1.12.0" 982 + source = "registry+https://github.com/rust-lang/crates.io-index" 983 + checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" 984 + 985 + [[package]] 986 + name = "unicode-width" 987 + version = "0.2.2" 988 + source = "registry+https://github.com/rust-lang/crates.io-index" 989 + checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" 990 + 991 + [[package]] 992 + name = "version_check" 993 + version = "0.9.5" 994 + source = "registry+https://github.com/rust-lang/crates.io-index" 995 + checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" 996 + 997 + [[package]] 998 + name = "vsimd" 999 + version = "0.8.0" 1000 + source = "registry+https://github.com/rust-lang/crates.io-index" 1001 + checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" 1002 + 1003 + [[package]] 1004 + name = "zmij" 1005 + version = "1.0.12" 1006 + source = "registry+https://github.com/rust-lang/crates.io-index" 1007 + checksum = "2fc5a66a20078bf1251bde995aa2fdcc4b800c70b5d92dd2c62abc5c60f679f8"
+22
src/strip/Cargo.toml
··· 1 + [package] 2 + name = "oxc" 3 + edition = "2024" 4 + 5 + [lib] 6 + path = "oxc.rs" 7 + crate-type = ["staticlib", "cdylib"] 8 + 9 + [dependencies] 10 + oxc_allocator = "0.107.0" 11 + oxc_parser = "0.107.0" 12 + oxc_span = "0.107.0" 13 + oxc_codegen = "0.107.0" 14 + oxc_transformer = "0.107.0" 15 + oxc_semantic = "0.107.0" 16 + 17 + [profile.release] 18 + lto = true 19 + codegen-units = 1 20 + panic = "abort" 21 + opt-level = "z" 22 + strip = true
+19
src/strip/oxc.h
··· 1 + #ifndef OXC_STRIP_H 2 + #define OXC_STRIP_H 3 + 4 + #include <stddef.h> 5 + 6 + #define OXC_ERR_NULL_INPUT -1 7 + #define OXC_ERR_INVALID_UTF8 -2 8 + #define OXC_ERR_PARSE_FAILED -3 9 + #define OXC_ERR_TRANSFORM_FAILED -4 10 + #define OXC_ERR_OUTPUT_TOO_LARGE -5 11 + 12 + int OXC_strip_types( 13 + const char *input, 14 + const char *filename, 15 + char *output, 16 + size_t output_len 17 + ); 18 + 19 + #endif
+90
src/strip/oxc.rs
··· 1 + use std::ffi::{c_char, c_int, CStr}; 2 + use std::path::Path; 3 + use std::ptr; 4 + 5 + use oxc_allocator::Allocator; 6 + use oxc_codegen::Codegen; 7 + use oxc_parser::Parser; 8 + use oxc_semantic::SemanticBuilder; 9 + use oxc_span::SourceType; 10 + use oxc_transformer::{TransformOptions, Transformer, TypeScriptOptions}; 11 + 12 + pub const OXC_ERR_NULL_INPUT: c_int = -1; 13 + pub const OXC_ERR_INVALID_UTF8: c_int = -2; 14 + pub const OXC_ERR_TRANSFORM_FAILED: c_int = -4; 15 + pub const OXC_ERR_OUTPUT_TOO_LARGE: c_int = -5; 16 + 17 + #[unsafe(no_mangle)] 18 + pub unsafe extern "C" fn OXC_strip_types( 19 + input: *const c_char, 20 + filename: *const c_char, 21 + output: *mut c_char, 22 + output_len: usize, 23 + ) -> c_int { 24 + if input.is_null() || output.is_null() { 25 + return OXC_ERR_NULL_INPUT; 26 + } 27 + 28 + let filename_str = match unsafe { CStr::from_ptr(filename).to_str() } { 29 + Ok(s) => s, 30 + Err(_) => return OXC_ERR_INVALID_UTF8, 31 + }; 32 + 33 + let input_str = match unsafe { CStr::from_ptr(input).to_str() } { 34 + Ok(s) => s, 35 + Err(_) => return OXC_ERR_INVALID_UTF8, 36 + }; 37 + 38 + match strip_types_internal(input_str, filename_str) { 39 + Ok(result) => { 40 + let bytes = result.as_bytes(); 41 + if bytes.len() + 1 > output_len { return OXC_ERR_OUTPUT_TOO_LARGE; } 42 + unsafe { 43 + ptr::copy_nonoverlapping(bytes.as_ptr(), output as *mut u8, bytes.len()); 44 + *output.add(bytes.len()) = 0; 45 + } 46 + bytes.len() as c_int 47 + } 48 + Err(_) => OXC_ERR_TRANSFORM_FAILED, 49 + } 50 + } 51 + 52 + fn strip_types_internal(source: &str, filename: &str) -> Result<String, String> { 53 + let allocator = Allocator::default(); 54 + let source_type = SourceType::from_path(filename).unwrap_or_else(|_| SourceType::ts()); 55 + let parser_ret = Parser::new(&allocator, source, source_type).parse(); 56 + 57 + if !parser_ret.errors.is_empty() { 58 + let errors: Vec<String> = parser_ret.errors.iter().map(|e| e.to_string()).collect(); 59 + return Err(format!("Parse errors: {}", errors.join("; "))); 60 + } 61 + 62 + let mut program = parser_ret.program; 63 + let semantic_ret = SemanticBuilder::new().build(&program); 64 + 65 + if !semantic_ret.errors.is_empty() { 66 + let errors: Vec<String> = semantic_ret.errors.iter().map(|e| e.to_string()).collect(); 67 + return Err(format!("Semantic errors: {}", errors.join("; "))); 68 + } 69 + 70 + let scoping = semantic_ret.semantic.into_scoping(); 71 + let transform_options = TransformOptions { 72 + typescript: TypeScriptOptions { 73 + only_remove_type_imports: true, 74 + ..Default::default() 75 + }, 76 + ..Default::default() 77 + }; 78 + 79 + let source_path = Path::new(filename); 80 + let transformer = Transformer::new(&allocator, source_path, &transform_options); 81 + let ret = transformer.build_with_scoping(scoping, &mut program); 82 + 83 + if !ret.errors.is_empty() { 84 + let errors: Vec<String> = ret.errors.iter().map(|e| e.to_string()).collect(); 85 + return Err(format!("Transform errors: {}", errors.join("; "))); 86 + } 87 + 88 + let output = Codegen::new().build(&program).code; 89 + Ok(output) 90 + }
+8
src/types/modules/child_process.d.ts
··· 48 48 function spawnSync(command: string, args?: string[], options?: SpawnSyncOptions): SpawnResult; 49 49 function fork(modulePath: string, options?: ForkOptions): ChildProcess & Promise<SpawnResult>; 50 50 } 51 + 52 + declare module 'ant:child_process' { 53 + export * from 'events'; 54 + } 55 + 56 + declare module 'node:child_process' { 57 + export * from 'events'; 58 + }
+8
src/types/modules/crypto.d.ts
··· 13 13 function randomUUID(): string; 14 14 function getRandomValues<T extends ArrayBufferView>(array: T): T; 15 15 } 16 + 17 + declare module 'ant:crypto' { 18 + export * from 'events'; 19 + } 20 + 21 + declare module 'node:crypto' { 22 + export * from 'events'; 23 + }
+8
src/types/modules/events.d.ts
··· 11 11 eventNames(): string[]; 12 12 } 13 13 } 14 + 15 + declare module 'ant:events' { 16 + export * from 'events'; 17 + } 18 + 19 + declare module 'node:events' { 20 + export * from 'events'; 21 + }
+7 -19
src/types/modules/ffi.d.ts
··· 1 - declare module 'ffi' { 2 - type FFIType = 3 - | 'void' 4 - | 'int8' 5 - | 'int16' 6 - | 'int' 7 - | 'int64' 8 - | 'uint8' 9 - | 'uint16' 10 - | 'uint64' 11 - | 'float' 12 - | 'double' 13 - | 'pointer' 14 - | 'string' 15 - | '...'; 16 - 1 + declare module 'ant:ffi' { 17 2 interface FFITypeConstants { 18 3 void: 'void'; 19 4 int8: 'int8'; ··· 30 15 spread: '...'; 31 16 } 32 17 18 + type FFIType = FFITypeConstants[keyof FFITypeConstants]; 19 + 33 20 interface FunctionSignature { 34 21 returns: FFIType; 35 22 args: FFIType[]; 36 23 } 37 24 38 25 interface FFILibrary { 39 - define(name: string, signature: FunctionSignature | [FFIType, FFIType[]]): (...args: unknown[]) => unknown; 26 + define(name: string, signature: FunctionSignature | [FFIType, FFIType[]]): void; 40 27 call(name: string, ...args: unknown[]): unknown; 41 28 } 42 29 43 30 const suffix: 'dylib' | 'so' | 'dll'; 44 31 const FFIType: FFITypeConstants; 45 32 46 - function dlopen(libraryPath: string): FFILibrary; 47 33 function alloc(size: number): number; 48 34 function free(ptr: number): void; 49 35 function read(ptr: number, size: number, type?: FFIType): unknown; 50 36 function write(ptr: number, value: unknown, type?: FFIType): void; 51 37 function pointer(value: unknown): number; 52 - function callback(signature: FunctionSignature | [FFIType, FFIType[]], fn: (...args: unknown[]) => unknown): number; 53 38 function freeCallback(ptr: number): void; 54 39 function readPtr(ptr: number): number; 40 + 41 + function callback(signature: FunctionSignature | [FFIType, FFIType[]], fn: (...args: unknown[]) => unknown): number; 42 + function dlopen<T extends object = {}>(libraryPath: string): FFILibrary & T; 55 43 }
+8
src/types/modules/fs.d.ts
··· 28 28 function readdir(path: string): Promise<string[]>; 29 29 function readdirSync(path: string): string[]; 30 30 } 31 + 32 + declare module 'ant:fs' { 33 + export * from 'fs'; 34 + } 35 + 36 + declare module 'node:fs' { 37 + export * from 'fs'; 38 + }
+8
src/types/modules/os.d.ts
··· 106 106 function setPriority(priority: number): void; 107 107 function setPriority(pid: number, priority: number): void; 108 108 } 109 + 110 + declare module 'ant:os' { 111 + export * from 'os'; 112 + } 113 + 114 + declare module 'node:os' { 115 + export * from 'os'; 116 + }
+8
src/types/modules/path.d.ts
··· 21 21 function parse(path: string): ParsedPath; 22 22 function format(pathObject: Partial<ParsedPath>): string; 23 23 } 24 + 25 + declare module 'ant:path' { 26 + export * from 'path'; 27 + } 28 + 29 + declare module 'node:path' { 30 + export * from 'path'; 31 + }
+1 -1
src/types/modules/shell.d.ts
··· 1 - declare module 'shell' { 1 + declare module 'ant:shell' { 2 2 interface ShellResult { 3 3 stdout: string; 4 4 stderr: string;