xbintsc 0.6.28 → 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/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/help.d.ts +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 +17 -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 +18 -12
- 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 +2 -2
- 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/options.d.ts +1 -4
- 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 +24 -5
- 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/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/registry.d.ts +7 -0
- package/dist/src/extensions/registry.js +13 -4
- package/dist/src/extensions/registry.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/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/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/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-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.js +44 -29
- package/dist/tests/e2e/web-streams.test.js.map +1 -1
- 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 +1 -0
- package/doc/ai/zh-CN/cli.md +1 -0
- package/doc/implemented/binder.md +2 -1
- package/doc/implemented/checker.md +5 -0
- 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.md +7 -1
- 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/unimplemented/classes.md +1 -0
- package/doc/unimplemented/modules.md +1 -0
- package/doc/unimplemented/stdlib.md +2 -1
- package/doc/xbintsc.config.schema.json +5 -0
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +3 -0
- 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.md +1 -1
- 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/unimplemented/classes.md +1 -0
- package/doc/zh-CN/unimplemented/modules.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +2 -1
- package/package.json +7 -7
- 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/rt.h +36 -0
- package/runtime/rt_internal.h +10 -10
- package/runtime/xt_alloc.c +67 -49
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +26 -23
- package/runtime/xt_constructors.c +101 -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/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +70 -53
- package/runtime/xt_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/scripts/build-runtime.ts +8 -0
- 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/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 +17 -0
- package/src/codegen/generator/tables.ts +18 -12
- 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 +2 -2
- 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/options.ts +1 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +24 -5
- package/src/driver/version.ts +1 -1
- 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/registry.ts +21 -4
- package/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/literals.ts +6 -2
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { parse } from "../helpers.js";
|
|
4
4
|
import { SyntaxKind } from "../../src/ast/nodes.js";
|
|
5
|
+
import { DiagnosticCode } from "../../src/diagnostics/diagnostic.js";
|
|
5
6
|
function statements(source) {
|
|
6
7
|
const { file, diagnostics } = parse(source);
|
|
7
8
|
return { stmts: file.statements, diagnostics };
|
|
@@ -87,6 +88,18 @@ describe("class member parsing", () => {
|
|
|
87
88
|
expect(stmts[0].members[0].questionToken).toBe(true);
|
|
88
89
|
expect(stmts[0].members[1].exclamationToken).toBe(true);
|
|
89
90
|
});
|
|
91
|
+
it("reads a regex that starts a for-loop body as a regex", () => {
|
|
92
|
+
/* After `e++)` the scanner has to decide whether `/` divides or starts a
|
|
93
|
+
* regex; the paren that ends the header looks like the end of an
|
|
94
|
+
* expression, so lookahead reads the pattern as code. The parser's regex
|
|
95
|
+
* fallback rescans it correctly, and the mis-scan must stay silent. */
|
|
96
|
+
const { diagnostics } = statements('for (let e = 0; e < r.length; e++) /[^ \\t]/.exec(r[e]) && (i = e);');
|
|
97
|
+
expect(diagnostics.filter((d) => d.category === "error")).toHaveLength(0);
|
|
98
|
+
});
|
|
99
|
+
it("still reports an invalid character that lookahead scanned first", () => {
|
|
100
|
+
const { diagnostics } = statements("function f(x: number) { return x; }\nf(1);\n\\\n");
|
|
101
|
+
expect(diagnostics.some((d) => d.code === DiagnosticCode.InvalidCharacter)).toBe(true);
|
|
102
|
+
});
|
|
90
103
|
it("parses bodyless accessor, method and constructor signatures", () => {
|
|
91
104
|
const source = "class C { get x(): number; set x(v: number); constructor(); m(): void; }";
|
|
92
105
|
const { diagnostics } = statements(source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"statements.test.js","sourceRoot":"","sources":["../../../tests/parser/statements.test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"statements.test.js","sourceRoot":"","sources":["../../../tests/parser/statements.test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,UAAmB,EAAE,WAAW,EAAE,CAAC;AAC1D,CAAC;AAED,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC,c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,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/doc/ai/cli.md
CHANGED
|
@@ -125,6 +125,7 @@ matching field. `--no-config` skips discovery entirely.
|
|
|
125
125
|
| `extNative` | string[] | Native extension manifest paths |
|
|
126
126
|
| `features` | string[] | Optional link features to force on, e.g. `["media"]` / `["all"]` |
|
|
127
127
|
| `noFeatures` | string[] | Optional link features to keep out even when detected |
|
|
128
|
+
| `moduleOverrides` | `{ [specifier: string]: string }` | Map imports to local files, e.g. `{ "jiti": "stubs/jiti.ts" }` (exact match) |
|
|
128
129
|
| `force` | boolean | Ignore the incremental cache |
|
|
129
130
|
| `storage.backend` | `"memory"|"file"` | Storage backend for `localStorage` / `sessionStorage` / `indexedDB` (default `memory`) |
|
|
130
131
|
| `storage.path` | string | Database file for `backend: "file"`, resolved against this config |
|
package/doc/ai/zh-CN/cli.md
CHANGED
|
@@ -106,6 +106,7 @@ profile 数据可能独立于源码变化。
|
|
|
106
106
|
| `extNative` | string[] | 原生扩展清单路径 |
|
|
107
107
|
| `features` | string[] | 强制开启的可选链接特性,如 `["media"]` / `["all"]` |
|
|
108
108
|
| `noFeatures` | string[] | 即使检测到也保持关闭的可选链接特性 |
|
|
109
|
+
| `moduleOverrides` | `{ [说明符: string]: string }` | 把导入映射到本地文件,如 `{ "jiti": "stubs/jiti.ts" }`(精确匹配) |
|
|
109
110
|
| `force` | boolean | 忽略增量缓存 |
|
|
110
111
|
| `storage.backend` | `"memory"|"file"` | `localStorage` / `sessionStorage` / `indexedDB` 的存储后端(默认 `memory`) |
|
|
111
112
|
| `storage.path` | string | `backend: "file"` 时的数据库文件,相对本配置解析 |
|
|
@@ -6,7 +6,8 @@ Location: `src/binder/binder.ts`
|
|
|
6
6
|
|
|
7
7
|
- Scope kinds: module, function, block, `for`, `catch`
|
|
8
8
|
- Symbol kinds: `var` / `let` / `const` / `function` / `parameter` / `class` / `interface` / `type` / `enum` / `import` / `namespace`
|
|
9
|
-
- `var` and function declarations hoist to the function scope; `let` / `const` stay block-scoped
|
|
9
|
+
- `var` and function declarations hoist to the function scope; `let` / `const` stay block-scoped. A `var` written inside a nested block or in a `for` head reuses that one hoisted symbol, so `{ var x = 1 }` is visible (and assignable) after the block
|
|
10
|
+
- A destructuring *parameter* pre-declares its names and then binds the default values nested inside the pattern, so `({ a = () => 1 }) => a()` gets a function of its own
|
|
10
11
|
- A `switch` body is one shared block scope: the declarations of every `case` / `default` clause are pre-declared before any clause is bound
|
|
11
12
|
- A `static { ... }` class block is bound as a hidden static function of the class (see [Classes](../unimplemented/classes.md))
|
|
12
13
|
- Identifier → declaration resolution; unresolved identifier collection (`CannotFindName`)
|
|
@@ -29,6 +29,11 @@ else as `any`:
|
|
|
29
29
|
- classes: instance fields, methods, accessors, parameter properties,
|
|
30
30
|
`this.x = ...` members and local ancestor classes. Static members are not
|
|
31
31
|
instance members;
|
|
32
|
+
- declaration visibility: interfaces, type aliases and classes declared at
|
|
33
|
+
module top level are visible to the whole bundle, while one declared *inside a
|
|
34
|
+
function body* only counts in the file that declares it. Bundled dependencies
|
|
35
|
+
are full of function-local classes (`babel.cjs` has its own `class Token`), and
|
|
36
|
+
those must not capture a type name the importing file meant;
|
|
32
37
|
- arrays, tuples, function types, object literals and `new LocalClass()`;
|
|
33
38
|
- simple generics: a type parameter is `any` at its declaration, and a call
|
|
34
39
|
infers it from an argument (`T`, `T[]`, `Array<T>`) or takes it from an
|
package/doc/implemented/lexer.md
CHANGED
|
@@ -16,7 +16,7 @@ Location: `src/lexer/scanner.ts`, `src/lexer/token.ts`
|
|
|
16
16
|
- Single / double quotes
|
|
17
17
|
- Escapes: `\n \t \r \b \f \0 \\ \' \"`, `\xHH`, `\uHHHH`, `\u{...}`
|
|
18
18
|
- Template literals (lexer level): no-substitution templates, `TemplateHead`, `TemplateMiddle`, `TemplateTail`, with `${}` and escapes.
|
|
19
|
-
- Regex literal scanning (`/pattern/flags`), distinguishing division `/`.
|
|
19
|
+
- Regex literal scanning (`/pattern/flags`), distinguishing division `/`. The scanner decides from the previous token, which cannot be right everywhere (`for (;;) /re/.test(x)` looks like a division); the parser keeps a regex fallback that re-reads the raw source, so a mis-scan only has to stay silent.
|
|
20
20
|
- Private identifiers `#name`.
|
|
21
21
|
- Comments: line `//` and block `/* */` (with unterminated diagnostics).
|
|
22
22
|
- Newline and whitespace tracking (for ASI), BOM / CRLF normalization (`SourceFile`).
|
|
@@ -8,7 +8,7 @@ Location: `src/parser/parser.ts` (syntax), `src/driver/modules.ts` (bundling),
|
|
|
8
8
|
## Syntax
|
|
9
9
|
|
|
10
10
|
- `import default, { named } from "..."`, `import * as ns from "..."` (namespace imports of relative modules are lowered to a synthetic object literal; extension modules such as `path` are also supported), `import "./side-effect"`, `import type`
|
|
11
|
-
- `export default`, `export { a as b }`, `export *`, `export =`
|
|
11
|
+
- `export default`, `export { a as b }`, `export *`, `export * as ns from "..."`, `export =`
|
|
12
12
|
- Import attributes (`with` / `assert`)
|
|
13
13
|
|
|
14
14
|
## Runtime semantics
|
|
@@ -32,13 +32,35 @@ Location: `src/parser/parser.ts` (syntax), `src/driver/modules.ts` (bundling),
|
|
|
32
32
|
stripped, so a bare or `node:` specifier links like any ordinary module import.
|
|
33
33
|
- Modules also reachable through a normal (non-marker) import stay eager and get
|
|
34
34
|
a thin wrapper over their already-initialised exports.
|
|
35
|
+
- Two triggers share that machinery. An HTML page's `<script src>` (or inline
|
|
36
|
+
script) imports are marked with `__xt_deferred_module`, and the generated
|
|
37
|
+
script calls the marker when the engine runs it after `loadHTML`; a literal
|
|
38
|
+
`import("…")` calls the same wrapper at the import site. Both evaluate the
|
|
39
|
+
module once (`__xt_defer` memoises by module id) and both see identical
|
|
40
|
+
wrapper semantics — hoisted functions, `export * as` bindings and cycles
|
|
41
|
+
behave the same in either. Both calls end up in the same runtime helper
|
|
42
|
+
(`xt_defer_module`, the bundler emits it as a bare global call), so the only
|
|
43
|
+
difference is *who* triggers the evaluation; the engine decides the moment for
|
|
44
|
+
a script, the program for `import("…")`.
|
|
35
45
|
- The wrapper body is synchronous: top-level `await` inside a deferred script
|
|
36
46
|
module is not supported.
|
|
47
|
+
- Function declarations and the bindings of simple top-level `const`/`let`/`var`
|
|
48
|
+
declarations are *hoisted* out of the wrapper, and a wrapper assigns their
|
|
49
|
+
values in source order. That is what lets a module cycle call a dependency's
|
|
50
|
+
function before either body has run (an import of such a function refers to it
|
|
51
|
+
directly instead of copying it into an alias). Modules with destructuring, a
|
|
52
|
+
`class` or an `enum` at the top level keep every declaration inside the
|
|
53
|
+
wrapper, so a cycle that calls *their* functions still sees `undefined`.
|
|
37
54
|
|
|
38
55
|
## import.meta
|
|
39
56
|
|
|
40
57
|
- `import.meta.url` / `.dirname` / `.filename`, resolved from the running executable's path.
|
|
41
58
|
|
|
59
|
+
## Dynamic `import()`
|
|
60
|
+
|
|
61
|
+
- A *literal* specifier is a static edge: the module is bundled and the call resolves to its namespace object.
|
|
62
|
+
- A *computed* specifier cannot be loaded at run time (a compiled binary has no module loader), but the modules linked into the build are known: `import(<expression>)` resolves to the namespace of any enabled extension module, accepting both its bare and its `node:`-prefixed name — `const fs = await import("node:" + "fs")`. Any other specifier rejects with an error that names it.
|
|
63
|
+
|
|
42
64
|
## Extension modules
|
|
43
65
|
|
|
44
66
|
- Extension modules (such as `fs`) are importable by bare or `node:`-prefixed specifier and resolve to their runtime entries; see [Extensions](./extensions.md).
|
|
@@ -4,11 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
Location: `src/extensions/node/buffer/index.ts`, `runtime/ext_node/buffer/buffer.c`
|
|
6
6
|
|
|
7
|
-
xbintsc has no native binary value type, so `Buffer` is
|
|
8
|
-
|
|
9
|
-
property, sharing the `xt_buffer_proto()` prototype that provides
|
|
10
|
-
methods. `
|
|
11
|
-
bytes
|
|
7
|
+
xbintsc has no native binary value type, so a `Buffer` is an ordinary object
|
|
8
|
+
that keeps its bytes in an `ArrayBuffer` under a private symbol, plus a
|
|
9
|
+
`length` property, sharing the `xt_buffer_proto()` prototype that provides
|
|
10
|
+
instance methods. Dynamic-property hooks answer `buf[i]` and `buf[i] = 65` from
|
|
11
|
+
that store, so index access behaves like a real Buffer while the bytes stay out
|
|
12
|
+
of the property table: building one is a single bulk copy instead of one
|
|
13
|
+
property insert per byte (which was quadratic and stalled on multi-kilobyte
|
|
14
|
+
decodes). `xt_node_is_buffer` / `xt_node_buffer_bytes` let other modules access
|
|
15
|
+
bytes across modules; `xt_node_buffer_bytes` copies through
|
|
16
|
+
`xt_array_buffer_copy_bytes_out`, so the fs module does not pay one lookup per
|
|
17
|
+
byte.
|
|
12
18
|
|
|
13
19
|
| Static method | Notes |
|
|
14
20
|
| --- | --- |
|
|
@@ -24,6 +30,13 @@ bytes across modules.
|
|
|
24
30
|
|
|
25
31
|
Instance methods: `toString([encoding])`, `toJSON()`, `slice(start, end)`, `subarray(...)`, `equals(other)`, `compare(other)`, `copy(target[, targetStart, sourceStart, sourceEnd])`, `write(string[, offset[, length[, encoding]]])`, `fill(value)`, `reverse()`, `indexOf(value)`, `lastIndexOf(value)`, `includes(value)`, `keys()`, `values()`, plus `readUInt8/UInt16LE/UInt16BE/UInt32LE/UInt32BE`, `writeUInt8/UInt16LE/UInt16BE/UInt32LE/UInt32BE`.
|
|
26
32
|
|
|
33
|
+
Index access works through the object hooks: `buf[0]` reads a byte, `buf[0] =
|
|
34
|
+
65` writes one (out-of-range writes are dropped and cannot grow the buffer),
|
|
35
|
+
`0 in buf` is true inside the range, and `Object.keys(buf)` lists the indices
|
|
36
|
+
after the real properties. The store is an `ArrayBuffer`, so each byte costs
|
|
37
|
+
one `xt_value` slot (the representation `ArrayBuffer` already uses) in exchange
|
|
38
|
+
for garbage collection without a finalizer.
|
|
39
|
+
|
|
27
40
|
```ts
|
|
28
41
|
const buf = Buffer.from("hello");
|
|
29
42
|
console.log(buf.toString(), buf.length); // hello 5
|
|
@@ -4,6 +4,27 @@
|
|
|
4
4
|
|
|
5
5
|
Location: `src/extensions/node/fs/*.ts`, `runtime/ext_node/fs/*.c`
|
|
6
6
|
|
|
7
|
+
## Callback forms
|
|
8
|
+
|
|
9
|
+
Every operation below also has Node's callback form, running on the
|
|
10
|
+
asynchronous I/O pool: `readFile(path[, options], callback)`,
|
|
11
|
+
`writeFile`, `appendFile`, `stat`, `lstat`, `statfs`, `realpath`, `access`,
|
|
12
|
+
`mkdir`, `mkdtemp`, `readdir`, `rm`, `rmdir`, `unlink`, `rename`, `copyFile`,
|
|
13
|
+
`cp`, `open`, `chmod`, `lchmod`, `chown`, `lchown`, `truncate`, `utimes`,
|
|
14
|
+
`lutimes`, `link`, `symlink`, `readlink`, `opendir` and `glob`. The callback
|
|
15
|
+
receives `(error, value)` — `error` is `null` on success and a Node-shaped
|
|
16
|
+
`Error` (`code`, `errno`, `syscall`, `path`) on failure. `exists(path, cb)` is
|
|
17
|
+
the exception: `cb(boolean)` with no error argument.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { readFile } from "node:fs";
|
|
21
|
+
|
|
22
|
+
readFile("package.json", "utf8", (error, text) => {
|
|
23
|
+
if (error) throw error;
|
|
24
|
+
console.log(text.length);
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
7
28
|
## Available functions (imported from `fs`)
|
|
8
29
|
|
|
9
30
|
| Imported function | Runtime symbol | Notes |
|
|
@@ -22,7 +43,7 @@ Location: `src/extensions/node/fs/*.ts`, `runtime/ext_node/fs/*.c`
|
|
|
22
43
|
| `copyFileSync(src, dest[, flags])` | `xt_node_copy_file` | copy a file; honours `COPYFILE_EXCL` |
|
|
23
44
|
| `cpSync(src, dest[, options])` | `xt_node_cp` | recursive copy; `recursive`, `force`, `errorOnExist`, `dereference`, `preserveTimestamps` |
|
|
24
45
|
| `realpathSync(path)` | `xt_node_realpath` | resolve to an absolute path |
|
|
25
|
-
| `statSync(path)` | `xt_node_stat` | file metadata object (follows symlinks) |
|
|
46
|
+
| `statSync(path)` | `xt_node_stat` | file metadata object (follows symlinks); `mtime` / `atime` / `ctime` / `birthtime` are `Date`s, with the matching `*Ms` numbers |
|
|
26
47
|
| `lstatSync(path)` | `xt_node_lstat` | file metadata object (does not follow symlinks) |
|
|
27
48
|
| `statfsSync(path)` | `xt_node_statfs` | filesystem statistics (`bsize`, `blocks`, `bfree`, …) |
|
|
28
49
|
| `accessSync(path[, mode])` | `xt_node_access` | check accessibility |
|
|
@@ -2,22 +2,82 @@
|
|
|
2
2
|
|
|
3
3
|
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/process.md)
|
|
4
4
|
|
|
5
|
-
Location: `src/extensions/node/process/index.ts`, `runtime/ext_node/process/process.c
|
|
5
|
+
Location: `src/extensions/node/process/index.ts`, `runtime/ext_node/process/process.c`,
|
|
6
|
+
`runtime/ext_node/process/streams.c`
|
|
6
7
|
|
|
7
|
-
Method calls lower to `xt_process_call(<name>, argc, argv)`, property
|
|
8
|
-
|
|
8
|
+
Method calls lower to `xt_process_call(<name>, argc, argv)`, property reads to
|
|
9
|
+
`xt_process_get(<name>)` and property writes to `xt_process_set(<name>, value)`
|
|
10
|
+
(see `NAMESPACE_STATICS` / `NAMESPACE_PROPERTIES` / `NAMESPACE_PROPERTY_SETTERS`
|
|
11
|
+
in `src/codegen/generator/tables.ts`). Import the object
|
|
12
|
+
(`import process from "process"`) to reach these.
|
|
9
13
|
|
|
10
14
|
| Method / property | Notes |
|
|
11
15
|
| --- | --- |
|
|
12
16
|
| `process.cwd()` | current working directory |
|
|
13
|
-
| `process.exit([code])` |
|
|
17
|
+
| `process.exit([code])` | run the "exit" listeners, then exit with `code` |
|
|
14
18
|
| `process.uptime()` | process uptime (seconds) |
|
|
15
19
|
| `process.hrtime()` | `[seconds, nanoseconds]` array |
|
|
16
20
|
| `process.getuid()` | user ID (returns 0 on Windows) |
|
|
21
|
+
| `process.on` / `once` / `addListener` / `prependListener` | register an event listener |
|
|
22
|
+
| `process.off` / `removeListener` / `removeAllListeners` | remove listeners |
|
|
23
|
+
| `process.emit(event, ...args)` | fire an event by hand |
|
|
24
|
+
| `process.nextTick(fn, ...args)` | queue on the microtask queue |
|
|
25
|
+
| `process.exitCode` | read **and** write; becomes the program's exit status |
|
|
26
|
+
| `process.versions` | `{ node: "0.0.0" }` — no `bun` key, so `process.versions.bun` is `undefined` |
|
|
17
27
|
| `process.platform` / `process.arch` | platform / architecture |
|
|
18
28
|
| `process.pid` / `process.ppid` | process ID / parent process ID |
|
|
19
29
|
| `process.argv` | argument array (`argv[0]` is the executable) |
|
|
20
30
|
| `process.env` | environment variable object |
|
|
21
|
-
| `process.
|
|
31
|
+
| `process.execPath` | path of the running binary |
|
|
32
|
+
| `process.version` / `process.title` | placeholder version string / writable title |
|
|
33
|
+
| `process.stdin` / `process.stdout` / `process.stderr` | standard streams, see below |
|
|
22
34
|
|
|
23
35
|
> `argv` is captured by the generated `main` via `xt_set_program_args` and provided to the runtime.
|
|
36
|
+
|
|
37
|
+
## Termination and the exit status
|
|
38
|
+
|
|
39
|
+
The generated `main` ends with `xt_finish()`: it runs the "exit" listeners once
|
|
40
|
+
and returns the status the program asked for, so `process.exitCode = 1` and
|
|
41
|
+
`process.exit(1)` both reach the parent process. `process.exit(code)` runs the
|
|
42
|
+
listeners before leaving, which means a listener sees the final code as its
|
|
43
|
+
argument.
|
|
44
|
+
|
|
45
|
+
## Standard streams
|
|
46
|
+
|
|
47
|
+
`process.stdout` and `process.stderr` are cached EventEmitter objects with
|
|
48
|
+
`write(text)`, `end()`, `destroy()`, `fd`, `isTTY`, `columns` and `rows`.
|
|
49
|
+
`columns`/`rows` come from the console window (Windows) or `TIOCGWINSZ` (POSIX),
|
|
50
|
+
falling back to `COLUMNS`/`LINES` and then 80x24; they are read once when the
|
|
51
|
+
object is created.
|
|
52
|
+
|
|
53
|
+
`process.stdin` is a cached EventEmitter:
|
|
54
|
+
|
|
55
|
+
| Member | Notes |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `on("data", fn)` / `once` / `off` | attaching a "data" listener switches the stream to flowing mode |
|
|
58
|
+
| `resume()` / `pause()` | start or stop the read loop |
|
|
59
|
+
| `setEncoding(name)` | records `encoding`; chunks are always UTF-8 strings |
|
|
60
|
+
| `setRawMode(bool)` | console/terminal raw mode, see below |
|
|
61
|
+
| `destroy()` | stops reading |
|
|
62
|
+
| `isTTY` / `isRaw` / `fd` / `readable` | stream state |
|
|
63
|
+
|
|
64
|
+
A blocking read runs on the async I/O worker pool (the reactor's `select(2)`
|
|
65
|
+
cannot watch a console or a pipe on Windows), and its completion — which runs on
|
|
66
|
+
the main thread — decodes the bytes and emits `data` with a string chunk of at
|
|
67
|
+
most 4096 bytes. End of input emits `end` and then `close`.
|
|
68
|
+
|
|
69
|
+
Raw mode flips the console into `ENABLE_VIRTUAL_TERMINAL_INPUT` (Windows) or a
|
|
70
|
+
`termios` raw mode (POSIX) so a TUI receives escape sequences per keystroke
|
|
71
|
+
instead of line-buffered text. An `atexit` handler restores the previous mode, so
|
|
72
|
+
a program that exits without calling `setRawMode(false)` leaves the terminal
|
|
73
|
+
usable.
|
|
74
|
+
|
|
75
|
+
Known limits:
|
|
76
|
+
|
|
77
|
+
- No `resize` events: `stdout.on("resize", fn)` registers but never fires.
|
|
78
|
+
- No signal events: `process.on("SIGINT", fn)` never fires. In raw mode the
|
|
79
|
+
terminal delivers Ctrl+C as input (`"\u0003"`), which is what a TUI wants; a
|
|
80
|
+
line-buffered program terminates through the OS default.
|
|
81
|
+
- Chunks are strings, not `Buffer`s, and there is no `read(size)` pull API.
|
|
82
|
+
- `process.on` listeners are stored on the emitter object; `prependListener`
|
|
83
|
+
appends like `on` (order is registration order).
|
package/doc/implemented/node.md
CHANGED
|
@@ -23,7 +23,7 @@ work on another. Missing or different behaviour is recorded under
|
|
|
23
23
|
| `path` | [path](./node/path.md) | `path.<name>(...)` namespace calls |
|
|
24
24
|
| `os` | [os](./node/os.md) | `os.<name>(...)` namespace calls |
|
|
25
25
|
| `process` | [process](./node/process.md) | object: methods and properties |
|
|
26
|
-
| `buffer` | [buffer](./node/buffer.md) | `Buffer`
|
|
26
|
+
| `buffer` | [buffer](./node/buffer.md) | `Buffer` keeps its bytes in an `ArrayBuffer` store, not in properties |
|
|
27
27
|
| `stream` | [stream](./node/stream.md) | `Readable` / `Writable` / `Duplex` / `Transform` / `PassThrough` |
|
|
28
28
|
| `stream/promises` | [stream/promises](./node/stream-promises.md) | `pipeline` only |
|
|
29
29
|
| `stream/web` | [stream/web](./node/stream-web.md) | WHATWG streams, re-exported from the core runtime |
|
|
@@ -51,6 +51,12 @@ Additional small modules are provided with their core surface: `timers`
|
|
|
51
51
|
(`StringDecoder`), `diagnostics_channel` (`channel`/`tracingChannel`), and
|
|
52
52
|
`util/types` (the type predicates).
|
|
53
53
|
|
|
54
|
+
`createRequire(url)` returns a `require` that resolves the modules linked into
|
|
55
|
+
the binary: `require("fs")` / `require("node:fs")` answer the same namespace a
|
|
56
|
+
static import would. A specifier that names nothing linked (an arbitrary file or
|
|
57
|
+
an npm package the program never imported) throws — a compiled binary has no
|
|
58
|
+
module loader.
|
|
59
|
+
|
|
54
60
|
`tls` and `http2` are implemented as optional **link features** backed by the
|
|
55
61
|
vendored mbedTLS and nghttp2 libraries: `npm run tls` fetches and builds
|
|
56
62
|
`runtime/lib/<os>-<arch>/{tls,nghttp2}.{a,lib}`, and the driver links them only
|
|
@@ -32,7 +32,9 @@ Location: `src/codegen/llvm.ts` (`BINARY_RUNTIME`, `emitPrefix`, `emitPostfix`,
|
|
|
32
32
|
|
|
33
33
|
- Comma expression `,` (lowers to a `SequenceExpression`: every operand is
|
|
34
34
|
evaluated left to right and the value of the last one is the result)
|
|
35
|
-
- `in` operator (`key in obj`, mapped to `xt_in`)
|
|
35
|
+
- `in` operator (`key in obj`, mapped to `xt_in`): own properties, built-in
|
|
36
|
+
methods and the whole prototype chain, so `"map" in []` and `"slice" in "abc"`
|
|
37
|
+
behave like JavaScript
|
|
36
38
|
- `delete obj.key` / `delete obj[key]` (mapped to `xt_delete`)
|
|
37
39
|
- `instanceof` (mapped to `xt_instance_of`, walking the prototype chain)
|
|
38
40
|
|
|
@@ -29,7 +29,7 @@ Module syntax (`import` / `export`, import attributes) and the driver-level bund
|
|
|
29
29
|
- Conditional (ternary) expressions `a ? b : c`
|
|
30
30
|
- Comma / sequence expressions `a, b, c` (in `for` headers, parenthesized groups and expression statements)
|
|
31
31
|
- Arrow functions `() => expr` / `() => { ... }` (including type parameters and return type annotations)
|
|
32
|
-
- Function expressions `function () {}` and named function expressions `function g() {}` (also `async function` expressions)
|
|
32
|
+
- Function expressions `function () {}` and named function expressions `function g() {}` (also `async function` expressions); the name may be a contextual keyword (`function get() {}`, `function constructor() {}`), like a class expression name
|
|
33
33
|
- Call expressions `f(...)`, member access `a.b`, element access `a[i]`
|
|
34
34
|
- Array literals `[1, 2]`, sparse array elision, spread `[...a]` (also over strings, `Map` and `Set`)
|
|
35
35
|
- Object literals `{ a: 1 }`, shorthand properties `{ a }`, method shorthand `{ m() {} }`, getter / setter shorthand `{ get x() {} }` / `{ set x(v) {} }`, computed keys `{ [expr]: 1 }`, object spread `{ ...obj }`
|
|
@@ -16,7 +16,10 @@ standard-library surface have their own pages:
|
|
|
16
16
|
- [Async, promises and generators](./async.md)
|
|
17
17
|
- [fetch](./fetch.md)
|
|
18
18
|
|
|
19
|
-
- Allocator: non-moving mark-sweep collector behind `xt_alloc` (explicit roots, subsystem root providers and a conservative C-stack scan).
|
|
19
|
+
- Allocator: non-moving mark-sweep collector behind `xt_alloc` (explicit roots, subsystem root providers and a conservative C-stack scan). Collection is deferred while a bundle's module bodies run (`xt_gc_begin_startup` raises the threshold to 512 MiB until `xt_gc_end_startup`): a large module graph is built entirely inside one generated function, and collecting in the middle of it has corrupted live objects. `XT_GC_THRESHOLD` still overrides both values. Two environment switches exist for this class of bug: `XT_GC_VERIFY=1` re-scans
|
|
20
|
+
every marked object's payload before the sweep and prints any block it
|
|
21
|
+
references that stayed unmarked (a tracer or root gap), and the crash report
|
|
22
|
+
names a fault address that falls inside a block the collector freed. I/O worker threads allocate result values but never collect (`xt_gc_worker_thread`): the collector scans the main stack region and is not thread-safe, and a block born during a collection is marked so the sweep keeps it.
|
|
20
23
|
- Value construction: `xt_undefined/xt_null/xt_bool/xt_number/xt_string_new/xt_string_from_cstr`.
|
|
21
24
|
- Type conversion: `xt_truthy`, `xt_to_number`, `xt_to_string`, `xt_typeof`.
|
|
22
25
|
- Arithmetic: `add/sub/mul/div/mod/pow/neg/pos`.
|
|
@@ -28,5 +31,6 @@ standard-library surface have their own pages:
|
|
|
28
31
|
- Operator helpers: `xt_in` (`in`), `xt_delete` (`delete`), `xt_rest_args` (rest parameters / `arguments`).
|
|
29
32
|
- Box: `box_new/get/set` (for closure-captured variables).
|
|
30
33
|
- Functions and closures: `arg`, `closure_new/call/env/arity`.
|
|
31
|
-
- Exceptions: `xt_try_enter` / `xt_try_exception` / `xt_try_leave` maintain the `_setjmp` frame stack; `xt_throw` long-jumps to the nearest `try` when a frame exists, otherwise prints `Uncaught ...` and exits. A promise rejection nobody observes is fatal too: `xt_promise_report_unhandled` runs once the event loop drains, prints `Unhandled promise rejection` plus the reason and exits with status 1 (see [Async](./async.md)). Codegen also maintains a shadow call stack (function name, source file and line) that `Error.stack` captures (see [Standard library](./stdlib.md)), and a fatal-signal handler dumps the same frames on a native crash. `--debug` additionally emits `!DICompileUnit` / `!DISubprogram` / `!DILocation` metadata and compiles with `-g -fno-omit-frame-pointer`, so gdb/lldb/WinDbg map instructions back to source lines.
|
|
34
|
+
- Exceptions: `xt_try_enter` / `xt_try_exception` / `xt_try_leave` maintain the `_setjmp` frame stack; `xt_throw` long-jumps to the nearest `try` when a frame exists, otherwise prints `Uncaught ...` and exits. A promise rejection nobody observes is fatal too: `xt_promise_report_unhandled` runs once the event loop drains, prints `Unhandled promise rejection` plus the reason and exits with status 1 (see [Async](./async.md)). Codegen also maintains a shadow call stack (function name, source file and line) that `Error.stack` captures (see [Standard library](./stdlib.md)), and a fatal-signal handler dumps the same frames on a native crash. While a bundle's module bodies run, the stack names the module being initialised (` module: <path>` above the frames): every module shares one generated function, so its frames alone all carry the entry file's coordinates. `--debug` additionally emits `!DICompileUnit` / `!DISubprogram` / `!DILocation` metadata and compiles with `-g -fno-omit-frame-pointer`, so gdb/lldb/WinDbg map instructions back to source lines.
|
|
35
|
+
- Typed pointers that the collector follows from inside a struct (a promise's reaction list, an active coroutine frame, a string's rope children) are validated against the heap table before marking, so a stale one is skipped instead of dereferenced (`XT_GC_VERIFY=1` reports it).
|
|
32
36
|
- Objects / functions: `xt_object` with a prototype chain, `xt_function` with a property bag (static members and `prototype`); `xt_new` (instantiation), `xt_instance_of` (prototype chain), `xt_object_freeze/is_frozen/from_entries`; `xt_constructors.c` holds the first-class constructor cache, constructor prototypes and static-value dispatch.
|
|
@@ -19,6 +19,31 @@ own pages: [Collections](./collections.md), [Typed arrays and binary data](./typ
|
|
|
19
19
|
- `Object.freeze` / `is_frozen` / `from_entries`, `Object.getPrototypeOf`.
|
|
20
20
|
- `Object.prototype`: `hasOwnProperty` / `toString` / `valueOf` / `isPrototypeOf` / `propertyIsEnumerable` / `__proto__`; `Object.getPrototypeOf({}) === Object.prototype`.
|
|
21
21
|
- First-class built-in constructors (`const A = Array`, `new A(...)`, `A.isArray`, `x instanceof A`) are covered in [Codegen](./codegen.md#llvm-ir-code-generation-codegen).
|
|
22
|
+
- A function value's `.prototype` is created on first read (with a
|
|
23
|
+
`constructor` back-reference) and shared by every closure of one declaration, so
|
|
24
|
+
the ES5 pattern `function Foo() {}; Foo.prototype.bar = ...; new Foo().bar()`
|
|
25
|
+
works. Function *values* are still fresh per reference (`Foo === Foo` is false).
|
|
26
|
+
- `Object.getOwnPropertyNames` / `Object.keys` report no own string keys for
|
|
27
|
+
`Map` / `Set` / `Date` / `RegExp` / `Promise` / `Symbol` instead of reading past
|
|
28
|
+
their allocation.
|
|
29
|
+
|
|
30
|
+
## `globalThis` and `Intl`
|
|
31
|
+
|
|
32
|
+
- `globalThis.x` / `global.x` read a *known* global as the bare name
|
|
33
|
+
(`globalThis.fetch`, `globalThis.Deno`); any other property is an ordinary
|
|
34
|
+
read on the global object, so `globalThis.missing` is `undefined` and
|
|
35
|
+
`global[key] = v` round-trips.
|
|
36
|
+
- `globalThis` (and Node's alias `global`) is a value: one plain property bag
|
|
37
|
+
shared by both spellings, so `const g = globalThis`, `globalThis.x = 1` and
|
|
38
|
+
publishing state under a symbol key on `global` all work. It is not the
|
|
39
|
+
runtime's scope object — a name the compiler does not resolve is `undefined`
|
|
40
|
+
even when a library wrote it with `global.foo = ...`.
|
|
41
|
+
- `Intl.Segmenter` with `granularity: "grapheme" | "word"`; `segment(text)`
|
|
42
|
+
returns an **array** of `{ segment, index, isWordLike }`. It is a documented
|
|
43
|
+
approximation of UAX #29 (no ICU): graphemes are code points plus combining
|
|
44
|
+
marks, variation selectors, emoji modifiers, ZWJ sequences and regional
|
|
45
|
+
indicator pairs; words are runs of whitespace, word characters and punctuation.
|
|
46
|
+
`resolvedOptions()` reports `{ locale: "en", granularity }`.
|
|
22
47
|
|
|
23
48
|
## Arrays
|
|
24
49
|
|
|
@@ -38,12 +63,12 @@ own pages: [Collections](./collections.md), [Typed arrays and binary data](./typ
|
|
|
38
63
|
## JSON
|
|
39
64
|
|
|
40
65
|
- `JSON.parse` with a `reviver`; malformed input (bad numbers/strings, trailing text, missing separators) throws a catchable `SyntaxError` instead of returning `undefined`.
|
|
41
|
-
- `JSON.stringify` with a function or array `replacer`, `toJSON`, and `space` (number or string, clamped to 10). `undefined` / function / symbol values follow the standard omission rules.
|
|
66
|
+
- `JSON.stringify` with a function or array `replacer`, `toJSON`, and `space` (number or string, clamped to 10). `toJSON` runs for every object and receives the property key (`""` at the top level, the index for an array element), before the value is inspected, so a value whose `toJSON` returns `undefined` is omitted from an object and becomes `null` in an array. `undefined` / function / symbol values follow the standard omission rules.
|
|
42
67
|
- Object keys are emitted in insertion order, with integer keys ordered numerically; circular references throw.
|
|
43
68
|
|
|
44
69
|
## Date
|
|
45
70
|
|
|
46
|
-
- `Date` backed by `gmtime_r`; ISO 8601 parsing through `Date.parse` / `new Date(string)`.
|
|
71
|
+
- `Date` backed by `gmtime_r`; ISO 8601 parsing through `Date.parse` / `new Date(string)`. `toJSON` returns `null` for an invalid (NaN) time instead of throwing.
|
|
47
72
|
- `toLocaleDateString` / `toLocaleTimeString` / `toLocaleString` format the local time (`M/D/YYYY`, `h:mm:ss AM`); a small options subset (`weekday`/`year`/`month`/`day`/`hour`/`minute`/`second`/`hour12`) is honoured. `toDateString` / `toTimeString` / `toUTCString` are available too, and an invalid date formats as `Invalid Date`.
|
|
48
73
|
|
|
49
74
|
## RegExp
|
|
@@ -102,3 +127,45 @@ own pages: [Collections](./collections.md), [Typed arrays and binary data](./typ
|
|
|
102
127
|
- `crypto.getRandomValues(typedArray)` fills an integer typed array (up to 65 536 bytes) from the OS CSPRNG and returns it; `crypto.randomUUID()` returns a v4 UUID string. `crypto` is also a first-class object and the methods can be detached (`const uuid = crypto.randomUUID`).
|
|
103
128
|
- `Math.random` draws from a xoshiro256** stream seeded from the OS CSPRNG (53 random bits), not from the C `rand()`.
|
|
104
129
|
- Node's `crypto.randomBytes` / `randomInt` / `randomFillSync` / `pbkdf2Sync` surface is documented in [node/crypto](../implemented/node/crypto.md).
|
|
130
|
+
|
|
131
|
+
## Proxy
|
|
132
|
+
|
|
133
|
+
`new Proxy(target, handler)` is implemented as a host view (`runtime/xt_proxy.c`):
|
|
134
|
+
the proxy is an object whose own property bag stays empty, so every string-keyed
|
|
135
|
+
lookup misses and reaches the handler.
|
|
136
|
+
|
|
137
|
+
- Traps: `get(target, key, receiver)`, `set(target, key, value, receiver)`,
|
|
138
|
+
`has(target, key)`, `deleteProperty(target, key)` and `ownKeys(target)`.
|
|
139
|
+
An absent trap forwards the operation to the target, so `new Proxy(obj, {})`
|
|
140
|
+
behaves like `obj` (writes and deletes included).
|
|
141
|
+
- `Object.keys` / `JSON.stringify` / `for...in` use the `ownKeys` result; reads
|
|
142
|
+
of those keys go through `get`. `typeof` is `"object"`, and the proxy inherits
|
|
143
|
+
the target's prototype, so inherited methods and `instanceof` work.
|
|
144
|
+
- Not modelled: function targets (`apply` / `construct` traps), `Proxy.revocable`,
|
|
145
|
+
the prototype and property-descriptor traps (`getPrototypeOf`,
|
|
146
|
+
`setPrototypeOf`, `getOwnPropertyDescriptor`, `defineProperty`,
|
|
147
|
+
`isExtensible`, …), and invariant checking (a trap may report a key the target
|
|
148
|
+
does not have). The target and handler are stored as hidden symbol-keyed
|
|
149
|
+
properties, so `Object.getOwnPropertySymbols(proxy)` reports them.
|
|
150
|
+
|
|
151
|
+
## Web platform globals
|
|
152
|
+
|
|
153
|
+
Implemented in `runtime/xt_web_abort.c` (aborts) and `runtime/xt_fetch/webapi.inc`
|
|
154
|
+
(`Headers` / `Response`, built on the `fetch` implementation):
|
|
155
|
+
|
|
156
|
+
- `AbortController` / `AbortSignal`: `abort(reason?)`, the `aborted` / `reason` /
|
|
157
|
+
`onabort` accessors, `addEventListener("abort", fn[, { once }])` /
|
|
158
|
+
`removeEventListener`, `throwIfAborted()`, and the statics `AbortSignal.abort()`,
|
|
159
|
+
`AbortSignal.timeout(ms)` and `AbortSignal.any([...])`. The default reasons are
|
|
160
|
+
`AbortError` / `TimeoutError` errors (`error.name`). `fetch` does not consume a
|
|
161
|
+
signal yet, so aborting does not cancel an in-flight request.
|
|
162
|
+
- `Headers`: the case-insensitive map `get` / `has` / `set` / `append` / `delete`
|
|
163
|
+
/ `forEach` / `keys` / `values` / `entries` / `getSetCookie`, constructible from
|
|
164
|
+
a plain object, an array of pairs or another `Headers`. `fetch` hands out
|
|
165
|
+
`Headers` instances (`instanceof` holds).
|
|
166
|
+
- `Response`: `new Response(body?, init?)` with `status` / `statusText` /
|
|
167
|
+
`headers`, and `text()` / `json()` / `arrayBuffer()` / `bytes()` / `clone()`.
|
|
168
|
+
`arrayBuffer()` resolves to a real `ArrayBuffer`, `bytes()` to a `Uint8Array`.
|
|
169
|
+
- `JSON`, `ArrayBuffer` and `DataView` are values too (`const s = JSON.stringify`,
|
|
170
|
+
`ArrayBuffer.prototype`, `new DataView(buffer)`); `JSON` keeps its dedicated
|
|
171
|
+
call lowering and also works when read as an object.
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
| `static get` / `static set` accessors | ✓ (accessors on the constructor value; inherited static setters are honoured) |
|
|
14
14
|
| `super[key]` / `super[key](...)` | ✓ |
|
|
15
15
|
| Inheritance `extends` / `super` | ✓ (single level correct; `super` takes the prototype of `this`'s prototype — see [Runtime deviations](./deviations.md)) |
|
|
16
|
+
| `extends` a native/extension class (`class X extends EventEmitter`) | ✓ (the parent is never constructed at class-definition time: a class value publishes its prototype, an extension constructor value publishes its own — `EventEmitter.prototype` — through the extension registry, and anything else gets the plain object a function's `.prototype` is. `super(...)` runs the parent's `__ctor` hook, or the parent constructor itself when it has none) |
|
|
16
17
|
| Prototype chain / method lookup | ✓ |
|
|
17
18
|
| `instanceof` | ✓ |
|
|
18
19
|
| `new` / instantiation | ✓ |
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
| Live bindings | ✗ namespace objects and imported bindings are snapshots at module-evaluation time |
|
|
14
14
|
| ESM `node_modules` packages | ✓ bare specifiers resolve up the tree through `exports` / `module` / `main`, including scoped packages and subpaths; the package sources are bundled like relative modules |
|
|
15
15
|
| CommonJS `require` / `module.exports` | ✓ inside `node_modules` only: the bundler gives each CommonJS package a synthetic `module` / `exports` pair, lowers `require("x")` to the bundled dependency's exports, and hoists external/built-in `require`s into ESM imports. `require()` in user code (outside `node_modules`) is still rejected with a diagnostic pointing at the ESM `import` form. |
|
|
16
|
+
| Dynamic `import()` | ✓ a literal specifier is bundled as a deferred module; a computed one resolves at run time against the extension modules linked into the build (bare and `node:` names) and rejects otherwise. It cannot load an arbitrary file or npm package at run time |
|
|
16
17
|
|
|
17
18
|
> Extension modules (such as `fs`) are importable by bare or `node:`-prefixed
|
|
18
19
|
> specifier — `import { readFileSync } from "fs"` / `import path from "path"` —
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
| Generators (`function*`, `yield`, `yield*`, `next`/`throw`/`return`) | ✓ implemented with stackful coroutines; `for...of`, spread and delegation supported. `return()` completes without running `finally` |
|
|
34
34
|
| Timers and microtasks | ✓ `setTimeout` / `clearTimeout` / `setInterval` / `clearInterval` / `setImmediate` / `clearImmediate` / `queueMicrotask` and `performance.now` (numeric ids, no `Timeout` / `Immediate` object). A promise settled from a timer can be awaited: the async body suspends on the pending promise and resumes when the timer fires |
|
|
35
35
|
| I/O / process and other host APIs | only via extensions (e.g. Node `fs`) |
|
|
36
|
-
| Web-platform globals (`
|
|
36
|
+
| Web-platform globals (`Reflect`, `Intl`, `FormData`, `Blob`, `Request`, `EventTarget`) | ✗ recognized (they type-check and lower to `undefined`), but no runtime implementation. `AbortController` / `AbortSignal` / `Headers` / `Response` are implemented, and `globalThis` / `global` are a plain property bag (see [Implemented: standard library](../implemented/stdlib.md#web-platform-globals)) |
|
|
37
|
+
| `Proxy` | ✓ object targets with `get` / `set` / `has` / `deleteProperty` / `ownKeys` (see [Implemented: Proxy](../implemented/stdlib.md#proxy)). ✗ function targets (`apply`/`construct`), `Proxy.revocable`, prototype and property-descriptor traps, invariant checking |
|
|
37
38
|
| Web Streams (`ReadableStream`, `WritableStream`, `TransformStream`, readers/writers, text streams) | ✓ implemented as core globals; see [Web Streams](../implemented/streams.md). BYOB byte streams and compression streams are not implemented |
|
|
38
39
|
|
|
39
40
|
## Typed arrays
|
|
@@ -58,6 +58,11 @@
|
|
|
58
58
|
"items": { "type": "string" },
|
|
59
59
|
"description": "Optional link features to keep out even when auto-detection finds a use."
|
|
60
60
|
},
|
|
61
|
+
"moduleOverrides": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"description": "Replace module specifiers with local files, e.g. { \"jiti\": \"stubs/jiti.ts\" }. Keys match the exact specifier text; values are file paths (with extension) resolved against this config's directory. An override wins over node_modules, Node built-ins and extension modules.",
|
|
64
|
+
"additionalProperties": { "type": "string" }
|
|
65
|
+
},
|
|
61
66
|
"force": {
|
|
62
67
|
"type": "boolean",
|
|
63
68
|
"description": "Ignore the incremental cache."
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
- 作用域种类:模块、函数、块、`for`、`catch`
|
|
8
8
|
- 符号种类:`var` / `let` / `const` / `function` / `parameter` / `class` / `interface` / `type` / `enum` / `import` / `namespace`
|
|
9
|
-
- `var` 与函数声明提升到函数作用域;`let` / `const`
|
|
9
|
+
- `var` 与函数声明提升到函数作用域;`let` / `const` 保持块作用域。写在嵌套块内或 `for` 头部的 `var` 复用同一个提升符号,因此 `{ var x = 1 }` 在块之后依然可见(可赋值)
|
|
10
|
+
- 解构**参数**先声明其名字,再绑定模式内部的默认值,因此 `({ a = () => 1 }) => a()` 中的箭头函数能拿到自己的函数信息
|
|
10
11
|
- `switch` 主体是一个共享块作用域:所有 `case` / `default` 子句中的声明会在绑定任意子句之前预先声明
|
|
11
12
|
- `static { ... }` 类静态块绑定为类的隐藏静态函数(见[类与面向对象](../unimplemented/classes.md))
|
|
12
13
|
- 标识符 → 声明 的解析;未解析标识符收集(`CannotFindName`)
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
- 接口与类型别名(含泛型别名与 `extends`);
|
|
27
27
|
- 类:实例字段、方法、访问器、参数属性、`this.x = ...` 成员与本地祖先类。
|
|
28
28
|
静态成员不算实例成员;
|
|
29
|
+
- 声明可见性:模块顶层的 interface / type alias / class 对整个 bundle 可见,
|
|
30
|
+
而**函数体内**声明的只在其所在文件内生效。打包后的依赖里满是函数内的类
|
|
31
|
+
(`babel.cjs` 自带一个 `class Token`),它们不能劫持引用方想要的那个类型名;
|
|
29
32
|
- 数组、元组、函数类型、对象字面量与 `new LocalClass()`;
|
|
30
33
|
- 简单泛型:声明处的类型参数视为 `any`;调用时从实参推断(`T`、`T[]`、
|
|
31
34
|
`Array<T>`),或使用显式类型实参。
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
- 单引号 / 双引号
|
|
17
17
|
- 转义:`\n \t \r \b \f \0 \\ \' \"`、`\xHH`、`\uHHHH`、`\u{...}`
|
|
18
18
|
- 模板字面量(词法层):无替换模板、模板头 `TemplateHead`、模板中 `TemplateMiddle`、模板尾 `TemplateTail`,支持 `${}` 与转义。
|
|
19
|
-
- 正则字面量扫描(`/pattern/flags`),并区分除法
|
|
19
|
+
- 正则字面量扫描(`/pattern/flags`),并区分除法 `/`。判定依赖上一个 token,因此不可能处处正确(`for (;;) /re/.test(x)` 看起来像除法);parser 保留了重新读取原始源码的兜底,误判只需保持静默。
|
|
20
20
|
- 私有标识符 `#name`。
|
|
21
21
|
- 注释:单行 `//` 与块注释 `/* */`(含未闭合诊断)。
|
|
22
22
|
- 换行与空白跟踪(用于 ASI),BOM / CRLF 规范化(`SourceFile`)。
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
## 语法
|
|
9
9
|
|
|
10
10
|
- `import default, { named } from "..."`、`import * as ns from "..."`(相对模块的命名空间导入会降级为合成对象字面量;扩展模块如 `path` 亦已支持)、`import "./side-effect"`、`import type`
|
|
11
|
-
- `export default`、`export { a as b }`、`export *`、`export =`
|
|
11
|
+
- `export default`、`export { a as b }`、`export *`、`export * as ns from "..."`、`export =`
|
|
12
12
|
- import attributes(`with` / `assert`)
|
|
13
13
|
|
|
14
14
|
## 运行时语义
|
|
@@ -31,12 +31,28 @@
|
|
|
31
31
|
import 一样链接。
|
|
32
32
|
- 同时被普通(非标记)import 引用的模块保持立即求值,并获得一个返回已初始化
|
|
33
33
|
导出的薄包装。
|
|
34
|
+
- 函数声明与简单顶层 `const`/`let`/`var` 的绑定会*提升*到 wrapper 之外,wrapper 按源码
|
|
35
|
+
顺序给它们赋值。这样模块循环才能在对模块体执行前调用依赖的函数(对这类函数的 import
|
|
36
|
+
直接引用其最终名字,而不是复制成别名)。顶层含解构、`class` 或 `enum` 的模块仍把
|
|
37
|
+
所有声明留在 wrapper 内,因此循环调用它们的函数仍会拿到 `undefined`。
|
|
38
|
+
- 同一条机制有两个触发点。HTML 页面里 `<script src>`(或内联脚本)的 import 会带上
|
|
39
|
+
`__xt_deferred_module` 标记,脚本在 `loadHTML` 之后由引擎执行时调用该标记;字面量
|
|
40
|
+
`import("…")` 则在 import 处直接调用同一个 wrapper。两者都只求值一次(`__xt_defer`
|
|
41
|
+
按模块 id 记忆),wrapper 语义完全一致——函数提升、`export * as` 绑定、模块循环在两种
|
|
42
|
+
触发方式下表现相同。两者的调用最终都进入同一个运行时助手(`xt_defer_module`,bundler
|
|
43
|
+
以裸全局调用的形式发射它),区别只在*谁*触发求值:脚本由引擎决定时机,`import("…")`
|
|
44
|
+
由程序自己决定。
|
|
34
45
|
- 包装体是同步的:延迟脚本模块中的顶层 `await` 不受支持。
|
|
35
46
|
|
|
36
47
|
## import.meta
|
|
37
48
|
|
|
38
49
|
- `import.meta.url` / `.dirname` / `.filename`,由正在运行的可执行文件路径解析。
|
|
39
50
|
|
|
51
|
+
## 动态 `import()`
|
|
52
|
+
|
|
53
|
+
- **字面量**说明符是静态边:模块被打包,调用解析为它的命名空间对象。
|
|
54
|
+
- **计算出来**的说明符在运行时无法加载模块(编译产物没有模块加载器),但构建时链接进来的模块是已知的:`import(<表达式>)` 会解析到任一已启用扩展模块的命名空间,裸名称与 `node:` 前缀两种写法都接受——`const fs = await import("node:" + "fs")`。其他说明符会以带说明符名字的错误拒绝。
|
|
55
|
+
|
|
40
56
|
## 扩展模块
|
|
41
57
|
|
|
42
58
|
- 扩展模块(如 `fs`)可通过裸名称或 `node:` 前缀的 `import` 引入,并解析到运行时入口;见[扩展机制](./extensions.md)。
|