xbintsc 0.6.24 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/dist/src/binder/declarations.d.ts +1 -0
- package/dist/src/binder/declarations.js +37 -0
- package/dist/src/binder/declarations.js.map +1 -1
- package/dist/src/binder/references.js +12 -0
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/globals.js +1 -0
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-system.d.ts +5 -0
- package/dist/src/checker/type-system.js +22 -3
- package/dist/src/checker/type-system.js.map +1 -1
- package/dist/src/cli/extensions.js +11 -3
- package/dist/src/cli/extensions.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/help.js +1 -1
- package/dist/src/codegen/generator/calls/access.js +25 -0
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +13 -0
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls/super.js +3 -4
- package/dist/src/codegen/generator/calls/super.js.map +1 -1
- package/dist/src/codegen/generator/calls/unwrap.d.ts +18 -0
- package/dist/src/codegen/generator/calls/unwrap.js +45 -0
- package/dist/src/codegen/generator/calls/unwrap.js.map +1 -0
- package/dist/src/codegen/generator/expressions/assignment.js +14 -0
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/module-values.d.ts +6 -0
- package/dist/src/codegen/generator/expressions/module-values.js +51 -17
- package/dist/src/codegen/generator/expressions/module-values.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.js +9 -5
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/generator.js +4 -0
- package/dist/src/codegen/generator/generator.js.map +1 -1
- package/dist/src/codegen/generator/lookup-tables.d.ts +22 -0
- package/dist/src/codegen/generator/lookup-tables.js +48 -0
- package/dist/src/codegen/generator/lookup-tables.js.map +1 -0
- package/dist/src/codegen/generator/module.js +38 -7
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +24 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +2 -6
- package/dist/src/codegen/generator/tables.js +37 -13
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.d.ts +9 -2
- package/dist/src/driver/bundler/commonjs.js +11 -4
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.d.ts +20 -0
- package/dist/src/driver/bundler/concatenate.js +68 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/deferred.d.ts +29 -1
- package/dist/src/driver/bundler/deferred.js +114 -5
- package/dist/src/driver/bundler/deferred.js.map +1 -1
- package/dist/src/driver/bundler/dynamic-import.d.ts +6 -0
- package/dist/src/driver/bundler/dynamic-import.js +59 -3
- package/dist/src/driver/bundler/dynamic-import.js.map +1 -1
- package/dist/src/driver/bundler/graph.d.ts +13 -0
- package/dist/src/driver/bundler/graph.js +11 -7
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +32 -8
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/namespace-object.d.ts +11 -0
- package/dist/src/driver/bundler/namespace-object.js +32 -0
- package/dist/src/driver/bundler/namespace-object.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +8 -2
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/bundler/symbols.d.ts +4 -0
- package/dist/src/driver/bundler/symbols.js +14 -1
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/fingerprint.d.ts +2 -2
- package/dist/src/driver/fingerprint.js +3 -3
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/link-features.js +1 -1
- package/dist/src/driver/link-features.js.map +1 -1
- package/dist/src/driver/options.d.ts +1 -4
- package/dist/src/driver/paths.js +8 -4
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-lib.d.ts +27 -0
- package/dist/src/driver/runtime-lib.js +78 -2
- package/dist/src/driver/runtime-lib.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +37 -6
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/driver/version.js.map +1 -1
- package/dist/src/extensions/catalog.js +5 -1
- package/dist/src/extensions/catalog.js.map +1 -1
- package/dist/src/extensions/gui/index.js +0 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/link-feature.d.ts +8 -0
- package/dist/src/extensions/node/buffer/index.d.ts +5 -4
- package/dist/src/extensions/node/buffer/index.js +5 -4
- package/dist/src/extensions/node/buffer/index.js.map +1 -1
- package/dist/src/extensions/node/events/index.js +8 -1
- package/dist/src/extensions/node/events/index.js.map +1 -1
- package/dist/src/extensions/node/fs/callbacks.d.ts +9 -0
- package/dist/src/extensions/node/fs/callbacks.js +42 -0
- package/dist/src/extensions/node/fs/callbacks.js.map +1 -0
- package/dist/src/extensions/node/fs/index.d.ts +2 -3
- package/dist/src/extensions/node/fs/index.js +11 -4
- package/dist/src/extensions/node/fs/index.js.map +1 -1
- package/dist/src/extensions/node/process/index.d.ts +10 -3
- package/dist/src/extensions/node/process/index.js +30 -5
- package/dist/src/extensions/node/process/index.js.map +1 -1
- package/dist/src/extensions/node/stream-web/index.d.ts +6 -1
- package/dist/src/extensions/node/stream-web/index.js +59 -4
- package/dist/src/extensions/node/stream-web/index.js.map +1 -1
- package/dist/src/extensions/node/worker_threads/index.d.ts +14 -4
- package/dist/src/extensions/node/worker_threads/index.js +24 -11
- package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +16 -1
- package/dist/src/extensions/registry.js +17 -5
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/wasm-asset.d.ts +16 -0
- package/dist/src/extensions/wasm-asset.js +28 -0
- package/dist/src/extensions/wasm-asset.js.map +1 -0
- package/dist/src/extensions/wasm.d.ts +17 -0
- package/dist/src/extensions/wasm.js +68 -0
- package/dist/src/extensions/wasm.js.map +1 -0
- package/dist/src/extensions/webworker/index.d.ts +24 -0
- package/dist/src/extensions/webworker/index.js +54 -0
- package/dist/src/extensions/webworker/index.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/lexer/scanner.d.ts +7 -1
- package/dist/src/lexer/scanner.js +15 -0
- package/dist/src/lexer/scanner.js.map +1 -1
- package/dist/src/parser/context.d.ts +10 -0
- package/dist/src/parser/context.js +42 -3
- package/dist/src/parser/context.js.map +1 -1
- package/dist/src/parser/literals.js +6 -2
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/binder/binder.test.js +43 -0
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +15 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/driver/bundler-resolve.test.js +12 -0
- package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
- package/dist/tests/driver/commonjs-prelude.test.d.ts +11 -0
- package/dist/tests/driver/commonjs-prelude.test.js +69 -0
- package/dist/tests/driver/commonjs-prelude.test.js.map +1 -0
- package/dist/tests/driver/compiler.test.js +42 -1
- package/dist/tests/driver/compiler.test.js.map +1 -1
- package/dist/tests/driver/html-deferred-cycles.test.d.ts +10 -0
- package/dist/tests/driver/html-deferred-cycles.test.js +75 -0
- package/dist/tests/driver/html-deferred-cycles.test.js.map +1 -0
- package/dist/tests/driver/link-features.test.js +9 -0
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/driver/namespace-type-exports.test.d.ts +9 -0
- package/dist/tests/driver/namespace-type-exports.test.js +59 -0
- package/dist/tests/driver/namespace-type-exports.test.js.map +1 -0
- package/dist/tests/driver/runtime-lib.test.js +49 -1
- package/dist/tests/driver/runtime-lib.test.js.map +1 -1
- package/dist/tests/e2e/async-fs.test.js +44 -0
- package/dist/tests/e2e/async-fs.test.js.map +1 -1
- package/dist/tests/e2e/compile-basics.test.js +53 -0
- package/dist/tests/e2e/compile-basics.test.js.map +1 -1
- package/dist/tests/e2e/compile-deferred-marker.test.d.ts +14 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js +68 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js.map +1 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.d.ts +12 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js +89 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js.map +1 -0
- package/dist/tests/e2e/compile-error-module.test.d.ts +9 -0
- package/dist/tests/e2e/compile-error-module.test.js +29 -0
- package/dist/tests/e2e/compile-error-module.test.js.map +1 -0
- package/dist/tests/e2e/compile-gc-promises.test.d.ts +11 -0
- package/dist/tests/e2e/compile-gc-promises.test.js +52 -0
- package/dist/tests/e2e/compile-gc-promises.test.js.map +1 -0
- package/dist/tests/e2e/compile-modules.test.js +40 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-node-fs-callbacks.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js +46 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-inheritance.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js +48 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-require.test.d.ts +9 -0
- package/dist/tests/e2e/compile-node-require.test.js +29 -0
- package/dist/tests/e2e/compile-node-require.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-stats.test.d.ts +8 -0
- package/dist/tests/e2e/compile-node-stats.test.js +26 -0
- package/dist/tests/e2e/compile-node-stats.test.js.map +1 -0
- package/dist/tests/e2e/compile-proxy.test.d.ts +6 -0
- package/dist/tests/e2e/compile-proxy.test.js +66 -0
- package/dist/tests/e2e/compile-proxy.test.js.map +1 -0
- package/dist/tests/e2e/compile-web-globals.test.d.ts +6 -0
- package/dist/tests/e2e/compile-web-globals.test.js +94 -0
- package/dist/tests/e2e/compile-web-globals.test.js.map +1 -0
- package/dist/tests/e2e/fetch.test.js +1 -1
- package/dist/tests/e2e/gui-script-import-order.test.js +24 -0
- package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +6 -0
- package/dist/tests/e2e/harness.js +13 -1
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/json-stringify-to-json.test.d.ts +10 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js +61 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js.map +1 -0
- package/dist/tests/e2e/node-crypto-random.test.d.ts +8 -0
- package/dist/tests/e2e/node-crypto-random.test.js +148 -0
- package/dist/tests/e2e/node-crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +1 -1
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/node-process.test.d.ts +7 -0
- package/dist/tests/e2e/node-process.test.js +50 -0
- package/dist/tests/e2e/node-process.test.js.map +1 -0
- package/dist/tests/e2e/runtime-coverage-buffer.test.js +31 -0
- package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.d.ts +8 -0
- package/dist/tests/e2e/web-streams.test.js +289 -0
- package/dist/tests/e2e/web-streams.test.js.map +1 -0
- package/dist/tests/e2e/web-worker.test.d.ts +7 -0
- package/dist/tests/e2e/web-worker.test.js +74 -0
- package/dist/tests/e2e/web-worker.test.js.map +1 -0
- package/dist/tests/e2e/webassembly.test.d.ts +8 -0
- package/dist/tests/e2e/webassembly.test.js +113 -0
- package/dist/tests/e2e/webassembly.test.js.map +1 -0
- package/dist/tests/e2e/worker-api.test.d.ts +14 -0
- package/dist/tests/e2e/worker-api.test.js +460 -0
- package/dist/tests/e2e/worker-api.test.js.map +1 -0
- package/dist/tests/e2e/worker-threads.test.d.ts +8 -0
- package/dist/tests/e2e/worker-threads.test.js +160 -0
- package/dist/tests/e2e/worker-threads.test.js.map +1 -0
- package/dist/tests/extensions/wasm.test.d.ts +1 -0
- package/dist/tests/extensions/wasm.test.js +53 -0
- package/dist/tests/extensions/wasm.test.js.map +1 -0
- package/dist/tests/parser/literals.test.js +19 -0
- package/dist/tests/parser/literals.test.js.map +1 -1
- package/dist/tests/parser/statements.test.js +13 -0
- package/dist/tests/parser/statements.test.js.map +1 -1
- package/doc/ai/cli.md +2 -1
- package/doc/ai/contributing.md +11 -4
- package/doc/ai/extensions.md +25 -2
- package/doc/ai/language-support.md +14 -2
- package/doc/ai/zh-CN/cli.md +2 -1
- package/doc/ai/zh-CN/contributing.md +8 -3
- package/doc/ai/zh-CN/extensions.md +23 -2
- package/doc/ai/zh-CN/language-support.md +13 -2
- package/doc/gui/api.md +1 -1
- package/doc/implemented/binder.md +2 -1
- package/doc/implemented/checker.md +5 -0
- package/doc/implemented/cli.md +1 -1
- package/doc/implemented/extensions.md +6 -5
- package/doc/implemented/lexer.md +1 -1
- package/doc/implemented/modules.md +23 -1
- package/doc/implemented/node/buffer.md +18 -5
- package/doc/implemented/node/fs.md +22 -1
- package/doc/implemented/node/process.md +65 -5
- package/doc/implemented/node/stream-web.md +31 -0
- package/doc/implemented/node/worker-threads.md +88 -5
- package/doc/implemented/node.md +9 -2
- package/doc/implemented/operators.md +3 -1
- package/doc/implemented/parser.md +1 -1
- package/doc/implemented/runtime-core.md +6 -2
- package/doc/implemented/stdlib.md +69 -2
- package/doc/implemented/streams.md +82 -0
- package/doc/implemented/wasm.md +80 -18
- package/doc/implemented/web-worker.md +84 -0
- package/doc/implemented.md +6 -2
- package/doc/unimplemented/classes.md +1 -0
- package/doc/unimplemented/deviations.md +1 -0
- package/doc/unimplemented/modules.md +1 -0
- package/doc/unimplemented/node/worker-threads.md +23 -0
- package/doc/unimplemented/node.md +1 -0
- package/doc/unimplemented/stdlib.md +3 -1
- package/doc/unimplemented/wasm.md +21 -9
- package/doc/unimplemented.md +1 -1
- package/doc/xbintsc.config.schema.json +5 -0
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +3 -0
- package/doc/zh-CN/implemented/cli.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +7 -6
- package/doc/zh-CN/implemented/lexer.md +1 -1
- package/doc/zh-CN/implemented/modules.md +17 -1
- package/doc/zh-CN/implemented/node/buffer.md +3 -1
- package/doc/zh-CN/implemented/node/fs.md +19 -1
- package/doc/zh-CN/implemented/node/process.md +59 -5
- package/doc/zh-CN/implemented/node/stream-web.md +24 -0
- package/doc/zh-CN/implemented/node/worker-threads.md +77 -4
- package/doc/zh-CN/implemented/node.md +3 -2
- package/doc/zh-CN/implemented/operators.md +2 -1
- package/doc/zh-CN/implemented/parser.md +1 -1
- package/doc/zh-CN/implemented/runtime-core.md +3 -2
- package/doc/zh-CN/implemented/stdlib.md +58 -2
- package/doc/zh-CN/implemented/streams.md +60 -0
- package/doc/zh-CN/implemented/wasm.md +73 -16
- package/doc/zh-CN/implemented/web-worker.md +79 -0
- package/doc/zh-CN/implemented.md +6 -2
- package/doc/zh-CN/unimplemented/classes.md +1 -0
- package/doc/zh-CN/unimplemented/deviations.md +1 -0
- package/doc/zh-CN/unimplemented/modules.md +1 -0
- package/doc/zh-CN/unimplemented/node/worker-threads.md +20 -0
- package/doc/zh-CN/unimplemented/node.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +3 -1
- package/doc/zh-CN/unimplemented/wasm.md +16 -8
- package/doc/zh-CN/unimplemented.md +1 -1
- package/llms.txt +2 -0
- package/package.json +8 -7
- package/runtime/ext_gui/browser.cpp +1 -1
- package/runtime/ext_node/buffer/buffer.c +5 -4
- package/runtime/ext_node/buffer/parts/byte-access.inc +115 -11
- package/runtime/ext_node/buffer/parts/prototype.inc +4 -1
- package/runtime/ext_node/events/events.c +9 -0
- package/runtime/ext_node/fs/callbacks.c +138 -0
- package/runtime/ext_node/fs/fs_ops.c +28 -15
- package/runtime/ext_node/module/module.c +18 -9
- package/runtime/ext_node/process/process.c +117 -32
- package/runtime/ext_node/process/streams.c +370 -0
- package/runtime/ext_node/process/streams.h +20 -0
- package/runtime/ext_node/stream_web/stream_web.c +20 -6
- package/runtime/rt.h +36 -0
- package/runtime/rt_internal.h +10 -10
- package/runtime/worker/worker_api.c +422 -0
- package/runtime/worker/worker_codec.c +489 -0
- package/runtime/worker/worker_core.c +445 -0
- package/runtime/worker/worker_internal.h +223 -0
- package/runtime/worker/worker_platform.c +344 -0
- package/runtime/worker/worker_ports.c +203 -0
- package/runtime/worker/worker_transport.c +464 -0
- package/runtime/worker/worker_wire.c +150 -0
- package/runtime/xt_alloc.c +67 -49
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +41 -23
- package/runtime/xt_constructors.c +148 -2
- package/runtime/xt_containers/access.inc +29 -1
- package/runtime/xt_containers/function_prototypes.inc +58 -0
- package/runtime/xt_containers/objects.inc +18 -2
- package/runtime/xt_containers.c +1 -0
- package/runtime/xt_exit.c +34 -0
- package/runtime/xt_fetch/headers.inc +1 -0
- package/runtime/xt_fetch/response.inc +28 -8
- package/runtime/xt_fetch/webapi.inc +82 -0
- package/runtime/xt_fetch.c +5 -0
- package/runtime/xt_gc_verify.c +135 -0
- package/runtime/xt_intl.c +224 -0
- package/runtime/xt_io/exception.inc +40 -1
- package/runtime/xt_module_values.c +82 -0
- package/runtime/xt_proxy.c +140 -0
- package/runtime/xt_stdlib/dispatch.inc +98 -9
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/error.inc +4 -0
- package/runtime/xt_stdlib2/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +70 -53
- package/runtime/xt_streams/common.inc +232 -0
- package/runtime/xt_streams/constructors.inc +232 -0
- package/runtime/xt_streams/encoding.inc +124 -0
- package/runtime/xt_streams/readable-extra.inc +372 -0
- package/runtime/xt_streams/readable.inc +415 -0
- package/runtime/xt_streams/transform.inc +195 -0
- package/runtime/xt_streams/writable.inc +542 -0
- package/runtime/xt_streams.c +30 -0
- package/runtime/xt_wasm/wasm.h +148 -0
- package/runtime/xt_wasm/wasm_api.c +357 -0
- package/runtime/xt_wasm/wasm_api.h +37 -0
- package/runtime/xt_wasm/wasm_bridge.c +30 -0
- package/runtime/xt_wasm/wasm_instance.c +591 -0
- package/runtime/xt_wasm/wasm_module.c +270 -0
- package/runtime/xt_wasm/wasm_values.c +177 -0
- package/runtime/xt_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/runtime/xt_webassembly.c +15 -4
- package/scripts/build-runtime.ts +8 -0
- package/scripts/fetch-vendored.ts +187 -20
- package/scripts/package-release.ts +3 -2
- package/src/binder/declarations.ts +34 -0
- package/src/binder/references.ts +12 -0
- package/src/checker/globals.ts +1 -0
- package/src/checker/type-system.ts +23 -3
- package/src/cli/extensions.ts +11 -3
- package/src/cli/help.ts +1 -1
- package/src/codegen/generator/calls/access.ts +23 -0
- package/src/codegen/generator/calls/invocation.ts +12 -0
- package/src/codegen/generator/calls/super.ts +5 -4
- package/src/codegen/generator/calls/unwrap.ts +47 -0
- package/src/codegen/generator/expressions/assignment.ts +15 -0
- package/src/codegen/generator/expressions/module-values.ts +57 -19
- package/src/codegen/generator/expressions/primary.ts +9 -9
- package/src/codegen/generator/generator.ts +4 -0
- package/src/codegen/generator/lookup-tables.ts +63 -0
- package/src/codegen/generator/module.ts +38 -7
- package/src/codegen/generator/state.ts +24 -0
- package/src/codegen/generator/tables.ts +37 -13
- package/src/driver/bundler/commonjs.ts +12 -5
- package/src/driver/bundler/concatenate.ts +84 -7
- package/src/driver/bundler/deferred.ts +122 -6
- package/src/driver/bundler/dynamic-import.ts +75 -2
- package/src/driver/bundler/graph.ts +11 -7
- package/src/driver/bundler/merge.ts +31 -5
- package/src/driver/bundler/namespace-object.ts +44 -0
- package/src/driver/bundler/reexport-resolution.ts +12 -2
- package/src/driver/bundler/symbols.ts +17 -0
- package/src/driver/config.ts +1 -1
- package/src/driver/fingerprint.ts +3 -3
- package/src/driver/link-features.ts +1 -1
- package/src/driver/options.ts +1 -4
- package/src/driver/paths.ts +8 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +37 -6
- package/src/driver/version.ts +1 -1
- package/src/extensions/catalog.ts +5 -1
- package/src/extensions/gui/index.ts +0 -1
- package/src/extensions/link-feature.ts +8 -0
- package/src/extensions/node/buffer/index.ts +5 -4
- package/src/extensions/node/events/index.ts +8 -1
- package/src/extensions/node/fs/callbacks.ts +45 -0
- package/src/extensions/node/fs/index.ts +11 -4
- package/src/extensions/node/process/index.ts +30 -5
- package/src/extensions/node/stream-web/index.ts +59 -4
- package/src/extensions/node/worker_threads/index.ts +24 -11
- package/src/extensions/registry.ts +34 -6
- package/src/extensions/wasm-asset.ts +32 -0
- package/src/extensions/wasm.ts +74 -0
- package/src/extensions/webworker/index.ts +58 -0
- package/src/index.ts +1 -0
- package/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/literals.ts +6 -2
- package/vendor/wasm3/.pin +1 -0
- package/vendor/wasm3/LICENSE +21 -0
- package/vendor/wasm3/m3_api_libc.c +265 -0
- package/vendor/wasm3/m3_api_libc.h +19 -0
- package/vendor/wasm3/m3_api_meta_wasi.c +1107 -0
- package/vendor/wasm3/m3_api_tracer.c +173 -0
- package/vendor/wasm3/m3_api_tracer.h +19 -0
- package/vendor/wasm3/m3_api_uvwasi.c +1290 -0
- package/vendor/wasm3/m3_api_wasi.c +1207 -0
- package/vendor/wasm3/m3_api_wasi.h +74 -0
- package/vendor/wasm3/m3_api_wasi_host.h +137 -0
- package/vendor/wasm3/m3_api_wasi_posix.h +979 -0
- package/vendor/wasm3/m3_api_wasi_win32.h +1093 -0
- package/vendor/wasm3/m3_atomic.h +114 -0
- package/vendor/wasm3/m3_bind.c +174 -0
- package/vendor/wasm3/m3_bind.h +20 -0
- package/vendor/wasm3/m3_code.c +232 -0
- package/vendor/wasm3/m3_code.h +74 -0
- package/vendor/wasm3/m3_compile.c +6603 -0
- package/vendor/wasm3/m3_compile.h +354 -0
- package/vendor/wasm3/m3_config.h +448 -0
- package/vendor/wasm3/m3_config_platforms.h +345 -0
- package/vendor/wasm3/m3_core.c +1034 -0
- package/vendor/wasm3/m3_core.h +526 -0
- package/vendor/wasm3/m3_deterministic.c +65 -0
- package/vendor/wasm3/m3_deterministic.h +59 -0
- package/vendor/wasm3/m3_env.c +3146 -0
- package/vendor/wasm3/m3_env.h +748 -0
- package/vendor/wasm3/m3_exception.h +33 -0
- package/vendor/wasm3/m3_exec.c +8 -0
- package/vendor/wasm3/m3_exec.h +4110 -0
- package/vendor/wasm3/m3_exec_atomic.h +146 -0
- package/vendor/wasm3/m3_exec_defs.h +76 -0
- package/vendor/wasm3/m3_function.c +278 -0
- package/vendor/wasm3/m3_function.h +244 -0
- package/vendor/wasm3/m3_host.h +226 -0
- package/vendor/wasm3/m3_host_none.h +76 -0
- package/vendor/wasm3/m3_host_posix.h +543 -0
- package/vendor/wasm3/m3_host_win32.h +253 -0
- package/vendor/wasm3/m3_info.c +616 -0
- package/vendor/wasm3/m3_info.h +38 -0
- package/vendor/wasm3/m3_math_utils.h +560 -0
- package/vendor/wasm3/m3_module.c +431 -0
- package/vendor/wasm3/m3_parse.c +1549 -0
- package/vendor/wasm3/m3_snapshot.c +3825 -0
- package/vendor/wasm3/m3_validate.c +1770 -0
- package/vendor/wasm3/m3_validate.h +25 -0
- package/vendor/wasm3/m3_wasi.h +10 -0
- package/vendor/wasm3/m3_xxh64.c +211 -0
- package/vendor/wasm3/wasm3.h +684 -0
- package/vendor/wasm3/wasm3_defs.h +350 -0
- package/runtime/ext_node/worker_threads/worker_threads.c +0 -214
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
* vendor/nanosvg/nanosvg.h, nanosvgrast.h
|
|
15
15
|
* vendor/miniz/… the `compression` link feature
|
|
16
16
|
* vendor/sqlite3/sqlite3.{c,h} the `storage` link feature
|
|
17
|
+
* vendor/wasm3/… the `wasm` link feature
|
|
17
18
|
*
|
|
18
19
|
* `build-gui.ts` fetches just `stb`/`nanosvg`; `npm test` fetches everything.
|
|
19
|
-
* CI caches the
|
|
20
|
+
* CI caches the fetched directories keyed on this script.
|
|
20
21
|
*
|
|
21
22
|
* Note: miniz's upstream tree has no `miniz_export.h` (its CMake build generates
|
|
22
23
|
* one). The static-only shim below is written here rather than tracked.
|
|
@@ -24,22 +25,22 @@
|
|
|
24
25
|
* Run via `npm run vendor` (or `tsx scripts/fetch-vendored.ts`).
|
|
25
26
|
*/
|
|
26
27
|
|
|
27
|
-
import { spawnSync } from "node:child_process";
|
|
28
28
|
import { createHash } from "node:crypto";
|
|
29
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
30
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
29
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
30
|
+
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
31
31
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
32
|
+
import { gunzipSync, inflateRawSync } from "node:zlib";
|
|
32
33
|
import { downloadTarball } from "./fetch-tarball.js";
|
|
33
34
|
|
|
34
35
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
35
36
|
export const vendorDir = join(root, "vendor");
|
|
36
37
|
|
|
37
38
|
/** The vendored packages, each a directory under `vendor/`. */
|
|
38
|
-
export const VENDOR_PACKAGES = ["stb", "nanosvg", "miniz", "sqlite3"] as const;
|
|
39
|
+
export const VENDOR_PACKAGES = ["stb", "nanosvg", "miniz", "sqlite3", "wasm3"] as const;
|
|
39
40
|
export type VendorPackage = (typeof VENDOR_PACKAGES)[number];
|
|
40
41
|
|
|
41
42
|
interface VendoredFile {
|
|
42
|
-
readonly package: Exclude<VendorPackage, "sqlite3">;
|
|
43
|
+
readonly package: Exclude<VendorPackage, "sqlite3" | "wasm3">;
|
|
43
44
|
readonly name: string;
|
|
44
45
|
readonly url: string;
|
|
45
46
|
readonly sha256: string;
|
|
@@ -122,6 +123,15 @@ const SQLITE_FILES = [
|
|
|
122
123
|
},
|
|
123
124
|
] as const;
|
|
124
125
|
|
|
126
|
+
/* wasm3's interpreter is fetched as one commit archive: its `source/` tree is
|
|
127
|
+
* small but the headers and the `.c` files have to stay in lockstep, so a
|
|
128
|
+
* single pinned tarball is the reviewable unit. Only `source/` and the license
|
|
129
|
+
* are copied out; the archive's tools, tests and examples are not compiled. */
|
|
130
|
+
const WASM3_COMMIT = "28ecb9af6d2040e474a70f7cb7f43666740141fb";
|
|
131
|
+
const WASM3_TARBALL_URL = `https://github.com/wasm3/wasm3/archive/${WASM3_COMMIT}.tar.gz`;
|
|
132
|
+
const WASM3_TARBALL_SHA256 = "5ecbb8851bd9acb54a83be10f0536167cb0da13b007406578761672b0bd94b18";
|
|
133
|
+
const WASM3_PIN = `${WASM3_COMMIT} ${WASM3_TARBALL_SHA256}\n`;
|
|
134
|
+
|
|
125
135
|
function sha256(file: string): string {
|
|
126
136
|
return createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
127
137
|
}
|
|
@@ -154,22 +164,68 @@ function ensureMinizExportHeader(): void {
|
|
|
154
164
|
writeFileSync(target, MINIZ_EXPORT_H);
|
|
155
165
|
}
|
|
156
166
|
|
|
157
|
-
/**
|
|
167
|
+
/** A 32-bit little-endian field of a zip record. */
|
|
168
|
+
function zipU32(bytes: Uint8Array, offset: number): number {
|
|
169
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(offset, true);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A 16-bit little-endian field of a zip record. */
|
|
173
|
+
function zipU16(bytes: Uint8Array, offset: number): number {
|
|
174
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint16(offset, true);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Extract a zip archive in Node.
|
|
179
|
+
*
|
|
180
|
+
* An external `unzip`/`tar` is not guaranteed on every runner image, and a CI
|
|
181
|
+
* cache miss (for example after editing this script) must not turn a missing
|
|
182
|
+
* shell tool into a failed job. The central directory is the authoritative
|
|
183
|
+
* index, so it is read instead of walking local headers; stored and deflated
|
|
184
|
+
* entries cover the pinned SQLite amalgamation. Contents are pinned by SHA-256
|
|
185
|
+
* after extraction, which is why the CRC is not rechecked here.
|
|
186
|
+
*/
|
|
158
187
|
function extractZip(zip: string, destination: string): void {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
188
|
+
const archive = readFileSync(zip);
|
|
189
|
+
const SIGNATURE_EOCD = 0x06054b50;
|
|
190
|
+
const SIGNATURE_CENTRAL = 0x02014b50;
|
|
191
|
+
let eocd = -1;
|
|
192
|
+
for (let offset = archive.length - 22; offset >= 0 && offset >= archive.length - 65557; offset--) {
|
|
193
|
+
if (zipU32(archive, offset) === SIGNATURE_EOCD) {
|
|
194
|
+
eocd = offset;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (eocd < 0) throw new Error(`${basename(zip)}: not a zip archive`);
|
|
199
|
+
const count = zipU16(archive, eocd + 10);
|
|
200
|
+
let offset = zipU32(archive, eocd + 16);
|
|
201
|
+
for (let index = 0; index < count; index++) {
|
|
202
|
+
if (zipU32(archive, offset) !== SIGNATURE_CENTRAL) {
|
|
203
|
+
throw new Error(`${basename(zip)}: corrupt central directory`);
|
|
204
|
+
}
|
|
205
|
+
const method = zipU16(archive, offset + 10);
|
|
206
|
+
const compressedSize = zipU32(archive, offset + 20);
|
|
207
|
+
const nameLength = zipU16(archive, offset + 28);
|
|
208
|
+
const extraLength = zipU16(archive, offset + 30);
|
|
209
|
+
const commentLength = zipU16(archive, offset + 32);
|
|
210
|
+
const localOffset = zipU32(archive, offset + 42);
|
|
211
|
+
const name = Buffer.from(archive.subarray(offset + 46, offset + 46 + nameLength)).toString("utf8");
|
|
212
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
213
|
+
if (name.endsWith("/")) continue;
|
|
214
|
+
const localNameLength = zipU16(archive, localOffset + 26);
|
|
215
|
+
const localExtraLength = zipU16(archive, localOffset + 28);
|
|
216
|
+
const dataStart = localOffset + 30 + localNameLength + localExtraLength;
|
|
217
|
+
const payload = archive.subarray(dataStart, dataStart + compressedSize);
|
|
218
|
+
let content: Buffer;
|
|
219
|
+
if (method === 0) content = Buffer.from(payload);
|
|
220
|
+
else if (method === 8) content = inflateRawSync(payload);
|
|
221
|
+
else throw new Error(`${basename(zip)}: unsupported compression method ${method}`);
|
|
222
|
+
const target = resolve(destination, name);
|
|
223
|
+
if (target !== destination && !target.startsWith(`${destination}${sep}`)) {
|
|
224
|
+
throw new Error(`refusing to extract ${name} outside ${destination}`);
|
|
225
|
+
}
|
|
226
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
227
|
+
writeFileSync(target, content);
|
|
171
228
|
}
|
|
172
|
-
throw new Error(`cannot extract ${basename(zip)}; install unzip (or a tar that reads zip archives)`);
|
|
173
229
|
}
|
|
174
230
|
|
|
175
231
|
/** Fetch the pinned SQLite amalgamation and copy out its two sources. */
|
|
@@ -213,6 +269,113 @@ function ensureSqlite(): void {
|
|
|
213
269
|
rmSync(zip, { force: true });
|
|
214
270
|
}
|
|
215
271
|
|
|
272
|
+
/** Read a NUL/space-padded text field out of a tar block. */
|
|
273
|
+
function tarText(bytes: Uint8Array, start: number, length: number): string {
|
|
274
|
+
let end = start;
|
|
275
|
+
while (end < start + length && bytes[end] !== 0) end++;
|
|
276
|
+
return Buffer.from(bytes.subarray(start, end)).toString("utf8").replace(/\s+$/, "");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Read an octal field (tar pads it with spaces and/or NULs). */
|
|
280
|
+
function tarSize(bytes: Uint8Array, start: number, length: number): number {
|
|
281
|
+
const text = tarText(bytes, start, length);
|
|
282
|
+
return text.length === 0 ? 0 : parseInt(text, 8);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Extract selected members of a gzip-compressed tarball.
|
|
287
|
+
*
|
|
288
|
+
* An external `tar` is not reliable here: an older bsdtar on the Windows
|
|
289
|
+
* runners rejects this archive, and a runner image may not ship `tar` at all.
|
|
290
|
+
* Node's gzip decoder plus a minimal ustar reader keeps a cache miss working —
|
|
291
|
+
* the GitHub archive is plain ustar. Only regular files under the named members
|
|
292
|
+
* are written; directories, symlinks and the other repository trees are
|
|
293
|
+
* skipped (which is also why the wasm3 archive's platform symlinks cannot
|
|
294
|
+
* break extraction).
|
|
295
|
+
*/
|
|
296
|
+
function extractTarball(tarball: string, destination: string, members: readonly string[]): void {
|
|
297
|
+
const archive = gunzipSync(readFileSync(tarball));
|
|
298
|
+
const wanted = (path: string): boolean =>
|
|
299
|
+
members.some((member) => path === member || path.startsWith(`${member}/`));
|
|
300
|
+
let offset = 0;
|
|
301
|
+
while (offset + 512 <= archive.length) {
|
|
302
|
+
const header = archive.subarray(offset, offset + 512);
|
|
303
|
+
/* Two zero blocks mark the end of the archive; one is enough to stop. */
|
|
304
|
+
if (header.every((byte) => byte === 0)) return;
|
|
305
|
+
const name = tarText(header, 0, 100);
|
|
306
|
+
const prefix = tarText(header, 345, 155);
|
|
307
|
+
const type = header[156] === 0 ? "0" : String.fromCharCode(header[156]);
|
|
308
|
+
const size = tarSize(header, 124, 12);
|
|
309
|
+
const path = prefix.length > 0 ? `${prefix}/${name}` : name;
|
|
310
|
+
const dataStart = offset + 512;
|
|
311
|
+
const next = dataStart + Math.ceil(size / 512) * 512;
|
|
312
|
+
if ((type === "0" || type === "7") && wanted(path)) {
|
|
313
|
+
const target = resolve(destination, path);
|
|
314
|
+
if (target !== destination && !target.startsWith(`${destination}${sep}`)) {
|
|
315
|
+
throw new Error(`refusing to extract ${path} outside ${destination}`);
|
|
316
|
+
}
|
|
317
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
318
|
+
writeFileSync(target, archive.subarray(dataStart, dataStart + size));
|
|
319
|
+
}
|
|
320
|
+
offset = next;
|
|
321
|
+
}
|
|
322
|
+
throw new Error(`${basename(tarball)}: truncated tar archive`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Fetch the pinned wasm3 archive and copy its interpreter sources into
|
|
327
|
+
* `vendor/wasm3`. A `.pin` marker records the commit and tarball hash, so an
|
|
328
|
+
* already-fetched tree is reused without touching the network and a changed
|
|
329
|
+
* pin re-extracts instead of silently mixing revisions.
|
|
330
|
+
*/
|
|
331
|
+
function ensureWasm3(): void {
|
|
332
|
+
const directory = join(vendorDir, "wasm3");
|
|
333
|
+
const pin = join(directory, ".pin");
|
|
334
|
+
if (
|
|
335
|
+
existsSync(join(directory, "wasm3.h")) &&
|
|
336
|
+
existsSync(pin) &&
|
|
337
|
+
readFileSync(pin, "utf8").replace(/\r\n/g, "\n") === WASM3_PIN
|
|
338
|
+
) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const cache = join(vendorDir, ".cache");
|
|
343
|
+
mkdirSync(cache, { recursive: true });
|
|
344
|
+
const tarball = join(cache, `wasm3-${WASM3_COMMIT}.tar.gz`);
|
|
345
|
+
if (!isPinned(tarball, WASM3_TARBALL_SHA256)) {
|
|
346
|
+
rmSync(tarball, { force: true });
|
|
347
|
+
downloadTarball(tarball, WASM3_TARBALL_URL, `wasm3-${WASM3_COMMIT}.tar.gz`);
|
|
348
|
+
if (!isPinned(tarball, WASM3_TARBALL_SHA256)) {
|
|
349
|
+
const actual = sha256(tarball);
|
|
350
|
+
rmSync(tarball, { force: true });
|
|
351
|
+
throw new Error(`wasm3-${WASM3_COMMIT}.tar.gz: expected sha256 ${WASM3_TARBALL_SHA256}, got ${actual}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const extracted = join(cache, `wasm3-${WASM3_COMMIT}`);
|
|
356
|
+
rmSync(extracted, { recursive: true, force: true });
|
|
357
|
+
mkdirSync(extracted, { recursive: true });
|
|
358
|
+
const archiveRoot = `wasm3-${WASM3_COMMIT}`;
|
|
359
|
+
extractTarball(tarball, extracted, [`${archiveRoot}/source`, `${archiveRoot}/LICENSE`]);
|
|
360
|
+
const sourceDir = join(extracted, archiveRoot, "source");
|
|
361
|
+
if (!existsSync(join(sourceDir, "wasm3.h"))) {
|
|
362
|
+
throw new Error(`expected ${archiveRoot}/source/wasm3.h after extracting the archive`);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
rmSync(directory, { recursive: true, force: true });
|
|
366
|
+
mkdirSync(directory, { recursive: true });
|
|
367
|
+
for (const entry of readdirSync(sourceDir, { withFileTypes: true })) {
|
|
368
|
+
if (!entry.isFile()) continue;
|
|
369
|
+
if (!entry.name.endsWith(".c") && !entry.name.endsWith(".h")) continue;
|
|
370
|
+
copyFileSync(join(sourceDir, entry.name), join(directory, entry.name));
|
|
371
|
+
}
|
|
372
|
+
const license = join(extracted, `wasm3-${WASM3_COMMIT}`, "LICENSE");
|
|
373
|
+
if (existsSync(license)) copyFileSync(license, join(directory, "LICENSE"));
|
|
374
|
+
writeFileSync(pin, WASM3_PIN);
|
|
375
|
+
rmSync(extracted, { recursive: true, force: true });
|
|
376
|
+
rmSync(tarball, { force: true });
|
|
377
|
+
}
|
|
378
|
+
|
|
216
379
|
/**
|
|
217
380
|
* Ensure the requested vendored packages exist and match their pins.
|
|
218
381
|
* Downloads only what is missing; everything else is a content check.
|
|
@@ -223,6 +386,10 @@ export function ensureVendoredSources(packages: readonly VendorPackage[] = VENDO
|
|
|
223
386
|
ensureSqlite();
|
|
224
387
|
continue;
|
|
225
388
|
}
|
|
389
|
+
if (name === "wasm3") {
|
|
390
|
+
ensureWasm3();
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
226
393
|
for (const file of FILES) {
|
|
227
394
|
if (file.package === name) ensureFile(file);
|
|
228
395
|
}
|
|
@@ -110,8 +110,9 @@ cpSync(findRuntimeDir(), join(stage, "runtime"), { recursive: true });
|
|
|
110
110
|
console.log("xbintsc: packaged runtime/");
|
|
111
111
|
|
|
112
112
|
// 3. Vendored sources the driver compiles on demand (SQLite for `storage`,
|
|
113
|
-
// miniz for `compression`). They are fetched by `npm run vendor`,
|
|
114
|
-
|
|
113
|
+
// miniz for `compression`, wasm3 for `wasm`). They are fetched by `npm run vendor`,
|
|
114
|
+
// not committed.
|
|
115
|
+
for (const name of ["stb", "nanosvg", "miniz", "sqlite3", "wasm3"]) {
|
|
115
116
|
const source = join(root, "vendor", name);
|
|
116
117
|
if (!existsSync(source)) fail(`missing vendor/${name}; run \`npm run vendor\` before packaging`);
|
|
117
118
|
cpSync(source, join(stage, "vendor", name), { recursive: true });
|
|
@@ -92,6 +92,7 @@ export interface DeclarationMethods {
|
|
|
92
92
|
predeclareVariableList(this: Binder, list: VariableDeclarationList, scope: Scope): void;
|
|
93
93
|
predeclareImport(this: Binder, node: ImportDeclaration, scope: Scope): void;
|
|
94
94
|
collectFunctionScoped(this: Binder, statements: readonly Statement[], fn: MutableFunction): void;
|
|
95
|
+
reuseHoistedVar(this: Binder, name: BindingName, scope: Scope): boolean;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
export const declarationMethods: DeclarationMethods = {
|
|
@@ -215,10 +216,43 @@ export const declarationMethods: DeclarationMethods = {
|
|
|
215
216
|
? SymbolKind.Var
|
|
216
217
|
: SymbolKind.Let;
|
|
217
218
|
for (const declaration of list.declarations) {
|
|
219
|
+
if (kind === SymbolKind.Var) {
|
|
220
|
+
if (this.reuseHoistedVar(declaration.name, scope)) continue;
|
|
221
|
+
/* `var` is function scoped even when the declaration sits in a block
|
|
222
|
+
* or in a `for` head, so it always lands in the function scope. */
|
|
223
|
+
this.declareBinding(declaration.name, kind, declaration, scope.fn.scope ?? scope, true);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
218
226
|
this.declareBinding(declaration.name, kind, declaration, scope, kind !== SymbolKind.Const);
|
|
219
227
|
}
|
|
220
228
|
},
|
|
221
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Point a `var` declaration that sits in a nested block (or in a `for` head)
|
|
232
|
+
* at the symbol `collectFunctionScoped` already hoisted into the function
|
|
233
|
+
* scope. Declaring it again in the block would *shadow* the hoisted name, so
|
|
234
|
+
* `{ var x = 1 }` would write a block-local `x` the rest of the function
|
|
235
|
+
* never sees — the bug behind `if (c) { var label = "big" }` losing its
|
|
236
|
+
* value in minified bundles.
|
|
237
|
+
*/
|
|
238
|
+
reuseHoistedVar(name: BindingName, scope: Scope): boolean {
|
|
239
|
+
const functionScope = scope.fn.scope;
|
|
240
|
+
if (functionScope === undefined || scope === functionScope) return false;
|
|
241
|
+
if (name.kind === SyntaxKind.Identifier) {
|
|
242
|
+
const hoisted = functionScope.symbols.get(name.text);
|
|
243
|
+
if (!hoisted || hoisted.kind !== SymbolKind.Var) return false;
|
|
244
|
+
this.symbolOfDeclaration.set(name, hoisted);
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
const pattern = name as ArrayBindingPattern | ObjectBindingPattern;
|
|
248
|
+
let reused = true;
|
|
249
|
+
for (const element of pattern.elements) {
|
|
250
|
+
if (!element) continue;
|
|
251
|
+
if (!this.reuseHoistedVar(element.name, scope)) reused = false;
|
|
252
|
+
}
|
|
253
|
+
return reused;
|
|
254
|
+
},
|
|
255
|
+
|
|
222
256
|
predeclareImport(node: ImportDeclaration, scope: Scope): void {
|
|
223
257
|
const clause = node.importClause;
|
|
224
258
|
if (!clause) return;
|
package/src/binder/references.ts
CHANGED
|
@@ -339,6 +339,12 @@ export const referenceMethods: ReferenceMethods = {
|
|
|
339
339
|
const paramSymbol = this.declareBinding(parameter.name, SymbolKind.Parameter, parameter, scope, true);
|
|
340
340
|
if (paramSymbol) params.push(paramSymbol);
|
|
341
341
|
if (parameter.initializer) this.bindNode(parameter.initializer, scope);
|
|
342
|
+
/* A destructuring parameter binds its names through `declareBinding`
|
|
343
|
+
* above, but the *default values* inside the pattern are expressions:
|
|
344
|
+
* `({ noNewArrows = !(e => e) })` contains an arrow that has to get a
|
|
345
|
+
* FunctionInfo of its own, or codegen reports "does not yet support this
|
|
346
|
+
* closure". */
|
|
347
|
+
this.bindBindingPattern(parameter.name, scope);
|
|
342
348
|
}
|
|
343
349
|
(fn as { params: SymbolInfo[] }).params = params;
|
|
344
350
|
|
|
@@ -402,6 +408,12 @@ export const referenceMethods: ReferenceMethods = {
|
|
|
402
408
|
|
|
403
409
|
const classScope = this.createScope(ScopeKind.Block, node, scope);
|
|
404
410
|
this.scopes.set(node, classScope);
|
|
411
|
+
/* A class *expression* binds its own name inside the class body only: the
|
|
412
|
+
* enclosing scope never sees it (`const A = class Inner { m() { return Inner } }`).
|
|
413
|
+
* A declaration's name already lives in the enclosing scope. */
|
|
414
|
+
if (node.kind === SyntaxKind.ClassExpression && node.name && !classScope.symbols.has(node.name.text)) {
|
|
415
|
+
this.declare(node.name.text, SymbolKind.Class, node, classScope, false);
|
|
416
|
+
}
|
|
405
417
|
|
|
406
418
|
let constructor: FunctionInfo | undefined;
|
|
407
419
|
/* `static { ... }` functions, so the field pass below can interleave them
|
package/src/checker/globals.ts
CHANGED
|
@@ -68,7 +68,10 @@ type TypeDeclaration =
|
|
|
68
68
|
|
|
69
69
|
/** Resolve type syntax and symbol annotations into the small model above. */
|
|
70
70
|
export class TypeResolver {
|
|
71
|
+
/** Module-scope declarations, visible from every file in the bundle. */
|
|
71
72
|
private readonly declarations = new Map<string, TypeDeclaration | undefined>();
|
|
73
|
+
/** Declarations nested inside a function body, visible only in their file. */
|
|
74
|
+
private readonly localDeclarations = new Map<string, Map<string, TypeDeclaration | undefined>>();
|
|
72
75
|
private readonly symbolTypes = new Map<number, Type>();
|
|
73
76
|
private readonly resolvingSymbols = new Set<number>();
|
|
74
77
|
private readonly resolvingAliases = new Set<string>();
|
|
@@ -116,11 +119,28 @@ export class TypeResolver {
|
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
private addDeclaration(name: string, declaration: TypeDeclaration): void {
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
/* A class declared inside a function body is scoped to that function: a
|
|
123
|
+
* bundled dependency is full of them (`babel.cjs` has its own `class
|
|
124
|
+
* Token`), and treating those as program-wide would hijack a type the
|
|
125
|
+
* importing file meant (`import type { Token } from "marked"`). */
|
|
126
|
+
const symbol = this.binding.symbolOfDeclaration.get(declaration.node);
|
|
127
|
+
if (symbol && !symbol.fn.isModule) {
|
|
128
|
+
const file = this.sourceFile.origins?.get(declaration.node) ?? this.sourceFile.fileName;
|
|
129
|
+
const local = this.localDeclarations.get(file) ?? new Map<string, TypeDeclaration | undefined>();
|
|
130
|
+
this.localDeclarations.set(file, local);
|
|
131
|
+
local.set(name, local.has(name) ? undefined : declaration);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
// A duplicate means bundling made the name ambiguous; `any` is the only safe answer.
|
|
121
135
|
this.declarations.set(name, this.declarations.has(name) ? undefined : declaration);
|
|
122
136
|
}
|
|
123
137
|
|
|
138
|
+
/** The declaration a type reference in `node` names, if one is in scope. */
|
|
139
|
+
private declarationFor(name: string, node: Node): TypeDeclaration | undefined {
|
|
140
|
+
const file = this.sourceFile.origins?.get(node) ?? this.sourceFile.fileName;
|
|
141
|
+
return this.localDeclarations.get(file)?.get(name) ?? this.declarations.get(name);
|
|
142
|
+
}
|
|
143
|
+
|
|
124
144
|
private collectDynamicClasses(): void {
|
|
125
145
|
walk(this.sourceFile, (node) => {
|
|
126
146
|
if (node.kind === SyntaxKind.BinaryExpression) {
|
|
@@ -334,7 +354,7 @@ export class TypeResolver {
|
|
|
334
354
|
if (typeParams.has(name)) return typeParams.get(name)!;
|
|
335
355
|
const builtin = this.builtinType(name, node.typeArguments.map((argument) => this.resolve(argument, typeParams)));
|
|
336
356
|
if (builtin) return builtin;
|
|
337
|
-
const declaration = this.
|
|
357
|
+
const declaration = this.declarationFor(name, node);
|
|
338
358
|
if (!declaration) return { kind: "typeParam", name };
|
|
339
359
|
if (declaration.kind === "interface") return this.interfaceType(declaration.node, node.typeArguments.map((argument) => this.resolve(argument, typeParams)));
|
|
340
360
|
if (declaration.kind === "alias") return this.aliasType(declaration.node, node.typeArguments.map((argument) => this.resolve(argument, typeParams)));
|
package/src/cli/extensions.ts
CHANGED
|
@@ -18,10 +18,18 @@ export function buildRegistry(
|
|
|
18
18
|
): ExtensionRegistry {
|
|
19
19
|
const registry = createDefaultRegistry();
|
|
20
20
|
const bundled = bundledExtensions();
|
|
21
|
+
const requested = new Set(extNames);
|
|
21
22
|
for (const name of extNames) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (!bundled.some((candidate) => candidate.name === name)) {
|
|
24
|
+
throw new Error(`Unknown extension '${name}'`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/* Register in catalog order, not flag order: later extensions override
|
|
28
|
+
* earlier global names (`gui` and `webworker` both define `self`), and a
|
|
29
|
+
* deterministic winner is easier to document than "whatever the user typed
|
|
30
|
+
* last". */
|
|
31
|
+
for (const extension of bundled) {
|
|
32
|
+
if (requested.has(extension.name)) registry.register(extension);
|
|
25
33
|
}
|
|
26
34
|
// Each manifest describes a pre-built C++ or Rust library.
|
|
27
35
|
for (const manifest of nativeManifests) {
|
package/src/cli/help.ts
CHANGED
|
@@ -26,7 +26,7 @@ Options:
|
|
|
26
26
|
--emit <kind> exe | obj | ir (default: exe)
|
|
27
27
|
-O0..-O3 Optimization level (default: -O2)
|
|
28
28
|
--ext <names> Comma separated extensions (e.g. node,gui)
|
|
29
|
-
--feature <names> Force optional link features on (media,gpu,images,shaping,webgl,all)
|
|
29
|
+
--feature <names> Force optional link features on (media,gpu,images,shaping,webgl,storage,tls,wasm,all)
|
|
30
30
|
--no-feature <n> Keep optional link features out even when detected
|
|
31
31
|
--ext-native <m> Register a C++/Rust extension from a JSON manifest
|
|
32
32
|
(comma separated for several)
|
|
@@ -16,6 +16,7 @@ import { i64, numberLiteral, XT_TRUE, XT_UNDEFINED } from "../../values.js";
|
|
|
16
16
|
import { MATH_CONSTANTS, NAMESPACE_PROPERTIES, NUMBER_CONSTANTS, SYMBOL_WELL_KNOWN, TYPED_ARRAYS } from "../tables.js";
|
|
17
17
|
import { isSuperKeyword } from "./super.js";
|
|
18
18
|
import type { Generator } from "../generator.js";
|
|
19
|
+
import { globalObjectReceiver } from "./unwrap.js";
|
|
19
20
|
|
|
20
21
|
export interface AccessCallMethods {
|
|
21
22
|
emitDelete(this: Generator, node: DeleteExpression): string;
|
|
@@ -58,6 +59,28 @@ export const accessCallMethods: AccessCallMethods = {
|
|
|
58
59
|
this.emit(` ${value} = call i64 @xt_get(i64 ${parentProto}, i64 ${key})`);
|
|
59
60
|
return value;
|
|
60
61
|
}
|
|
62
|
+
/* `globalThis.fetch` / `global.Deno`: the global object *is* the global
|
|
63
|
+
* scope, so a *known* global reads as the bare global name. Without this the
|
|
64
|
+
* receiver would be the global bag and every feature probe
|
|
65
|
+
* (`globalThis.Deno ? ... : ...`) would miss the real global. `global` is
|
|
66
|
+
* Node's alias for the same object. Parentheses and `as`/`!` wrappers are
|
|
67
|
+
* transparent here.
|
|
68
|
+
*
|
|
69
|
+
* A name the compiler does not know is an ordinary property read on the
|
|
70
|
+
* global bag instead: `global.gracefulQueue = q` stores there, so
|
|
71
|
+
* `global.gracefulQueue` must read it back (libraries publish state on
|
|
72
|
+
* `global` this way). */
|
|
73
|
+
{
|
|
74
|
+
const receiver = globalObjectReceiver(node.expression);
|
|
75
|
+
if (receiver && !this.binding.symbolOfIdentifier.get(receiver)) {
|
|
76
|
+
/* `globalThis.require` is how bundled CommonJS detects the loader. It is
|
|
77
|
+
* a probe, not a use: an absent global property reads as `undefined`.
|
|
78
|
+
* Only invoking it (`globalThis.require("x")`) is a CommonJS call, and
|
|
79
|
+
* the invocation path reports that. */
|
|
80
|
+
if (node.name.text === "require") return i64(XT_UNDEFINED);
|
|
81
|
+
if (this.globalTypeOf(node.name.text) !== undefined) return this.emitIdentifier(node.name);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
61
84
|
if (
|
|
62
85
|
node.name.text in MATH_CONSTANTS &&
|
|
63
86
|
node.expression.kind === SyntaxKind.Identifier &&
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
NAMESPACE_STATICS,
|
|
26
26
|
} from "../tables.js";
|
|
27
27
|
import { isSuperKeyword } from "./super.js";
|
|
28
|
+
import { globalObjectReceiver } from "./unwrap.js";
|
|
28
29
|
import type { Generator } from "../generator.js";
|
|
29
30
|
|
|
30
31
|
export interface InvocationCallMethods {
|
|
@@ -71,6 +72,14 @@ export const invocationCallMethods: InvocationCallMethods = {
|
|
|
71
72
|
}
|
|
72
73
|
if (callee.kind === SyntaxKind.PropertyAccessExpression) {
|
|
73
74
|
const access = callee as PropertyAccessExpression;
|
|
75
|
+
/* Reading `globalThis.require` is a CommonJS loader probe and reads as
|
|
76
|
+
* `undefined`; calling it is a real CommonJS use, which xbintsc has no
|
|
77
|
+
* runtime for. */
|
|
78
|
+
const globalReceiver = globalObjectReceiver(access.expression);
|
|
79
|
+
if (globalReceiver && !this.binding.symbolOfIdentifier.get(globalReceiver) && access.name.text === "require") {
|
|
80
|
+
this.reportRequireUse(node);
|
|
81
|
+
return i64(XT_UNDEFINED);
|
|
82
|
+
}
|
|
74
83
|
const special = this.tryEmitBuiltinCall(node, access);
|
|
75
84
|
if (special) return special;
|
|
76
85
|
if (isSuperKeyword(access.expression)) return this.emitSuperCall(node, access);
|
|
@@ -244,6 +253,9 @@ export const invocationCallMethods: InvocationCallMethods = {
|
|
|
244
253
|
/** Lower a call to an imported module binding to its runtime symbol. */
|
|
245
254
|
emitModuleExport(node: CallExpression, exported: ModuleExport): string {
|
|
246
255
|
const args = this.emitArguments(node.arguments);
|
|
256
|
+
/* `createRequire(url)` hands back a `require` that answers from the table
|
|
257
|
+
* of modules linked into this binary, so it has to exist first. */
|
|
258
|
+
if (exported.symbol === "xt_module_create_require") this.ensureModuleRegistry();
|
|
247
259
|
if (exported.symbol) {
|
|
248
260
|
this.extraDeclarations.add(
|
|
249
261
|
exported.returnVoid
|
|
@@ -55,12 +55,13 @@ export const superCallMethods: SuperCallMethods = {
|
|
|
55
55
|
this.emit(` ${proto} = call i64 @xt_function_get_prototype(i64 ${owner})`);
|
|
56
56
|
const parentProto = this.reg();
|
|
57
57
|
this.emit(` ${parentProto} = call i64 @xt_object_get_prototype(i64 ${proto})`);
|
|
58
|
-
const key = this.stringValue("__ctor");
|
|
59
|
-
const ctor = this.reg();
|
|
60
|
-
this.emit(` ${ctor} = call i64 @xt_get(i64 ${parentProto}, i64 ${key})`);
|
|
61
58
|
const args = this.emitArguments(node.arguments);
|
|
62
59
|
const result = this.reg();
|
|
63
|
-
|
|
60
|
+
/* The runtime resolves the parent's `__ctor` hook, and falls back to
|
|
61
|
+
* calling a native/extension parent constructor (which has none). */
|
|
62
|
+
this.emit(
|
|
63
|
+
` ${result} = call i64 @xt_super_construct(i64 ${thisValue}, i64 ${owner}, i64 ${parentProto}, i32 ${args.argc}, i64* ${args.ptr})`,
|
|
64
|
+
);
|
|
64
65
|
return result;
|
|
65
66
|
},
|
|
66
67
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small AST helpers shared by the call-access and call-invocation lowering.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { SyntaxKind, type Expression, type Identifier } from "../../../ast/nodes.js";
|
|
6
|
+
|
|
7
|
+
/** Strip `(...)`, `x as T`, `x satisfies T` and `x!` to the underlying expression. */
|
|
8
|
+
export function unwrapExpression(expression: Expression): Expression {
|
|
9
|
+
let current = expression;
|
|
10
|
+
for (;;) {
|
|
11
|
+
if (
|
|
12
|
+
current.kind === SyntaxKind.ParenthesizedExpression ||
|
|
13
|
+
current.kind === SyntaxKind.AsExpression ||
|
|
14
|
+
current.kind === SyntaxKind.SatisfiesExpression ||
|
|
15
|
+
current.kind === SyntaxKind.NonNullExpression
|
|
16
|
+
) {
|
|
17
|
+
current = (current as { expression: Expression }).expression;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The identifier naming the global object (`globalThis`, or Node's alias
|
|
26
|
+
* `global`) when `expression` is one, ignoring `(...)`/`as`/`!` wrappers.
|
|
27
|
+
* Callers still have to check that the name is not shadowed by a binding.
|
|
28
|
+
*/
|
|
29
|
+
export function globalObjectReceiver(expression: Expression): Identifier | undefined {
|
|
30
|
+
const receiver = unwrapExpression(expression);
|
|
31
|
+
if (receiver.kind !== SyntaxKind.Identifier) return undefined;
|
|
32
|
+
const name = (receiver as Identifier).text;
|
|
33
|
+
return name === "globalThis" || name === "global" ? (receiver as Identifier) : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Source text of a `new` callee (`Foo`, `ns.Bar`, `expr.Baz`), for the runtime's
|
|
38
|
+
* "new X is not a constructor" message. `undefined` when the callee is an
|
|
39
|
+
* arbitrary expression.
|
|
40
|
+
*/
|
|
41
|
+
export function newCalleeName(callee: Expression): string | undefined {
|
|
42
|
+
const name = unwrapExpression(callee);
|
|
43
|
+
if (name.kind === SyntaxKind.Identifier) return (name as Identifier).text;
|
|
44
|
+
if (name.kind !== SyntaxKind.PropertyAccessExpression) return undefined;
|
|
45
|
+
const access = name as { name: { text: string } };
|
|
46
|
+
return access.name.text;
|
|
47
|
+
}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { SymbolKind } from "../../../binder/binder.js";
|
|
20
20
|
import { DiagnosticCode } from "../../../diagnostics/diagnostic.js";
|
|
21
21
|
import { i64, numberLiteral, XT_UNDEFINED } from "../../values.js";
|
|
22
|
+
import { NAMESPACE_PROPERTY_SETTERS } from "../lookup-tables.js";
|
|
22
23
|
import { BINARY_RUNTIME, compoundToBinary, propertyNameText } from "../tables.js";
|
|
23
24
|
import type { Generator } from "../generator.js";
|
|
24
25
|
|
|
@@ -127,6 +128,20 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
|
|
|
127
128
|
}
|
|
128
129
|
case SyntaxKind.PropertyAccessExpression: {
|
|
129
130
|
const access = target as PropertyAccessExpression;
|
|
131
|
+
/* `process.exitCode = 1`: a namespace property with a runtime setter.
|
|
132
|
+
* Reads go through `NAMESPACE_PROPERTIES`, writes through the matching
|
|
133
|
+
* entry here; a namespace without one keeps the generic object path. */
|
|
134
|
+
const holder =
|
|
135
|
+
access.expression.kind === SyntaxKind.Identifier ? (access.expression as Identifier) : undefined;
|
|
136
|
+
const symbol = holder ? this.binding.symbolOfIdentifier.get(holder) : undefined;
|
|
137
|
+
const namespace = holder ? (symbol ? this.namespaceOfSymbol(symbol) : holder.text) : undefined;
|
|
138
|
+
const setter = namespace === undefined ? undefined : NAMESPACE_PROPERTY_SETTERS[namespace];
|
|
139
|
+
if (setter) {
|
|
140
|
+
const key = this.stringValue(access.name.text);
|
|
141
|
+
this.extraDeclarations.add(`declare i64 @${setter}(i64, i64)`);
|
|
142
|
+
this.emit(` call i64 @${setter}(i64 ${key}, i64 ${value})`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
130
145
|
const object = this.emitExpression(access.expression);
|
|
131
146
|
const key = this.stringValue(access.name.text);
|
|
132
147
|
this.emit(` call i64 @xt_set(i64 ${object}, i64 ${key}, i64 ${value})`);
|