xbintsc 0.2.9 → 0.3.1
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/README.md +17 -2
- package/README.zh-CN.md +16 -2
- package/bin/xbintsc.js +49 -10
- package/dist/src/ast/expressions.d.ts +2 -0
- package/dist/src/binder/binder.d.ts +24 -98
- package/dist/src/binder/binder.js +13 -559
- package/dist/src/binder/binder.js.map +1 -1
- package/dist/src/binder/declarations.d.ts +16 -0
- package/dist/src/binder/declarations.js +168 -0
- package/dist/src/binder/declarations.js.map +1 -0
- package/dist/src/binder/helpers.d.ts +11 -0
- package/dist/src/binder/helpers.js +46 -0
- package/dist/src/binder/helpers.js.map +1 -0
- package/dist/src/binder/references.d.ts +21 -0
- package/dist/src/binder/references.js +349 -0
- package/dist/src/binder/references.js.map +1 -0
- package/dist/src/binder/types.d.ts +114 -0
- package/dist/src/binder/types.js +27 -0
- package/dist/src/binder/types.js.map +1 -0
- package/dist/src/cli/main.d.ts +1 -0
- package/dist/src/cli/main.js +40 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.d.ts +13 -0
- package/dist/src/codegen/generator/calls/access.js +115 -0
- package/dist/src/codegen/generator/calls/access.js.map +1 -0
- package/dist/src/codegen/generator/calls/closures.d.ts +11 -0
- package/dist/src/codegen/generator/calls/closures.js +50 -0
- package/dist/src/codegen/generator/calls/closures.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.d.ts +18 -0
- package/dist/src/codegen/generator/calls/invocation.js +242 -0
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -0
- package/dist/src/codegen/generator/calls/literals.d.ts +10 -0
- package/dist/src/codegen/generator/calls/literals.js +69 -0
- package/dist/src/codegen/generator/calls/literals.js.map +1 -0
- package/dist/src/codegen/generator/calls/super.d.ts +10 -0
- package/dist/src/codegen/generator/calls/super.js +47 -0
- package/dist/src/codegen/generator/calls/super.js.map +1 -0
- package/dist/src/codegen/generator/calls.d.ts +15 -24
- package/dist/src/codegen/generator/calls.js +15 -482
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/context.d.ts +1 -1
- package/dist/src/codegen/generator/context.js +2 -2
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.d.ts +13 -0
- package/dist/src/codegen/generator/expressions/assignment.js +203 -0
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -0
- package/dist/src/codegen/generator/expressions/operators.d.ts +14 -0
- package/dist/src/codegen/generator/expressions/operators.js +163 -0
- package/dist/src/codegen/generator/expressions/operators.js.map +1 -0
- package/dist/src/codegen/generator/expressions/primary.d.ts +17 -0
- package/dist/src/codegen/generator/expressions/primary.js +260 -0
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -0
- package/dist/src/codegen/generator/expressions.d.ts +11 -21
- package/dist/src/codegen/generator/expressions.js +11 -494
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/module.js +16 -4
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +8 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/statements/control-flow.d.ts +14 -0
- package/dist/src/codegen/generator/statements/control-flow.js +199 -0
- package/dist/src/codegen/generator/statements/control-flow.js.map +1 -0
- package/dist/src/codegen/generator/statements/dispatch.d.ts +12 -0
- package/dist/src/codegen/generator/statements/dispatch.js +100 -0
- package/dist/src/codegen/generator/statements/dispatch.js.map +1 -0
- package/dist/src/codegen/generator/statements/loops.d.ts +13 -0
- package/dist/src/codegen/generator/statements/loops.js +152 -0
- package/dist/src/codegen/generator/statements/loops.js.map +1 -0
- package/dist/src/codegen/generator/statements/variables.d.ts +13 -0
- package/dist/src/codegen/generator/statements/variables.js +146 -0
- package/dist/src/codegen/generator/statements/variables.js.map +1 -0
- package/dist/src/codegen/generator/statements.d.ts +13 -21
- package/dist/src/codegen/generator/statements.js +13 -568
- package/dist/src/codegen/generator/statements.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +7 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/codegen/values.d.ts +17 -17
- package/dist/src/codegen/values.js +21 -57
- package/dist/src/codegen/values.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.d.ts +1 -0
- package/dist/src/diagnostics/diagnostic.js +1 -0
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +1 -1
- package/dist/src/diagnostics/source.js +7 -12
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/compiler.d.ts +4 -0
- package/dist/src/driver/compiler.js +51 -16
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/index.d.ts +5 -2
- package/dist/src/driver/index.js +5 -2
- package/dist/src/driver/index.js.map +1 -1
- package/dist/src/driver/paths.d.ts +20 -0
- package/dist/src/driver/paths.js +49 -0
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-lib.d.ts +18 -0
- package/dist/src/driver/runtime-lib.js +31 -0
- package/dist/src/driver/runtime-lib.js.map +1 -0
- package/dist/src/driver/toolchain-download.d.ts +50 -0
- package/dist/src/driver/toolchain-download.js +76 -0
- package/dist/src/driver/toolchain-download.js.map +1 -0
- package/dist/src/driver/toolchain-provider.d.ts +33 -0
- package/dist/src/driver/toolchain-provider.js +71 -0
- package/dist/src/driver/toolchain-provider.js.map +1 -0
- package/dist/src/driver/toolchain.d.ts +9 -4
- package/dist/src/driver/toolchain.js +6 -10
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/extensions/node/child_process/index.d.ts +4 -2
- package/dist/src/extensions/node/child_process/index.js +4 -2
- package/dist/src/extensions/node/child_process/index.js.map +1 -1
- package/dist/src/extensions/node/events/index.d.ts +10 -0
- package/dist/src/extensions/node/events/index.js +22 -0
- package/dist/src/extensions/node/events/index.js.map +1 -0
- package/dist/src/extensions/node/index.js +6 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/querystring/index.d.ts +10 -0
- package/dist/src/extensions/node/querystring/index.js +25 -0
- package/dist/src/extensions/node/querystring/index.js.map +1 -0
- package/dist/src/extensions/node/util/index.d.ts +11 -0
- package/dist/src/extensions/node/util/index.js +41 -0
- package/dist/src/extensions/node/util/index.js.map +1 -0
- package/dist/src/extensions/registry.d.ts +6 -0
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lexer/scanner/identifiers.d.ts +9 -0
- package/dist/src/lexer/scanner/identifiers.js +33 -0
- package/dist/src/lexer/scanner/identifiers.js.map +1 -0
- package/dist/src/lexer/scanner/numbers.d.ts +10 -0
- package/dist/src/lexer/scanner/numbers.js +89 -0
- package/dist/src/lexer/scanner/numbers.js.map +1 -0
- package/dist/src/lexer/scanner/punctuation.d.ts +9 -0
- package/dist/src/lexer/scanner/punctuation.js +151 -0
- package/dist/src/lexer/scanner/punctuation.js.map +1 -0
- package/dist/src/lexer/scanner/regex.d.ts +11 -0
- package/dist/src/lexer/scanner/regex.js +69 -0
- package/dist/src/lexer/scanner/regex.js.map +1 -0
- package/dist/src/lexer/scanner/strings.d.ts +13 -0
- package/dist/src/lexer/scanner/strings.js +118 -0
- package/dist/src/lexer/scanner/strings.js.map +1 -0
- package/dist/src/lexer/scanner.d.ts +20 -27
- package/dist/src/lexer/scanner.js +11 -415
- package/dist/src/lexer/scanner.js.map +1 -1
- package/dist/src/parser/declarations/classes.d.ts +14 -0
- package/dist/src/parser/declarations/classes.js +191 -0
- package/dist/src/parser/declarations/classes.js.map +1 -0
- package/dist/src/parser/declarations/functions.d.ts +17 -0
- package/dist/src/parser/declarations/functions.js +241 -0
- package/dist/src/parser/declarations/functions.js.map +1 -0
- package/dist/src/parser/declarations/type-members.d.ts +16 -0
- package/dist/src/parser/declarations/type-members.js +156 -0
- package/dist/src/parser/declarations/type-members.js.map +1 -0
- package/dist/src/parser/declarations.d.ts +13 -24
- package/dist/src/parser/declarations.js +13 -571
- package/dist/src/parser/declarations.js.map +1 -1
- package/dist/src/parser/helpers.js +13 -4
- package/dist/src/parser/helpers.js.map +1 -1
- package/dist/src/parser/literals.js +10 -1
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +24 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/driver/compiler.test.js +3 -0
- package/dist/tests/driver/compiler.test.js.map +1 -1
- package/dist/tests/driver/paths.test.d.ts +1 -0
- package/dist/tests/driver/paths.test.js +26 -0
- package/dist/tests/driver/paths.test.js.map +1 -0
- package/dist/tests/driver/toolchain-download.test.d.ts +1 -0
- package/dist/tests/driver/toolchain-download.test.js +38 -0
- package/dist/tests/driver/toolchain-download.test.js.map +1 -0
- package/dist/tests/driver/toolchain-provider.test.d.ts +1 -0
- package/dist/tests/driver/toolchain-provider.test.js +37 -0
- package/dist/tests/driver/toolchain-provider.test.js.map +1 -0
- package/dist/tests/e2e/compile-node.test.d.ts +7 -0
- package/dist/tests/e2e/compile-node.test.js +123 -0
- package/dist/tests/e2e/compile-node.test.js.map +1 -0
- package/dist/tests/e2e/compile.test.d.ts +4 -1
- package/dist/tests/e2e/compile.test.js +78 -130
- package/dist/tests/e2e/compile.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +36 -0
- package/dist/tests/e2e/harness.js +64 -0
- package/dist/tests/e2e/harness.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +60 -0
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/extensions/registry.test.js +4 -0
- package/dist/tests/extensions/registry.test.js.map +1 -1
- package/package.json +5 -3
- package/runtime/ext_node/buffer/buffer.c +12 -552
- package/runtime/ext_node/buffer/parts/byte-access.inc +35 -0
- package/runtime/ext_node/buffer/parts/construction.inc +60 -0
- package/runtime/ext_node/buffer/parts/integer-io.inc +119 -0
- package/runtime/ext_node/buffer/parts/methods.inc +135 -0
- package/runtime/ext_node/buffer/parts/prototype.inc +54 -0
- package/runtime/ext_node/buffer/parts/search.inc +86 -0
- package/runtime/ext_node/buffer/parts/static-api.inc +58 -0
- package/runtime/ext_node/child_process/child_process.c +37 -3
- package/runtime/ext_node/events/events.c +285 -0
- package/runtime/ext_node/http/http.c +11 -736
- package/runtime/ext_node/http/parts/client.inc +290 -0
- package/runtime/ext_node/http/parts/helpers.inc +45 -0
- package/runtime/ext_node/http/parts/prototypes.inc +57 -0
- package/runtime/ext_node/http/parts/response.inc +149 -0
- package/runtime/ext_node/http/parts/server.inc +133 -0
- package/runtime/ext_node/http/parts/string-builder.inc +58 -0
- package/runtime/ext_node/net/net.c +12 -504
- package/runtime/ext_node/net/parts/construction.inc +22 -0
- package/runtime/ext_node/net/parts/platform.inc +60 -0
- package/runtime/ext_node/net/parts/prototypes.inc +35 -0
- package/runtime/ext_node/net/parts/read-loop.inc +58 -0
- package/runtime/ext_node/net/parts/server.inc +131 -0
- package/runtime/ext_node/net/parts/socket-methods.inc +100 -0
- package/runtime/ext_node/net/parts/static-api.inc +93 -0
- package/runtime/ext_node/querystring/querystring.c +251 -0
- package/runtime/ext_node/util/util.c +456 -0
- package/runtime/rt.h +8 -2
- package/runtime/rt_internal.h +34 -0
- package/runtime/xt_bigint/arithmetic.inc +135 -0
- package/runtime/xt_bigint/bits.inc +98 -0
- package/runtime/xt_bigint/bitwise.inc +103 -0
- package/runtime/xt_bigint/compare.inc +30 -0
- package/runtime/xt_bigint/conversions.inc +51 -0
- package/runtime/xt_bigint/division.inc +85 -0
- package/runtime/xt_bigint/format.inc +145 -0
- package/runtime/xt_bigint/helpers.inc +92 -0
- package/runtime/xt_bigint/magnitude.inc +88 -0
- package/runtime/xt_bigint/public.inc +59 -0
- package/runtime/xt_bigint/small-arithmetic.inc +58 -0
- package/runtime/xt_bigint.c +42 -0
- package/runtime/xt_builtins.c +1 -0
- package/runtime/xt_io.c +7 -0
- package/runtime/xt_stdlib/arrays.inc +161 -0
- package/runtime/xt_stdlib/dispatch.inc +116 -0
- package/runtime/xt_stdlib/helpers.inc +23 -0
- package/runtime/xt_stdlib/math.inc +72 -0
- package/runtime/xt_stdlib/strings.inc +178 -0
- package/runtime/xt_stdlib.c +10 -549
- package/runtime/xt_stdlib2/array-statics.inc +37 -0
- package/runtime/xt_stdlib2/arrays.inc +189 -0
- package/runtime/xt_stdlib2/container.inc +23 -0
- package/runtime/xt_stdlib2/date.inc +72 -0
- package/runtime/xt_stdlib2/error.inc +22 -0
- package/runtime/xt_stdlib2/helpers.inc +43 -0
- package/runtime/xt_stdlib2/json.inc +213 -0
- package/runtime/xt_stdlib2/map.inc +95 -0
- package/runtime/xt_stdlib2/number-string-statics.inc +73 -0
- package/runtime/xt_stdlib2/numbers.inc +38 -0
- package/runtime/xt_stdlib2/objects.inc +41 -0
- package/runtime/xt_stdlib2/regexp-match.inc +204 -0
- package/runtime/xt_stdlib2/regexp.inc +20 -0
- package/runtime/xt_stdlib2/set.inc +105 -0
- package/runtime/xt_stdlib2/strings.inc +94 -0
- package/runtime/xt_stdlib2.c +19 -1278
- package/runtime/xt_values.c +155 -12
- package/scripts/build-runtime.ts +109 -0
- package/scripts/fetch-toolchain.ts +101 -0
- package/scripts/package-release.ts +192 -0
- package/src/ast/expressions.ts +2 -0
- package/src/binder/binder.ts +40 -725
- package/src/binder/declarations.ts +203 -0
- package/src/binder/helpers.ts +47 -0
- package/src/binder/references.ts +410 -0
- package/src/binder/types.ts +134 -0
- package/src/cli/main.ts +43 -0
- package/src/codegen/generator/calls/access.ts +139 -0
- package/src/codegen/generator/calls/closures.ts +60 -0
- package/src/codegen/generator/calls/invocation.ts +282 -0
- package/src/codegen/generator/calls/literals.ts +77 -0
- package/src/codegen/generator/calls/super.ts +61 -0
- package/src/codegen/generator/calls.ts +30 -552
- package/src/codegen/generator/context.ts +2 -2
- package/src/codegen/generator/expressions/assignment.ts +226 -0
- package/src/codegen/generator/expressions/operators.ts +182 -0
- package/src/codegen/generator/expressions/primary.ts +304 -0
- package/src/codegen/generator/expressions.ts +22 -553
- package/src/codegen/generator/module.ts +14 -4
- package/src/codegen/generator/state.ts +8 -0
- package/src/codegen/generator/statements/control-flow.ts +225 -0
- package/src/codegen/generator/statements/dispatch.ts +122 -0
- package/src/codegen/generator/statements/loops.ts +173 -0
- package/src/codegen/generator/statements/variables.ts +152 -0
- package/src/codegen/generator/statements.ts +26 -612
- package/src/codegen/generator/tables.ts +7 -0
- package/src/codegen/values.ts +22 -57
- package/src/diagnostics/diagnostic.ts +1 -0
- package/src/diagnostics/source.ts +7 -12
- package/src/driver/compiler.ts +61 -18
- package/src/driver/index.ts +17 -2
- package/src/driver/paths.ts +54 -0
- package/src/driver/runtime-lib.ts +32 -0
- package/src/driver/toolchain-download.ts +108 -0
- package/src/driver/toolchain-provider.ts +91 -0
- package/src/driver/toolchain.ts +29 -11
- package/src/extensions/node/child_process/index.ts +4 -2
- package/src/extensions/node/events/index.ts +27 -0
- package/src/extensions/node/index.ts +6 -0
- package/src/extensions/node/querystring/index.ts +29 -0
- package/src/extensions/node/util/index.ts +48 -0
- package/src/extensions/registry.ts +6 -0
- package/src/index.ts +1 -0
- package/src/lexer/scanner/identifiers.ts +37 -0
- package/src/lexer/scanner/numbers.ts +84 -0
- package/src/lexer/scanner/punctuation.ts +132 -0
- package/src/lexer/scanner/regex.ts +79 -0
- package/src/lexer/scanner/strings.ts +128 -0
- package/src/lexer/scanner.ts +35 -401
- package/src/parser/declarations/classes.ts +215 -0
- package/src/parser/declarations/functions.ts +254 -0
- package/src/parser/declarations/type-members.ts +181 -0
- package/src/parser/declarations.ts +32 -609
- package/src/parser/helpers.ts +13 -6
- package/src/parser/literals.ts +10 -1
- package/scripts/build-runtime.mjs +0 -55
package/README.md
CHANGED
|
@@ -97,6 +97,13 @@ xbintsc emit examples/hello.ts | head
|
|
|
97
97
|
xbintsc run examples/read-file.ts --ext node
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
#### Prebuilt standalone archives
|
|
101
|
+
|
|
102
|
+
Every GitHub Release also attaches a self-contained archive per platform
|
|
103
|
+
(`xbintsc-<os>-<arch>.tar.zst` or `.tar.gz`, plus a `.sha256`). Unpack it and
|
|
104
|
+
call `bin/xbintsc` directly — no Node.js or system compiler required. See
|
|
105
|
+
[doc/requirements.md](doc/requirements.md#prebuilt-releases-recommended).
|
|
106
|
+
|
|
100
107
|
### As a developer (from source)
|
|
101
108
|
|
|
102
109
|
In a source checkout, run the TypeScript sources directly through `tsx` (or use
|
|
@@ -210,8 +217,16 @@ Tests are organised by module under `tests/` (`lexer`, `parser`, `binder`,
|
|
|
210
217
|
|
|
211
218
|
## Requirements
|
|
212
219
|
|
|
213
|
-
-
|
|
214
|
-
|
|
220
|
+
See [Requirements](./doc/requirements.md) for the full, per-platform list.
|
|
221
|
+
|
|
222
|
+
- Node.js 20+ — only to run/build from source; released binaries are standalone
|
|
223
|
+
- macOS: the Xcode Command Line Tools (`xcode-select --install`)
|
|
224
|
+
- Windows: nothing extra — the MinGW-w64 toolchain is bundled
|
|
225
|
+
- Linux: a system C library (glibc)
|
|
226
|
+
- To build a binary yourself: a `clang`-compatible compiler on `PATH`
|
|
227
|
+
(override with `xbintsc_CLANG`)
|
|
228
|
+
|
|
229
|
+
Check your environment with `xbintsc doctor`.
|
|
215
230
|
|
|
216
231
|
## Language subset
|
|
217
232
|
|
package/README.zh-CN.md
CHANGED
|
@@ -91,6 +91,13 @@ xbintsc emit examples/hello.ts | head
|
|
|
91
91
|
xbintsc run examples/read-file.ts --ext node
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
#### 预编译独立发布包
|
|
95
|
+
|
|
96
|
+
每个 GitHub Release 也会附上各平台的自包含归档
|
|
97
|
+
(`xbintsc-<os>-<arch>.tar.zst` 或 `.tar.gz`,附 `.sha256`)。解压后直接调用
|
|
98
|
+
`bin/xbintsc` 即可,无需 Node.js 或系统编译器。详见
|
|
99
|
+
[doc/zh-CN/requirements.md](doc/zh-CN/requirements.md#预编译发布包推荐)。
|
|
100
|
+
|
|
94
101
|
### 作为开发者(从源码)
|
|
95
102
|
|
|
96
103
|
在源码检出中,通过 `tsx` 直接运行 TypeScript 源码(或使用 `npm run xbintsc`)。
|
|
@@ -200,8 +207,15 @@ npm run test:e2e # 仅编译并运行的测试
|
|
|
200
207
|
|
|
201
208
|
## 运行要求
|
|
202
209
|
|
|
203
|
-
-
|
|
204
|
-
|
|
210
|
+
完整的分平台要求见 [使用前置要求](./doc/zh-CN/requirements.md)。
|
|
211
|
+
|
|
212
|
+
- Node.js 20+ —— 仅从源码运行/构建时需要;发布版二进制是独立的
|
|
213
|
+
- macOS:Xcode Command Line Tools(`xcode-select --install`)
|
|
214
|
+
- Windows:无需额外安装 —— 自带 MinGW-w64 工具链
|
|
215
|
+
- Linux:系统 C 库(glibc)
|
|
216
|
+
- 若要自行编译二进制:`PATH` 中有兼容 `clang` 的 C 编译器(可用 `xbintsc_CLANG` 覆盖)
|
|
217
|
+
|
|
218
|
+
用 `xbintsc doctor` 检查环境。
|
|
205
219
|
|
|
206
220
|
## 语言子集
|
|
207
221
|
|
package/bin/xbintsc.js
CHANGED
|
@@ -2,25 +2,64 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* xbintsc launcher.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Resolution order:
|
|
6
|
+
* 1. a native compiler for this platform — an `xbintsc_BINARY` override, an
|
|
7
|
+
* installed `@xbintsc/<os>-<arch>` package, or a co-located `bin/xbintsc`.
|
|
8
|
+
* This is what a self-contained install provides; it needs no Node
|
|
9
|
+
* toolchain at runtime.
|
|
10
|
+
* 2. the compiled CLI in `dist/` (a checkout that ran `npm run build`).
|
|
11
|
+
* 3. the TypeScript sources through `tsx` (a plain checkout).
|
|
8
12
|
*/
|
|
9
13
|
|
|
10
14
|
import { existsSync } from "node:fs";
|
|
15
|
+
import { createRequire } from "node:module";
|
|
11
16
|
import { dirname, join, resolve } from "node:path";
|
|
12
17
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
18
|
import { spawnSync } from "node:child_process";
|
|
14
19
|
|
|
15
20
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
16
|
-
const
|
|
21
|
+
const exe = process.platform === "win32" ? ".exe" : "";
|
|
22
|
+
const slug = `${process.platform}-${process.arch}`;
|
|
23
|
+
|
|
24
|
+
/** A native compiler binary for this platform, if one ships with the package. */
|
|
25
|
+
function findNativeBinary() {
|
|
26
|
+
const override = process.env.xbintsc_BINARY;
|
|
27
|
+
if (override && existsSync(override)) return override;
|
|
28
|
+
|
|
29
|
+
const require = createRequire(import.meta.url);
|
|
30
|
+
for (const request of [`@xbintsc/${slug}/bin/xbintsc${exe}`, `@xbintsc/${slug}`]) {
|
|
31
|
+
try {
|
|
32
|
+
const resolved = require.resolve(request);
|
|
33
|
+
if (existsSync(resolved)) return resolved;
|
|
34
|
+
} catch {
|
|
35
|
+
// Not installed for this platform; keep looking.
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (const candidate of [
|
|
40
|
+
join(root, "bin", `xbintsc${exe}`),
|
|
41
|
+
join(root, "dist", `xbintsc${exe}`),
|
|
42
|
+
]) {
|
|
43
|
+
if (existsSync(candidate)) return candidate;
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const args = process.argv.slice(2);
|
|
17
49
|
|
|
50
|
+
const native = findNativeBinary();
|
|
51
|
+
if (native) {
|
|
52
|
+
const result = spawnSync(native, args, { stdio: "inherit" });
|
|
53
|
+
process.exit(result.status ?? 1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const compiled = join(root, "dist", "src", "cli", "main.js");
|
|
18
57
|
if (existsSync(compiled)) {
|
|
19
58
|
const { run } = await import(pathToFileURL(compiled).href);
|
|
20
|
-
process.exit(run(
|
|
21
|
-
} else {
|
|
22
|
-
const tsx = join(root, "node_modules", ".bin", process.platform === "win32" ? "tsx.cmd" : "tsx");
|
|
23
|
-
const entry = join(root, "src", "cli", "main.ts");
|
|
24
|
-
const result = spawnSync(tsx, [entry, ...process.argv.slice(2)], { stdio: "inherit" });
|
|
25
|
-
process.exit(result.status ?? 1);
|
|
59
|
+
process.exit(run(args));
|
|
26
60
|
}
|
|
61
|
+
|
|
62
|
+
const tsx = join(root, "node_modules", ".bin", process.platform === "win32" ? "tsx.cmd" : "tsx");
|
|
63
|
+
const entry = join(root, "src", "cli", "main.ts");
|
|
64
|
+
const result = spawnSync(tsx, [entry, ...args], { stdio: "inherit" });
|
|
65
|
+
process.exit(result.status ?? 1);
|
|
@@ -83,6 +83,8 @@ export interface PropertyAssignment extends Node {
|
|
|
83
83
|
export interface ShorthandPropertyAssignment extends Node {
|
|
84
84
|
readonly kind: SyntaxKind.ShorthandPropertyAssignment;
|
|
85
85
|
readonly name: Identifier;
|
|
86
|
+
/** Present for `{ a = default }` when used as a destructuring target. */
|
|
87
|
+
readonly initializer?: Expression;
|
|
86
88
|
}
|
|
87
89
|
export interface SpreadElement extends Node {
|
|
88
90
|
readonly kind: SyntaxKind.SpreadElement;
|
|
@@ -7,110 +7,36 @@
|
|
|
7
7
|
*
|
|
8
8
|
* The result is deliberately plain data — maps and records — so it can be
|
|
9
9
|
* cached, serialized for the incremental build, and unit tested in isolation.
|
|
10
|
+
*
|
|
11
|
+
* The walk is split by functional area into sibling modules:
|
|
12
|
+
* - `types` — the plain-data symbol/scope model
|
|
13
|
+
* - `declarations` — symbol/scope creation and hoisting
|
|
14
|
+
* - `references` — identifier resolution and capture analysis
|
|
15
|
+
* - `helpers` — small AST utilities
|
|
10
16
|
*/
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Interface = "interface",
|
|
20
|
-
TypeAlias = "type",
|
|
21
|
-
Enum = "enum",
|
|
22
|
-
Import = "import",
|
|
23
|
-
Namespace = "namespace"
|
|
24
|
-
}
|
|
25
|
-
export interface SymbolInfo {
|
|
26
|
-
readonly id: number;
|
|
27
|
-
readonly name: string;
|
|
28
|
-
readonly kind: SymbolKind;
|
|
29
|
-
/** False for `const` bindings and imports. */
|
|
30
|
-
readonly mutable: boolean;
|
|
31
|
-
/** The function this symbol belongs to. */
|
|
32
|
-
readonly fn: FunctionInfo;
|
|
33
|
-
readonly declarations: Node[];
|
|
34
|
-
readonly references: Identifier[];
|
|
35
|
-
/** Set when referenced from a nested function. */
|
|
36
|
-
captured: boolean;
|
|
37
|
-
/** Assigned after construction once we know it is captured. */
|
|
38
|
-
boxed: boolean;
|
|
39
|
-
}
|
|
40
|
-
export type FunctionNode = SourceFileNode | FunctionDeclaration | FunctionExpression | ArrowFunction;
|
|
41
|
-
export interface FunctionInfo {
|
|
42
|
-
readonly id: number;
|
|
43
|
-
readonly name: string;
|
|
44
|
-
readonly node: FunctionNode;
|
|
45
|
-
readonly parent?: FunctionInfo;
|
|
46
|
-
readonly scope: Scope;
|
|
47
|
-
readonly params: SymbolInfo[];
|
|
48
|
-
/** Every binding declared directly in this function (params + locals). */
|
|
49
|
-
readonly locals: SymbolInfo[];
|
|
50
|
-
/** Outer bindings referenced by this function or any descendant. */
|
|
51
|
-
readonly captures: SymbolInfo[];
|
|
52
|
-
readonly captureIndex: Map<number, number>;
|
|
53
|
-
readonly isModule: boolean;
|
|
54
|
-
readonly isArrow: boolean;
|
|
55
|
-
/** True when the function was declared `async`. */
|
|
56
|
-
readonly isAsync: boolean;
|
|
57
|
-
/** True when this function's body mentions `this` directly. */
|
|
58
|
-
usesThis: boolean;
|
|
59
|
-
/** True when an arrow function must receive `this` from its enclosing scope. */
|
|
60
|
-
capturesThis: boolean;
|
|
61
|
-
/** Set for class methods/constructors; carries the owning class. */
|
|
62
|
-
classInfo?: ClassInfo;
|
|
63
|
-
/** True for `static` class members. */
|
|
64
|
-
isStatic?: boolean;
|
|
65
|
-
/** True for an explicit `constructor`. */
|
|
66
|
-
isConstructor?: boolean;
|
|
67
|
-
}
|
|
68
|
-
export interface ClassInfo {
|
|
69
|
-
readonly id: number;
|
|
70
|
-
readonly name: string;
|
|
71
|
-
readonly node: Node;
|
|
72
|
-
readonly scope: Scope;
|
|
73
|
-
readonly parent?: ClassInfo;
|
|
74
|
-
readonly parentExpression?: Expression;
|
|
75
|
-
/** `this`-bearing fields declared on the class. */
|
|
76
|
-
readonly fields: ClassFieldInfo[];
|
|
77
|
-
readonly methods: FunctionInfo[];
|
|
78
|
-
readonly statics: FunctionInfo[];
|
|
79
|
-
ctor?: FunctionInfo;
|
|
80
|
-
}
|
|
81
|
-
export interface ClassFieldInfo {
|
|
82
|
-
readonly name: string;
|
|
83
|
-
readonly initializer: Expression | undefined;
|
|
84
|
-
readonly fn: FunctionInfo;
|
|
85
|
-
readonly isStatic: boolean;
|
|
86
|
-
}
|
|
87
|
-
export declare enum ScopeKind {
|
|
88
|
-
Module = "module",
|
|
89
|
-
Function = "function",
|
|
90
|
-
Block = "block",
|
|
91
|
-
For = "for",
|
|
92
|
-
Catch = "catch"
|
|
93
|
-
}
|
|
94
|
-
export interface Scope {
|
|
95
|
-
readonly kind: ScopeKind;
|
|
96
|
-
readonly parent?: Scope;
|
|
97
|
-
readonly fn: FunctionInfo;
|
|
98
|
-
readonly symbols: Map<string, SymbolInfo>;
|
|
99
|
-
/** The syntax node that introduced the scope, when there is one. */
|
|
100
|
-
readonly node?: Node;
|
|
101
|
-
}
|
|
102
|
-
export interface BindResult {
|
|
103
|
-
readonly moduleFunction: FunctionInfo;
|
|
17
|
+
import type { Identifier, Node, SourceFileNode } from "../ast/nodes.js";
|
|
18
|
+
import { ScopeKind, type ClassInfo, type FunctionInfo, type MutableFunction, type Scope, type SymbolInfo, type BindResult, type FunctionNode } from "./types.js";
|
|
19
|
+
import { type DeclarationMethods } from "./declarations.js";
|
|
20
|
+
import { type ReferenceMethods } from "./references.js";
|
|
21
|
+
export * from "./types.js";
|
|
22
|
+
export declare function bind(sourceFile: SourceFileNode): BindResult;
|
|
23
|
+
export declare class Binder {
|
|
24
|
+
readonly sourceFile: SourceFileNode;
|
|
104
25
|
readonly functions: FunctionInfo[];
|
|
105
26
|
readonly classes: ClassInfo[];
|
|
106
|
-
/** Maps a class-like AST node to the ClassInfo the binder built. */
|
|
107
27
|
readonly classOfNode: Map<Node, ClassInfo>;
|
|
108
|
-
/** Maps a function-like AST node to the FunctionInfo the binder built for it. */
|
|
109
|
-
readonly functionOfNode: Map<Node, FunctionInfo>;
|
|
110
28
|
readonly symbolOfDeclaration: Map<Node, SymbolInfo>;
|
|
111
29
|
readonly symbolOfIdentifier: Map<Identifier, SymbolInfo>;
|
|
112
30
|
readonly scopes: Map<Node, Scope>;
|
|
113
|
-
/** Identifier references that could not be resolved in user code. */
|
|
114
31
|
readonly unresolved: Identifier[];
|
|
32
|
+
nextSymbolId: number;
|
|
33
|
+
nextFunctionId: number;
|
|
34
|
+
nextClassId: number;
|
|
35
|
+
current: MutableFunction;
|
|
36
|
+
constructor(sourceFile: SourceFileNode);
|
|
37
|
+
bind(): BindResult;
|
|
38
|
+
createFunction(name: string, node: FunctionNode, parent: MutableFunction | undefined, isModule: boolean, isArrow: boolean): MutableFunction;
|
|
39
|
+
createScope(kind: ScopeKind, node: Node | undefined, parent: Scope | undefined): Scope;
|
|
40
|
+
}
|
|
41
|
+
export interface Binder extends DeclarationMethods, ReferenceMethods {
|
|
115
42
|
}
|
|
116
|
-
export declare function bind(sourceFile: SourceFileNode): BindResult;
|