xbintsc 0.6.28 → 0.7.6
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 +10 -0
- 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/source.js +4 -0
- package/dist/src/checker/source.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/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +29 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +95 -1
- 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/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +24 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- 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.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +13 -29
- 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/generator.js +4 -0
- package/dist/src/codegen/generator/generator.js.map +1 -1
- package/dist/src/codegen/generator/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- 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 +21 -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/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.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 +79 -8
- 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 +4 -4
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +43 -13
- 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 +11 -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/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +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 +28 -5
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.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/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +48 -0
- package/dist/src/extensions/gui/index.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 +27 -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/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.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/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +28 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- 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/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.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-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.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 +53 -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-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.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/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/fetch.test.js +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +35 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +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/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- 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/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.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/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- 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/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.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/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.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/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/cli.md +1 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +26 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/known-issues.md +35 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +2 -1
- package/doc/implemented/checker.md +14 -0
- package/doc/implemented/codegen.md +7 -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 +3 -2
- package/doc/implemented/runtime-core.md +13 -2
- package/doc/implemented/stdlib.md +79 -4
- package/doc/implemented/typed-arrays.md +18 -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/gui/api.md +19 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/known-issues.md +24 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +10 -0
- package/doc/zh-CN/implemented/codegen.md +7 -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 +3 -2
- package/doc/zh-CN/implemented/runtime-core.md +10 -2
- package/doc/zh-CN/implemented/stdlib.md +64 -4
- package/doc/zh-CN/implemented/typed-arrays.md +14 -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_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +9 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_internal.h +3 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +3 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +6 -1
- package/runtime/ext_gui/gui_engine.h +2 -0
- package/runtime/ext_gui/gui_events.cpp +13 -8
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +20 -170
- package/runtime/ext_gui/webgl_context.cpp +117 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_objects.h +16 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +8 -0
- 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 +63 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +61 -69
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +154 -181
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +29 -24
- package/runtime/xt_constructors.c +102 -2
- package/runtime/xt_containers/access.inc +125 -12
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/function_prototypes.inc +58 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +59 -75
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +5 -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_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +136 -0
- package/runtime/xt_intl.c +224 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +66 -1
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_module_values.c +82 -0
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_proxy.c +140 -0
- package/runtime/xt_stdlib/dispatch.inc +104 -9
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +71 -55
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/runtime/xt_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/scripts/build-runtime.ts +8 -0
- package/src/ast/common.ts +10 -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/source.ts +3 -0
- package/src/checker/type-system.ts +23 -3
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +28 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +99 -1
- package/src/codegen/generator/calls/super.ts +5 -4
- package/src/codegen/generator/calls/unwrap.ts +47 -0
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +26 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/module-values.ts +57 -19
- package/src/codegen/generator/expressions/primary.ts +13 -36
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/generator.ts +4 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/lookup-tables.ts +63 -0
- package/src/codegen/generator/module.ts +38 -7
- package/src/codegen/generator/state.ts +22 -0
- package/src/codegen/generator/tables.ts +18 -12
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/commonjs.ts +12 -5
- package/src/driver/bundler/concatenate.ts +96 -12
- package/src/driver/bundler/deferred.ts +122 -6
- package/src/driver/bundler/dynamic-import.ts +75 -2
- package/src/driver/bundler/graph.ts +4 -4
- package/src/driver/bundler/merge.ts +42 -9
- package/src/driver/bundler/namespace-object.ts +44 -0
- package/src/driver/bundler/reexport-resolution.ts +14 -2
- package/src/driver/bundler/symbols.ts +17 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/config.ts +1 -1
- package/src/driver/frontend.ts +3 -4
- package/src/driver/options.ts +1 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +28 -5
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +50 -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 +41 -4
- package/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
- package/src/parser/literals.ts +6 -2
|
@@ -24,9 +24,19 @@ import {
|
|
|
24
24
|
type VariableDeclarationList,
|
|
25
25
|
} from "../../ast/nodes.js";
|
|
26
26
|
import { SymbolKind } from "../../binder/binder.js";
|
|
27
|
-
import {
|
|
27
|
+
import type { AssetSourceRange } from "../../extensions/registry.js";
|
|
28
|
+
import {
|
|
29
|
+
assignmentStatement,
|
|
30
|
+
deferredAliasDeclarations,
|
|
31
|
+
deferredModuleFunctions,
|
|
32
|
+
deferredModuleSplit,
|
|
33
|
+
eagerModuleFunctions,
|
|
34
|
+
letDeclaration,
|
|
35
|
+
simpleVariableDeclarations,
|
|
36
|
+
type DeferredAlias,
|
|
37
|
+
} from "./deferred.js";
|
|
28
38
|
import { classifyDependency } from "./resolve.js";
|
|
29
|
-
import { renameSymbol, topLevelSymbols } from "./symbols.js";
|
|
39
|
+
import { moduleScope, renameSymbol, topLevelSymbols } from "./symbols.js";
|
|
30
40
|
import type { ModuleRecord } from "./types.js";
|
|
31
41
|
|
|
32
42
|
export interface ConcatenateOptions {
|
|
@@ -38,6 +48,13 @@ export interface ConcatenateOptions {
|
|
|
38
48
|
readonly namespaceStatements: ReadonlyMap<Statement, Statement>;
|
|
39
49
|
readonly externalSpecifiers: ReadonlySet<string>;
|
|
40
50
|
readonly moduleOverrides?: Readonly<Record<string, string>>;
|
|
51
|
+
/**
|
|
52
|
+
* `module`/`exports` state for every CommonJS module, emitted above the first
|
|
53
|
+
* module body. Node creates the pair when a module starts loading, so a
|
|
54
|
+
* `require` cycle reads the earlier module's partly filled object instead of
|
|
55
|
+
* one that is declared later in the concatenated program.
|
|
56
|
+
*/
|
|
57
|
+
readonly cjsPrelude?: readonly { readonly record: ModuleRecord; readonly statement: Statement }[];
|
|
41
58
|
}
|
|
42
59
|
|
|
43
60
|
export function concatenateModules(options: ConcatenateOptions): SourceFileNode {
|
|
@@ -50,6 +67,7 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
50
67
|
namespaceStatements,
|
|
51
68
|
externalSpecifiers,
|
|
52
69
|
moduleOverrides,
|
|
70
|
+
cjsPrelude,
|
|
53
71
|
} = options;
|
|
54
72
|
const merged: Statement[] = [];
|
|
55
73
|
/* Every node keeps the module it was parsed from, so a later codegen
|
|
@@ -61,17 +79,22 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
61
79
|
* src="app.js">` body, say. Nodes inside such a span keep that file, so a
|
|
62
80
|
* diagnostic points at real source and a plain-`.js` script stays exempt
|
|
63
81
|
* from the type checker. */
|
|
64
|
-
const originOf = (record: ModuleRecord, node: Node):
|
|
82
|
+
const originOf = (record: ModuleRecord, node: Node): AssetSourceRange | undefined => {
|
|
65
83
|
const ranges = record.originRanges;
|
|
66
|
-
if (ranges === undefined) return
|
|
84
|
+
if (ranges === undefined) return undefined;
|
|
67
85
|
for (const range of ranges) {
|
|
68
|
-
if (node.start >= range.start && node.end <= range.end) return range
|
|
86
|
+
if (node.start >= range.start && node.end <= range.end) return range;
|
|
69
87
|
}
|
|
70
|
-
return
|
|
88
|
+
return undefined;
|
|
71
89
|
};
|
|
90
|
+
/* Inline `<script>` bodies in an HTML page are JavaScript unless the tag says
|
|
91
|
+
* otherwise; the checker must not infer types from them. */
|
|
92
|
+
const untypedNodes = new Set<object>();
|
|
72
93
|
const trackOrigin = (record: ModuleRecord, root: Node): void => {
|
|
73
94
|
const visit = (node: Node): void => {
|
|
74
|
-
|
|
95
|
+
const range = originOf(record, node);
|
|
96
|
+
origins.set(node, range?.file ?? record.path);
|
|
97
|
+
if (range?.untyped) untypedNodes.add(node);
|
|
75
98
|
const fields = node as unknown as Record<string, unknown>;
|
|
76
99
|
for (const key of Object.keys(fields)) {
|
|
77
100
|
if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
|
|
@@ -91,6 +114,11 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
91
114
|
trackOrigin(record, statement);
|
|
92
115
|
merged.push(statement);
|
|
93
116
|
};
|
|
117
|
+
/* A module's `module`/`exports` pair exists as soon as the module starts
|
|
118
|
+
* loading, so hoist every pair above the first module body. A `require`
|
|
119
|
+
* cycle then reads the earlier module's object (partly filled, like Node)
|
|
120
|
+
* instead of a variable declared later in the concatenated program. */
|
|
121
|
+
for (const entry of cjsPrelude ?? []) push(entry.record, entry.statement);
|
|
94
122
|
const first = records[records.length - 1]!;
|
|
95
123
|
for (const record of records) {
|
|
96
124
|
if (deferredModules.has(record.path)) {
|
|
@@ -98,7 +126,15 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
98
126
|
* external imports stay top-level (codegen resolves them there); eager
|
|
99
127
|
* namespace objects likewise. */
|
|
100
128
|
const topLevel: Statement[] = [];
|
|
129
|
+
const hoisted: Statement[] = [];
|
|
130
|
+
const hoistedVariables: { name: string; start: number; end: number }[] = [];
|
|
101
131
|
const body: Statement[] = [];
|
|
132
|
+
/* A module cycle calls a dependency's *function declarations* before its
|
|
133
|
+
* body has run — that is what hoisting means in JavaScript. Keeping them
|
|
134
|
+
* inside the wrapper makes them `undefined` at that moment, so the
|
|
135
|
+
* declarations move to the top level and their module-level variable
|
|
136
|
+
* bindings become top-level `let`s whose values the wrapper assigns. */
|
|
137
|
+
const split = deferredModuleSplit(record);
|
|
102
138
|
for (const statement of record.sourceFile.statements) {
|
|
103
139
|
if (statement.kind === SyntaxKind.ImportDeclaration) {
|
|
104
140
|
const declaration = statement as ImportDeclaration;
|
|
@@ -112,6 +148,14 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
112
148
|
}
|
|
113
149
|
if (statement.kind === SyntaxKind.ExportDeclaration) {
|
|
114
150
|
const declaration = statement as ExportDeclaration;
|
|
151
|
+
/* `export * as ns from "..."` needs its synthetic namespace binding
|
|
152
|
+
* inside the wrapper: it reads the dependency's exports, which only
|
|
153
|
+
* exist once that dependency's wrapper has run. */
|
|
154
|
+
const synthetic = namespaceStatements.get(statement);
|
|
155
|
+
if (synthetic) {
|
|
156
|
+
body.push(synthetic);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
115
159
|
const inner = (declaration as unknown as { declaration?: Statement }).declaration;
|
|
116
160
|
if (inner) body.push(inner);
|
|
117
161
|
continue;
|
|
@@ -121,14 +165,42 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
121
165
|
continue;
|
|
122
166
|
}
|
|
123
167
|
stripExportModifiers(statement);
|
|
168
|
+
if (split) {
|
|
169
|
+
if (statement.kind === SyntaxKind.FunctionDeclaration) {
|
|
170
|
+
hoisted.push(statement);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const declarations = simpleVariableDeclarations(statement);
|
|
174
|
+
if (declarations) {
|
|
175
|
+
const scope = moduleScope(record);
|
|
176
|
+
for (const declaration of declarations) {
|
|
177
|
+
/* The rename pass rewrites references to the final name, so the
|
|
178
|
+
* synthetic binding and its assignment must use it too. */
|
|
179
|
+
const symbol = scope?.symbols.get(declaration.name);
|
|
180
|
+
const finalName =
|
|
181
|
+
(symbol ? record.finalNames.get(symbol.id) : undefined) ?? declaration.name;
|
|
182
|
+
hoistedVariables.push({
|
|
183
|
+
name: finalName,
|
|
184
|
+
start: declaration.start,
|
|
185
|
+
end: declaration.end,
|
|
186
|
+
});
|
|
187
|
+
if (declaration.initializer) {
|
|
188
|
+
body.push(
|
|
189
|
+
assignmentStatement(finalName, declaration.initializer, statement.start, statement.end),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
124
196
|
body.push(statement);
|
|
125
197
|
}
|
|
198
|
+
const aliases = deferredAliases.get(record.path) ?? [];
|
|
126
199
|
for (const statement of topLevel) push(record, statement);
|
|
127
|
-
for (const statement of
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
)) {
|
|
200
|
+
for (const statement of deferredAliasDeclarations(aliases)) push(record, statement);
|
|
201
|
+
if (hoistedVariables.length > 0) push(record, letDeclaration(hoistedVariables));
|
|
202
|
+
for (const statement of hoisted) push(record, statement);
|
|
203
|
+
for (const statement of deferredModuleFunctions(record, aliases, body)) {
|
|
132
204
|
push(record, statement);
|
|
133
205
|
}
|
|
134
206
|
continue;
|
|
@@ -188,6 +260,7 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
188
260
|
statements: merged,
|
|
189
261
|
fileName: first.path,
|
|
190
262
|
origins,
|
|
263
|
+
...(untypedNodes.size > 0 ? { untypedNodes } : {}),
|
|
191
264
|
moduleTexts: new Map(records.map((record) => [record.path, record.text])),
|
|
192
265
|
modulePrefixes: records.map((record) => record.prefix),
|
|
193
266
|
text: records.map((record) => record.text).join("\n"),
|
|
@@ -242,3 +315,14 @@ function exportAssignmentToStatement(record: ModuleRecord, assignment: ExportAss
|
|
|
242
315
|
end: assignment.end,
|
|
243
316
|
};
|
|
244
317
|
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Whether a deferred module's top-level declarations can be split into
|
|
321
|
+
* top-level bindings plus in-wrapper initialisation.
|
|
322
|
+
*
|
|
323
|
+
* Function declarations are hoisted (a cycle may call them before any body
|
|
324
|
+
* runs), so the bindings they reference must be top level too. That works for
|
|
325
|
+
* plain `const`/`let`/`var x = ...`; a destructuring pattern, a class or an
|
|
326
|
+
* enum needs code we do not synthesise, so those modules keep everything inside
|
|
327
|
+
* the wrapper (and behave as before).
|
|
328
|
+
*/
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type Expression,
|
|
25
25
|
type FunctionDeclaration,
|
|
26
26
|
type Identifier,
|
|
27
|
+
type ExportDeclaration,
|
|
27
28
|
type ImportDeclaration,
|
|
28
29
|
type ObjectLiteralElementLike,
|
|
29
30
|
type PropertyAssignment,
|
|
@@ -35,6 +36,9 @@ import {
|
|
|
35
36
|
type VariableStatement,
|
|
36
37
|
} from "../../ast/nodes.js";
|
|
37
38
|
import { SymbolKind } from "../../binder/types.js";
|
|
39
|
+
import { AssignmentOperator } from "../../ast/operators.js";
|
|
40
|
+
import { TokenKind } from "../../lexer/token.js";
|
|
41
|
+
import { isTypeOnlyExport, isTypeOnlyImport } from "./graph.js";
|
|
38
42
|
import { classifyDependency } from "./resolve.js";
|
|
39
43
|
import { topLevelSymbols } from "./symbols.js";
|
|
40
44
|
import type { ModuleRecord } from "./types.js";
|
|
@@ -105,6 +109,7 @@ function constDeclaration(
|
|
|
105
109
|
initializer: Expression | undefined,
|
|
106
110
|
start: number,
|
|
107
111
|
end: number,
|
|
112
|
+
declarationKind: "const" | "let" = "const",
|
|
108
113
|
): VariableStatement {
|
|
109
114
|
const declaration: VariableDeclaration = {
|
|
110
115
|
kind: SyntaxKind.VariableDeclaration,
|
|
@@ -117,22 +122,80 @@ function constDeclaration(
|
|
|
117
122
|
const list: VariableDeclarationList = {
|
|
118
123
|
kind: SyntaxKind.VariableDeclarationList,
|
|
119
124
|
declarations: [declaration],
|
|
120
|
-
declarationKind
|
|
125
|
+
declarationKind,
|
|
121
126
|
start,
|
|
122
127
|
end,
|
|
123
128
|
};
|
|
124
129
|
return { kind: SyntaxKind.VariableStatement, declarationList: list, modifiers: [], start, end };
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
/**
|
|
128
|
-
|
|
132
|
+
/**
|
|
133
|
+
* `<alias> = <wrapper>()[.<importedName>];`
|
|
134
|
+
*
|
|
135
|
+
* The alias itself is declared at top level (see
|
|
136
|
+
* {@link deferredAliasDeclarations}) so that a function declaration hoisted
|
|
137
|
+
* out of the wrapper can reference it: a module cycle calls that function
|
|
138
|
+
* before the wrapper body has run.
|
|
139
|
+
*/
|
|
140
|
+
function aliasStatement(alias: DeferredAlias): Statement {
|
|
129
141
|
const callee = identifier(alias.wrapper, alias.start, alias.end);
|
|
130
142
|
const namespace = call(callee, [], alias.start, alias.end);
|
|
131
143
|
const value =
|
|
132
144
|
alias.importedName === undefined || alias.namespace
|
|
133
145
|
? namespace
|
|
134
146
|
: property(namespace, alias.importedName, alias.start, alias.end);
|
|
135
|
-
return
|
|
147
|
+
return assignmentStatement(alias.name, value, alias.start, alias.end);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** `<name> = <value>;` — used to assign a top-level `let` from inside a wrapper. */
|
|
151
|
+
export function assignmentStatement(name: string, value: Expression, start: number, end: number): Statement {
|
|
152
|
+
const assignment = {
|
|
153
|
+
kind: SyntaxKind.BinaryExpression,
|
|
154
|
+
left: identifier(name, start, end),
|
|
155
|
+
operator: AssignmentOperator.Assign,
|
|
156
|
+
right: value,
|
|
157
|
+
operatorToken: { kind: TokenKind.Equals, text: "=", precededByLineBreak: false, start, end },
|
|
158
|
+
start,
|
|
159
|
+
end,
|
|
160
|
+
} as unknown as Expression;
|
|
161
|
+
return {
|
|
162
|
+
kind: SyntaxKind.ExpressionStatement,
|
|
163
|
+
expression: assignment,
|
|
164
|
+
start,
|
|
165
|
+
end,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** `let a, b;` for bindings a deferred module declares at its top level. */
|
|
170
|
+
export function letDeclaration(
|
|
171
|
+
names: readonly { readonly name: string; readonly start: number; readonly end: number }[],
|
|
172
|
+
): Statement {
|
|
173
|
+
const declarations: VariableDeclaration[] = names.map((entry) => ({
|
|
174
|
+
kind: SyntaxKind.VariableDeclaration,
|
|
175
|
+
name: identifier(entry.name, entry.start, entry.end),
|
|
176
|
+
exclamation: false,
|
|
177
|
+
initializer: undefined,
|
|
178
|
+
start: entry.start,
|
|
179
|
+
end: entry.end,
|
|
180
|
+
}));
|
|
181
|
+
const list: VariableDeclarationList = {
|
|
182
|
+
kind: SyntaxKind.VariableDeclarationList,
|
|
183
|
+
declarations,
|
|
184
|
+
declarationKind: "let",
|
|
185
|
+
start: declarations[0]!.start,
|
|
186
|
+
end: declarations[declarations.length - 1]!.end,
|
|
187
|
+
};
|
|
188
|
+
return { kind: SyntaxKind.VariableStatement, declarationList: list, modifiers: [], start: list.start, end: list.end };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** `let <alias>;` for every alias that binds a name, emitted at top level. */
|
|
192
|
+
export function deferredAliasDeclarations(aliases: readonly DeferredAlias[]): Statement[] {
|
|
193
|
+
const statements: Statement[] = [];
|
|
194
|
+
for (const alias of aliases) {
|
|
195
|
+
if (alias.sideEffect || alias.name.length === 0) continue;
|
|
196
|
+
statements.push(constDeclaration(alias.name, undefined, alias.start, alias.end, "let"));
|
|
197
|
+
}
|
|
198
|
+
return statements;
|
|
136
199
|
}
|
|
137
200
|
|
|
138
201
|
/** A wrapper call used for a side-effect-only import. */
|
|
@@ -299,14 +362,18 @@ export function computeDeferredModules(
|
|
|
299
362
|
const resolution = classifyDependency(dirname(record.path), specifier, externalSpecifiers, moduleOverrides);
|
|
300
363
|
return resolution.kind === "file" ? byPath.get(resolution.path) : undefined;
|
|
301
364
|
};
|
|
365
|
+
/* A type-only import or re-export is erased, so it is not a module edge: it
|
|
366
|
+
* must not make its target eager (`export type { T } from "pkg"` used to
|
|
367
|
+
* pull a whole package into the startup path). */
|
|
302
368
|
const specifierOf = (statement: Statement): string | undefined => {
|
|
303
369
|
if (statement.kind === SyntaxKind.ImportDeclaration) {
|
|
304
370
|
const declaration = statement as ImportDeclaration;
|
|
305
|
-
if (declaration
|
|
371
|
+
if (isTypeOnlyImport(declaration)) return undefined;
|
|
306
372
|
return declaration.moduleSpecifier.value;
|
|
307
373
|
}
|
|
308
374
|
if (statement.kind === SyntaxKind.ExportDeclaration) {
|
|
309
|
-
const declaration = statement as
|
|
375
|
+
const declaration = statement as ExportDeclaration;
|
|
376
|
+
if (isTypeOnlyExport(declaration)) return undefined;
|
|
310
377
|
return declaration.moduleSpecifier?.value;
|
|
311
378
|
}
|
|
312
379
|
return undefined;
|
|
@@ -350,3 +417,52 @@ export function computeDeferredModules(
|
|
|
350
417
|
}
|
|
351
418
|
return deferred;
|
|
352
419
|
}
|
|
420
|
+
/** The declarations of a `const`/`let`/`var` statement with plain identifiers. */
|
|
421
|
+
export function simpleVariableDeclarations(
|
|
422
|
+
statement: Statement,
|
|
423
|
+
): { name: string; initializer?: Expression; start: number; end: number }[] | undefined {
|
|
424
|
+
if (statement.kind !== SyntaxKind.VariableStatement) return undefined;
|
|
425
|
+
const list = (statement as VariableStatement).declarationList;
|
|
426
|
+
const declarations: { name: string; initializer?: Expression; start: number; end: number }[] = [];
|
|
427
|
+
for (const declaration of list.declarations) {
|
|
428
|
+
if (declaration.name.kind !== SyntaxKind.Identifier) return undefined;
|
|
429
|
+
declarations.push({
|
|
430
|
+
name: (declaration.name as Identifier).text,
|
|
431
|
+
initializer: declaration.initializer,
|
|
432
|
+
start: declaration.start,
|
|
433
|
+
end: declaration.end,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
return declarations;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Whether a deferred module's top-level declarations can be split into
|
|
441
|
+
* top-level bindings plus in-wrapper initialisation.
|
|
442
|
+
*
|
|
443
|
+
* Function declarations are hoisted (a cycle may call them before any body
|
|
444
|
+
* runs), so the bindings they reference must be top level too. That works for
|
|
445
|
+
* plain `const`/`let`/`var x = ...`; a destructuring pattern, a class or an
|
|
446
|
+
* enum needs code we do not synthesise, so those modules keep everything inside
|
|
447
|
+
* the wrapper (and behave as before).
|
|
448
|
+
*/
|
|
449
|
+
export function deferredModuleSplit(record: ModuleRecord): boolean {
|
|
450
|
+
for (const statement of record.sourceFile.statements) {
|
|
451
|
+
if (
|
|
452
|
+
statement.kind === SyntaxKind.ImportDeclaration ||
|
|
453
|
+
statement.kind === SyntaxKind.ExportDeclaration ||
|
|
454
|
+
statement.kind === SyntaxKind.ExportAssignment ||
|
|
455
|
+
statement.kind === SyntaxKind.FunctionDeclaration
|
|
456
|
+
) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
if (statement.kind === SyntaxKind.VariableStatement) {
|
|
460
|
+
if (simpleVariableDeclarations(statement) === undefined) return false;
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (statement.kind === SyntaxKind.ClassDeclaration || statement.kind === SyntaxKind.EnumDeclaration) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return true;
|
|
468
|
+
}
|
|
@@ -9,7 +9,21 @@
|
|
|
9
9
|
* and is left in place for the code generator to reject.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
SyntaxKind,
|
|
14
|
+
type CallExpression,
|
|
15
|
+
type Expression,
|
|
16
|
+
type Identifier,
|
|
17
|
+
type ImportDeclaration,
|
|
18
|
+
type ImportExpression,
|
|
19
|
+
type ImportSpecifier,
|
|
20
|
+
type NamedImports,
|
|
21
|
+
type Node,
|
|
22
|
+
type PropertyAccessExpression,
|
|
23
|
+
type SourceFileNode,
|
|
24
|
+
type Statement,
|
|
25
|
+
type StringLiteral,
|
|
26
|
+
} from "../../ast/nodes.js";
|
|
13
27
|
import { deferredWrapperName } from "./deferred.js";
|
|
14
28
|
import type { ModuleRecord } from "./types.js";
|
|
15
29
|
|
|
@@ -65,6 +79,47 @@ function member(object: string, name: string, anchor: number): PropertyAccessExp
|
|
|
65
79
|
};
|
|
66
80
|
}
|
|
67
81
|
|
|
82
|
+
/** `import { __xt_deferred_module as <name> } from "<specifier>"`. */
|
|
83
|
+
function markerImport(name: string, specifier: string, anchor: number): ImportDeclaration {
|
|
84
|
+
const moduleSpecifier: StringLiteral = {
|
|
85
|
+
kind: SyntaxKind.StringLiteral,
|
|
86
|
+
text: JSON.stringify(specifier),
|
|
87
|
+
value: specifier,
|
|
88
|
+
raw: JSON.stringify(specifier),
|
|
89
|
+
start: anchor,
|
|
90
|
+
end: anchor,
|
|
91
|
+
};
|
|
92
|
+
const element: ImportSpecifier = {
|
|
93
|
+
kind: SyntaxKind.ImportSpecifier,
|
|
94
|
+
isTypeOnly: false,
|
|
95
|
+
propertyName: identifier("__xt_deferred_module", anchor),
|
|
96
|
+
name: identifier(name, anchor),
|
|
97
|
+
start: anchor,
|
|
98
|
+
end: anchor,
|
|
99
|
+
};
|
|
100
|
+
const namedBindings: NamedImports = {
|
|
101
|
+
kind: SyntaxKind.NamedImports,
|
|
102
|
+
elements: [element],
|
|
103
|
+
start: anchor,
|
|
104
|
+
end: anchor,
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
kind: SyntaxKind.ImportDeclaration,
|
|
108
|
+
importClause: {
|
|
109
|
+
kind: SyntaxKind.ImportClause,
|
|
110
|
+
name: undefined,
|
|
111
|
+
isTypeOnly: false,
|
|
112
|
+
namedBindings,
|
|
113
|
+
start: anchor,
|
|
114
|
+
end: anchor,
|
|
115
|
+
},
|
|
116
|
+
moduleSpecifier,
|
|
117
|
+
attributes: [],
|
|
118
|
+
start: anchor,
|
|
119
|
+
end: anchor,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
68
123
|
function call(expression: Expression, args: Expression[], anchor: number): CallExpression {
|
|
69
124
|
return { kind: SyntaxKind.CallExpression, expression, typeArguments: [], arguments: args, optional: false, start: anchor, end: anchor };
|
|
70
125
|
}
|
|
@@ -115,6 +170,12 @@ export function rewriteDynamicImports(
|
|
|
115
170
|
* Rewrite every module's dynamic imports in place and return the set of module
|
|
116
171
|
* paths that are reached only through a dynamic import (so the merge can emit a
|
|
117
172
|
* namespace wrapper for them).
|
|
173
|
+
*
|
|
174
|
+
* A literal dynamic import must not evaluate its target at startup: it is
|
|
175
|
+
* deferred by marking the target with the same synthetic import the GUI
|
|
176
|
+
* `<script src>` loader uses (see `deferred.ts`). The marker edge is skipped by
|
|
177
|
+
* the eager-reachability walk, so a module that *only* appears in an
|
|
178
|
+
* `import(...)` is wrapped and its body runs on the first call.
|
|
118
179
|
*/
|
|
119
180
|
export function prepareDynamicImports(
|
|
120
181
|
records: readonly ModuleRecord[],
|
|
@@ -122,14 +183,26 @@ export function prepareDynamicImports(
|
|
|
122
183
|
): Set<string> {
|
|
123
184
|
const targets = new Set<string>();
|
|
124
185
|
for (const record of records) {
|
|
186
|
+
const markers: Statement[] = [];
|
|
187
|
+
const marked = new Set<string>();
|
|
125
188
|
const resolve = (specifier: string): string | undefined => {
|
|
126
189
|
const dependency = dependencyOf(record, specifier);
|
|
127
|
-
if (dependency)
|
|
190
|
+
if (!dependency) return undefined;
|
|
191
|
+
targets.add(dependency.path);
|
|
192
|
+
if (!marked.has(dependency.path)) {
|
|
193
|
+
marked.add(dependency.path);
|
|
194
|
+
markers.push(
|
|
195
|
+
markerImport(`__xt_dynamic_${markers.length}`, specifier, record.sourceFile.start),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
128
198
|
return dependency ? deferredWrapperName(dependency) : undefined;
|
|
129
199
|
};
|
|
130
200
|
for (const statement of record.sourceFile.statements) {
|
|
131
201
|
rewriteDynamicImports(statement, resolve, record.sourceFile.start);
|
|
132
202
|
}
|
|
203
|
+
if (markers.length > 0) {
|
|
204
|
+
(record.sourceFile.statements as Statement[]).unshift(...markers);
|
|
205
|
+
}
|
|
133
206
|
}
|
|
134
207
|
return targets;
|
|
135
208
|
}
|
|
@@ -9,7 +9,7 @@ import { SyntaxKind, type ExportDeclaration, type ImportDeclaration, type NamedE
|
|
|
9
9
|
import { bind } from "../../binder/binder.js";
|
|
10
10
|
import { DiagnosticBag, DiagnosticCode } from "../../diagnostics/diagnostic.js";
|
|
11
11
|
import { SourceFile } from "../../diagnostics/source.js";
|
|
12
|
-
import {
|
|
12
|
+
import { sourceTextFromBytes } from "../../diagnostics/source-text.js";
|
|
13
13
|
import { Parser } from "../../parser/parser.js";
|
|
14
14
|
import type { AssetLoader } from "../../extensions/registry.js";
|
|
15
15
|
import { classifyDependency } from "./resolve.js";
|
|
@@ -26,7 +26,7 @@ import type { ModuleRecord, OriginRange } from "./types.js";
|
|
|
26
26
|
* and, in particular, must not turn the mutual `import type` references
|
|
27
27
|
* between source files into a circular-import error.
|
|
28
28
|
*/
|
|
29
|
-
function isTypeOnlyImport(declaration: ImportDeclaration): boolean {
|
|
29
|
+
export function isTypeOnlyImport(declaration: ImportDeclaration): boolean {
|
|
30
30
|
const clause = declaration.importClause;
|
|
31
31
|
if (!clause) return false;
|
|
32
32
|
if (clause.isTypeOnly) return true;
|
|
@@ -39,7 +39,7 @@ function isTypeOnlyImport(declaration: ImportDeclaration): boolean {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/** True when an export declaration only re-exports types. */
|
|
42
|
-
function isTypeOnlyExport(declaration: ExportDeclaration): boolean {
|
|
42
|
+
export function isTypeOnlyExport(declaration: ExportDeclaration): boolean {
|
|
43
43
|
if (declaration.isTypeOnly) return true;
|
|
44
44
|
const clause = declaration.exportClause;
|
|
45
45
|
if (!clause || clause.kind !== SyntaxKind.NamedExports) return false;
|
|
@@ -103,7 +103,7 @@ export function loadGraph(
|
|
|
103
103
|
const fileBytes = readFileSync(path);
|
|
104
104
|
const raw = loader?.binary === true
|
|
105
105
|
? fileBytes.toString("latin1")
|
|
106
|
-
:
|
|
106
|
+
: sourceTextFromBytes(fileBytes);
|
|
107
107
|
let text = raw;
|
|
108
108
|
let originRanges: readonly OriginRange[] | undefined;
|
|
109
109
|
if (loader) {
|
|
@@ -27,6 +27,7 @@ import { lowerCommonJSRequires, prepareCommonJS } from "./commonjs.js";
|
|
|
27
27
|
import {
|
|
28
28
|
computeDeferredModules,
|
|
29
29
|
deferredAliasName,
|
|
30
|
+
deferredModuleSplit,
|
|
30
31
|
deferredWrapperName,
|
|
31
32
|
isDeferredMarkerImport,
|
|
32
33
|
type DeferredAlias,
|
|
@@ -39,6 +40,7 @@ import { classifyDependency } from "./resolve.js";
|
|
|
39
40
|
import {
|
|
40
41
|
declarationName,
|
|
41
42
|
hasModifier,
|
|
43
|
+
isTypeOnlySymbol,
|
|
42
44
|
moduleScope,
|
|
43
45
|
renameImport,
|
|
44
46
|
renameReferences,
|
|
@@ -75,8 +77,12 @@ export function bundleModules(
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
// Phase 1b: give every CommonJS module its `module`/`exports` state and
|
|
78
|
-
// record its export surface, so later phases can re-export it.
|
|
79
|
-
|
|
80
|
+
// record its export surface, so later phases can re-export it. The state
|
|
81
|
+
// itself is hoisted above every module body (see `cjsPrelude` below).
|
|
82
|
+
const cjsPrelude: Array<{ record: ModuleRecord; statement: Statement }> = [];
|
|
83
|
+
for (const record of records) {
|
|
84
|
+
for (const statement of prepareCommonJS(record)) cjsPrelude.push({ record, statement });
|
|
85
|
+
}
|
|
80
86
|
|
|
81
87
|
// Phase 2: collect each module's exported names.
|
|
82
88
|
const namespaceStatements = new Map<Statement, Statement>();
|
|
@@ -99,16 +105,25 @@ export function bundleModules(
|
|
|
99
105
|
if (target) record.exports.set(exportedName, target);
|
|
100
106
|
} else {
|
|
101
107
|
const symbol = symbolByName.get(localName);
|
|
102
|
-
|
|
108
|
+
/* A type-only local (`export { FooOptions }`) has no runtime
|
|
109
|
+
* binding; exporting its name would make every namespace import
|
|
110
|
+
* of this module read a slot that does not exist. */
|
|
111
|
+
if (symbol && !isTypeOnlySymbol(symbol)) {
|
|
103
112
|
const finalName = record.finalNames.get(symbol.id) ?? symbol.name;
|
|
104
113
|
record.exports.set(exportedName, finalName);
|
|
105
114
|
}
|
|
106
115
|
}
|
|
107
116
|
}
|
|
108
117
|
} else if (!declaration.exportClause && declaration.moduleSpecifier) {
|
|
109
|
-
// `export * from "..."`: copy every re-exported name.
|
|
118
|
+
// `export * from "..."`: copy every re-exported name. A star export
|
|
119
|
+
// never re-exports `default`; the module's own default must win.
|
|
110
120
|
const dependency = dependencyOf(record, declaration.moduleSpecifier.value);
|
|
111
|
-
if (dependency)
|
|
121
|
+
if (dependency) {
|
|
122
|
+
for (const [name, value] of dependency.exports) {
|
|
123
|
+
if (name === "default") continue;
|
|
124
|
+
record.exports.set(name, value);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
112
127
|
} else if (declaration.exportClause?.kind === SyntaxKind.NamespaceImport && declaration.moduleSpecifier) {
|
|
113
128
|
// `export * as ns from "..."`: re-export the dependency's namespace.
|
|
114
129
|
const nsName = (declaration.exportClause as { name: Identifier }).name.text;
|
|
@@ -129,7 +144,7 @@ export function bundleModules(
|
|
|
129
144
|
const name = declarationName(statement) ?? declarationName((statement as { declaration?: Node }).declaration ?? statement);
|
|
130
145
|
if (name) {
|
|
131
146
|
const symbol = symbolByName.get(name.text);
|
|
132
|
-
if (symbol) record.exports.set("default", record.finalNames.get(symbol.id) ?? symbol.name);
|
|
147
|
+
if (symbol && !isTypeOnlySymbol(symbol)) record.exports.set("default", record.finalNames.get(symbol.id) ?? symbol.name);
|
|
133
148
|
}
|
|
134
149
|
continue;
|
|
135
150
|
}
|
|
@@ -137,7 +152,7 @@ export function bundleModules(
|
|
|
137
152
|
const names = exportedNames(statement);
|
|
138
153
|
for (const name of names) {
|
|
139
154
|
const symbol = symbolByName.get(name);
|
|
140
|
-
if (symbol) record.exports.set(name, record.finalNames.get(symbol.id) ?? symbol.name);
|
|
155
|
+
if (symbol && !isTypeOnlySymbol(symbol)) record.exports.set(name, record.finalNames.get(symbol.id) ?? symbol.name);
|
|
141
156
|
}
|
|
142
157
|
}
|
|
143
158
|
}
|
|
@@ -189,9 +204,10 @@ export function bundleModules(
|
|
|
189
204
|
}
|
|
190
205
|
} else if (!clause) {
|
|
191
206
|
/* `export * from "./dep"`: alias every runtime export the deferred
|
|
192
|
-
* dependency contributes, so our own wrapper can return them.
|
|
207
|
+
* dependency contributes, so our own wrapper can return them.
|
|
208
|
+
* `default` is not part of a star export. */
|
|
193
209
|
for (const [name, target] of dependency.exports) {
|
|
194
|
-
if (!target) continue;
|
|
210
|
+
if (name === "default" || !target) continue;
|
|
195
211
|
const alias = deferredAliasName(record, aliases.length, `re_${name}`);
|
|
196
212
|
aliases.push({
|
|
197
213
|
name: alias,
|
|
@@ -269,6 +285,22 @@ export function bundleModules(
|
|
|
269
285
|
if (specifier.isTypeOnly) continue;
|
|
270
286
|
const importedName = specifier.propertyName?.text ?? specifier.name.text;
|
|
271
287
|
const local = scope.symbols.get(specifier.name.text);
|
|
288
|
+
/* A function declaration is hoisted out of the dependency's wrapper
|
|
289
|
+
* (see `concatenateModules`), so referring to its final name works
|
|
290
|
+
* even inside a module cycle — which is exactly when the alias
|
|
291
|
+
* would still be `undefined`. The dependency is still initialised
|
|
292
|
+
* once, through a side-effect alias. */
|
|
293
|
+
const target = dependency.exports.get(importedName);
|
|
294
|
+
const dependencyScope = moduleScope(dependency);
|
|
295
|
+
const hoisted =
|
|
296
|
+
target !== undefined &&
|
|
297
|
+
deferredModuleSplit(dependency) &&
|
|
298
|
+
dependencyScope?.symbols.get(importedName)?.kind === SymbolKind.Function;
|
|
299
|
+
if (hoisted) {
|
|
300
|
+
if (local) renameReferences(local, target);
|
|
301
|
+
aliases.push({ name: "", wrapper, sideEffect: true, start, end });
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
272
304
|
const alias = deferredAliasName(record, aliases.length, importedName);
|
|
273
305
|
if (local) renameReferences(local, alias);
|
|
274
306
|
aliases.push({
|
|
@@ -351,6 +383,7 @@ export function bundleModules(
|
|
|
351
383
|
namespaceStatements,
|
|
352
384
|
externalSpecifiers,
|
|
353
385
|
moduleOverrides,
|
|
386
|
+
cjsPrelude,
|
|
354
387
|
});
|
|
355
388
|
return { sourceFile, text: sourceFile.text, moduleCount: records.length };
|
|
356
389
|
}
|