xbintsc 0.7.0 → 0.7.7
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/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/source.js +4 -0
- package/dist/src/checker/source.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 +4 -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 +82 -1
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- 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 +10 -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/primary.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +4 -24
- 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/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/state.js +4 -0
- package/dist/src/codegen/generator/state.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/concatenate.js +11 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +2 -2
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +11 -5
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +3 -0
- package/dist/src/driver/bundler/reexport-resolution.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/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +4 -0
- 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/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +53 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +20 -0
- package/dist/src/extensions/registry.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/tests/binder/binder.test.js +26 -4
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +16 -0
- package/dist/tests/checker/checker.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 +13 -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/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-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +13 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- 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/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/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 +66 -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-events.test.js +89 -0
- package/dist/tests/e2e/gui-events.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-anisotropy.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.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-sampler-array.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.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/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/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/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/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/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/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 +35 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +43 -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 +1 -1
- package/doc/implemented/checker.md +9 -0
- package/doc/implemented/codegen.md +7 -0
- package/doc/implemented/parser.md +2 -1
- package/doc/implemented/runtime-core.md +9 -2
- package/doc/implemented/stdlib.md +10 -2
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/zh-CN/gui/api.md +27 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +30 -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 +1 -1
- package/doc/zh-CN/implemented/checker.md +7 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- package/doc/zh-CN/implemented/parser.md +2 -1
- package/doc/zh-CN/implemented/runtime-core.md +9 -2
- package/doc/zh-CN/implemented/stdlib.md +6 -2
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- 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 +11 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +11 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -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 +6 -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 +11 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +8 -1
- package/runtime/ext_gui/gui_engine.h +20 -2
- package/runtime/ext_gui/gui_events.cpp +31 -126
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- 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 +26 -170
- package/runtime/ext_gui/webgl_context.cpp +119 -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.h +4 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +18 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_shader.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 +11 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/runtime/rt.h +27 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +52 -60
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +88 -133
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_builtins.c +3 -1
- package/runtime/xt_constructors.c +1 -0
- package/runtime/xt_containers/access.inc +96 -11
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -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 +47 -79
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +4 -0
- package/runtime/xt_gc_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +1 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +32 -6
- 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_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_stdlib/dispatch.inc +7 -1
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/json_stringify.inc +1 -2
- 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/src/ast/common.ts +10 -0
- package/src/binder/references.ts +13 -7
- package/src/checker/source.ts +3 -0
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +5 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +87 -1
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +11 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/primary.ts +4 -27
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/state.ts +5 -0
- 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/concatenate.ts +12 -5
- package/src/driver/bundler/graph.ts +2 -2
- package/src/driver/bundler/merge.ts +11 -4
- package/src/driver/bundler/reexport-resolution.ts +2 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/frontend.ts +3 -4
- package/src/driver/runtime-objects.ts +4 -0
- 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 +55 -1
- package/src/extensions/registry.ts +20 -0
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type VariableDeclarationList,
|
|
25
25
|
} from "../../ast/nodes.js";
|
|
26
26
|
import { SymbolKind } from "../../binder/binder.js";
|
|
27
|
+
import type { AssetSourceRange } from "../../extensions/registry.js";
|
|
27
28
|
import {
|
|
28
29
|
assignmentStatement,
|
|
29
30
|
deferredAliasDeclarations,
|
|
@@ -78,17 +79,22 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
78
79
|
* src="app.js">` body, say. Nodes inside such a span keep that file, so a
|
|
79
80
|
* diagnostic points at real source and a plain-`.js` script stays exempt
|
|
80
81
|
* from the type checker. */
|
|
81
|
-
const originOf = (record: ModuleRecord, node: Node):
|
|
82
|
+
const originOf = (record: ModuleRecord, node: Node): AssetSourceRange | undefined => {
|
|
82
83
|
const ranges = record.originRanges;
|
|
83
|
-
if (ranges === undefined) return
|
|
84
|
+
if (ranges === undefined) return undefined;
|
|
84
85
|
for (const range of ranges) {
|
|
85
|
-
if (node.start >= range.start && node.end <= range.end) return range
|
|
86
|
+
if (node.start >= range.start && node.end <= range.end) return range;
|
|
86
87
|
}
|
|
87
|
-
return
|
|
88
|
+
return undefined;
|
|
88
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>();
|
|
89
93
|
const trackOrigin = (record: ModuleRecord, root: Node): void => {
|
|
90
94
|
const visit = (node: Node): void => {
|
|
91
|
-
|
|
95
|
+
const range = originOf(record, node);
|
|
96
|
+
origins.set(node, range?.file ?? record.path);
|
|
97
|
+
if (range?.untyped) untypedNodes.add(node);
|
|
92
98
|
const fields = node as unknown as Record<string, unknown>;
|
|
93
99
|
for (const key of Object.keys(fields)) {
|
|
94
100
|
if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
|
|
@@ -254,6 +260,7 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
254
260
|
statements: merged,
|
|
255
261
|
fileName: first.path,
|
|
256
262
|
origins,
|
|
263
|
+
...(untypedNodes.size > 0 ? { untypedNodes } : {}),
|
|
257
264
|
moduleTexts: new Map(records.map((record) => [record.path, record.text])),
|
|
258
265
|
modulePrefixes: records.map((record) => record.prefix),
|
|
259
266
|
text: records.map((record) => record.text).join("\n"),
|
|
@@ -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";
|
|
@@ -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) {
|
|
@@ -115,9 +115,15 @@ export function bundleModules(
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
} else if (!declaration.exportClause && declaration.moduleSpecifier) {
|
|
118
|
-
// `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.
|
|
119
120
|
const dependency = dependencyOf(record, declaration.moduleSpecifier.value);
|
|
120
|
-
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
|
+
}
|
|
121
127
|
} else if (declaration.exportClause?.kind === SyntaxKind.NamespaceImport && declaration.moduleSpecifier) {
|
|
122
128
|
// `export * as ns from "..."`: re-export the dependency's namespace.
|
|
123
129
|
const nsName = (declaration.exportClause as { name: Identifier }).name.text;
|
|
@@ -198,9 +204,10 @@ export function bundleModules(
|
|
|
198
204
|
}
|
|
199
205
|
} else if (!clause) {
|
|
200
206
|
/* `export * from "./dep"`: alias every runtime export the deferred
|
|
201
|
-
* 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. */
|
|
202
209
|
for (const [name, target] of dependency.exports) {
|
|
203
|
-
if (!target) continue;
|
|
210
|
+
if (name === "default" || !target) continue;
|
|
204
211
|
const alias = deferredAliasName(record, aliases.length, `re_${name}`);
|
|
205
212
|
aliases.push({
|
|
206
213
|
name: alias,
|
|
@@ -64,6 +64,8 @@ export function resolveReexports(
|
|
|
64
64
|
}
|
|
65
65
|
} else if (!clause) {
|
|
66
66
|
for (const [name, value] of dependency.exports) {
|
|
67
|
+
// `export *` re-exports named exports only, never `default`.
|
|
68
|
+
if (name === "default") continue;
|
|
67
69
|
if (record.exports.get(name) !== value) {
|
|
68
70
|
record.exports.set(name, value);
|
|
69
71
|
changed = true;
|
package/src/driver/compiler.ts
CHANGED
|
@@ -182,10 +182,20 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
182
182
|
const storage = resolveStorage(options.storage);
|
|
183
183
|
|
|
184
184
|
const runtimeDir = findRuntimeDir();
|
|
185
|
+
/* The toolchain is part of the cache key, so it has to be resolved before
|
|
186
|
+
* the freshness check. `emit: "ir"` is front-end only and must keep working
|
|
187
|
+
* without clang, so it is the one build that does not resolve one. */
|
|
188
|
+
const toolchain: Pick<ResolvedToolchain, "clang" | "linkerArgs" | "env" | "sdkRoot"> | undefined =
|
|
189
|
+
emit === "ir"
|
|
190
|
+
? undefined
|
|
191
|
+
: options.clang
|
|
192
|
+
? { clang: options.clang, linkerArgs: [], env: {} }
|
|
193
|
+
: resolveToolchain(runner);
|
|
185
194
|
const cacheKey = buildCacheKey({
|
|
186
195
|
sourceText: parsed.cacheText,
|
|
187
196
|
emit,
|
|
188
197
|
optimize,
|
|
198
|
+
arch: process.arch,
|
|
189
199
|
registry,
|
|
190
200
|
runtimeDir,
|
|
191
201
|
icon,
|
|
@@ -197,6 +207,7 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
197
207
|
pgo,
|
|
198
208
|
pgoDir,
|
|
199
209
|
features: linkFeatures.map((feature) => feature.name),
|
|
210
|
+
...(toolchain === undefined ? {} : { toolchain }),
|
|
200
211
|
});
|
|
201
212
|
|
|
202
213
|
// A `.app` bundle is deterministic from the output path and name, so it can be
|
|
@@ -255,10 +266,10 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
255
266
|
}
|
|
256
267
|
|
|
257
268
|
// -- toolchain -----------------------------------------------------------
|
|
269
|
+
if (toolchain === undefined) {
|
|
270
|
+
throw new Error("xbintsc: internal error: no toolchain resolved for a linked build");
|
|
271
|
+
}
|
|
258
272
|
const clangStarted = Date.now();
|
|
259
|
-
const toolchain: Pick<ResolvedToolchain, "clang" | "linkerArgs" | "env" | "sdkRoot"> = options.clang
|
|
260
|
-
? { clang: options.clang, linkerArgs: [], env: {} }
|
|
261
|
-
: resolveToolchain(runner);
|
|
262
273
|
const clang = toolchain.clang;
|
|
263
274
|
if (pgo === "use") {
|
|
264
275
|
try {
|
package/src/driver/frontend.ts
CHANGED
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
* `run` and `build`.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { readFileSync } from "node:fs";
|
|
11
10
|
import { resolve } from "node:path";
|
|
12
11
|
import { DiagnosticBag } from "../diagnostics/diagnostic.js";
|
|
13
12
|
import { SourceFile } from "../diagnostics/source.js";
|
|
14
|
-
import { sourceTextBytes } from "../diagnostics/source-text.js";
|
|
13
|
+
import { readSourceText, sourceTextBytes } from "../diagnostics/source-text.js";
|
|
15
14
|
import { Parser } from "../parser/parser.js";
|
|
16
15
|
import { generate } from "../codegen/llvm.js";
|
|
17
16
|
import { SyntaxKind, type SourceFileNode } from "../ast/nodes.js";
|
|
@@ -63,7 +62,7 @@ export function parseEntry(
|
|
|
63
62
|
moduleOverrides?: Readonly<Record<string, string>>,
|
|
64
63
|
): ParsedEntry {
|
|
65
64
|
const absoluteEntry = resolve(entryPath);
|
|
66
|
-
const sourceText =
|
|
65
|
+
const sourceText = readSourceText(absoluteEntry);
|
|
67
66
|
const file = new SourceFile(absoluteEntry, sourceText);
|
|
68
67
|
const parser = new Parser(file, diagnostics);
|
|
69
68
|
let sourceFile = parser.parseSourceFile();
|
|
@@ -92,7 +91,7 @@ export function compileString(
|
|
|
92
91
|
extensions?: ExtensionRegistry,
|
|
93
92
|
options: FrontendOptions = {},
|
|
94
93
|
): CompileStringResult {
|
|
95
|
-
const file = new SourceFile(fileName, source);
|
|
94
|
+
const file = new SourceFile(fileName, sourceTextBytes(source));
|
|
96
95
|
const diagnostics = new DiagnosticBag();
|
|
97
96
|
const parser = new Parser(file, diagnostics);
|
|
98
97
|
const sourceFile = parser.parseSourceFile();
|
|
@@ -18,6 +18,7 @@ import { COMPILER_VERSION } from "./version.js";
|
|
|
18
18
|
/** Core runtime translation units (each compiled and cached independently). */
|
|
19
19
|
export const RUNTIME_SOURCES = [
|
|
20
20
|
"xt_alloc.c",
|
|
21
|
+
"xt_gc_stack.c",
|
|
21
22
|
"xt_values.c",
|
|
22
23
|
"xt_bigint.c",
|
|
23
24
|
"xt_containers.c",
|
|
@@ -44,6 +45,9 @@ export const RUNTIME_SOURCES = [
|
|
|
44
45
|
"xt_constructors.c",
|
|
45
46
|
"xt_structured_clone.c",
|
|
46
47
|
"xt_performance.c",
|
|
48
|
+
"xt_profile.c",
|
|
49
|
+
"xt_pool.c",
|
|
50
|
+
"xt_gc_release.c",
|
|
47
51
|
"xt_random.c",
|
|
48
52
|
"xt_crypto.c",
|
|
49
53
|
"xt_text_codec.c",
|
package/src/driver/toolchain.ts
CHANGED
|
@@ -34,14 +34,37 @@ export const realRunner: Runner = {
|
|
|
34
34
|
};
|
|
35
35
|
if (options.env) spawnOptions.env = Object.assign({}, process.env, options.env);
|
|
36
36
|
const result = spawnSync(command, [...args], spawnOptions);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
const stdout = result.stdout?.toString() ?? "";
|
|
38
|
+
const baseStderr = result.stderr?.toString() ?? "";
|
|
39
|
+
/* `status === null` is never success: the child either failed to start
|
|
40
|
+
* (`error`) or was terminated by a signal. Treating the signal case as 0
|
|
41
|
+
* made a killed clang look like a successful compile and let `build`
|
|
42
|
+
* record a missing/truncated artifact. */
|
|
43
|
+
if (result.error) {
|
|
44
|
+
const detail = result.error.message;
|
|
45
|
+
return {
|
|
46
|
+
status: result.status ?? 1,
|
|
47
|
+
stdout,
|
|
48
|
+
stderr: appendLine(baseStderr, detail),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (result.status === null) {
|
|
52
|
+
return {
|
|
53
|
+
status: 1,
|
|
54
|
+
stdout,
|
|
55
|
+
stderr: appendLine(baseStderr, `terminated by signal ${result.signal ?? "unknown"}`),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return { status: result.status, stdout, stderr: baseStderr };
|
|
42
59
|
},
|
|
43
60
|
};
|
|
44
61
|
|
|
62
|
+
/** Append `line` to `text` without losing an existing final newline. */
|
|
63
|
+
function appendLine(text: string, line: string): string {
|
|
64
|
+
if (text.length === 0) return line;
|
|
65
|
+
return text.endsWith("\n") ? `${text}${line}` : `${text}\n${line}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
45
68
|
export class ToolchainError extends Error {
|
|
46
69
|
readonly command: string;
|
|
47
70
|
readonly status: number;
|
package/src/driver/version.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* "eager" execution point), i.e. every script is effectively `defer`red.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
import { existsSync
|
|
27
|
+
import { existsSync } from "node:fs";
|
|
28
28
|
import { dirname, relative, resolve } from "node:path";
|
|
29
29
|
import {
|
|
30
30
|
ModifierKind,
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
} from "../../ast/nodes.js";
|
|
38
38
|
import { DiagnosticBag } from "../../diagnostics/diagnostic.js";
|
|
39
39
|
import { SourceFile } from "../../diagnostics/source.js";
|
|
40
|
+
import { readSourceText } from "../../diagnostics/source-text.js";
|
|
40
41
|
import { Parser } from "../../parser/parser.js";
|
|
41
42
|
import { artifactPath } from "../../canonical.js";
|
|
42
43
|
import { hashString } from "../../driver/cache.js";
|
|
@@ -81,6 +82,22 @@ function isExecutable(type: string | undefined, lang: string | undefined): boole
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Whether an executable `<script>` is plain JavaScript rather than TypeScript.
|
|
87
|
+
*
|
|
88
|
+
* A browser page's script is JavaScript by default; only `lang="ts"` or a
|
|
89
|
+
* TypeScript MIME type opts into type checking. Untyped scripts skip the
|
|
90
|
+
* checker's inference (see `isPlainJavaScriptNode`), which is what keeps
|
|
91
|
+
* minified bundles — `Game.foo = …` installed after the literal, a closure
|
|
92
|
+
* variable initialized to `null`, calls that rely on default parameters — from
|
|
93
|
+
* failing on heuristics that a real browser never applies.
|
|
94
|
+
*/
|
|
95
|
+
function isPlainScript(type: string | undefined, lang: string | undefined): boolean {
|
|
96
|
+
if (lang !== undefined && /^(ts|tsx|typescript)$/i.test(lang)) return false;
|
|
97
|
+
if (type === undefined) return true;
|
|
98
|
+
return !/^(text\/typescript|application\/typescript)$/i.test(type);
|
|
99
|
+
}
|
|
100
|
+
|
|
84
101
|
/** Rewrite a relative import specifier so it resolves from the HTML file. */
|
|
85
102
|
function rewriteSpecifier(htmlPath: string, scriptPath: string, specifier: string): string {
|
|
86
103
|
if (!specifier.startsWith(".")) return specifier;
|
|
@@ -274,8 +291,9 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
274
291
|
const page = new SourceFile(path, source).text;
|
|
275
292
|
/* `file` is set for an external `<script src>`: its body keeps that file as
|
|
276
293
|
* the origin of every node, so a `.js` script stays untyped and diagnostics
|
|
277
|
-
* name the script, not the HTML page.
|
|
278
|
-
|
|
294
|
+
* name the script, not the HTML page. `untyped` marks an inline body that is
|
|
295
|
+
* JavaScript (the default) rather than `lang="ts"`. */
|
|
296
|
+
const scripts: Array<{ id: string; body: string; prelude: string[]; file?: string; untyped?: boolean }> = [];
|
|
279
297
|
const imports: string[] = [];
|
|
280
298
|
const lazyImports: string[] = [];
|
|
281
299
|
const importedText = new Set<string>();
|
|
@@ -301,12 +319,18 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
301
319
|
bound.add(name);
|
|
302
320
|
}
|
|
303
321
|
};
|
|
304
|
-
const register = (compiled: CompiledModule, file?: string): string => {
|
|
322
|
+
const register = (compiled: CompiledModule, options?: { file?: string; untyped?: boolean }): string => {
|
|
305
323
|
/* Hash the wrapped body, prelude included: the engine keys the registry by
|
|
306
324
|
* id, so two scripts with the same statements but different deferred
|
|
307
325
|
* imports must not collapse into one entry. */
|
|
308
326
|
const id = hashString([...compiled.prelude, compiled.body].join("\n"));
|
|
309
|
-
scripts.push({
|
|
327
|
+
scripts.push({
|
|
328
|
+
id,
|
|
329
|
+
body: compiled.body,
|
|
330
|
+
prelude: compiled.prelude,
|
|
331
|
+
...(options?.file ? { file: options.file } : {}),
|
|
332
|
+
...(options?.untyped ? { untyped: true } : {}),
|
|
333
|
+
});
|
|
310
334
|
return id;
|
|
311
335
|
};
|
|
312
336
|
|
|
@@ -314,7 +338,9 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
314
338
|
* would be dropped at runtime. Inline it (and its `@import`s) now. */
|
|
315
339
|
const styles = inlineStylesheets(path, page);
|
|
316
340
|
const html = styles.html.replace(SCRIPT_RE, (match, attributes: string, inlineBody: string) => {
|
|
317
|
-
|
|
341
|
+
const lang = attribute(attributes, "lang");
|
|
342
|
+
const type = attribute(attributes, "type");
|
|
343
|
+
if (!isExecutable(type, lang)) return match;
|
|
318
344
|
const src = attribute(attributes, "src");
|
|
319
345
|
|
|
320
346
|
if (src !== undefined && !URL_SPEC.test(src) && !src.startsWith("//")) {
|
|
@@ -322,9 +348,9 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
322
348
|
if (!existsSync(scriptPath)) {
|
|
323
349
|
throw new Error(`gui: <script src="${src}"> not found (looked for ${scriptPath})`);
|
|
324
350
|
}
|
|
325
|
-
const compiled = compileModuleSource(path, scriptPath,
|
|
351
|
+
const compiled = compileModuleSource(path, scriptPath, readSourceText(scriptPath), scripts.length);
|
|
326
352
|
hoistImports(compiled, `<script src="${src}">`, `alias it in ${scriptPath}`);
|
|
327
|
-
const id = register(compiled, scriptPath);
|
|
353
|
+
const id = register(compiled, { file: scriptPath });
|
|
328
354
|
return `<script data-xt-id="${id}"></script>`;
|
|
329
355
|
}
|
|
330
356
|
|
|
@@ -339,7 +365,7 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
339
365
|
* where codegen cannot link its binding (TS5001). */
|
|
340
366
|
const compiled = compileModuleSource(path, path, inlineBody, scripts.length);
|
|
341
367
|
hoistImports(compiled, "inline <script>", "alias it");
|
|
342
|
-
const id = register(compiled);
|
|
368
|
+
const id = register(compiled, { untyped: isPlainScript(type, lang) });
|
|
343
369
|
return `<script data-xt-id="${id}"></script>`;
|
|
344
370
|
});
|
|
345
371
|
|
|
@@ -348,14 +374,18 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
348
374
|
/* Offset of the next part once joined with "\n", so a body's span in the
|
|
349
375
|
* generated module can be reported back as the file it was copied from. */
|
|
350
376
|
let offset = parts.reduce((total, part) => total + part.length + 1, 0);
|
|
351
|
-
for (const { id, body, prelude, file } of scripts) {
|
|
377
|
+
for (const { id, body, prelude, file, untyped } of scripts) {
|
|
352
378
|
const header = `function __xt_script_${id}(window: any, document: any): void {\n`;
|
|
353
379
|
const preludeText = prelude.length > 0 ? `${prelude.join("\n")}\n` : "";
|
|
354
380
|
const part =
|
|
355
381
|
`${header}${preludeText}${body}\n}\n` + `__registerScript(${JSON.stringify(id)}, __xt_script_${id});`;
|
|
382
|
+
const bodyStart = offset + header.length + preludeText.length;
|
|
356
383
|
if (file !== undefined) {
|
|
357
|
-
const bodyStart = offset + header.length + preludeText.length;
|
|
358
384
|
sourceRanges.push({ start: bodyStart, end: bodyStart + body.length, file });
|
|
385
|
+
} else if (untyped) {
|
|
386
|
+
/* An inline JavaScript body: its origin is the page itself, and the
|
|
387
|
+
* checker must treat it as untyped JavaScript, not as TypeScript. */
|
|
388
|
+
sourceRanges.push({ start: bodyStart, end: bodyStart + body.length, file: path, untyped: true });
|
|
359
389
|
}
|
|
360
390
|
parts.push(part);
|
|
361
391
|
offset += part.length + 1;
|
|
@@ -66,6 +66,12 @@ const hostTypes = [
|
|
|
66
66
|
"HTMLImageElement",
|
|
67
67
|
"HTMLVideoElement",
|
|
68
68
|
"HTMLAudioElement",
|
|
69
|
+
/* Media-source and offline-rendering types. `VideoFrame` is a real
|
|
70
|
+
* constructor value so `frame instanceof VideoFrame` is a safe `false`
|
|
71
|
+
* instead of a `TypeError`; `OfflineAudioContext` renders through the same
|
|
72
|
+
* mixer as `AudioContext`. */
|
|
73
|
+
"VideoFrame",
|
|
74
|
+
"OfflineAudioContext",
|
|
69
75
|
"HTMLElement",
|
|
70
76
|
"Element",
|
|
71
77
|
"Node",
|
|
@@ -83,6 +89,11 @@ const hostTypes = [
|
|
|
83
89
|
"AbortController",
|
|
84
90
|
"AbortSignal",
|
|
85
91
|
"EventTarget",
|
|
92
|
+
/* An inert observer: bundlers build one unconditionally (Vite's
|
|
93
|
+
* `modulepreload` polyfill calls `new MutationObserver(…).observe(…)` at
|
|
94
|
+
* startup), so the name has to resolve and the methods have to exist. No
|
|
95
|
+
* callback ever fires — see `runtime/ext_gui/dom_api_mutation.cpp`. */
|
|
96
|
+
"MutationObserver",
|
|
86
97
|
"DOMParser",
|
|
87
98
|
"Request",
|
|
88
99
|
"Headers",
|
|
@@ -145,7 +156,7 @@ const hostTypes = [
|
|
|
145
156
|
"GPUDeviceLostInfo",
|
|
146
157
|
] as const;
|
|
147
158
|
|
|
148
|
-
const browserGlobals: Record<string, { symbol: string; argument?: string }> = {
|
|
159
|
+
const browserGlobals: Record<string, { symbol: string; argument?: string; member?: string }> = {
|
|
149
160
|
window: { symbol: "xt_browser_window" },
|
|
150
161
|
self: { symbol: "xt_browser_window" },
|
|
151
162
|
document: { symbol: "xt_browser_document" },
|
|
@@ -154,8 +165,51 @@ const browserGlobals: Record<string, { symbol: string; argument?: string }> = {
|
|
|
154
165
|
* by the SQLite `storage` link feature, so a page reaches them through core
|
|
155
166
|
* rather than the engine's in-memory `window.localStorage` store. */
|
|
156
167
|
__THREE_DEVTOOLS__: { symbol: "xt_browser_missing" },
|
|
168
|
+
/* Half-precision typed arrays exist in very new engines only, and the
|
|
169
|
+
* runtime has no 16-bit float element type. Answering `undefined` keeps
|
|
170
|
+
* feature probes (`typeof Float16Array < "u"`) on their fallback path instead
|
|
171
|
+
* of handing back a constructor that cannot hold data. */
|
|
172
|
+
Float16Array: { symbol: "xt_browser_missing" },
|
|
157
173
|
createImageBitmap: { symbol: "xt_browser_create_image_bitmap" },
|
|
158
174
|
};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Window members that a browser also exposes as bare globals.
|
|
178
|
+
*
|
|
179
|
+
* In a browser the global scope *is* the window, so `innerWidth`,
|
|
180
|
+
* `location.reload()` and `addEventListener("resize", …)` work without a
|
|
181
|
+
* `window.` prefix — pages and libraries (three.js probes `innerWidth`) rely on
|
|
182
|
+
* that. xbintsc has no global object here, so each name is declared as a member
|
|
183
|
+
* read of the window value: the read lowers to `xt_get(window, name)` and a
|
|
184
|
+
* call to `xt_call_method(window, name, …)`, which keeps getter-backed members
|
|
185
|
+
* live instead of capturing a value at startup.
|
|
186
|
+
*/
|
|
187
|
+
const windowGlobals: readonly string[] = [
|
|
188
|
+
"innerWidth",
|
|
189
|
+
"innerHeight",
|
|
190
|
+
"outerWidth",
|
|
191
|
+
"outerHeight",
|
|
192
|
+
"devicePixelRatio",
|
|
193
|
+
"location",
|
|
194
|
+
"screen",
|
|
195
|
+
"scrollX",
|
|
196
|
+
"scrollY",
|
|
197
|
+
"addEventListener",
|
|
198
|
+
"removeEventListener",
|
|
199
|
+
"dispatchEvent",
|
|
200
|
+
"setTimeout",
|
|
201
|
+
"clearTimeout",
|
|
202
|
+
"setInterval",
|
|
203
|
+
"clearInterval",
|
|
204
|
+
"queueMicrotask",
|
|
205
|
+
"focus",
|
|
206
|
+
"blur",
|
|
207
|
+
"scrollTo",
|
|
208
|
+
"scrollBy",
|
|
209
|
+
];
|
|
210
|
+
for (const member of windowGlobals) {
|
|
211
|
+
browserGlobals[member] = { symbol: "xt_browser_window", member };
|
|
212
|
+
}
|
|
159
213
|
for (const type of hostTypes) {
|
|
160
214
|
browserGlobals[type] = { symbol: "xt_browser_type", argument: type };
|
|
161
215
|
}
|
|
@@ -38,6 +38,20 @@ export interface GlobalValue {
|
|
|
38
38
|
readonly symbol: string;
|
|
39
39
|
/** Passed as the only argument; omit to call the getter with none. */
|
|
40
40
|
readonly argument?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Read (and call) this global as a *member of the object `symbol` returns*
|
|
43
|
+
* instead of as the getter's own result.
|
|
44
|
+
*
|
|
45
|
+
* Browsers put `innerWidth`, `location` or `addEventListener` in the global
|
|
46
|
+
* scope because the global object *is* the window; xbintsc's globals are
|
|
47
|
+
* compiler-provided names with no global object behind them. Declaring
|
|
48
|
+
* `{ symbol: "xt_browser_window", member: "innerWidth" }` gives the name the
|
|
49
|
+
* browser semantics with the host object the extension already exposes: a
|
|
50
|
+
* read lowers to `xt_get(window, "innerWidth")` (getters run with the window
|
|
51
|
+
* as `this`, so the value is live rather than snapshotted at startup) and a
|
|
52
|
+
* call lowers to `xt_call_method(window, "addEventListener", …)`.
|
|
53
|
+
*/
|
|
54
|
+
readonly member?: string;
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
/**
|
|
@@ -110,6 +124,12 @@ export interface AssetSourceRange {
|
|
|
110
124
|
readonly start: number;
|
|
111
125
|
readonly end: number;
|
|
112
126
|
readonly file: string;
|
|
127
|
+
/**
|
|
128
|
+
* The copied source is plain JavaScript even though `file` is not a `.js`
|
|
129
|
+
* file (an inline `<script>` body in an HTML page). Nodes inside the span
|
|
130
|
+
* then skip the type checker, exactly like an external `.js` script.
|
|
131
|
+
*/
|
|
132
|
+
readonly untyped?: boolean;
|
|
113
133
|
}
|
|
114
134
|
|
|
115
135
|
/** Rewrites an imported file (selected by extension) into a TS module. */
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
binaryPrecedence,
|
|
33
33
|
prefixUnaryOperator,
|
|
34
34
|
} from "./operators.js";
|
|
35
|
-
import { isAssignmentTarget } from "./helpers.js";
|
|
35
|
+
import { endsExpression, isAssignmentTarget } from "./helpers.js";
|
|
36
36
|
import { SpeculationError } from "./speculation.js";
|
|
37
37
|
import type { Parser } from "./parser.js";
|
|
38
38
|
|
|
@@ -284,7 +284,7 @@ export const expressionMethods: ExpressionMethods = {
|
|
|
284
284
|
this.nextToken();
|
|
285
285
|
delegate = true;
|
|
286
286
|
}
|
|
287
|
-
if (!this.canInsertSemicolon() && !
|
|
287
|
+
if (!this.canInsertSemicolon() && !endsExpression(this.token.kind)) {
|
|
288
288
|
expression = this.parseAssignmentExpression();
|
|
289
289
|
}
|
|
290
290
|
return { kind: SyntaxKind.YieldExpression, expression, delegate, start: token.start, end: expression?.end ?? token.end };
|
package/src/parser/helpers.ts
CHANGED
|
@@ -3,8 +3,30 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { SyntaxKind } from "../ast/kinds.js";
|
|
6
|
+
import { TokenKind } from "../lexer/token.js";
|
|
6
7
|
import type { Expression, PropertyName } from "../ast/nodes.js";
|
|
7
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Whether a token can never begin an expression, so an operand-optional prefix
|
|
11
|
+
* operator (`yield`, `return`) placed before it has no operand. `yield, x` and
|
|
12
|
+
* `[yield]` are the common minified shapes: `yield` on its own is a valid
|
|
13
|
+
* expression, and a comma or a closing bracket ends it.
|
|
14
|
+
*/
|
|
15
|
+
export function endsExpression(kind: TokenKind): boolean {
|
|
16
|
+
switch (kind) {
|
|
17
|
+
case TokenKind.Comma:
|
|
18
|
+
case TokenKind.Semicolon:
|
|
19
|
+
case TokenKind.Colon:
|
|
20
|
+
case TokenKind.CloseParen:
|
|
21
|
+
case TokenKind.CloseBracket:
|
|
22
|
+
case TokenKind.CloseBrace:
|
|
23
|
+
case TokenKind.EndOfFile:
|
|
24
|
+
return true;
|
|
25
|
+
default:
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
8
30
|
export function expressionToPropertyName(expr: Expression): PropertyName | undefined {
|
|
9
31
|
switch (expr.kind) {
|
|
10
32
|
case SyntaxKind.StringLiteral:
|