toiljs 0.0.4 → 0.0.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/.idea/prettier.xml +1 -0
- package/as-pect.config.js +1 -1
- package/build/backend/.tsbuildinfo +1 -1
- package/build/backend/index.js +1 -2
- package/build/cli/.tsbuildinfo +1 -1
- package/build/cli/configure.d.ts +15 -0
- package/build/cli/configure.js +201 -0
- package/build/cli/create.d.ts +4 -0
- package/build/cli/create.js +193 -68
- package/build/cli/features.d.ts +23 -0
- package/build/cli/features.js +85 -0
- package/build/cli/index.js +42 -2
- package/build/cli/proc.d.ts +1 -0
- package/build/cli/proc.js +11 -0
- package/build/cli/ui.js +1 -2
- package/build/cli/validate.d.ts +4 -0
- package/build/cli/validate.js +19 -0
- package/build/client/.tsbuildinfo +1 -1
- package/build/client/Link.d.ts +8 -0
- package/build/client/Link.js +44 -0
- package/build/client/NavLink.d.ts +14 -0
- package/build/client/NavLink.js +37 -0
- package/build/client/Router.d.ts +7 -0
- package/build/client/Router.js +55 -0
- package/build/client/channel/channel.d.ts +23 -0
- package/build/client/channel/channel.js +94 -0
- package/build/client/error-boundary.d.ts +16 -0
- package/build/client/error-boundary.js +19 -0
- package/build/client/head/head.d.ts +26 -0
- package/build/client/head/head.js +87 -0
- package/build/client/head.d.ts +26 -0
- package/build/client/head.js +87 -0
- package/build/client/hooks.d.ts +17 -0
- package/build/client/hooks.js +48 -0
- package/build/client/index.d.ts +18 -6
- package/build/client/index.js +10 -3
- package/build/client/lazy.d.ts +16 -0
- package/build/client/lazy.js +53 -0
- package/build/client/match.js +7 -0
- package/build/client/mount.d.ts +2 -0
- package/build/client/mount.js +13 -0
- package/build/client/navigation/Link.d.ts +8 -0
- package/build/client/navigation/Link.js +44 -0
- package/build/client/navigation/NavLink.d.ts +14 -0
- package/build/client/navigation/NavLink.js +37 -0
- package/build/client/navigation/navigation.d.ts +13 -0
- package/build/client/navigation/navigation.js +97 -0
- package/build/client/navigation/prefetch.d.ts +11 -0
- package/build/client/navigation/prefetch.js +100 -0
- package/build/client/navigation/scroll.d.ts +8 -0
- package/build/client/navigation/scroll.js +36 -0
- package/build/client/navigation.d.ts +13 -0
- package/build/client/navigation.js +97 -0
- package/build/client/params-context.d.ts +2 -0
- package/build/client/params-context.js +2 -0
- package/build/client/prefetch.d.ts +11 -0
- package/build/client/prefetch.js +100 -0
- package/build/client/routing/Router.d.ts +7 -0
- package/build/client/routing/Router.js +55 -0
- package/build/client/routing/error-boundary.d.ts +16 -0
- package/build/client/routing/error-boundary.js +19 -0
- package/build/client/routing/hooks.d.ts +17 -0
- package/build/client/routing/hooks.js +48 -0
- package/build/client/routing/lazy.d.ts +16 -0
- package/build/client/routing/lazy.js +53 -0
- package/build/client/routing/match.d.ts +2 -0
- package/build/client/routing/match.js +32 -0
- package/build/client/routing/mount.d.ts +2 -0
- package/build/client/routing/mount.js +13 -0
- package/build/client/routing/params-context.d.ts +2 -0
- package/build/client/routing/params-context.js +2 -0
- package/build/client/scroll.d.ts +8 -0
- package/build/client/scroll.js +36 -0
- package/build/client/types.d.ts +27 -0
- package/build/client/types.js +1 -0
- package/build/compiler/.tsbuildinfo +1 -1
- package/build/compiler/config.d.ts +2 -0
- package/build/compiler/config.js +14 -2
- package/build/compiler/docs.d.ts +10 -0
- package/build/compiler/docs.js +59 -0
- package/build/compiler/generate.js +144 -16
- package/build/compiler/index.d.ts +4 -2
- package/build/compiler/index.js +4 -3
- package/build/compiler/plugin.js +16 -1
- package/build/compiler/routes.js +5 -1
- package/build/compiler/vite.d.ts +1 -1
- package/build/compiler/vite.js +17 -1
- package/build/io/.tsbuildinfo +1 -1
- package/build/io/BinaryWriter.js +2 -2
- package/eslint.config.js +1 -1
- package/examples/basic/.toil/docs/cli.md +3 -0
- package/examples/basic/.toil/docs/client.md +3 -0
- package/examples/basic/.toil/docs/index.md +3 -0
- package/examples/basic/.toil/docs/routing.md +3 -0
- package/examples/basic/.toil/docs/server.md +3 -0
- package/examples/basic/.toil/docs/styling.md +3 -0
- package/examples/basic/.toil/entry.tsx +3 -8
- package/examples/basic/.toil/globals.ts +6 -0
- package/examples/basic/.toil/index.html +16 -12
- package/examples/basic/.toil/public/images/.gitkeep +1 -0
- package/examples/basic/.toil/public/images/logo.svg +37 -0
- package/examples/basic/.toil/public/robots.txt +2 -0
- package/examples/basic/.toil/routes.ts +9 -7
- package/examples/basic/build/client/assets/404-Bq0jNTUo.js +1 -0
- package/examples/basic/build/client/assets/_...slug_-CXKf6qnB.js +1 -0
- package/examples/basic/build/client/assets/_id_-BadAyQnb.js +1 -0
- package/examples/basic/build/client/assets/about-BOhoEcEO.js +1 -0
- package/examples/basic/build/client/assets/get-started-BIXpcjkT.js +9 -0
- package/examples/basic/build/client/assets/index-BmqcTaBB.js +1 -0
- package/examples/basic/build/client/assets/io-DEVjjaJj.js +1 -0
- package/examples/basic/build/client/assets/layout-DJegirdz.js +1 -0
- package/examples/basic/build/client/assets/react-DEQrz1q7.js +9 -0
- package/examples/basic/build/client/assets/rolldown-runtime-KL5VtC6j.js +1 -0
- package/examples/basic/build/client/assets/routes-BYWn6TxK.js +1 -0
- package/examples/basic/build/client/css/style.css +2 -0
- package/examples/basic/build/client/images/.gitkeep +1 -0
- package/examples/basic/build/client/images/logo.svg +37 -0
- package/examples/basic/build/client/index.html +17 -0
- package/examples/basic/build/client/robots.txt +2 -0
- package/examples/basic/client/404.tsx +2 -5
- package/examples/basic/client/components/.gitkeep +1 -0
- package/examples/basic/client/components/Footer.tsx +8 -0
- package/examples/basic/client/components/HoneycombBackground.tsx +162 -0
- package/examples/basic/client/layout.tsx +43 -26
- package/examples/basic/client/public/favicon.ico +0 -0
- package/examples/basic/client/public/images/.gitkeep +1 -0
- package/examples/basic/client/public/images/logo.svg +37 -0
- package/examples/basic/client/public/index.html +16 -0
- package/examples/basic/client/public/robots.txt +2 -0
- package/examples/basic/client/routes/about.tsx +1 -3
- package/examples/basic/client/routes/blog/[id].tsx +2 -4
- package/examples/basic/client/routes/docs/[...slug].tsx +3 -6
- package/examples/basic/client/routes/get-started.tsx +84 -0
- package/examples/basic/client/routes/index.tsx +74 -7
- package/examples/basic/client/routes/io.tsx +3 -7
- package/examples/basic/client/styles/main.css +461 -0
- package/examples/basic/client/toil.tsx +7 -0
- package/examples/basic/node_modules/.bin/toilinit +16 -0
- package/examples/basic/node_modules/.bin/toilinit.cmd +17 -0
- package/examples/basic/node_modules/.bin/toilinit.ps1 +28 -0
- package/examples/basic/node_modules/.bin/toilscript +16 -0
- package/examples/basic/node_modules/.bin/toilscript.cmd +17 -0
- package/examples/basic/node_modules/.bin/toilscript.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-as +16 -0
- package/examples/basic/node_modules/.bin/wasm-as.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-as.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-ctor-eval +16 -0
- package/examples/basic/node_modules/.bin/wasm-ctor-eval.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-ctor-eval.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-dis +16 -0
- package/examples/basic/node_modules/.bin/wasm-dis.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-dis.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-merge +16 -0
- package/examples/basic/node_modules/.bin/wasm-merge.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-merge.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-metadce +16 -0
- package/examples/basic/node_modules/.bin/wasm-metadce.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-metadce.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-opt +16 -0
- package/examples/basic/node_modules/.bin/wasm-opt.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-opt.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-reduce +16 -0
- package/examples/basic/node_modules/.bin/wasm-reduce.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-reduce.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm-shell +16 -0
- package/examples/basic/node_modules/.bin/wasm-shell.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm-shell.ps1 +28 -0
- package/examples/basic/node_modules/.bin/wasm2js +16 -0
- package/examples/basic/node_modules/.bin/wasm2js.cmd +17 -0
- package/examples/basic/node_modules/.bin/wasm2js.ps1 +28 -0
- package/examples/basic/node_modules/.package-lock.json +49 -1
- package/examples/basic/node_modules/.vite/deps/_metadata.json +9 -9
- package/examples/basic/node_modules/binaryen/LICENSE +201 -0
- package/examples/basic/node_modules/binaryen/README.md +1362 -0
- package/examples/basic/node_modules/binaryen/bin/package.json +3 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-as +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-ctor-eval +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-dis +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-merge +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-metadce +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-opt +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-reduce +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm-shell +0 -0
- package/examples/basic/node_modules/binaryen/bin/wasm2js +0 -0
- package/examples/basic/node_modules/binaryen/index.d.ts +2371 -0
- package/examples/basic/node_modules/binaryen/index.js +30552 -0
- package/examples/basic/node_modules/binaryen/package.json +50 -0
- package/examples/basic/node_modules/long/LICENSE +202 -0
- package/examples/basic/node_modules/long/README.md +286 -0
- package/examples/basic/node_modules/long/index.d.ts +2 -0
- package/examples/basic/node_modules/long/index.js +1581 -0
- package/examples/basic/node_modules/long/package.json +58 -0
- package/examples/basic/node_modules/long/types.d.ts +474 -0
- package/examples/basic/node_modules/long/umd/index.d.ts +3 -0
- package/examples/basic/node_modules/long/umd/index.js +1622 -0
- package/examples/basic/node_modules/long/umd/package.json +3 -0
- package/examples/basic/node_modules/long/umd/types.d.ts +474 -0
- package/examples/basic/node_modules/toilscript/LICENSE +201 -0
- package/examples/basic/node_modules/toilscript/NOTICE +94 -0
- package/examples/basic/node_modules/toilscript/README.md +66 -0
- package/examples/basic/node_modules/toilscript/bin/toilinit.js +468 -0
- package/examples/basic/node_modules/toilscript/bin/toilscript.js +35 -0
- package/examples/basic/node_modules/toilscript/dist/cli.d.ts +4 -0
- package/examples/basic/node_modules/toilscript/dist/cli.generated.d.ts +10027 -0
- package/examples/basic/node_modules/toilscript/dist/cli.js +24474 -0
- package/examples/basic/node_modules/toilscript/dist/cli.js.map +7 -0
- package/examples/basic/node_modules/toilscript/dist/importmap.json +9 -0
- package/examples/basic/node_modules/toilscript/dist/toilscript.d.ts +4 -0
- package/examples/basic/node_modules/toilscript/dist/toilscript.generated.d.ts +11242 -0
- package/examples/basic/node_modules/toilscript/dist/toilscript.js +337 -0
- package/examples/basic/node_modules/toilscript/dist/toilscript.js.map +7 -0
- package/examples/basic/node_modules/toilscript/dist/transform.cjs +1 -0
- package/examples/basic/node_modules/toilscript/dist/transform.d.ts +1 -0
- package/examples/basic/node_modules/toilscript/dist/transform.js +1 -0
- package/examples/basic/node_modules/toilscript/dist/web.js +22 -0
- package/examples/basic/node_modules/toilscript/lib/binaryen.d.ts +2 -0
- package/examples/basic/node_modules/toilscript/lib/binaryen.js +2 -0
- package/examples/basic/node_modules/toilscript/package.json +115 -0
- package/examples/basic/node_modules/toilscript/std/README.md +6 -0
- package/examples/basic/node_modules/toilscript/std/assembly/array.ts +550 -0
- package/examples/basic/node_modules/toilscript/std/assembly/arraybuffer.ts +77 -0
- package/examples/basic/node_modules/toilscript/std/assembly/atomics.ts +127 -0
- package/examples/basic/node_modules/toilscript/std/assembly/bindings/asyncify.ts +16 -0
- package/examples/basic/node_modules/toilscript/std/assembly/bindings/dom.ts +291 -0
- package/examples/basic/node_modules/toilscript/std/assembly/bindings/node.ts +6 -0
- package/examples/basic/node_modules/toilscript/std/assembly/bitflags.ts +53 -0
- package/examples/basic/node_modules/toilscript/std/assembly/builtins.ts +2650 -0
- package/examples/basic/node_modules/toilscript/std/assembly/byteslice.ts +177 -0
- package/examples/basic/node_modules/toilscript/std/assembly/compat.ts +2 -0
- package/examples/basic/node_modules/toilscript/std/assembly/console.ts +42 -0
- package/examples/basic/node_modules/toilscript/std/assembly/crypto.ts +9 -0
- package/examples/basic/node_modules/toilscript/std/assembly/dataview.ts +181 -0
- package/examples/basic/node_modules/toilscript/std/assembly/date.ts +375 -0
- package/examples/basic/node_modules/toilscript/std/assembly/diagnostics.ts +11 -0
- package/examples/basic/node_modules/toilscript/std/assembly/encoding.ts +151 -0
- package/examples/basic/node_modules/toilscript/std/assembly/endian.ts +45 -0
- package/examples/basic/node_modules/toilscript/std/assembly/error.ts +44 -0
- package/examples/basic/node_modules/toilscript/std/assembly/fixedarray.ts +173 -0
- package/examples/basic/node_modules/toilscript/std/assembly/fixedmap.ts +326 -0
- package/examples/basic/node_modules/toilscript/std/assembly/fixedset.ts +275 -0
- package/examples/basic/node_modules/toilscript/std/assembly/function.ts +42 -0
- package/examples/basic/node_modules/toilscript/std/assembly/index.d.ts +2892 -0
- package/examples/basic/node_modules/toilscript/std/assembly/iterator.ts +35 -0
- package/examples/basic/node_modules/toilscript/std/assembly/map.ts +269 -0
- package/examples/basic/node_modules/toilscript/std/assembly/math.ts +3289 -0
- package/examples/basic/node_modules/toilscript/std/assembly/memory.ts +123 -0
- package/examples/basic/node_modules/toilscript/std/assembly/number.ts +388 -0
- package/examples/basic/node_modules/toilscript/std/assembly/object.ts +36 -0
- package/examples/basic/node_modules/toilscript/std/assembly/performance.ts +9 -0
- package/examples/basic/node_modules/toilscript/std/assembly/pointer.ts +80 -0
- package/examples/basic/node_modules/toilscript/std/assembly/polyfills.ts +27 -0
- package/examples/basic/node_modules/toilscript/std/assembly/process.ts +50 -0
- package/examples/basic/node_modules/toilscript/std/assembly/reference.ts +48 -0
- package/examples/basic/node_modules/toilscript/std/assembly/regexp.ts +12 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/README.md +83 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/common.ts +81 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/index-incremental.ts +2 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/index-memory.ts +1 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/index-minimal.ts +2 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/index-stub.ts +1 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/index.d.ts +37 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/itcms.ts +419 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/memory-runtime.ts +94 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/rtrace.ts +15 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/stub.ts +133 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/tcms.ts +254 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt/tlsf.ts +592 -0
- package/examples/basic/node_modules/toilscript/std/assembly/rt.ts +90 -0
- package/examples/basic/node_modules/toilscript/std/assembly/set.ts +225 -0
- package/examples/basic/node_modules/toilscript/std/assembly/shared/feature.ts +68 -0
- package/examples/basic/node_modules/toilscript/std/assembly/shared/runtime.ts +13 -0
- package/examples/basic/node_modules/toilscript/std/assembly/shared/target.ts +11 -0
- package/examples/basic/node_modules/toilscript/std/assembly/shared/tsconfig.json +11 -0
- package/examples/basic/node_modules/toilscript/std/assembly/shared/typeinfo.ts +72 -0
- package/examples/basic/node_modules/toilscript/std/assembly/staticarray.ts +423 -0
- package/examples/basic/node_modules/toilscript/std/assembly/string.ts +850 -0
- package/examples/basic/node_modules/toilscript/std/assembly/symbol.ts +114 -0
- package/examples/basic/node_modules/toilscript/std/assembly/table.ts +16 -0
- package/examples/basic/node_modules/toilscript/std/assembly/toilscript.ts +16 -0
- package/examples/basic/node_modules/toilscript/std/assembly/tsconfig.json +6 -0
- package/examples/basic/node_modules/toilscript/std/assembly/typedarray.ts +1954 -0
- package/examples/basic/node_modules/toilscript/std/assembly/uri.ts +17 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/bytes.ts +107 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/casemap.ts +497 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/error.ts +58 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/hash.ts +117 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/math.ts +1922 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/memory.ts +290 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/number.ts +873 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/sort.ts +313 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/string.ts +1202 -0
- package/examples/basic/node_modules/toilscript/std/assembly/util/uri.ts +275 -0
- package/examples/basic/node_modules/toilscript/std/assembly/vector.ts +4 -0
- package/examples/basic/node_modules/toilscript/std/assembly.json +16 -0
- package/examples/basic/node_modules/toilscript/std/portable/index.d.ts +461 -0
- package/examples/basic/node_modules/toilscript/std/portable/index.js +416 -0
- package/examples/basic/node_modules/toilscript/std/portable.json +11 -0
- package/examples/basic/node_modules/toilscript/std/types/assembly/index.d.ts +1 -0
- package/examples/basic/node_modules/toilscript/std/types/assembly/package.json +3 -0
- package/examples/basic/node_modules/toilscript/std/types/portable/index.d.ts +1 -0
- package/examples/basic/node_modules/toilscript/std/types/portable/package.json +3 -0
- package/examples/basic/node_modules/toilscript/tsconfig-base.json +13 -0
- package/examples/basic/node_modules/toilscript/util/README.md +23 -0
- package/examples/basic/node_modules/toilscript/util/browser/fs.js +1 -0
- package/examples/basic/node_modules/toilscript/util/browser/module.js +5 -0
- package/examples/basic/node_modules/toilscript/util/browser/path.js +520 -0
- package/examples/basic/node_modules/toilscript/util/browser/process.js +59 -0
- package/examples/basic/node_modules/toilscript/util/browser/url.js +23 -0
- package/examples/basic/node_modules/toilscript/util/cpu.d.ts +9 -0
- package/examples/basic/node_modules/toilscript/util/cpu.js +42 -0
- package/examples/basic/node_modules/toilscript/util/find.d.ts +6 -0
- package/examples/basic/node_modules/toilscript/util/find.js +20 -0
- package/examples/basic/node_modules/toilscript/util/node.d.ts +21 -0
- package/examples/basic/node_modules/toilscript/util/node.js +34 -0
- package/examples/basic/node_modules/toilscript/util/options.d.ts +70 -0
- package/examples/basic/node_modules/toilscript/util/options.js +262 -0
- package/examples/basic/node_modules/toilscript/util/terminal.d.ts +52 -0
- package/examples/basic/node_modules/toilscript/util/terminal.js +35 -0
- package/examples/basic/node_modules/toilscript/util/text.d.ts +26 -0
- package/examples/basic/node_modules/toilscript/util/text.js +114 -0
- package/examples/basic/node_modules/toilscript/util/tsconfig.json +9 -0
- package/examples/basic/node_modules/toilscript/util/web.d.ts +11 -0
- package/examples/basic/node_modules/toilscript/util/web.js +33 -0
- package/examples/basic/package-lock.json +50 -1
- package/examples/basic/package.json +5 -2
- package/examples/basic/server/index.ts +3 -0
- package/examples/basic/server/main.ts +6 -0
- package/examples/basic/server/tsconfig.json +7 -0
- package/examples/basic/toil-env.d.ts +20 -1
- package/examples/basic/toil.config.ts +2 -5
- package/examples/basic/toilconfig.json +30 -0
- package/package.json +2 -2
- package/presets/eslint.js +2 -7
- package/presets/no-uint8array-tostring.js +4 -5
- package/presets/prettier.json +8 -1
- package/src/backend/index.ts +11 -18
- package/src/cli/configure.ts +272 -0
- package/src/cli/create.ts +267 -82
- package/src/cli/features.ts +128 -0
- package/src/cli/index.ts +44 -3
- package/src/cli/proc.ts +20 -0
- package/src/cli/ui.ts +4 -6
- package/src/cli/validate.ts +31 -0
- package/src/client/head/head.ts +140 -0
- package/src/client/index.ts +39 -9
- package/src/client/navigation/Link.tsx +99 -0
- package/src/client/navigation/NavLink.tsx +86 -0
- package/src/client/navigation/navigation.ts +142 -0
- package/src/client/navigation/prefetch.ts +130 -0
- package/src/client/navigation/scroll.ts +53 -0
- package/src/client/routing/Router.tsx +95 -0
- package/src/client/routing/error-boundary.tsx +43 -0
- package/src/client/routing/hooks.ts +115 -0
- package/src/client/routing/lazy.ts +93 -0
- package/src/client/{match.ts → routing/match.ts} +11 -3
- package/src/client/routing/mount.tsx +28 -0
- package/src/client/routing/params-context.ts +10 -0
- package/src/client/types.ts +36 -0
- package/src/compiler/config.ts +26 -10
- package/src/compiler/docs.ts +87 -0
- package/src/compiler/generate.ts +180 -23
- package/src/compiler/index.ts +6 -4
- package/src/compiler/plugin.ts +22 -1
- package/src/compiler/routes.ts +13 -7
- package/src/compiler/vite.ts +28 -5
- package/src/io/BinaryReader.ts +1 -5
- package/src/io/BinaryWriter.ts +3 -3
- package/src/server/index.ts +3 -4
- package/src/server/tsconfig.json +4 -0
- package/templates/app/client/404.tsx +11 -0
- package/templates/app/client/components/.gitkeep +1 -0
- package/templates/app/client/components/Footer.tsx +8 -0
- package/templates/app/client/components/HoneycombBackground.tsx +162 -0
- package/templates/app/client/layout.tsx +53 -0
- package/templates/app/client/public/favicon.ico +0 -0
- package/templates/app/client/public/images/.gitkeep +1 -0
- package/templates/app/client/public/images/logo.svg +37 -0
- package/templates/app/client/public/index.html +16 -0
- package/templates/app/client/public/robots.txt +2 -0
- package/templates/app/client/routes/about.tsx +11 -0
- package/templates/app/client/routes/blog/[id].tsx +12 -0
- package/templates/app/client/routes/docs/[...slug].tsx +12 -0
- package/templates/app/client/routes/get-started.tsx +84 -0
- package/templates/app/client/routes/index.tsx +80 -0
- package/templates/app/client/routes/io.tsx +24 -0
- package/templates/app/client/styles/main.css +461 -0
- package/templates/app/client/toil.tsx +7 -0
- package/test/channel.test.ts +1 -1
- package/test/configure.test.ts +90 -0
- package/test/features.test.ts +111 -0
- package/test/head.test.ts +35 -0
- package/test/io.test.ts +8 -0
- package/test/navlink.test.ts +28 -0
- package/test/routes.test.ts +16 -1
- package/test/validate.test.ts +42 -0
- package/vitest.config.ts +1 -1
- package/examples/basic/dist/assets/404-D1bS2aH_.js +0 -1
- package/examples/basic/dist/assets/_...slug_-wR3shlWn.js +0 -1
- package/examples/basic/dist/assets/_id_-EWYvHfi2.js +0 -1
- package/examples/basic/dist/assets/about-Ddvj1tjF.js +0 -1
- package/examples/basic/dist/assets/index-CdG0me90.js +0 -1
- package/examples/basic/dist/assets/io-CODNJU57.js +0 -1
- package/examples/basic/dist/assets/layout-C15ZTPYI.js +0 -1
- package/examples/basic/dist/assets/react-JbAfoxYe.js +0 -9
- package/examples/basic/dist/assets/rolldown-runtime-1VNLd2iN.js +0 -1
- package/examples/basic/dist/assets/routes-GoydenoY.js +0 -1
- package/examples/basic/dist/index.html +0 -12
- package/src/client/runtime.tsx +0 -190
- /package/src/client/{channel.ts → channel/channel.ts} +0 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
/// <reference path="./rt/index.d.ts" />
|
|
2
|
+
|
|
3
|
+
import { BLOCK_MAXSIZE } from "./rt/common";
|
|
4
|
+
import { Runtime } from "shared/runtime";
|
|
5
|
+
import { COMPARATOR, SORT } from "./util/sort";
|
|
6
|
+
import { REVERSE, FILL } from "./util/bytes";
|
|
7
|
+
import { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from "./util/string";
|
|
8
|
+
import { idof, isArray as builtin_isArray } from "./builtins";
|
|
9
|
+
import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_EMPTYARRAY, E_HOLEYARRAY } from "./util/error";
|
|
10
|
+
|
|
11
|
+
// @ts-ignore: decorator
|
|
12
|
+
@inline @lazy const MIN_SIZE: usize = 8;
|
|
13
|
+
|
|
14
|
+
/** Ensures that the given array has _at least_ the specified backing size. */
|
|
15
|
+
function ensureCapacity(array: usize, newSize: usize, alignLog2: u32, canGrow: bool = true): void {
|
|
16
|
+
// Depends on the fact that Arrays mimic ArrayBufferView
|
|
17
|
+
let oldCapacity = <usize>changetype<ArrayBufferView>(array).byteLength;
|
|
18
|
+
if (newSize > oldCapacity >>> alignLog2) {
|
|
19
|
+
if (newSize > BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);
|
|
20
|
+
let oldData = changetype<usize>(changetype<ArrayBufferView>(array).buffer);
|
|
21
|
+
// Grows old capacity by factor of two.
|
|
22
|
+
// Make sure we don't reach BLOCK_MAXSIZE for new growed capacity.
|
|
23
|
+
let newCapacity = max(newSize, MIN_SIZE) << alignLog2;
|
|
24
|
+
if (canGrow) newCapacity = max(min(oldCapacity << 1, BLOCK_MAXSIZE), newCapacity);
|
|
25
|
+
let newData = __renew(oldData, newCapacity);
|
|
26
|
+
// __new / __renew already init memory range as zeros in Incremental runtime.
|
|
27
|
+
// So try to avoid this.
|
|
28
|
+
if (ASC_RUNTIME != Runtime.Incremental) {
|
|
29
|
+
memory.fill(newData + oldCapacity, 0, newCapacity - oldCapacity);
|
|
30
|
+
}
|
|
31
|
+
if (newData != oldData) { // oldData has been free'd
|
|
32
|
+
store<usize>(array, newData, offsetof<ArrayBufferView>("buffer"));
|
|
33
|
+
store<usize>(array, newData, offsetof<ArrayBufferView>("dataStart"));
|
|
34
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
35
|
+
__link(array, changetype<usize>(newData), false);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
store<u32>(array, <u32>newCapacity, offsetof<ArrayBufferView>("byteLength"));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class Array<T> {
|
|
43
|
+
[key: number]: T;
|
|
44
|
+
|
|
45
|
+
// Mimicking ArrayBufferView isn't strictly necessary here but is done to allow glue code
|
|
46
|
+
// to work with typed and normal arrays interchangeably. Technically, normal arrays do not need
|
|
47
|
+
// `dataStart` (equals `buffer`) and `byteLength` (equals computed `buffer.byteLength`), but the
|
|
48
|
+
// block is 16 bytes anyway so it's fine to have a couple extra fields in there.
|
|
49
|
+
|
|
50
|
+
private buffer: ArrayBuffer;
|
|
51
|
+
@unsafe readonly dataStart: usize;
|
|
52
|
+
private byteLength: i32; // Uses here as capacity
|
|
53
|
+
|
|
54
|
+
// Also note that Array<T> with non-nullable T must guard against uninitialized null values
|
|
55
|
+
// whenever an element is accessed. Otherwise, the compiler wouldn't be able to guarantee
|
|
56
|
+
// type-safety anymore. For lack of a better word, such an array is "holey".
|
|
57
|
+
|
|
58
|
+
private length_: i32;
|
|
59
|
+
|
|
60
|
+
static isArray<U>(value: U): bool {
|
|
61
|
+
return isReference<U>() ? changetype<usize>(value) != 0 && builtin_isArray(value) : false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static create<T>(capacity: i32 = 0): Array<T> {
|
|
65
|
+
WARNING("'Array.create' is deprecated. Use 'new Array' instead, making sure initial elements are initialized.");
|
|
66
|
+
let array = new Array<T>(capacity);
|
|
67
|
+
array.length = 0;
|
|
68
|
+
return array;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
constructor(length: i32 = 0) {
|
|
72
|
+
if (<u32>length > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new RangeError(E_INVALIDLENGTH);
|
|
73
|
+
// reserve capacity for at least MIN_SIZE elements
|
|
74
|
+
let bufferSize = max(<usize>length, MIN_SIZE) << alignof<T>();
|
|
75
|
+
let buffer = changetype<ArrayBuffer>(__new(bufferSize, idof<ArrayBuffer>()));
|
|
76
|
+
if (ASC_RUNTIME != Runtime.Incremental) {
|
|
77
|
+
memory.fill(changetype<usize>(buffer), 0, bufferSize);
|
|
78
|
+
}
|
|
79
|
+
this.buffer = buffer; // links
|
|
80
|
+
this.dataStart = changetype<usize>(buffer);
|
|
81
|
+
this.byteLength = <i32>bufferSize;
|
|
82
|
+
this.length_ = length;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get length(): i32 {
|
|
86
|
+
return this.length_;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
set length(newLength: i32) {
|
|
90
|
+
ensureCapacity(changetype<usize>(this), newLength, alignof<T>(), false);
|
|
91
|
+
this.length_ = newLength;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
every(fn: (value: T, index: i32, array: Array<T>) => bool): bool {
|
|
95
|
+
for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
|
|
96
|
+
if (!fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
findIndex(fn: (value: T, index: i32, array: Array<T>) => bool): i32 {
|
|
102
|
+
for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
|
|
103
|
+
if (fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return i;
|
|
104
|
+
}
|
|
105
|
+
return -1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
findLastIndex(fn: (value: T, index: i32, array: Array<T>) => bool): i32 {
|
|
109
|
+
for (let i = this.length_ - 1; i >= 0; --i) {
|
|
110
|
+
if (fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return i;
|
|
111
|
+
}
|
|
112
|
+
return -1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@operator("[]") private __get(index: i32): T {
|
|
116
|
+
if (<u32>index >= <u32>this.length_) throw new RangeError(E_INDEXOUTOFRANGE);
|
|
117
|
+
let value = load<T>(this.dataStart + (<usize>index << alignof<T>()));
|
|
118
|
+
if (isReference<T>()) {
|
|
119
|
+
if (!isNullable<T>()) {
|
|
120
|
+
if (!changetype<usize>(value)) throw new Error(E_HOLEYARRAY);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@unsafe @operator("{}") private __uget(index: i32): T {
|
|
127
|
+
return load<T>(this.dataStart + (<usize>index << alignof<T>()));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@operator("[]=") private __set(index: i32, value: T): void {
|
|
131
|
+
if (<u32>index >= <u32>this.length_) {
|
|
132
|
+
if (index < 0) throw new RangeError(E_INDEXOUTOFRANGE);
|
|
133
|
+
ensureCapacity(changetype<usize>(this), index + 1, alignof<T>());
|
|
134
|
+
this.length_ = index + 1;
|
|
135
|
+
}
|
|
136
|
+
store<T>(this.dataStart + (<usize>index << alignof<T>()), value);
|
|
137
|
+
if (isManaged<T>()) {
|
|
138
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
139
|
+
__link(changetype<usize>(this), changetype<usize>(value), true);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
at(index: i32): T {
|
|
145
|
+
let len = this.length_;
|
|
146
|
+
index += select(0, len, index >= 0);
|
|
147
|
+
if (<u32>index >= <u32>len) throw new RangeError(E_INDEXOUTOFRANGE);
|
|
148
|
+
let value = load<T>(this.dataStart + (<usize>index << alignof<T>()));
|
|
149
|
+
if (isReference<T>()) {
|
|
150
|
+
if (!isNullable<T>()) {
|
|
151
|
+
if (!changetype<usize>(value)) throw new Error(E_HOLEYARRAY);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): Array<T> {
|
|
158
|
+
if (isManaged<T>()) {
|
|
159
|
+
FILL<usize>(this.dataStart, this.length_, changetype<usize>(value), start, end);
|
|
160
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
161
|
+
__link(changetype<usize>(this), changetype<usize>(value), false);
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
FILL<T>(this.dataStart, this.length_, value, start, end);
|
|
165
|
+
}
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
includes(value: T, fromIndex: i32 = 0): bool {
|
|
170
|
+
if (isFloat<T>()) {
|
|
171
|
+
let len = this.length_;
|
|
172
|
+
if (len == 0 || fromIndex >= len) return false;
|
|
173
|
+
if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);
|
|
174
|
+
let ptr = this.dataStart;
|
|
175
|
+
while (fromIndex < len) {
|
|
176
|
+
let elem = load<T>(ptr + (<usize>fromIndex << alignof<T>()));
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
if (elem == value || isNaN(elem) & isNaN(value)) return true;
|
|
179
|
+
++fromIndex;
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
} else {
|
|
183
|
+
return this.indexOf(value, fromIndex) >= 0;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
indexOf(value: T, fromIndex: i32 = 0): i32 {
|
|
188
|
+
let len = this.length_;
|
|
189
|
+
if (len == 0 || fromIndex >= len) return -1;
|
|
190
|
+
if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);
|
|
191
|
+
let ptr = this.dataStart;
|
|
192
|
+
while (fromIndex < len) {
|
|
193
|
+
if (load<T>(ptr + (<usize>fromIndex << alignof<T>())) == value) return fromIndex;
|
|
194
|
+
++fromIndex;
|
|
195
|
+
}
|
|
196
|
+
return -1;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
lastIndexOf(value: T, fromIndex: i32 = this.length_): i32 {
|
|
200
|
+
let len = this.length_;
|
|
201
|
+
if (len == 0) return -1;
|
|
202
|
+
if (fromIndex < 0) fromIndex = len + fromIndex;
|
|
203
|
+
else if (fromIndex >= len) fromIndex = len - 1;
|
|
204
|
+
let ptr = this.dataStart;
|
|
205
|
+
while (fromIndex >= 0) {
|
|
206
|
+
if (load<T>(ptr + (<usize>fromIndex << alignof<T>())) == value) return fromIndex;
|
|
207
|
+
--fromIndex;
|
|
208
|
+
}
|
|
209
|
+
return -1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
push(value: T): i32 {
|
|
213
|
+
let oldLen = this.length_;
|
|
214
|
+
let len = oldLen + 1;
|
|
215
|
+
ensureCapacity(changetype<usize>(this), len, alignof<T>());
|
|
216
|
+
if (isManaged<T>()) {
|
|
217
|
+
store<usize>(this.dataStart + (<usize>oldLen << alignof<T>()), changetype<usize>(value));
|
|
218
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
219
|
+
__link(changetype<usize>(this), changetype<usize>(value), true);
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
store<T>(this.dataStart + (<usize>oldLen << alignof<T>()), value);
|
|
223
|
+
}
|
|
224
|
+
this.length_ = len;
|
|
225
|
+
return len;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
concat(other: Array<T>): Array<T> {
|
|
229
|
+
let thisLen = this.length_;
|
|
230
|
+
let otherLen = other.length_;
|
|
231
|
+
let outLen = thisLen + otherLen;
|
|
232
|
+
if (<u32>outLen > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new Error(E_INVALIDLENGTH);
|
|
233
|
+
let out = changetype<Array<T>>(__newArray(outLen, alignof<T>(), idof<Array<T>>()));
|
|
234
|
+
let outStart = out.dataStart;
|
|
235
|
+
let thisSize = <usize>thisLen << alignof<T>();
|
|
236
|
+
if (isManaged<T>()) {
|
|
237
|
+
let thisStart = this.dataStart;
|
|
238
|
+
for (let offset: usize = 0; offset < thisSize; offset += sizeof<T>()) {
|
|
239
|
+
let ref = load<usize>(thisStart + offset);
|
|
240
|
+
store<usize>(outStart + offset, ref);
|
|
241
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
242
|
+
__link(changetype<usize>(out), ref, true);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
outStart += thisSize;
|
|
246
|
+
let otherStart = other.dataStart;
|
|
247
|
+
let otherSize = <usize>otherLen << alignof<T>();
|
|
248
|
+
for (let offset: usize = 0; offset < otherSize; offset += sizeof<T>()) {
|
|
249
|
+
let ref = load<usize>(otherStart + offset);
|
|
250
|
+
store<usize>(outStart + offset, ref);
|
|
251
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
252
|
+
__link(changetype<usize>(out), ref, true);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
memory.copy(outStart, this.dataStart, thisSize);
|
|
257
|
+
memory.copy(outStart + thisSize, other.dataStart, <usize>otherLen << alignof<T>());
|
|
258
|
+
}
|
|
259
|
+
return out;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Array<T> {
|
|
263
|
+
let ptr = this.dataStart;
|
|
264
|
+
let len = this.length_;
|
|
265
|
+
|
|
266
|
+
end = min<i32>(end, len);
|
|
267
|
+
|
|
268
|
+
let to = target < 0 ? max(len + target, 0) : min(target, len);
|
|
269
|
+
let from = start < 0 ? max(len + start, 0) : min(start, len);
|
|
270
|
+
let last = end < 0 ? max(len + end, 0) : min(end, len);
|
|
271
|
+
let count = min(last - from, len - to);
|
|
272
|
+
|
|
273
|
+
memory.copy( // is memmove
|
|
274
|
+
ptr + (<usize>to << alignof<T>()),
|
|
275
|
+
ptr + (<usize>from << alignof<T>()),
|
|
276
|
+
<usize>count << alignof<T>()
|
|
277
|
+
);
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
pop(): T {
|
|
282
|
+
let len = this.length_;
|
|
283
|
+
if (len < 1) throw new RangeError(E_EMPTYARRAY);
|
|
284
|
+
let val = load<T>(this.dataStart + (<usize>(--len) << alignof<T>()));
|
|
285
|
+
this.length_ = len;
|
|
286
|
+
return val;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
forEach(fn: (value: T, index: i32, array: Array<T>) => void): void {
|
|
290
|
+
for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
|
|
291
|
+
fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
map<U>(fn: (value: T, index: i32, array: Array<T>) => U): Array<U> {
|
|
296
|
+
let len = this.length_;
|
|
297
|
+
let out = changetype<Array<U>>(__newArray(len, alignof<U>(), idof<Array<U>>()));
|
|
298
|
+
let outStart = out.dataStart;
|
|
299
|
+
for (let i = 0; i < min(len, this.length_); ++i) {
|
|
300
|
+
let result = fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
|
|
301
|
+
store<U>(outStart + (<usize>i << alignof<U>()), result);
|
|
302
|
+
if (isManaged<U>()) {
|
|
303
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
304
|
+
__link(changetype<usize>(out), changetype<usize>(result), true);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
filter(fn: (value: T, index: i32, array: Array<T>) => bool): Array<T> {
|
|
312
|
+
let result = changetype<Array<T>>(__newArray(0, alignof<T>(), idof<Array<T>>()));
|
|
313
|
+
for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
|
|
314
|
+
let value = load<T>(this.dataStart + (<usize>i << alignof<T>()));
|
|
315
|
+
if (fn(value, i, this)) result.push(value);
|
|
316
|
+
}
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
reduce<U>(
|
|
321
|
+
fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array<T>) => U,
|
|
322
|
+
initialValue: U
|
|
323
|
+
): U {
|
|
324
|
+
let acc = initialValue;
|
|
325
|
+
for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
|
|
326
|
+
acc = fn(acc, load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
|
|
327
|
+
}
|
|
328
|
+
return acc;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
reduceRight<U>(
|
|
332
|
+
fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array<T>) => U,
|
|
333
|
+
initialValue: U
|
|
334
|
+
): U {
|
|
335
|
+
let acc = initialValue;
|
|
336
|
+
for (let i = this.length_ - 1; i >= 0; --i) {
|
|
337
|
+
acc = fn(acc, load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
|
|
338
|
+
}
|
|
339
|
+
return acc;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
shift(): T {
|
|
343
|
+
let len = this.length_;
|
|
344
|
+
if (len < 1) throw new RangeError(E_EMPTYARRAY);
|
|
345
|
+
let base = this.dataStart;
|
|
346
|
+
let element = load<T>(base);
|
|
347
|
+
let lastIndex = len - 1;
|
|
348
|
+
memory.copy(
|
|
349
|
+
base,
|
|
350
|
+
base + sizeof<T>(),
|
|
351
|
+
<usize>lastIndex << alignof<T>()
|
|
352
|
+
);
|
|
353
|
+
if (isReference<T>()) {
|
|
354
|
+
store<usize>(base + (<usize>lastIndex << alignof<T>()), 0);
|
|
355
|
+
} else {
|
|
356
|
+
// @ts-ignore
|
|
357
|
+
store<T>(base + (<usize>lastIndex << alignof<T>()), <T>0);
|
|
358
|
+
}
|
|
359
|
+
this.length_ = lastIndex;
|
|
360
|
+
return element;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
some(fn: (value: T, index: i32, array: Array<T>) => bool): bool {
|
|
364
|
+
for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
|
|
365
|
+
if (fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return true;
|
|
366
|
+
}
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
unshift(value: T): i32 {
|
|
371
|
+
let len = this.length_ + 1;
|
|
372
|
+
ensureCapacity(changetype<usize>(this), len, alignof<T>());
|
|
373
|
+
let ptr = this.dataStart;
|
|
374
|
+
memory.copy(
|
|
375
|
+
ptr + sizeof<T>(),
|
|
376
|
+
ptr,
|
|
377
|
+
<usize>(len - 1) << alignof<T>()
|
|
378
|
+
);
|
|
379
|
+
store<T>(ptr, value);
|
|
380
|
+
if (isManaged<T>()) {
|
|
381
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
382
|
+
__link(changetype<usize>(this), changetype<usize>(value), true);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
this.length_ = len;
|
|
386
|
+
return len;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
slice(start: i32 = 0, end: i32 = i32.MAX_VALUE): Array<T> {
|
|
390
|
+
let len = this.length_;
|
|
391
|
+
start = start < 0 ? max(start + len, 0) : min(start, len);
|
|
392
|
+
end = end < 0 ? max(end + len, 0) : min(end , len);
|
|
393
|
+
len = max(end - start, 0);
|
|
394
|
+
let slice = changetype<Array<T>>(__newArray(len, alignof<T>(), idof<Array<T>>()));
|
|
395
|
+
let sliceBase = slice.dataStart;
|
|
396
|
+
let thisBase = this.dataStart + (<usize>start << alignof<T>());
|
|
397
|
+
if (isManaged<T>()) {
|
|
398
|
+
let off = <usize>0;
|
|
399
|
+
let end = <usize>len << alignof<usize>();
|
|
400
|
+
while (off < end) {
|
|
401
|
+
let ref = load<usize>(thisBase + off);
|
|
402
|
+
store<usize>(sliceBase + off, ref);
|
|
403
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
404
|
+
__link(changetype<usize>(slice), ref, true);
|
|
405
|
+
}
|
|
406
|
+
off += sizeof<usize>();
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
memory.copy(sliceBase, thisBase, len << alignof<T>());
|
|
410
|
+
}
|
|
411
|
+
return slice;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): Array<T> {
|
|
415
|
+
let len = this.length_;
|
|
416
|
+
start = start < 0 ? max<i32>(len + start, 0) : min<i32>(start, len);
|
|
417
|
+
deleteCount = max<i32>(min<i32>(deleteCount, len - start), 0);
|
|
418
|
+
let result = changetype<Array<T>>(__newArray(deleteCount, alignof<T>(), idof<Array<T>>()));
|
|
419
|
+
let resultStart = result.dataStart;
|
|
420
|
+
let thisStart = this.dataStart;
|
|
421
|
+
let thisBase = thisStart + (<usize>start << alignof<T>());
|
|
422
|
+
memory.copy(
|
|
423
|
+
resultStart,
|
|
424
|
+
thisBase,
|
|
425
|
+
<usize>deleteCount << alignof<T>()
|
|
426
|
+
);
|
|
427
|
+
let offset = start + deleteCount;
|
|
428
|
+
if (len != offset) {
|
|
429
|
+
memory.copy(
|
|
430
|
+
thisBase,
|
|
431
|
+
thisStart + (<usize>offset << alignof<T>()),
|
|
432
|
+
<usize>(len - offset) << alignof<T>()
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
this.length_ = len - deleteCount;
|
|
436
|
+
return result;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
reverse(): Array<T> {
|
|
440
|
+
REVERSE<T>(this.dataStart, this.length_);
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
sort(comparator: (a: T, b: T) => i32 = COMPARATOR<T>()): Array<T> {
|
|
445
|
+
SORT<T>(this.dataStart, this.length_, comparator);
|
|
446
|
+
return this;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
join(separator: string = ","): string {
|
|
450
|
+
let ptr = this.dataStart;
|
|
451
|
+
let len = this.length_;
|
|
452
|
+
if (isBoolean<T>()) return joinBooleanArray(ptr, len, separator);
|
|
453
|
+
if (isInteger<T>()) return joinIntegerArray<T>(ptr, len, separator);
|
|
454
|
+
if (isFloat<T>()) return joinFloatArray<T>(ptr, len, separator);
|
|
455
|
+
|
|
456
|
+
if (ASC_SHRINK_LEVEL < 1) {
|
|
457
|
+
if (isString<T>()) return joinStringArray(ptr, len, separator);
|
|
458
|
+
}
|
|
459
|
+
// For rest objects and arrays use general join routine
|
|
460
|
+
if (isReference<T>()) return joinReferenceArray<T>(ptr, len, separator);
|
|
461
|
+
ERROR("unspported element type");
|
|
462
|
+
return <string>unreachable();
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
flat(): T {
|
|
466
|
+
if (!isArray<T>()) {
|
|
467
|
+
ERROR("Cannot call flat() on Array<T> where T is not an Array.");
|
|
468
|
+
}
|
|
469
|
+
// Get the length and data start values
|
|
470
|
+
let ptr = this.dataStart;
|
|
471
|
+
let len = this.length_;
|
|
472
|
+
|
|
473
|
+
// calculate the end size with an initial pass
|
|
474
|
+
let size = 0;
|
|
475
|
+
for (let i = 0; i < len; ++i) {
|
|
476
|
+
let child = load<usize>(ptr + (i << alignof<T>()));
|
|
477
|
+
size += child == 0 ? 0 : load<i32>(child, offsetof<T>("length_"));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// calculate the byteLength of the resulting backing ArrayBuffer
|
|
481
|
+
const align = alignof<valueof<T>>();
|
|
482
|
+
let byteLength = <usize>size << align;
|
|
483
|
+
let outBuffer = changetype<ArrayBuffer>(__new(byteLength, idof<ArrayBuffer>()));
|
|
484
|
+
|
|
485
|
+
// create the return value and initialize it
|
|
486
|
+
let outArray = changetype<T>(__new(offsetof<T>(), idof<T>()));
|
|
487
|
+
store<i32>(changetype<usize>(outArray), size, offsetof<T>("length_"));
|
|
488
|
+
|
|
489
|
+
// byteLength, dataStart, and buffer are all readonly
|
|
490
|
+
store<i32>(changetype<usize>(outArray), byteLength, offsetof<T>("byteLength"));
|
|
491
|
+
store<usize>(changetype<usize>(outArray), changetype<usize>(outBuffer), offsetof<T>("dataStart"));
|
|
492
|
+
store<usize>(changetype<usize>(outArray), changetype<usize>(outBuffer), offsetof<T>("buffer"));
|
|
493
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
494
|
+
__link(changetype<usize>(outArray), changetype<usize>(outBuffer), false);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// set the elements
|
|
498
|
+
let resultOffset: usize = 0;
|
|
499
|
+
for (let i = 0; i < len; ++i) { // for each child
|
|
500
|
+
let child = load<usize>(ptr + (<usize>i << alignof<T>()));
|
|
501
|
+
|
|
502
|
+
// ignore null arrays
|
|
503
|
+
if (!child) continue;
|
|
504
|
+
|
|
505
|
+
// copy the underlying buffer data to the result buffer
|
|
506
|
+
let childDataLength = <usize>load<i32>(child, offsetof<T>("length_")) << align;
|
|
507
|
+
memory.copy(
|
|
508
|
+
changetype<usize>(outBuffer) + resultOffset,
|
|
509
|
+
load<usize>(child, offsetof<T>("dataStart")),
|
|
510
|
+
childDataLength
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
// advance the result length
|
|
514
|
+
resultOffset += childDataLength;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// if the `valueof<T>` type is managed, we must link each reference
|
|
518
|
+
if (isManaged<valueof<T>>()) {
|
|
519
|
+
for (let i = 0; i < size; ++i) {
|
|
520
|
+
let ref = load<usize>(changetype<usize>(outBuffer) + (<usize>i << usize(alignof<valueof<T>>())));
|
|
521
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
522
|
+
__link(changetype<usize>(outBuffer), ref, true);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return outArray;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
toString(): string {
|
|
531
|
+
return this.join();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// RT integration
|
|
535
|
+
|
|
536
|
+
@unsafe private __visit(cookie: u32): void {
|
|
537
|
+
if (ASC_RUNTIME != Runtime.Memory) {
|
|
538
|
+
if (isManaged<T>()) {
|
|
539
|
+
let cur = this.dataStart;
|
|
540
|
+
let end = cur + (<usize>this.length_ << alignof<T>());
|
|
541
|
+
while (cur < end) {
|
|
542
|
+
let val = load<usize>(cur);
|
|
543
|
+
if (val) __visit(val, cookie);
|
|
544
|
+
cur += sizeof<usize>();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
__visit(changetype<usize>(this.buffer), cookie);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/// <reference path="./rt/index.d.ts" />
|
|
2
|
+
|
|
3
|
+
import { OBJECT, BLOCK_MAXSIZE, TOTAL_OVERHEAD } from "./rt/common";
|
|
4
|
+
import { Runtime } from "shared/runtime";
|
|
5
|
+
import { idof } from "./builtins";
|
|
6
|
+
import { E_INVALIDLENGTH } from "./util/error";
|
|
7
|
+
|
|
8
|
+
export abstract class ArrayBufferView {
|
|
9
|
+
|
|
10
|
+
readonly buffer: ArrayBuffer;
|
|
11
|
+
@unsafe readonly dataStart: usize;
|
|
12
|
+
readonly byteLength: i32;
|
|
13
|
+
|
|
14
|
+
get byteOffset(): i32 {
|
|
15
|
+
return <i32>(this.dataStart - changetype<usize>(this.buffer));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
protected constructor(length: i32, alignLog2: i32) {
|
|
19
|
+
if (<u32>length > <u32>BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);
|
|
20
|
+
let buffer = changetype<ArrayBuffer>(__new(length = length << alignLog2, idof<ArrayBuffer>()));
|
|
21
|
+
if (ASC_RUNTIME != Runtime.Incremental) {
|
|
22
|
+
memory.fill(changetype<usize>(buffer), 0, <usize>length);
|
|
23
|
+
}
|
|
24
|
+
this.buffer = buffer; // links
|
|
25
|
+
this.dataStart = changetype<usize>(buffer);
|
|
26
|
+
this.byteLength = length;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@final export class ArrayBuffer {
|
|
31
|
+
|
|
32
|
+
static isView<T>(value: T): bool {
|
|
33
|
+
if (isNullable<T>()) {
|
|
34
|
+
if (changetype<usize>(value) == 0) return false;
|
|
35
|
+
}
|
|
36
|
+
if (value instanceof Int8Array) return true;
|
|
37
|
+
if (value instanceof Uint8Array) return true;
|
|
38
|
+
if (value instanceof Uint8ClampedArray) return true;
|
|
39
|
+
if (value instanceof Int16Array) return true;
|
|
40
|
+
if (value instanceof Uint16Array) return true;
|
|
41
|
+
if (value instanceof Int32Array) return true;
|
|
42
|
+
if (value instanceof Uint32Array) return true;
|
|
43
|
+
if (value instanceof Int64Array) return true;
|
|
44
|
+
if (value instanceof Uint64Array) return true;
|
|
45
|
+
if (value instanceof Float32Array) return true;
|
|
46
|
+
if (value instanceof Float64Array) return true;
|
|
47
|
+
if (value instanceof DataView) return true;
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
constructor(length: i32) {
|
|
52
|
+
if (<u32>length > <u32>BLOCK_MAXSIZE) throw new RangeError(E_INVALIDLENGTH);
|
|
53
|
+
let buffer = changetype<ArrayBuffer>(__new(<usize>length, idof<ArrayBuffer>()));
|
|
54
|
+
if (ASC_RUNTIME != Runtime.Incremental) {
|
|
55
|
+
memory.fill(changetype<usize>(buffer), 0, <usize>length);
|
|
56
|
+
}
|
|
57
|
+
return buffer;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get byteLength(): i32 {
|
|
61
|
+
return changetype<OBJECT>(changetype<usize>(this) - TOTAL_OVERHEAD).rtSize;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
slice(begin: i32 = 0, end: i32 = BLOCK_MAXSIZE): ArrayBuffer {
|
|
65
|
+
let length = this.byteLength;
|
|
66
|
+
begin = begin < 0 ? max(length + begin, 0) : min(begin, length);
|
|
67
|
+
end = end < 0 ? max(length + end , 0) : min(end , length);
|
|
68
|
+
let outSize = <usize>max(end - begin, 0);
|
|
69
|
+
let out = changetype<ArrayBuffer>(__new(outSize, idof<ArrayBuffer>()));
|
|
70
|
+
memory.copy(changetype<usize>(out), changetype<usize>(this) + <usize>begin, outSize);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
toString(): string {
|
|
75
|
+
return "[object ArrayBuffer]";
|
|
76
|
+
}
|
|
77
|
+
}
|