xbintsc 0.6.18 → 0.6.20
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/ast/common.d.ts +2 -2
- package/dist/src/ast/declarations.d.ts +2 -0
- package/dist/src/ast/expressions.d.ts +5 -0
- package/dist/src/ast/kinds.d.ts +2 -0
- package/dist/src/ast/kinds.js +2 -0
- package/dist/src/ast/kinds.js.map +1 -1
- package/dist/src/ast/types.d.ts +2 -0
- package/dist/src/binder/binder.d.ts +6 -0
- package/dist/src/binder/binder.js +13 -0
- package/dist/src/binder/binder.js.map +1 -1
- package/dist/src/binder/references.js +9 -2
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/assignability.js +11 -3
- package/dist/src/checker/assignability.js.map +1 -1
- package/dist/src/checker/calls.js +4 -0
- package/dist/src/checker/calls.js.map +1 -1
- package/dist/src/checker/flow.js +16 -12
- package/dist/src/checker/flow.js.map +1 -1
- package/dist/src/checker/globals.js +3 -1
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-system.js +1 -0
- package/dist/src/checker/type-system.js.map +1 -1
- package/dist/src/checker/typecheck.js +8 -1
- package/dist/src/checker/typecheck.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +3 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +3 -1
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +8 -4
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/context.js +3 -3
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +1 -0
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/module-values.d.ts +21 -0
- package/dist/src/codegen/generator/expressions/module-values.js +84 -0
- package/dist/src/codegen/generator/expressions/module-values.js.map +1 -0
- package/dist/src/codegen/generator/expressions/primary.js +38 -6
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/module.js +16 -6
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +6 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/statements/dispatch.js +10 -0
- package/dist/src/codegen/generator/statements/dispatch.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +7 -0
- package/dist/src/codegen/generator/tables.js +26 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.js +9 -5
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/deferred.d.ts +1 -1
- package/dist/src/driver/bundler/deferred.js +2 -2
- package/dist/src/driver/bundler/deferred.js.map +1 -1
- package/dist/src/driver/bundler/dynamic-import.d.ts +30 -0
- package/dist/src/driver/bundler/dynamic-import.js +123 -0
- package/dist/src/driver/bundler/dynamic-import.js.map +1 -0
- package/dist/src/driver/bundler/graph.d.ts +1 -1
- package/dist/src/driver/bundler/graph.js +30 -12
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.d.ts +1 -1
- package/dist/src/driver/bundler/merge.js +37 -55
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/namespace-import.d.ts +7 -0
- package/dist/src/driver/bundler/namespace-import.js +46 -0
- package/dist/src/driver/bundler/namespace-import.js.map +1 -0
- package/dist/src/driver/bundler/reexport-fixup.d.ts +14 -0
- package/dist/src/driver/bundler/reexport-fixup.js +92 -0
- package/dist/src/driver/bundler/reexport-fixup.js.map +1 -0
- package/dist/src/driver/bundler/resolve.d.ts +6 -5
- package/dist/src/driver/bundler/resolve.js +52 -6
- package/dist/src/driver/bundler/resolve.js.map +1 -1
- package/dist/src/driver/bundler/symbols.d.ts +4 -0
- package/dist/src/driver/bundler/symbols.js +12 -0
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/bundler/types.d.ts +1 -0
- package/dist/src/driver/compiler.js +1 -1
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +2 -0
- package/dist/src/driver/config.js +18 -0
- package/dist/src/driver/config.js.map +1 -1
- package/dist/src/driver/frontend.d.ts +3 -1
- package/dist/src/driver/frontend.js +5 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/options.d.ts +5 -0
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +2 -0
- 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/extensions/node/async-hooks/index.d.ts +6 -0
- package/dist/src/extensions/node/async-hooks/index.js +19 -0
- package/dist/src/extensions/node/async-hooks/index.js.map +1 -0
- package/dist/src/extensions/node/buffer/index.js +2 -0
- package/dist/src/extensions/node/buffer/index.js.map +1 -1
- package/dist/src/extensions/node/child_process/index.js +10 -1
- package/dist/src/extensions/node/child_process/index.js.map +1 -1
- package/dist/src/extensions/node/console/index.d.ts +6 -0
- package/dist/src/extensions/node/console/index.js +34 -0
- package/dist/src/extensions/node/console/index.js.map +1 -0
- package/dist/src/extensions/node/constants/index.d.ts +6 -0
- package/dist/src/extensions/node/constants/index.js +27 -0
- package/dist/src/extensions/node/constants/index.js.map +1 -0
- package/dist/src/extensions/node/diagnostics-channel/index.d.ts +5 -0
- package/dist/src/extensions/node/diagnostics-channel/index.js +16 -0
- package/dist/src/extensions/node/diagnostics-channel/index.js.map +1 -0
- package/dist/src/extensions/node/dns/index.d.ts +5 -0
- package/dist/src/extensions/node/dns/index.js +14 -0
- package/dist/src/extensions/node/dns/index.js.map +1 -0
- package/dist/src/extensions/node/events/index.js +1 -0
- package/dist/src/extensions/node/events/index.js.map +1 -1
- package/dist/src/extensions/node/http/index.js +5 -1
- package/dist/src/extensions/node/http/index.js.map +1 -1
- package/dist/src/extensions/node/http2/index.d.ts +5 -0
- package/dist/src/extensions/node/http2/index.js +16 -0
- package/dist/src/extensions/node/http2/index.js.map +1 -0
- package/dist/src/extensions/node/index.js +36 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/module/index.d.ts +5 -0
- package/dist/src/extensions/node/module/index.js +15 -0
- package/dist/src/extensions/node/module/index.js.map +1 -0
- package/dist/src/extensions/node/os/index.js +4 -1
- package/dist/src/extensions/node/os/index.js.map +1 -1
- package/dist/src/extensions/node/path/index.js +9 -1
- package/dist/src/extensions/node/path/index.js.map +1 -1
- package/dist/src/extensions/node/perf_hooks/index.d.ts +6 -0
- package/dist/src/extensions/node/perf_hooks/index.js +15 -0
- package/dist/src/extensions/node/perf_hooks/index.js.map +1 -0
- package/dist/src/extensions/node/readline-promises/index.d.ts +5 -0
- package/dist/src/extensions/node/readline-promises/index.js +14 -0
- package/dist/src/extensions/node/readline-promises/index.js.map +1 -0
- package/dist/src/extensions/node/sqlite/index.d.ts +6 -0
- package/dist/src/extensions/node/sqlite/index.js +16 -0
- package/dist/src/extensions/node/sqlite/index.js.map +1 -0
- package/dist/src/extensions/node/stream/index.js +2 -0
- package/dist/src/extensions/node/stream/index.js.map +1 -1
- package/dist/src/extensions/node/stream-web/index.d.ts +5 -0
- package/dist/src/extensions/node/stream-web/index.js +17 -0
- package/dist/src/extensions/node/stream-web/index.js.map +1 -0
- package/dist/src/extensions/node/string-decoder/index.d.ts +5 -0
- package/dist/src/extensions/node/string-decoder/index.js +14 -0
- package/dist/src/extensions/node/string-decoder/index.js.map +1 -0
- package/dist/src/extensions/node/timers/index.d.ts +6 -0
- package/dist/src/extensions/node/timers/index.js +20 -0
- package/dist/src/extensions/node/timers/index.js.map +1 -0
- package/dist/src/extensions/node/timers-promises/index.d.ts +5 -0
- package/dist/src/extensions/node/timers-promises/index.js +15 -0
- package/dist/src/extensions/node/timers-promises/index.js.map +1 -0
- package/dist/src/extensions/node/tls/index.d.ts +5 -0
- package/dist/src/extensions/node/tls/index.js +16 -0
- package/dist/src/extensions/node/tls/index.js.map +1 -0
- package/dist/src/extensions/node/tty/index.d.ts +5 -0
- package/dist/src/extensions/node/tty/index.js +14 -0
- package/dist/src/extensions/node/tty/index.js.map +1 -0
- package/dist/src/extensions/node/url/index.js +1 -0
- package/dist/src/extensions/node/url/index.js.map +1 -1
- package/dist/src/extensions/node/util/index.js +15 -1
- package/dist/src/extensions/node/util/index.js.map +1 -1
- package/dist/src/extensions/node/util-types/index.d.ts +6 -0
- package/dist/src/extensions/node/util-types/index.js +26 -0
- package/dist/src/extensions/node/util-types/index.js.map +1 -0
- package/dist/src/extensions/node/worker_threads/index.js +1 -0
- package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
- package/dist/src/extensions/node/zlib/compression.d.ts +10 -0
- package/dist/src/extensions/node/zlib/compression.js +44 -0
- package/dist/src/extensions/node/zlib/compression.js.map +1 -0
- package/dist/src/extensions/node/zlib/index.d.ts +5 -2
- package/dist/src/extensions/node/zlib/index.js +21 -2
- package/dist/src/extensions/node/zlib/index.js.map +1 -1
- package/dist/src/lexer/scanner/punctuation.js +8 -2
- package/dist/src/lexer/scanner/punctuation.js.map +1 -1
- package/dist/src/lexer/scanner/regex.d.ts +3 -1
- package/dist/src/lexer/scanner/regex.js +32 -22
- package/dist/src/lexer/scanner/regex.js.map +1 -1
- package/dist/src/lexer/scanner.d.ts +2 -0
- package/dist/src/lexer/scanner.js +8 -0
- package/dist/src/lexer/scanner.js.map +1 -1
- package/dist/src/lexer/token.d.ts +1 -0
- package/dist/src/lexer/token.js +2 -0
- package/dist/src/lexer/token.js.map +1 -1
- package/dist/src/parser/declarations/classes.js +7 -0
- package/dist/src/parser/declarations/classes.js.map +1 -1
- package/dist/src/parser/declarations/functions.js +8 -2
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/expressions.d.ts +2 -2
- package/dist/src/parser/expressions.js +32 -17
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.js +1 -0
- package/dist/src/parser/helpers.js.map +1 -1
- package/dist/src/parser/literals.js +27 -0
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/src/parser/statements.js +3 -0
- package/dist/src/parser/statements.js.map +1 -1
- package/dist/src/parser/types.js +106 -45
- package/dist/src/parser/types.js.map +1 -1
- package/dist/tests/binder/binder.test.js +8 -1
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +63 -0
- package/dist/tests/checker/checker.test.js.map +1 -1
- package/dist/tests/codegen/expressions.test.js +8 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/conformance/test262/manifest.js +9 -10
- package/dist/tests/conformance/test262/manifest.js.map +1 -1
- package/dist/tests/driver/bundler-resolve.test.js +22 -0
- package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
- package/dist/tests/driver/config.test.js +15 -0
- package/dist/tests/driver/config.test.js.map +1 -1
- package/dist/tests/driver/deferred-reexport.test.d.ts +9 -0
- package/dist/tests/driver/deferred-reexport.test.js +62 -0
- package/dist/tests/driver/deferred-reexport.test.js.map +1 -0
- package/dist/tests/driver/modules.test.js +110 -11
- package/dist/tests/driver/modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-basics.test.js +11 -0
- package/dist/tests/e2e/compile-basics.test.js.map +1 -1
- 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.test.js +49 -0
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js +32 -0
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/node-modules.test.js +174 -0
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/npm-modules.test.js +8 -0
- package/dist/tests/e2e/npm-modules.test.js.map +1 -1
- package/dist/tests/e2e/weak-collections.test.js +12 -0
- package/dist/tests/e2e/weak-collections.test.js.map +1 -1
- package/dist/tests/lexer/scanner.test.js +17 -0
- package/dist/tests/lexer/scanner.test.js.map +1 -1
- package/dist/tests/parser/declarations.test.js +24 -0
- package/dist/tests/parser/declarations.test.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +34 -7
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/dist/tests/parser/literals.test.js +15 -0
- package/dist/tests/parser/literals.test.js.map +1 -1
- package/dist/tests/parser/types.test.js +26 -0
- package/dist/tests/parser/types.test.js.map +1 -1
- package/doc/ai/language-support.md +4 -2
- package/doc/ai/zh-CN/language-support.md +4 -2
- package/doc/implemented/node/buffer.md +2 -0
- package/doc/implemented/node/child-process.md +29 -6
- package/doc/implemented/node/http.md +2 -0
- package/doc/implemented/node/os.md +1 -0
- package/doc/implemented/node/path.md +3 -0
- package/doc/implemented/node/stream.md +3 -0
- package/doc/implemented/node/util.md +1 -0
- package/doc/implemented/node/zlib.md +12 -1
- package/doc/implemented/node.md +8 -1
- package/doc/implemented/wasm.md +22 -0
- package/doc/implemented.md +1 -0
- package/doc/support-matrix.md +3 -3
- package/doc/unimplemented/node/modules.md +4 -3
- package/doc/unimplemented/stdlib.md +1 -0
- package/doc/unimplemented/wasm.md +15 -0
- package/doc/unimplemented.md +1 -0
- package/doc/zh-CN/implemented/node/child-process.md +27 -5
- package/doc/zh-CN/implemented/node.md +1 -1
- package/doc/zh-CN/implemented/wasm.md +20 -0
- package/doc/zh-CN/implemented.md +1 -0
- package/doc/zh-CN/support-matrix.md +3 -3
- package/doc/zh-CN/unimplemented/node/modules.md +3 -2
- package/doc/zh-CN/unimplemented/stdlib.md +1 -0
- package/doc/zh-CN/unimplemented/wasm.md +14 -0
- package/doc/zh-CN/unimplemented.md +1 -0
- package/package.json +7 -7
- package/runtime/ext_node/async_hooks/async_hooks.c +59 -0
- package/runtime/ext_node/buffer/parts/static-api.inc +39 -0
- package/runtime/ext_node/child_process/spawn.c +201 -0
- package/runtime/ext_node/child_process/spawn.h +56 -0
- package/runtime/ext_node/child_process/spawn_posix.c +206 -0
- package/runtime/ext_node/child_process/spawn_win.c +276 -0
- package/runtime/ext_node/console/console.c +67 -0
- package/runtime/ext_node/constants/constants.c +72 -0
- package/runtime/ext_node/diagnostics_channel/diagnostics_channel.c +61 -0
- package/runtime/ext_node/dns/dns.c +77 -0
- package/runtime/ext_node/events/events.c +7 -0
- package/runtime/ext_node/http/http.c +38 -0
- package/runtime/ext_node/http2/http2.c +26 -0
- package/runtime/ext_node/module/module.c +31 -0
- package/runtime/ext_node/os/os.c +42 -0
- package/runtime/ext_node/path/path.c +93 -0
- package/runtime/ext_node/perf_hooks/perf_hooks.c +22 -0
- package/runtime/ext_node/readline_promises/readline_promises.c +59 -0
- package/runtime/ext_node/sqlite/sqlite.c +24 -0
- package/runtime/ext_node/stream/stream.c +19 -1
- package/runtime/ext_node/stream_web/stream_web.c +22 -0
- package/runtime/ext_node/string_decoder/string_decoder.c +31 -0
- package/runtime/ext_node/timers_promises/timers_promises.c +58 -0
- package/runtime/ext_node/tls/tls.c +26 -0
- package/runtime/ext_node/tty/tty.c +18 -0
- package/runtime/ext_node/util/util.c +84 -0
- package/runtime/ext_node/worker_threads/worker_threads.c +8 -0
- package/runtime/ext_node/zlib/miniz/compression_bridge.c +43 -0
- package/runtime/ext_node/zlib/miniz/miniz.c +646 -0
- package/runtime/ext_node/zlib/miniz/miniz.h +615 -0
- package/runtime/ext_node/zlib/miniz/miniz_common.h +89 -0
- package/runtime/ext_node/zlib/miniz/miniz_export.h +4 -0
- package/runtime/ext_node/zlib/miniz/miniz_tdef.c +1653 -0
- package/runtime/ext_node/zlib/miniz/miniz_tdef.h +206 -0
- package/runtime/ext_node/zlib/miniz/miniz_tinfl.c +778 -0
- package/runtime/ext_node/zlib/miniz/miniz_tinfl.h +150 -0
- package/runtime/ext_node/zlib/miniz/miniz_zip.h +454 -0
- package/runtime/ext_node/zlib/zlib.c +194 -0
- package/runtime/xt_builtins.c +1 -0
- package/runtime/xt_constructors.c +5 -0
- package/runtime/xt_module_values.c +29 -0
- package/runtime/xt_weak.c +43 -0
- package/runtime/xt_webassembly.c +53 -0
- package/scripts/check-file-length.ts +10 -0
- package/src/ast/common.ts +2 -0
- package/src/ast/declarations.ts +2 -0
- package/src/ast/expressions.ts +6 -0
- package/src/ast/kinds.ts +2 -0
- package/src/ast/types.ts +2 -0
- package/src/binder/binder.ts +13 -0
- package/src/binder/references.ts +9 -2
- package/src/checker/assignability.ts +12 -2
- package/src/checker/calls.ts +3 -0
- package/src/checker/flow.ts +13 -9
- package/src/checker/globals.ts +3 -0
- package/src/checker/type-system.ts +1 -0
- package/src/checker/typecheck.ts +8 -1
- package/src/cli/main.ts +3 -0
- package/src/codegen/generator/calls/access.ts +4 -1
- package/src/codegen/generator/calls/invocation.ts +8 -4
- package/src/codegen/generator/context.ts +5 -3
- package/src/codegen/generator/expressions/assignment.ts +1 -0
- package/src/codegen/generator/expressions/module-values.ts +105 -0
- package/src/codegen/generator/expressions/primary.ts +35 -5
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/module.ts +16 -5
- package/src/codegen/generator/state.ts +6 -0
- package/src/codegen/generator/statements/dispatch.ts +9 -0
- package/src/codegen/generator/tables.ts +27 -0
- package/src/driver/bundler/commonjs.ts +18 -5
- package/src/driver/bundler/deferred.ts +2 -1
- package/src/driver/bundler/dynamic-import.ts +135 -0
- package/src/driver/bundler/graph.ts +34 -19
- package/src/driver/bundler/merge.ts +38 -64
- package/src/driver/bundler/namespace-import.ts +59 -0
- package/src/driver/bundler/reexport-fixup.ts +102 -0
- package/src/driver/bundler/resolve.ts +49 -5
- package/src/driver/bundler/symbols.ts +13 -0
- package/src/driver/bundler/types.ts +1 -0
- package/src/driver/compiler.ts +1 -1
- package/src/driver/config.ts +20 -0
- package/src/driver/frontend.ts +13 -8
- package/src/driver/options.ts +5 -0
- package/src/driver/runtime-objects.ts +2 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/node/async-hooks/index.ts +23 -0
- package/src/extensions/node/buffer/index.ts +2 -0
- package/src/extensions/node/child_process/index.ts +13 -1
- package/src/extensions/node/console/index.ts +44 -0
- package/src/extensions/node/constants/index.ts +34 -0
- package/src/extensions/node/diagnostics-channel/index.ts +20 -0
- package/src/extensions/node/dns/index.ts +18 -0
- package/src/extensions/node/events/index.ts +1 -0
- package/src/extensions/node/http/index.ts +5 -3
- package/src/extensions/node/http2/index.ts +20 -0
- package/src/extensions/node/index.ts +36 -0
- package/src/extensions/node/module/index.ts +19 -0
- package/src/extensions/node/os/index.ts +4 -3
- package/src/extensions/node/path/index.ts +9 -3
- package/src/extensions/node/perf_hooks/index.ts +19 -0
- package/src/extensions/node/readline-promises/index.ts +18 -0
- package/src/extensions/node/sqlite/index.ts +20 -0
- package/src/extensions/node/stream/index.ts +3 -0
- package/src/extensions/node/stream-web/index.ts +21 -0
- package/src/extensions/node/string-decoder/index.ts +18 -0
- package/src/extensions/node/timers/index.ts +27 -0
- package/src/extensions/node/timers-promises/index.ts +19 -0
- package/src/extensions/node/tls/index.ts +20 -0
- package/src/extensions/node/tty/index.ts +18 -0
- package/src/extensions/node/url/index.ts +1 -0
- package/src/extensions/node/util/index.ts +15 -3
- package/src/extensions/node/util-types/index.ts +33 -0
- package/src/extensions/node/worker_threads/index.ts +1 -0
- package/src/extensions/node/zlib/compression.ts +48 -0
- package/src/extensions/node/zlib/index.ts +23 -2
- package/src/lexer/scanner/punctuation.ts +7 -1
- package/src/lexer/scanner/regex.ts +31 -22
- package/src/lexer/scanner.ts +7 -0
- package/src/lexer/token.ts +2 -0
- package/src/parser/declarations/classes.ts +7 -0
- package/src/parser/declarations/functions.ts +9 -3
- package/src/parser/expressions.ts +29 -20
- package/src/parser/helpers.ts +1 -0
- package/src/parser/literals.ts +28 -0
- package/src/parser/statements.ts +3 -0
- package/src/parser/types.ts +106 -43
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `sqlite` module: `DatabaseSync` / `StatementSync` (both throw, since
|
|
3
|
+
* SQLite is not linked).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { NodeModule } from "../module.js";
|
|
7
|
+
import { resolveFrom } from "../module.js";
|
|
8
|
+
import type { ModuleExports } from "../../registry.js";
|
|
9
|
+
|
|
10
|
+
const exports: ModuleExports = {
|
|
11
|
+
DatabaseSync: { symbol: "xt_sqlite_database_sync_ctor", isConstructor: true },
|
|
12
|
+
StatementSync: { symbol: "xt_sqlite_statement_sync_ctor", isConstructor: true },
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const sqliteModule: NodeModule = {
|
|
16
|
+
name: "sqlite",
|
|
17
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/sqlite/sqlite.c")],
|
|
18
|
+
builtins: () => ({}),
|
|
19
|
+
exports: () => exports,
|
|
20
|
+
};
|
|
@@ -11,12 +11,15 @@ import type { NodeModule } from "../module.js";
|
|
|
11
11
|
import { resolveFrom } from "../module.js";
|
|
12
12
|
import type { ModuleExports } from "../../registry.js";
|
|
13
13
|
|
|
14
|
+
const methods = ["isReadable", "isErrored", "isDisturbed", "finished", "pipeline"] as const;
|
|
15
|
+
|
|
14
16
|
const exports: ModuleExports = {
|
|
15
17
|
Readable: { symbol: "xt_readable_ctor", isConstructor: true },
|
|
16
18
|
Writable: { symbol: "xt_writable_ctor", isConstructor: true },
|
|
17
19
|
Duplex: { symbol: "xt_duplex_ctor", isConstructor: true },
|
|
18
20
|
Transform: { symbol: "xt_transform_ctor", isConstructor: true },
|
|
19
21
|
PassThrough: { symbol: "xt_pass_through_ctor", isConstructor: true },
|
|
22
|
+
...Object.fromEntries(methods.map((method) => [method, { namespace: "stream", method }])),
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
export const streamModule: NodeModule = {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `stream/web` subpath module (WHATWG streams, not implemented).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { NodeModule } from "../module.js";
|
|
6
|
+
import { resolveFrom } from "../module.js";
|
|
7
|
+
import type { ModuleExports } from "../../registry.js";
|
|
8
|
+
|
|
9
|
+
const exports: ModuleExports = {
|
|
10
|
+
ReadableStreamTee: { valueSymbol: "xt_stream_web_tee" },
|
|
11
|
+
ReadableStream: { symbol: "xt_stream_web_unsupported_ctor", isConstructor: true },
|
|
12
|
+
WritableStream: { symbol: "xt_stream_web_unsupported_ctor", isConstructor: true },
|
|
13
|
+
TransformStream: { symbol: "xt_stream_web_unsupported_ctor", isConstructor: true },
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const streamWebModule: NodeModule = {
|
|
17
|
+
name: "stream/web",
|
|
18
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/stream_web/stream_web.c")],
|
|
19
|
+
builtins: () => ({}),
|
|
20
|
+
exports: () => exports,
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `string_decoder` module: the `StringDecoder` class.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { NodeModule } from "../module.js";
|
|
6
|
+
import { resolveFrom } from "../module.js";
|
|
7
|
+
import type { ModuleExports } from "../../registry.js";
|
|
8
|
+
|
|
9
|
+
const exports: ModuleExports = {
|
|
10
|
+
StringDecoder: { symbol: "xt_string_decoder_ctor", isConstructor: true },
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const stringDecoderModule: NodeModule = {
|
|
14
|
+
name: "string_decoder",
|
|
15
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/string_decoder/string_decoder.c")],
|
|
16
|
+
builtins: () => ({}),
|
|
17
|
+
exports: () => exports,
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `timers` module: re-exports the timer globals the core runtime already
|
|
3
|
+
* provides (`setTimeout`, `setInterval`, `setImmediate` and their clear forms).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { NodeModule } from "../module.js";
|
|
7
|
+
import type { ModuleExports } from "../../registry.js";
|
|
8
|
+
|
|
9
|
+
const symbols: Record<string, string> = {
|
|
10
|
+
setTimeout: "xt_set_timeout",
|
|
11
|
+
clearTimeout: "xt_clear_timeout",
|
|
12
|
+
setInterval: "xt_set_interval",
|
|
13
|
+
clearInterval: "xt_clear_interval",
|
|
14
|
+
setImmediate: "xt_set_immediate",
|
|
15
|
+
clearImmediate: "xt_clear_immediate",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const exports: ModuleExports = Object.fromEntries(
|
|
19
|
+
Object.entries(symbols).map(([name, symbol]) => [name, { symbol }]),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const timersModule: NodeModule = {
|
|
23
|
+
name: "timers",
|
|
24
|
+
runtimeSources: () => [],
|
|
25
|
+
builtins: () => ({}),
|
|
26
|
+
exports: () => exports,
|
|
27
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `timers/promises` subpath module: promise-returning timer functions.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { NodeModule } from "../module.js";
|
|
6
|
+
import { resolveFrom } from "../module.js";
|
|
7
|
+
import type { ModuleExports } from "../../registry.js";
|
|
8
|
+
|
|
9
|
+
const exports: ModuleExports = {
|
|
10
|
+
setTimeout: { symbol: "xt_timers_promises_set_timeout" },
|
|
11
|
+
setImmediate: { symbol: "xt_timers_promises_set_immediate" },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const timersPromisesModule: NodeModule = {
|
|
15
|
+
name: "timers/promises",
|
|
16
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/timers_promises/timers_promises.c")],
|
|
17
|
+
builtins: () => ({}),
|
|
18
|
+
exports: () => exports,
|
|
19
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `tls` module — a stub (TLS is not implemented).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { NodeModule } from "../module.js";
|
|
6
|
+
import { resolveFrom } from "../module.js";
|
|
7
|
+
import type { ModuleExports } from "../../registry.js";
|
|
8
|
+
|
|
9
|
+
const exports: ModuleExports = {
|
|
10
|
+
connect: { symbol: "xt_tls_connect" },
|
|
11
|
+
createServer: { symbol: "xt_tls_create_server" },
|
|
12
|
+
TLSSocket: { symbol: "xt_tls_socket_ctor", isConstructor: true },
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const tlsModule: NodeModule = {
|
|
16
|
+
name: "tls",
|
|
17
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/tls/tls.c")],
|
|
18
|
+
builtins: () => ({}),
|
|
19
|
+
exports: () => exports,
|
|
20
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `tty` module: `isatty(fd)`.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { NodeModule } from "../module.js";
|
|
6
|
+
import { resolveFrom } from "../module.js";
|
|
7
|
+
import type { ModuleExports } from "../../registry.js";
|
|
8
|
+
|
|
9
|
+
const exports: ModuleExports = {
|
|
10
|
+
isatty: { symbol: "xt_tty_isatty" },
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const ttyModule: NodeModule = {
|
|
14
|
+
name: "tty",
|
|
15
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/tty/tty.c")],
|
|
16
|
+
builtins: () => ({}),
|
|
17
|
+
exports: () => exports,
|
|
18
|
+
};
|
|
@@ -16,6 +16,7 @@ const builtins: Record<string, BuiltinFunction> = {
|
|
|
16
16
|
const exports: ModuleExports = {
|
|
17
17
|
pathToFileURL: { symbol: "xt_url_path_to_file_url" },
|
|
18
18
|
fileURLToPath: { symbol: "xt_url_file_url_to_path" },
|
|
19
|
+
URL: { symbol: "xt_url_ctor", isConstructor: true },
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export const urlModule: NodeModule = {
|
|
@@ -33,11 +33,23 @@ const symbols: Record<string, string> = {
|
|
|
33
33
|
isRegExp: "xt_util_is_regexp",
|
|
34
34
|
isPromise: "xt_util_is_promise",
|
|
35
35
|
isError: "xt_util_is_error",
|
|
36
|
+
isMap: "xt_util_is_map",
|
|
37
|
+
isSet: "xt_util_is_set",
|
|
38
|
+
isWeakMap: "xt_util_is_weak_map",
|
|
39
|
+
isWeakSet: "xt_util_is_weak_set",
|
|
40
|
+
isArrayBuffer: "xt_util_is_array_buffer",
|
|
41
|
+
isTypedArray: "xt_util_is_typed_array",
|
|
42
|
+
isUint8Array: "xt_util_is_uint8_array",
|
|
43
|
+
isProxy: "xt_util_is_proxy",
|
|
44
|
+
debuglog: "xt_util_debuglog",
|
|
36
45
|
};
|
|
37
46
|
|
|
38
|
-
const exports: ModuleExports =
|
|
39
|
-
Object.entries(symbols).map(([name, symbol]) => [name, { symbol }]),
|
|
40
|
-
|
|
47
|
+
const exports: ModuleExports = {
|
|
48
|
+
...Object.fromEntries(Object.entries(symbols).map(([name, symbol]) => [name, { symbol }])),
|
|
49
|
+
TextDecoder: { symbol: "xt_text_decoder_ctor", isConstructor: true },
|
|
50
|
+
TextEncoder: { symbol: "xt_text_encoder_ctor", isConstructor: true },
|
|
51
|
+
types: { valueSymbol: "xt_util_types_value" },
|
|
52
|
+
};
|
|
41
53
|
|
|
42
54
|
export const utilModule: NodeModule = {
|
|
43
55
|
name: "util",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `util/types` subpath module: the `util.types` predicate functions as
|
|
3
|
+
* named exports, reusing the `util` module's `isX` runtime symbols.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { NodeModule } from "../module.js";
|
|
7
|
+
import type { ModuleExports } from "../../registry.js";
|
|
8
|
+
|
|
9
|
+
const symbols: Record<string, string> = {
|
|
10
|
+
isAnyArrayBuffer: "xt_util_is_array_buffer",
|
|
11
|
+
isArrayBuffer: "xt_util_is_array_buffer",
|
|
12
|
+
isDate: "xt_util_is_date",
|
|
13
|
+
isMap: "xt_util_is_map",
|
|
14
|
+
isPromise: "xt_util_is_promise",
|
|
15
|
+
isRegExp: "xt_util_is_regexp",
|
|
16
|
+
isSet: "xt_util_is_set",
|
|
17
|
+
isTypedArray: "xt_util_is_typed_array",
|
|
18
|
+
isUint8Array: "xt_util_is_uint8_array",
|
|
19
|
+
isWeakMap: "xt_util_is_weak_map",
|
|
20
|
+
isWeakSet: "xt_util_is_weak_set",
|
|
21
|
+
isProxy: "xt_util_is_proxy",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const exports: ModuleExports = Object.fromEntries(
|
|
25
|
+
Object.entries(symbols).map(([name, symbol]) => [name, { symbol }]),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const utilTypesModule: NodeModule = {
|
|
29
|
+
name: "util/types",
|
|
30
|
+
runtimeSources: () => [],
|
|
31
|
+
builtins: () => ({}),
|
|
32
|
+
exports: () => exports,
|
|
33
|
+
};
|
|
@@ -16,6 +16,7 @@ const exports: ModuleExports = {
|
|
|
16
16
|
isMainThread: { valueSymbol: "xt_worker_is_main_thread" },
|
|
17
17
|
workerData: { valueSymbol: "xt_worker_data" },
|
|
18
18
|
parentPort: { valueSymbol: "xt_worker_parent_port" },
|
|
19
|
+
markAsUncloneable: { symbol: "xt_worker_mark_as_uncloneable" },
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export const workerThreadsModule: NodeModule = {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `compression` link feature: miniz DEFLATE for `node:zlib`.
|
|
3
|
+
*
|
|
4
|
+
* The always-linked `zlib` module exposes `deflateRawSync` etc. with a
|
|
5
|
+
* stored-block (uncompressed) fallback. When a program actually reaches for
|
|
6
|
+
* compression, this feature compiles and links the miniz single-file library
|
|
7
|
+
* and installs its raw-DEFLATE backend into the `zlib` module.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { LinkFeature, ProgramUsage } from "../../link-feature.js";
|
|
11
|
+
import { resolveFrom } from "../module.js";
|
|
12
|
+
|
|
13
|
+
const COMPRESSION_IDENTIFIERS: ReadonlySet<string> = new Set([
|
|
14
|
+
"deflateRawSync",
|
|
15
|
+
"deflateSync",
|
|
16
|
+
"inflateSync",
|
|
17
|
+
"gzipSync",
|
|
18
|
+
"gunzipSync",
|
|
19
|
+
"unzipSync",
|
|
20
|
+
"createDeflate",
|
|
21
|
+
"createInflate",
|
|
22
|
+
"createGzip",
|
|
23
|
+
"createGunzip",
|
|
24
|
+
"createUnzip",
|
|
25
|
+
"createInflateRaw",
|
|
26
|
+
"createDeflateRaw",
|
|
27
|
+
"brotliCompressSync",
|
|
28
|
+
"brotliDecompressSync",
|
|
29
|
+
"createBrotliCompress",
|
|
30
|
+
"createBrotliDecompress",
|
|
31
|
+
"zstdCompressSync",
|
|
32
|
+
"zstdDecompressSync",
|
|
33
|
+
"createZstdCompress",
|
|
34
|
+
"createZstdDecompress",
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
export const compressionFeature: LinkFeature = {
|
|
38
|
+
name: "compression",
|
|
39
|
+
description: "miniz DEFLATE compression/decompression for node:zlib",
|
|
40
|
+
runtimeSources: () => [
|
|
41
|
+
resolveFrom(import.meta.url, "../../../../runtime/ext_node/zlib/miniz/miniz.c"),
|
|
42
|
+
resolveFrom(import.meta.url, "../../../../runtime/ext_node/zlib/miniz/miniz_tdef.c"),
|
|
43
|
+
resolveFrom(import.meta.url, "../../../../runtime/ext_node/zlib/miniz/miniz_tinfl.c"),
|
|
44
|
+
resolveFrom(import.meta.url, "../../../../runtime/ext_node/zlib/miniz/compression_bridge.c"),
|
|
45
|
+
],
|
|
46
|
+
used: (usage: ProgramUsage): boolean =>
|
|
47
|
+
[...usage.identifiers].some((name) => COMPRESSION_IDENTIFIERS.has(name)),
|
|
48
|
+
};
|
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Node's `zlib` module.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
4
|
+
* `createGzip()` returns a descriptor consumed by `stream/promises` `pipeline`;
|
|
5
|
+
* `crc32` and `deflateRawSync` are implemented (the latter via the optional
|
|
6
|
+
* `compression` link feature, miniz). The remaining `create*` decompressors
|
|
7
|
+
* return descriptors and the `zstd*` sync helpers are stubs. See
|
|
8
|
+
* `runtime/ext_node/zlib/zlib.c`.
|
|
6
9
|
*/
|
|
7
10
|
|
|
8
11
|
import type { NodeModule } from "../module.js";
|
|
9
12
|
import { resolveFrom } from "../module.js";
|
|
13
|
+
import type { ModuleExports } from "../../registry.js";
|
|
14
|
+
|
|
15
|
+
const exports: ModuleExports = {
|
|
16
|
+
createGzip: { symbol: "xt_node_create_gzip" },
|
|
17
|
+
crc32: { symbol: "xt_node_crc32" },
|
|
18
|
+
constants: { valueSymbol: "xt_zlib_constants_value" },
|
|
19
|
+
Z_DEFAULT_WINDOWBITS: { valueSymbol: "xt_zlib_default_windowbits_value" },
|
|
20
|
+
deflateRawSync: { symbol: "xt_node_deflate_raw_sync" },
|
|
21
|
+
createInflate: { symbol: "xt_node_create_inflate" },
|
|
22
|
+
createGunzip: { symbol: "xt_node_create_gunzip" },
|
|
23
|
+
createInflateRaw: { symbol: "xt_node_create_inflate_raw" },
|
|
24
|
+
createBrotliDecompress: { symbol: "xt_node_create_brotli_decompress" },
|
|
25
|
+
createZstdDecompress: { symbol: "xt_node_create_zstd_decompress" },
|
|
26
|
+
zstdCompressSync: { symbol: "xt_node_zstd_compress_sync" },
|
|
27
|
+
zstdDecompressSync: { symbol: "xt_node_zstd_decompress_sync" },
|
|
28
|
+
};
|
|
10
29
|
|
|
11
30
|
export const zlibModule: NodeModule = {
|
|
12
31
|
name: "zlib",
|
|
13
32
|
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/zlib/zlib.c")],
|
|
14
33
|
builtins: () => ({
|
|
15
34
|
createGzip: { symbol: "xt_node_create_gzip" },
|
|
35
|
+
crc32: { symbol: "xt_node_crc32" },
|
|
16
36
|
}),
|
|
37
|
+
exports: () => exports,
|
|
17
38
|
};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { DiagnosticCode } from "../../diagnostics/diagnostic.js";
|
|
6
6
|
import { Token, TokenKind } from "../token.js";
|
|
7
7
|
import { Char, isDigit } from "../char.js";
|
|
8
|
+
import { valueEndsExpression } from "./regex.js";
|
|
8
9
|
import type { Scanner } from "../scanner.js";
|
|
9
10
|
|
|
10
11
|
export interface PunctuationMethods {
|
|
@@ -65,6 +66,9 @@ export const punctuationMethods: PunctuationMethods = {
|
|
|
65
66
|
case Char.Exclamation:
|
|
66
67
|
if (next === Char.Equals && third === Char.Equals) return emit(TokenKind.ExclamationEqualsEquals, 3);
|
|
67
68
|
if (next === Char.Equals) return emit(TokenKind.ExclamationEquals, 2);
|
|
69
|
+
// A `!` after a complete value is a postfix non-null assertion, so a
|
|
70
|
+
// following `/` is division, not a regex.
|
|
71
|
+
this.postfixExclamation = valueEndsExpression(this._token.kind);
|
|
68
72
|
return emit(TokenKind.Exclamation, 1);
|
|
69
73
|
case Char.Plus:
|
|
70
74
|
if (next === Char.Plus) return emit(TokenKind.PlusPlus, 2);
|
|
@@ -82,8 +86,10 @@ export const punctuationMethods: PunctuationMethods = {
|
|
|
82
86
|
if (next === Char.Equals) return emit(TokenKind.AsteriskEquals, 2);
|
|
83
87
|
return emit(TokenKind.Asterisk, 1);
|
|
84
88
|
case Char.Slash:
|
|
85
|
-
|
|
89
|
+
// A `/` in regex position starts a regex even when followed by `=`
|
|
90
|
+
// (`illegal: /=/` is the regex `/=/`, not division-assign).
|
|
86
91
|
if (this.regexAllowed()) return this.scanRegex(start, precededByLineBreak);
|
|
92
|
+
if (next === Char.Equals) return emit(TokenKind.SlashEquals, 2);
|
|
87
93
|
return emit(TokenKind.Slash, 1);
|
|
88
94
|
case Char.Percent:
|
|
89
95
|
if (next === Char.Equals) return emit(TokenKind.PercentEquals, 2);
|
|
@@ -13,34 +13,43 @@ export interface RegexMethods {
|
|
|
13
13
|
scanRegex(this: Scanner, start: number, precededByLineBreak: boolean): Token;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/** True for a token that ends a complete value (`x`, `)`, `]`, `this`, …). */
|
|
17
|
+
export function valueEndsExpression(kind: TokenKind): boolean {
|
|
18
|
+
switch (kind) {
|
|
19
|
+
case TokenKind.Identifier:
|
|
20
|
+
case TokenKind.PrivateIdentifier:
|
|
21
|
+
case TokenKind.NumericLiteral:
|
|
22
|
+
case TokenKind.BigIntLiteral:
|
|
23
|
+
case TokenKind.StringLiteral:
|
|
24
|
+
case TokenKind.NoSubstitutionTemplateLiteral:
|
|
25
|
+
case TokenKind.TemplateTail:
|
|
26
|
+
case TokenKind.RegularExpressionLiteral:
|
|
27
|
+
case TokenKind.CloseParen:
|
|
28
|
+
case TokenKind.CloseBracket:
|
|
29
|
+
case TokenKind.TrueKeyword:
|
|
30
|
+
case TokenKind.FalseKeyword:
|
|
31
|
+
case TokenKind.NullKeyword:
|
|
32
|
+
case TokenKind.UndefinedKeyword:
|
|
33
|
+
case TokenKind.ThisKeyword:
|
|
34
|
+
case TokenKind.PlusPlus:
|
|
35
|
+
case TokenKind.MinusMinus:
|
|
36
|
+
return true;
|
|
37
|
+
default:
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
16
42
|
export const regexMethods: RegexMethods = {
|
|
17
43
|
/**
|
|
18
44
|
* True when a `/` in this position starts a regular expression rather than a
|
|
19
45
|
* division. The decision is made from the previous significant token.
|
|
20
46
|
*/
|
|
21
47
|
regexAllowed(this: Scanner): boolean {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
case TokenKind.StringLiteral:
|
|
28
|
-
case TokenKind.NoSubstitutionTemplateLiteral:
|
|
29
|
-
case TokenKind.TemplateTail:
|
|
30
|
-
case TokenKind.RegularExpressionLiteral:
|
|
31
|
-
case TokenKind.CloseParen:
|
|
32
|
-
case TokenKind.CloseBracket:
|
|
33
|
-
case TokenKind.TrueKeyword:
|
|
34
|
-
case TokenKind.FalseKeyword:
|
|
35
|
-
case TokenKind.NullKeyword:
|
|
36
|
-
case TokenKind.UndefinedKeyword:
|
|
37
|
-
case TokenKind.ThisKeyword:
|
|
38
|
-
case TokenKind.PlusPlus:
|
|
39
|
-
case TokenKind.MinusMinus:
|
|
40
|
-
return false;
|
|
41
|
-
default:
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
48
|
+
if (valueEndsExpression(this._token.kind)) return false;
|
|
49
|
+
// `x! / y` is division (the `!` is a postfix non-null assertion), while
|
|
50
|
+
// `!x / y` allows a regex after the logical-not prefix.
|
|
51
|
+
if (this._token.kind === TokenKind.Exclamation) return !this.postfixExclamation;
|
|
52
|
+
return true;
|
|
44
53
|
},
|
|
45
54
|
|
|
46
55
|
/** Scan a `/pattern/flags` literal, starting at the leading slash. */
|
package/src/lexer/scanner.ts
CHANGED
|
@@ -29,6 +29,8 @@ export class Scanner {
|
|
|
29
29
|
text: "",
|
|
30
30
|
precededByLineBreak: false,
|
|
31
31
|
};
|
|
32
|
+
/** Whether the just-scanned `!` was a postfix non-null assertion (`x!`). */
|
|
33
|
+
postfixExclamation = false;
|
|
32
34
|
|
|
33
35
|
constructor(source: SourceFile, diagnostics: DiagnosticBag) {
|
|
34
36
|
this.source = source;
|
|
@@ -74,6 +76,11 @@ export class Scanner {
|
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
scan(): Token {
|
|
79
|
+
// A leading `#!` hashbang (e.g. `#!/usr/bin/env node`) is a comment, not a
|
|
80
|
+
// private identifier: skip the whole first line.
|
|
81
|
+
if (this.pos === 0 && this.text.charCodeAt(0) === Char.Hash && this.text.charCodeAt(1) === Char.Exclamation) {
|
|
82
|
+
while (this.pos < this.text.length && !isLineBreak(this.text.charCodeAt(this.pos))) this.pos++;
|
|
83
|
+
}
|
|
77
84
|
let precededByLineBreak = false;
|
|
78
85
|
// Skip trivia.
|
|
79
86
|
for (;;) {
|
package/src/lexer/token.ts
CHANGED
|
@@ -128,6 +128,7 @@ export enum TokenKind {
|
|
|
128
128
|
NullKeyword = "null",
|
|
129
129
|
NumberKeyword = "number",
|
|
130
130
|
ObjectKeyword = "object",
|
|
131
|
+
OverrideKeyword = "override",
|
|
131
132
|
PackageKeyword = "package",
|
|
132
133
|
PrivateKeyword = "private",
|
|
133
134
|
ProtectedKeyword = "protected",
|
|
@@ -217,6 +218,7 @@ export const KEYWORDS = new Map<string, TokenKind>([
|
|
|
217
218
|
["null", TokenKind.NullKeyword],
|
|
218
219
|
["number", TokenKind.NumberKeyword],
|
|
219
220
|
["object", TokenKind.ObjectKeyword],
|
|
221
|
+
["override", TokenKind.OverrideKeyword],
|
|
220
222
|
["package", TokenKind.PackageKeyword],
|
|
221
223
|
["private", TokenKind.PrivateKeyword],
|
|
222
224
|
["protected", TokenKind.ProtectedKeyword],
|
|
@@ -219,6 +219,13 @@ export const declarationClassMethods: DeclarationClassMethods = {
|
|
|
219
219
|
this.nextToken();
|
|
220
220
|
return { kind: SyntaxKind.NumericLiteral, text: token.text, value: Number(token.value ?? 0), start: token.start, end: token.end };
|
|
221
221
|
}
|
|
222
|
+
if (token.kind === TokenKind.BigIntLiteral) {
|
|
223
|
+
// A BigInt property key coerces to its decimal string (`{ 0n: "x" }` reads
|
|
224
|
+
// as the string key "0").
|
|
225
|
+
this.nextToken();
|
|
226
|
+
const text = token.text.endsWith("n") ? token.text.slice(0, -1) : token.text;
|
|
227
|
+
return { kind: SyntaxKind.StringLiteral, text, raw: token.text, value: text, start: token.start, end: token.end };
|
|
228
|
+
}
|
|
222
229
|
if (token.kind === TokenKind.OpenBracket) {
|
|
223
230
|
const start = this.nextToken().start;
|
|
224
231
|
const expr = this.parseAssignmentExpression();
|
|
@@ -84,6 +84,11 @@ export const declarationFunctionMethods: DeclarationFunctionMethods = {
|
|
|
84
84
|
this.nextToken();
|
|
85
85
|
const params: TypeParameterDeclaration[] = [];
|
|
86
86
|
while (!this.at(TokenKind.GreaterThan) && !this.at(TokenKind.EndOfFile)) {
|
|
87
|
+
let isConst = false;
|
|
88
|
+
if (this.at(TokenKind.ConstKeyword)) {
|
|
89
|
+
this.nextToken();
|
|
90
|
+
isConst = true;
|
|
91
|
+
}
|
|
87
92
|
const name = this.parseIdentifier();
|
|
88
93
|
let constraint: TypeNode | undefined;
|
|
89
94
|
if (this.at(TokenKind.ExtendsKeyword)) {
|
|
@@ -95,7 +100,7 @@ export const declarationFunctionMethods: DeclarationFunctionMethods = {
|
|
|
95
100
|
this.nextToken();
|
|
96
101
|
defaultType = this.parseType();
|
|
97
102
|
}
|
|
98
|
-
params.push({ kind: SyntaxKind.TypeParameterDeclaration, name, constraint, default: defaultType, start: name.start, end: defaultType?.end ?? constraint?.end ?? name.end });
|
|
103
|
+
params.push({ kind: SyntaxKind.TypeParameterDeclaration, name, const: isConst || undefined, constraint, default: defaultType, start: name.start, end: defaultType?.end ?? constraint?.end ?? name.end });
|
|
99
104
|
if (this.at(TokenKind.Comma)) this.nextToken();
|
|
100
105
|
else break;
|
|
101
106
|
}
|
|
@@ -220,13 +225,14 @@ export const declarationFunctionMethods: DeclarationFunctionMethods = {
|
|
|
220
225
|
this.parseExpected(TokenKind.Colon);
|
|
221
226
|
name = this.parseBindingName();
|
|
222
227
|
} else if (allowPropertyName && !this.at(TokenKind.OpenBrace) && !this.at(TokenKind.OpenBracket)) {
|
|
223
|
-
const first = this.
|
|
228
|
+
const first = this.parsePropertyName();
|
|
224
229
|
if (this.at(TokenKind.Colon)) {
|
|
225
230
|
this.nextToken();
|
|
226
231
|
propertyName = first;
|
|
227
232
|
name = this.parseBindingName();
|
|
228
233
|
} else {
|
|
229
|
-
name
|
|
234
|
+
// Shorthand `{ a }`: only an identifier can name the binding.
|
|
235
|
+
name = first as unknown as BindingName;
|
|
230
236
|
/* `{ a }` reads the key `a`; record it in a separate node so a later
|
|
231
237
|
* rename of the binding does not change which property is read. */
|
|
232
238
|
propertyName =
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
type ConditionalExpression,
|
|
21
21
|
type Expression,
|
|
22
22
|
type Identifier,
|
|
23
|
-
type NewExpression,
|
|
24
23
|
type NumericLiteral,
|
|
25
24
|
type Parameter,
|
|
26
25
|
type ParenthesizedExpression,
|
|
@@ -49,7 +48,7 @@ export interface ExpressionMethods {
|
|
|
49
48
|
parseUnaryExpression(this: Parser): Expression;
|
|
50
49
|
parsePostfixExpression(this: Parser): Expression;
|
|
51
50
|
parseLeftHandSideExpression(this: Parser): Expression;
|
|
52
|
-
parseNewExpression(this: Parser):
|
|
51
|
+
parseNewExpression(this: Parser): Expression;
|
|
53
52
|
parseMemberOnlyExpression(this: Parser): Expression;
|
|
54
53
|
parsePrimaryExpression(this: Parser): Expression;
|
|
55
54
|
parseCallAndMemberTail(this: Parser, base: Expression): Expression;
|
|
@@ -111,7 +110,7 @@ export const expressionMethods: ExpressionMethods = {
|
|
|
111
110
|
let cursor = 0;
|
|
112
111
|
if (this.at(TokenKind.AsyncKeyword) && !this.lookAhead(1).precededByLineBreak) {
|
|
113
112
|
const next = this.lookAhead(1);
|
|
114
|
-
if (next.kind === TokenKind.OpenParen || this.isIdentifierLike(next)) async = true;
|
|
113
|
+
if (next.kind === TokenKind.OpenParen || next.kind === TokenKind.LessThan || this.isIdentifierLike(next)) async = true;
|
|
115
114
|
}
|
|
116
115
|
if (async) cursor = 1;
|
|
117
116
|
const afterTypeParams = this.countTypeParameterTokens(cursor);
|
|
@@ -190,15 +189,23 @@ export const expressionMethods: ExpressionMethods = {
|
|
|
190
189
|
|
|
191
190
|
skipTypeTokens(this: Parser, startIndex: number): number {
|
|
192
191
|
let depth = 0;
|
|
192
|
+
let angle = 0;
|
|
193
193
|
for (let i = startIndex; ; i++) {
|
|
194
194
|
const t = this.lookAhead(i);
|
|
195
195
|
if (t.kind === TokenKind.EndOfFile) return -1;
|
|
196
|
+
if (t.kind === TokenKind.LessThan) angle++;
|
|
197
|
+
else if (t.kind === TokenKind.GreaterThan) {
|
|
198
|
+
if (angle > 0) angle--;
|
|
199
|
+
} else if (t.kind === TokenKind.GreaterThanGreaterThan) {
|
|
200
|
+
if (angle > 1) angle -= 2;
|
|
201
|
+
else angle = 0;
|
|
202
|
+
}
|
|
196
203
|
if (t.kind === TokenKind.OpenParen || t.kind === TokenKind.OpenBracket || t.kind === TokenKind.OpenBrace) depth++;
|
|
197
204
|
else if (t.kind === TokenKind.CloseParen || t.kind === TokenKind.CloseBracket || t.kind === TokenKind.CloseBrace) {
|
|
198
205
|
if (depth === 0) return -1;
|
|
199
206
|
depth--;
|
|
200
|
-
} else if (t.kind === TokenKind.EqualsGreaterThan && depth === 0) return i;
|
|
201
|
-
else if (depth === 0 && (t.kind === TokenKind.Semicolon || t.kind === TokenKind.Comma)) return -1;
|
|
207
|
+
} else if (t.kind === TokenKind.EqualsGreaterThan && depth === 0 && angle === 0) return i;
|
|
208
|
+
else if (depth === 0 && angle === 0 && (t.kind === TokenKind.Semicolon || t.kind === TokenKind.Comma)) return -1;
|
|
202
209
|
}
|
|
203
210
|
},
|
|
204
211
|
|
|
@@ -310,26 +317,14 @@ export const expressionMethods: ExpressionMethods = {
|
|
|
310
317
|
return this.parseCallAndMemberTail(expression);
|
|
311
318
|
},
|
|
312
319
|
|
|
313
|
-
parseNewExpression(this: Parser):
|
|
320
|
+
parseNewExpression(this: Parser): Expression {
|
|
314
321
|
const newToken = this.parseExpected(TokenKind.NewKeyword);
|
|
315
322
|
const start = newToken.start;
|
|
316
|
-
/* `new.target` is
|
|
317
|
-
* access produced "Unexpected token '.'" pointing at the dot; report what
|
|
318
|
-
* is actually unsupported instead. */
|
|
323
|
+
/* `new.target` is a meta-property, not a constructor call. */
|
|
319
324
|
if (this.at(TokenKind.Dot) && this.atAhead(1, TokenKind.Identifier) && this.lookAhead(1).text === "target") {
|
|
320
325
|
this.nextToken(); // .
|
|
321
326
|
const target = this.nextToken(); // target
|
|
322
|
-
|
|
323
|
-
...newToken,
|
|
324
|
-
end: target.end,
|
|
325
|
-
});
|
|
326
|
-
const placeholder: Expression = {
|
|
327
|
-
kind: SyntaxKind.Identifier,
|
|
328
|
-
text: "undefined",
|
|
329
|
-
start: target.start,
|
|
330
|
-
end: target.end,
|
|
331
|
-
};
|
|
332
|
-
return { kind: SyntaxKind.NewExpression, expression: placeholder, typeArguments: [], arguments: [], start, end: target.end };
|
|
327
|
+
return { kind: SyntaxKind.Identifier, text: "new.target", start: newToken.start, end: target.end };
|
|
333
328
|
}
|
|
334
329
|
const callee = this.parseMemberOnlyExpression();
|
|
335
330
|
const typeArguments = this.at(TokenKind.LessThan) ? this.parseTypeArguments() : [];
|
|
@@ -418,7 +413,21 @@ export const expressionMethods: ExpressionMethods = {
|
|
|
418
413
|
const metaName = this.parseIdentifierName();
|
|
419
414
|
return { kind: SyntaxKind.Identifier, text: "import.meta", start: importToken.start, end: metaName.end };
|
|
420
415
|
}
|
|
416
|
+
if (this.atAhead(1, TokenKind.OpenParen)) {
|
|
417
|
+
// Dynamic `import(specifier)`: the specifier is an expression; a
|
|
418
|
+
// string literal is what the bundler can resolve statically.
|
|
419
|
+
const importToken = this.nextToken();
|
|
420
|
+
this.nextToken();
|
|
421
|
+
const specifier = this.parseAssignmentExpression();
|
|
422
|
+
const close = this.parseExpected(TokenKind.CloseParen);
|
|
423
|
+
return { kind: SyntaxKind.ImportExpression, specifier, start: importToken.start, end: close.end };
|
|
424
|
+
}
|
|
421
425
|
break;
|
|
426
|
+
case TokenKind.PrivateIdentifier:
|
|
427
|
+
// A bare `#field` in expression position is the `#field in obj`
|
|
428
|
+
// private-field existence test; the binary parser handles the `in`.
|
|
429
|
+
this.nextToken();
|
|
430
|
+
return { kind: SyntaxKind.PrivateIdentifier, text: token.text, start: token.start, end: token.end };
|
|
422
431
|
default:
|
|
423
432
|
break;
|
|
424
433
|
}
|
package/src/parser/helpers.ts
CHANGED
|
@@ -42,6 +42,7 @@ export function isAssignmentTarget(expr: Expression): boolean {
|
|
|
42
42
|
case SyntaxKind.PropertyAccessExpression:
|
|
43
43
|
case SyntaxKind.ElementAccessExpression:
|
|
44
44
|
case SyntaxKind.ParenthesizedExpression:
|
|
45
|
+
case SyntaxKind.NonNullExpression:
|
|
45
46
|
case SyntaxKind.ArrayLiteralExpression:
|
|
46
47
|
case SyntaxKind.ObjectLiteralExpression:
|
|
47
48
|
return true;
|