diff options
author | 2022-02-27 23:20:10 -0800 | |
---|---|---|
committer | 2022-02-27 23:20:10 -0800 | |
commit | 50560e169ca39c0b4ec163cb32897baf7620aa69 (patch) | |
tree | 83eb721bfd4a0318874c1f69d254a4fd9446512b | |
parent | 36c249e9c1fc6e0000d23ae0055eed54a5437c74 (diff) | |
download | bun-50560e169ca39c0b4ec163cb32897baf7620aa69.tar.gz bun-50560e169ca39c0b4ec163cb32897baf7620aa69.tar.zst bun-50560e169ca39c0b4ec163cb32897baf7620aa69.zip |
WASM
83 files changed, 10789 insertions, 690 deletions
diff --git a/.gitattributes b/.gitattributes index 813f045f9..cf006809b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ .vscode/launch.json linguist-generated src/api/schema.d.ts linguist-generated src/api/schema.js linguist-generated +*.lockb binary diff=lockb diff --git a/.vscode/launch.json b/.vscode/launch.json index 5ce2c2c39..a5abe5387 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -220,46 +220,35 @@ "program": "bun-debug", // "args": ["--serve", "--origin=http://localhost:3000"], "args": ["dev", "--origin=http://localhost:3000"], - "cwd": "${workspaceFolder}/examples/hello-next", + "cwd": "/tmp/next-app", "console": "internalConsole" }, { "type": "lldb", "request": "launch", - "name": "Demo Serve aarch64", - "program": "${workspaceFolder}/build/macos-aarch64/bun", + "name": "Demo ", + "program": "bun-debug", // "args": ["--serve", "--origin=http://localhost:3000"], - "args": ["dev", "--origin=http://ci.local:3000"], - "cwd": "${workspaceFolder}/examples/hello-next", + "args": ["/Users/jarred/Desktop/text-encoder-hello.js"], + "cwd": "${workspaceFolder}", "console": "internalConsole" }, { "type": "lldb", "request": "launch", - "name": "Demo Lazy Build", + "name": "wiptest", "program": "bun-debug", - "args": [ - "./src/index.tsx", - "--resolve=lazy", - "--origin=http://localhost:9000/" - ], - "cwd": "${workspaceFolder}/examples/simple-react", + "args": ["wiptest", "transpiler"], + "cwd": "${workspaceFolder}/integration", "console": "internalConsole" }, - { "type": "lldb", "request": "launch", - "name": "Demo Build", + "name": "debug test", "program": "bun-debug", - "args": [ - "./src/index.tsx", - "--resolve=dev", - "--outdir=outcss", - "--platform=browser", - "--origin=http://localhost:9000/" - ], - "cwd": "${workspaceFolder}/examples/css-stress-test", + "args": ["build", "/tmp/foo.ts"], + "cwd": "/tmp", "console": "internalConsole" }, { @@ -267,11 +256,7 @@ "request": "launch", "name": "Dazzle serve", "program": "bun-debug", - "args": [ - "--origin=http://localhost:5001", - "--disable-bun.js", - "--disable-hmr" - ], + "args": ["dev"], "cwd": "/Users/jarred/Build/lattice/apps/dazzle", "console": "internalConsole" }, @@ -280,10 +265,9 @@ "request": "launch", "name": "Dazzle bun", "program": "bun-debug", - "args": ["bun", "--use=next"], + "args": ["bun"], "cwd": "/Users/jarred/Build/lattice/apps/dazzle", - "console": "internalConsole", - "env": { "GOMAXPROCS": "1" } + "console": "internalConsole" }, { "type": "lldb", @@ -308,8 +292,23 @@ "request": "launch", "name": "bun test", "program": "bun-debug", - "args": ["wiptest", "import-meta"], - "cwd": "${workspaceFolder}", + "args": ["wiptest", "transpiler"], + "cwd": "${workspaceFolder}/integration", + "env": { + "FORCE_COLOR": "1" + }, + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "bun tes2t", + "program": "bun-debug", + "args": ["build", "hello.jsx", "--platform=bun"], + "cwd": "/Users/jarred/Desktop/", + "env": { + "FORCE_COLOR": "1" + }, "console": "internalConsole" }, { @@ -431,6 +430,35 @@ { "type": "lldb", "request": "launch", + "name": "bun.sh dev", + "program": "bun-debug", + "args": ["dev"], + "cwd": "${workspaceFolder}/../bun.sh", + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Instal 1l", + "program": "bun-debug", + "args": ["install", "-g", "which"], + "cwd": "/tmp/new-app", + "env": {}, + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", + "name": "Instal 32", + "program": "bun-debug", + "args": ["install"], + "cwd": "/tmp/foo", + "env": {}, + "console": "internalConsole" + }, + { + "type": "lldb", + "request": "launch", "name": "Install", "program": "bun-debug", "args": ["install", "--backend=clonefile", "--force"], diff --git a/.vscode/settings.json b/.vscode/settings.json index bd7699e02..704406bc6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ "search.exclude": {}, "search.followSymlinks": false, "search.useIgnoreFiles": true, - "zig.buildOnSave": false, + "zig.buildOnSave": true, "[zig]": { "editor.defaultFormatter": "AugusteRame.zls-vscode" }, @@ -382,6 +382,26 @@ init-submodules: build-obj: $(ZIG) build obj -Drelease-fast +dev-build-obj-wasm: + $(ZIG) build bun-wasm -Dtarget=wasm32-freestanding --prominent-compile-errors + +dev-wasm: dev-build-obj-wasm + emcc -sEXPORTED_FUNCTIONS="['_bun_free', '_cycleStart', '_cycleEnd', '_bun_malloc', '_scan', '_transform', '_init']" \ + -g -s ERROR_ON_UNDEFINED_SYMBOLS=0 -DNDEBUG \ + $(BUN_DEPS_DIR)/libmimalloc.a.wasm \ + packages/debug-bun-freestanding-wasm32/bun-wasm.o -O3 --no-entry --allow-undefined -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_BIGINT=1 \ + -o packages/debug-bun-freestanding-wasm32/bun-wasm.wasm + cp packages/debug-bun-freestanding-wasm32/bun-wasm.wasm src/api/demo/public/bun-wasm.wasm + +build-obj-wasm: + $(ZIG) build bun-wasm -Drelease-fast -Dtarget=wasm32-freestanding --prominent-compile-errors + emcc -sEXPORTED_FUNCTIONS="['_bun_free', '_cycleStart', '_cycleEnd', '_bun_malloc', '_scan', '_transform', '_init']" \ + -g -s ERROR_ON_UNDEFINED_SYMBOLS=0 -DNDEBUG \ + $(BUN_DEPS_DIR)/libmimalloc.a.wasm \ + packages/bun-freestanding-wasm32/bun-wasm.o -O3 --no-entry --allow-undefined -s ASSERTIONS=0 -s ALLOW_MEMORY_GROWTH=1 -s WASM_BIGINT=1 \ + -o packages/bun-freestanding-wasm32/bun-wasm.wasm + cp packages/bun-freestanding-wasm32/bun-wasm.wasm src/api/demo/public/bun-wasm.wasm + build-obj-safe: $(ZIG) build obj -Drelease-safe @@ -803,9 +823,15 @@ jsc-bindings-mac: $(OBJ_FILES) # mimalloc is built as object files so that it can overload the system malloc mimalloc: + rm -rf $(BUN_DEPS_DIR)/mimalloc/CMakeCache* $(BUN_DEPS_DIR)/mimalloc/CMakeFiles cd $(BUN_DEPS_DIR)/mimalloc; CFLAGS="$(CFLAGS)" cmake $(CMAKE_FLAGS) -DMI_SKIP_COLLECT_ON_EXIT=1 -DMI_BUILD_SHARED=OFF -DMI_BUILD_STATIC=ON -DMI_BUILD_TESTS=OFF -DMI_BUILD_OBJECT=ON ${MIMALLOC_OVERRIDE_FLAG} -DMI_USE_CXX=ON .; make; cp $(BUN_DEPS_DIR)/mimalloc/$(MIMALLOC_INPUT_PATH) $(BUN_DEPS_OUT_DIR)/$(MIMALLOC_FILE) + +mimalloc-wasm: + cd $(BUN_DEPS_DIR)/mimalloc; emcmake cmake -DMI_BUILD_SHARED=OFF -DMI_BUILD_STATIC=ON -DMI_BUILD_TESTS=OFF -DMI_BUILD_OBJECT=ON ${MIMALLOC_OVERRIDE_FLAG} -DMI_USE_CXX=ON .; emmake make; + cp $(BUN_DEPS_DIR)/mimalloc/$(MIMALLOC_INPUT_PATH) $(BUN_DEPS_OUT_DIR)/$(MIMALLOC_FILE).wasm + bun-link-lld-debug: $(CXX) $(BUN_LLD_FLAGS) \ -g \ @@ -69,11 +69,17 @@ fn addInternalPackages(step: *std.build.LibExeObjStep, _: std.mem.Allocator, tar .name = "io", .path = pkgPath("src/io/io_linux.zig"), }; + var io_stub: std.build.Pkg = .{ + .name = "io", + .path = pkgPath("src/io/io_stub.zig"), + }; var io = if (target.isDarwin()) io_darwin + else if (target.isLinux()) + io_linux else - io_linux; + io_stub; var strings: std.build.Pkg = .{ .name = "strings", @@ -90,11 +96,21 @@ fn addInternalPackages(step: *std.build.LibExeObjStep, _: std.mem.Allocator, tar .path = pkgPath("src/http_client_async.zig"), }; - var javascript_core: std.build.Pkg = .{ + var javascript_core_real: std.build.Pkg = .{ .name = "javascript_core", .path = pkgPath("src/jsc.zig"), }; + var javascript_core_stub: std.build.Pkg = .{ + .name = "javascript_core", + .path = pkgPath("src/jsc_stub.zig"), + }; + + var javascript_core = if (target.getOsTag() == .freestanding) + javascript_core_stub + else + javascript_core_real; + var analytics: std.build.Pkg = .{ .name = "analytics", .path = pkgPath("src/analytics.zig"), @@ -169,6 +185,12 @@ fn updateRuntime() anyerror!void { var x64 = "x64"; var mode: std.builtin.Mode = undefined; + +const Builder = std.build.Builder; +const CrossTarget = std.zig.CrossTarget; +const Mode = std.builtin.Mode; +const fs = std.fs; + pub fn build(b: *std.build.Builder) !void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which @@ -221,7 +243,10 @@ pub fn build(b: *std.build.Builder) !void { const output_dir_base = try std.fmt.bufPrint(&output_dir_buf, "{s}{s}", .{ bin_label, triplet }); output_dir = b.pathFromRoot(output_dir_base); const bun_executable_name = if (mode == std.builtin.Mode.Debug) "bun-debug" else "bun"; - exe = b.addExecutable(bun_executable_name, "src/main.zig"); + exe = b.addExecutable(bun_executable_name, if (target.getOsTag() == std.Target.Os.Tag.freestanding) + "src/main_wasm.zig" + else + "src/main.zig"); // exe.setLibCFile("libc.txt"); exe.linkLibC(); // exe.linkLibCpp(); @@ -235,14 +260,22 @@ pub fn build(b: *std.build.Builder) !void { var typings_exe = b.addExecutable("typescript-decls", "src/typegen.zig"); + const min_version: std.builtin.Version = if (target.getOsTag() != .freestanding) + target.getOsVersionMin().semver + else .{ .major = 0, .minor = 0, .patch = 0 }; + + const max_version: std.builtin.Version = if (target.getOsTag() != .freestanding) + target.getOsVersionMin().semver + else .{ .major = 0, .minor = 0, .patch = 0 }; + // exe.want_lto = true; defer b.default_step.dependOn(&b.addLog("Output: {s}/{s}\n", .{ output_dir, bun_executable_name }).step); defer b.default_step.dependOn(&b.addLog( "Build {s} v{} - v{}\n", .{ triplet, - target.getOsVersionMin().semver, - target.getOsVersionMax().semver, + min_version, + max_version, }, ).step); @@ -265,8 +298,8 @@ pub fn build(b: *std.build.Builder) !void { "Build {s} v{} - v{}\n", .{ triplet, - obj.target.getOsVersionMin().semver, - obj.target.getOsVersionMax().semver, + min_version, + max_version, }, ).step); } @@ -307,6 +340,17 @@ pub fn build(b: *std.build.Builder) !void { } { + const wasm = b.step("bun-wasm", "Build WASM"); + var wasm_step: *std.build.LibExeObjStep = b.addStaticLibrary("bun-wasm", "src/main_wasm.zig"); + defer wasm.dependOn(&wasm_step.step); + wasm_step.strip = false; + // wasm_step.link_function_sections = true; + // wasm_step.link_emit_relocs = true; + // wasm_step.single_threaded = true; + try configureObjectStep(wasm_step, target, obj.main_pkg_path.?); + } + + { const headers_step = b.step("httpbench-obj", "Build HTTPBench tool (object files)"); var headers_obj: *std.build.LibExeObjStep = b.addObject("httpbench", "misctools/http_bench.zig"); defer headers_step.dependOn(&headers_obj.step); @@ -399,6 +443,8 @@ pub var original_make_fn: ?fn (step: *std.build.Step) anyerror!void = null; // so I am leaving this here for now, with the eventual intent to switch to std.build.Builder // but it is dead code pub fn linkObjectFiles(b: *std.build.Builder, obj: *std.build.LibExeObjStep, target: anytype) !void { + if (target.getOsTag() == .freestanding) + return; var dirs_to_search = std.BoundedArray([]const u8, 32).init(0) catch unreachable; const arm_brew_prefix: []const u8 = "/opt/homebrew"; const x86_brew_prefix: []const u8 = "/usr/local"; @@ -455,16 +501,16 @@ pub fn linkObjectFiles(b: *std.build.Builder, obj: *std.build.LibExeObjStep, tar pub fn configureObjectStep(obj: *std.build.LibExeObjStep, target: anytype, main_pkg_path: []const u8) !void { obj.setMainPkgPath(main_pkg_path); obj.setTarget(target); - try addInternalPackages(obj, std.heap.page_allocator, target); - addPicoHTTP(obj, false); + if (target.getOsTag() != .freestanding) + addPicoHTTP(obj, false); obj.strip = false; obj.setOutputDir(output_dir); obj.setBuildMode(mode); - obj.linkLibC(); - obj.linkLibCpp(); - obj.bundle_compiler_rt = true; + if (target.getOsTag() != .freestanding) obj.linkLibC(); + if (target.getOsTag() != .freestanding) obj.linkLibCpp(); + if (target.getOsTag() != .freestanding) obj.bundle_compiler_rt = true; if (target.getOsTag() == .linux) { // obj.want_lto = tar; diff --git a/examples/next/pages/index.tsx b/examples/next/pages/index.tsx index e5656a27d..90b988011 100644 --- a/examples/next/pages/index.tsx +++ b/examples/next/pages/index.tsx @@ -29,8 +29,6 @@ export default function Home({}) { <code className={styles.code}>pages/index.tsx</code> </p> </main> - - <footer className={styles.footer}></footer> </div> ); } diff --git a/misctools/fetch.zig b/misctools/fetch.zig index f8c06be5d..9a05c82f1 100644 --- a/misctools/fetch.zig +++ b/misctools/fetch.zig @@ -60,8 +60,8 @@ const MethodNames = std.ComptimeStringMap(Method, .{ .{ "head", Method.HEAD }, }); -var file_path_buf: [std.fs.MAX_PATH_BYTES + 1]u8 = undefined; -var cwd_buf: [std.fs.MAX_PATH_BYTES + 1]u8 = undefined; +var file_path_buf: [_global.MAX_PATH_BYTES + 1]u8 = undefined; +var cwd_buf: [_global.MAX_PATH_BYTES + 1]u8 = undefined; pub const Arguments = struct { url: URL, diff --git a/misctools/http_bench.zig b/misctools/http_bench.zig index 81b81ff13..06ce4ace6 100644 --- a/misctools/http_bench.zig +++ b/misctools/http_bench.zig @@ -63,8 +63,8 @@ const MethodNames = std.ComptimeStringMap(Method, .{ .{ "head", Method.HEAD }, }); -var file_path_buf: [std.fs.MAX_PATH_BYTES + 1]u8 = undefined; -var cwd_buf: [std.fs.MAX_PATH_BYTES + 1]u8 = undefined; +var file_path_buf: [_global.MAX_PATH_BYTES + 1]u8 = undefined; +var cwd_buf: [_global.MAX_PATH_BYTES + 1]u8 = undefined; pub const Arguments = struct { url: URL, diff --git a/misctools/readlink-getfd.zig b/misctools/readlink-getfd.zig index f7934f54a..73faf23fc 100644 --- a/misctools/readlink-getfd.zig +++ b/misctools/readlink-getfd.zig @@ -29,12 +29,12 @@ pub fn main() anyerror!void { const to_resolve = args[args.len - 1]; const cwd = try std.process.getCwdAlloc(allocator); var path: []u8 = undefined; - var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; var j: usize = 0; while (j < 1000) : (j += 1) { var parts = [1][]const u8{std.mem.span(to_resolve)}; - var joined_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var joined_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var joined = path_handler.joinAbsStringBuf( cwd, &joined_buf, diff --git a/misctools/readlink-realpath.zig b/misctools/readlink-realpath.zig index e88a2e883..bc8b604de 100644 --- a/misctools/readlink-realpath.zig +++ b/misctools/readlink-realpath.zig @@ -27,7 +27,7 @@ pub fn main() anyerror!void { var args = std.mem.span(try std.process.argsAlloc(allocator)); const to_resolve = args[args.len - 1]; - var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; var path: []u8 = undefined; var j: usize = 0; diff --git a/misctools/tgz.zig b/misctools/tgz.zig index ef319056e..cac2ddf6e 100644 --- a/misctools/tgz.zig +++ b/misctools/tgz.zig @@ -38,7 +38,7 @@ pub fn main() anyerror!void { std.os.abort(); } - var tarball_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var tarball_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var basename = std.fs.path.basename(std.mem.span(args[args.len - 1])); while (RecognizedExtensions.has(std.fs.path.extension(basename))) { basename = basename[0 .. basename.len - std.fs.path.extension(basename).len]; diff --git a/packages/bun-framework-next/bun.lockb b/packages/bun-framework-next/bun.lockb Binary files differnew file mode 100755 index 000000000..d6178a6eb --- /dev/null +++ b/packages/bun-framework-next/bun.lockb diff --git a/src/allocators.zig b/src/allocators.zig index f956de4d0..8dcfb1fd0 100644 --- a/src/allocators.zig +++ b/src/allocators.zig @@ -5,7 +5,7 @@ const Environment = @import("./env.zig"); const Wyhash = std.hash.Wyhash; const FixedBufferAllocator = std.heap.FixedBufferAllocator; const constStrToU8 = @import("./global.zig").constStrToU8; - +const _global = @import("./global.zig"); pub fn isSliceInBuffer(slice: anytype, buffer: anytype) bool { return (@ptrToInt(&buffer) <= @ptrToInt(slice.ptr) and (@ptrToInt(slice.ptr) + slice.len) <= (@ptrToInt(buffer) + buffer.len)); } @@ -345,7 +345,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type return try self.doAppend(AppendType, _value); } - threadlocal var lowercase_append_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + threadlocal var lowercase_append_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn appendLowerCase(self: *Self, comptime AppendType: type, _value: AppendType) ![]const u8 { mutex.lock(); defer mutex.unlock(); diff --git a/src/allocators/mimalloc.zig b/src/allocators/mimalloc.zig index 9a30195ab..b8badec99 100644 --- a/src/allocators/mimalloc.zig +++ b/src/allocators/mimalloc.zig @@ -122,23 +122,30 @@ pub const mi_option_t = enum(c_uint) { show_stats = 1, verbose = 2, eager_commit = 3, - eager_region_commit = 4, - reset_decommits = 5, + deprecated_eager_region_commit = 4, + deprecated_reset_decommits = 5, large_os_pages = 6, reserve_huge_os_pages = 7, - reserve_os_memory = 8, - segment_cache = 9, - page_reset = 10, - abandoned_page_reset = 11, - segment_reset = 12, - eager_commit_delay = 13, - reset_delay = 14, - use_numa_nodes = 15, - limit_os_alloc = 16, - os_tag = 17, - max_errors = 18, - max_warnings = 19, + reserve_huge_os_pages_at = 8, + reserve_os_memory = 9, + segment_cache = 10, + page_reset = 11, + abandoned_page_decommit = 12, + deprecated_segment_reset = 13, + eager_commit_delay = 14, + decommit_delay = 15, + use_numa_nodes = 16, + limit_os_alloc = 17, + os_tag = 18, + max_errors = 19, + max_warnings = 20, + + // mimalloc v2 specific + allow_decommit = 21, + segment_decommit_delay = 22, + decommit_extend_delay = 23, }; + pub extern fn mi_option_is_enabled(option: mi_option_t) bool; pub extern fn mi_option_enable(option: mi_option_t) void; pub extern fn mi_option_disable(option: mi_option_t) void; diff --git a/src/api/demo/bun.lockb b/src/api/demo/bun.lockb Binary files differnew file mode 100755 index 000000000..703042857 --- /dev/null +++ b/src/api/demo/bun.lockb diff --git a/src/api/demo/lib/api.ts b/src/api/demo/lib/api.ts index b861bb78b..455c73290 100644 --- a/src/api/demo/lib/api.ts +++ b/src/api/demo/lib/api.ts @@ -1,15 +1,15 @@ import * as Schema from "../../schema"; -import { ByteBuffer } from "peechy/bb"; +import { ByteBuffer } from "peechy"; +import path from "path"; +import { Loader } from "../schema"; // import { transform as sucraseTransform } from "sucrase"; export interface WebAssemblyModule { init(): number; transform(a: number): number; - malloc(a: number): number; - calloc(a: number): number; - realloc(a: number): number; - free(a: number): number; - cycle(): void; + bun_malloc(a: number): number; + bun_free(a: number): number; + scan(a: number): number; } const wasm_imports_sym: symbol | string = @@ -17,168 +17,266 @@ const wasm_imports_sym: symbol | string = ? "wasm_imports" : Symbol("wasm_imports"); -const ptr_converter = new ArrayBuffer(8); -const ptr_float = new Float64Array(ptr_converter); +const ptr_converter = new ArrayBuffer(16); +const ptr_float = new BigUint64Array(ptr_converter); const slice = new Uint32Array(ptr_converter); +const Wasi = { + clock_time_get(clk_id, tp) { + return Date.now(); + }, + environ_sizes_get() { + debugger; + return 0; + }, + environ_get(__environ, environ_buf) { + debugger; + return 0; + }, + + fd_close(fd) { + debugger; + return 0; + }, + proc_exit() {}, + + fd_seek(fd, offset_bigint, whence, newOffset) { + debugger; + }, + fd_write(fd, iov, iovcnt, pnum) { + debugger; + }, +}; + var scratch: Uint8Array; +var scratch2: Uint8Array; -export class ESDev { +export class Bun { static has_initialized = false; static wasm_source: WebAssembly.WebAssemblyInstantiatedSource = null; static get wasm_exports(): WebAssemblyModule { - return ESDev.wasm_source.instance.exports as any; + return Bun.wasm_source.instance.exports as any; } - static get memory() { - return ESDev[wasm_imports_sym].memory as WebAssembly.Memory; + static get memory(): WebAssembly.Memory { + return Bun.wasm_source.instance.exports.memory as any; } static memory_array: Uint8Array; static _decoder: TextDecoder; - static _wasmPtrToSlice(offset: number) { - if (ESDev.memory_array.buffer !== ESDev.memory.buffer) { - ESDev.memory_array = new Uint8Array(ESDev.memory.buffer); - } - ptr_float[0] = offset; - return ESDev.memory_array.subarray(slice[0], slice[0] + slice[1]); + static _wasmPtrToSlice(offset: number | bigint) { + ptr_float[0] = typeof offset === "number" ? BigInt(offset) : offset; + return new Uint8Array(Bun.memory.buffer, slice[0], slice[1]); } static _wasmPtrLenToString(slice: number) { - if (!ESDev._decoder) { - ESDev._decoder = new TextDecoder("utf8"); + if (!Bun._decoder) { + Bun._decoder = new TextDecoder("utf8"); } const region = this._wasmPtrToSlice(slice); - - return ESDev._decoder.decode(region); + return Bun._decoder.decode(region); } // We don't want people to be calling these manually static [wasm_imports_sym] = { console_log(slice: number) { - console.log(ESDev._wasmPtrLenToString(slice)); + console.log(Bun._wasmPtrLenToString(slice)); }, console_error(slice: number) { - console.error(ESDev._wasmPtrLenToString(slice)); + console.error(Bun._wasmPtrLenToString(slice)); }, console_warn(slice: number) { - console.warn(ESDev._wasmPtrLenToString(slice)); + console.warn(Bun._wasmPtrLenToString(slice)); }, console_info(slice: number) { - console.info(ESDev._wasmPtrLenToString(slice)); + console.info(Bun._wasmPtrLenToString(slice)); + }, + + __indirect_function_table: new WebAssembly.Table({ + initial: 0, + element: "anyfunc", + }), + __stack_pointer: new WebAssembly.Global({ + mutable: true, + value: "i32", + }), + __multi3(one: number, two: number) { + return Math.imul(one | 0, two | 0); + }, + fmod(one: number, two: number) { + return one % two; + }, + memset(ptr: number, value: number, len: number) { + Bun.memory_array.fill(value, ptr, ptr + len); + }, + memcpy(ptr: number, value: number, len: number) { + Bun.memory_array.copyWithin(ptr, value, value + len); + }, + // These functions convert a to an unsigned long long, rounding toward zero. Negative values all become zero. + __fixunsdfti(a: number) { + return Math.floor(a); }, - memory: null, - // __indirect_function_table: new WebAssembly.Table({ - // initial: 0, - // element: "anyfunc", - // }), - // __stack_pointer: new WebAssembly.Global({ - // mutable: true, - // value: "i32", - // }), - // __multi3(one: number, two: number) { - // return Math.imul(one | 0, two | 0); - // }, - // fmod(one: number, two: number) { - // return one % two; - // }, - // memset(ptr: number, value: number, len: number) { - // ESDev.memory_array.fill(value, ptr, ptr + len); - // }, - // memcpy(ptr: number, value: number, len: number) { - // ESDev.memory_array.copyWithin(ptr, value, value + len); - // }, - // // These functions convert a to an unsigned long long, rounding toward zero. Negative values all become zero. - // __fixunsdfti(a: number) { - // return Math.floor(a); - // }, - // // These functions return the remainder of the unsigned division of a and b. - // __umodti3(a: number, b: number) { - // return (a | 0) % (b | 0); - // }, - // // These functions return the quotient of the unsigned division of a and b. - // __udivti3(a: number, b: number) { - // return (a | 0) / (b | 0); - // }, - // // These functions return the result of shifting a left by b bits. - // __ashlti3(a: number, b: number) { - // return (a | 0) >> (b | 0); - // }, - // /* Returns: convert a to a double, rounding toward even. */ - // __floatuntidf(a: number) { - // const mod = a % 2; - // if (mod === 0) { - // return Math.ceil(a); - // } else if (mod === 1) { - // return Math.floor(a); - // } - // }, + // These functions return the remainder of the unsigned division of a and b. + __umodti3(a: number, b: number) { + return (a | 0) % (b | 0); + }, + // These functions return the quotient of the unsigned division of a and b. + __udivti3(a: number, b: number) { + return (a | 0) / (b | 0); + }, + // These functions return the result of shifting a left by b bits. + __ashlti3(a: number, b: number) { + return (a | 0) >> (b | 0); + }, + /* Returns: convert a to a double, rounding toward even. */ + __floatuntidf(a: number) { + const mod = a % 2; + if (mod === 0) { + return Math.ceil(a); + } else if (mod === 1) { + return Math.floor(a); + } + }, + emscripten_notify_memory_growth() {}, }; static async init(url) { // globalThis.sucraseTransform = sucraseTransform; scratch = new Uint8Array(8096); - if (ESDev.has_initialized) { + if (Bun.has_initialized) { return; } - ESDev[wasm_imports_sym].memory = new WebAssembly.Memory({ - initial: 20, - // shared: typeof SharedArrayBuffer !== "undefined", - maximum: typeof SharedArrayBuffer !== "undefined" ? 5000 : undefined, - }); - - ESDev.wasm_source = await globalThis.WebAssembly.instantiateStreaming( + Bun.wasm_source = await globalThis.WebAssembly.instantiateStreaming( fetch(url), - { env: ESDev[wasm_imports_sym] } + { env: Bun[wasm_imports_sym], wasi_snapshot_preview1: Wasi } ); - ESDev.memory_array = new Uint8Array(ESDev.memory.buffer); - const res = ESDev.wasm_exports.init(); + const res = Bun.wasm_exports.init(); if (res < 0) { - throw `[ESDev] Failed to initialize WASM module: code ${res}`; + throw `[Bun] Failed to initialize WASM module: code ${res}`; } else { console.log("WASM loaded."); } - ESDev.has_initialized = true; + Bun.has_initialized = true; } - static transform(content: Uint8Array, file_name: string) { - if (!ESDev.has_initialized) { - throw "Please run await ESDev.init(wasm_url) before using this."; + static transformSync(content: Uint8Array | string, file_name: string) { + if (!Bun.has_initialized) { + throw "Please run await Bun.init(wasm_url) before using this."; } // if (process.env.NODE_ENV === "development") { - // console.time("[ESDev] Transform " + file_name); + // console.time("[Bun] Transform " + file_name); // } const bb = new ByteBuffer(scratch); bb.length = 0; + bb.index = 0; + var contents_buffer; + if (typeof content === "string") { + if (!scratch2) { + scratch2 = new Uint8Array(content.length * 2); + } + + let i = 0; + for (; i < content.length; i++) { + if (i > scratch2.length) { + var scratch3 = new Uint8Array(scratch2.length * 2); + scratch3.set(scratch2); + scratch2 = scratch3; + } + scratch2[i] = content.charCodeAt(i); + } + contents_buffer = scratch2.subarray(0, i); + } else { + contents_buffer = content; + } Schema.encodeTransform( { - contents: content, + contents: contents_buffer, path: file_name, + loader: { + ".jsx": Loader.jsx, + ".tsx": Loader.tsx, + ".ts": Loader.ts, + ".js": Loader.js, + ".json": Loader.json, + }[path.extname(file_name)], }, bb ); const data = bb.toUint8Array(); - if (bb._data.buffer !== scratch.buffer) { - scratch = bb._data; - } - ESDev.wasm_exports.cycleStart(); - const ptr = ESDev.wasm_exports.malloc(data.byteLength); - this._wasmPtrToSlice(ptr).set(data); - const resp_ptr = ESDev.wasm_exports.transform(ptr); + + const input_ptr = Bun.wasm_exports.bun_malloc(data.length); + var buffer = this._wasmPtrToSlice(input_ptr); + buffer.set(data); + + const resp_ptr = Bun.wasm_exports.transform(input_ptr); var _bb = new ByteBuffer(this._wasmPtrToSlice(resp_ptr)); const response = Schema.decodeTransformResponse(_bb); - ESDev.wasm_exports.cycleEnd(); + Bun.wasm_exports.bun_free(input_ptr); + scratch = bb.data; + return response; + } + + static scan(content: Uint8Array | string, file_name: string, loader: Loader) { + if (!Bun.has_initialized) { + throw "Please run await Bun.init(wasm_url) before using this."; + } + + // if (process.env.NODE_ENV === "development") { + // console.time("[Bun] Transform " + file_name); + // } + scratch.fill(0); + const bb = new ByteBuffer(scratch); + bb.length = 0; + bb.index = 0; + var contents_buffer; + if (typeof content === "string") { + if (!scratch2) { + scratch2 = new Uint8Array(content.length * 2); + } + const encode_into = new TextEncoder().encodeInto(content, scratch2); + contents_buffer = scratch2.subarray(0, encode_into.written); + } else { + contents_buffer = content; + } + + Schema.encodeScan( + { + contents: contents_buffer, + path: file_name, + loader: + loader || + { + ".jsx": Loader.jsx, + ".tsx": Loader.tsx, + ".ts": Loader.ts, + ".js": Loader.js, + ".json": Loader.json, + }[path.extname(file_name)], + }, + bb + ); + const data = bb.toUint8Array(); + + const input_ptr = Bun.wasm_exports.bun_malloc(data.length); + var buffer = this._wasmPtrToSlice(input_ptr); + buffer.set(data); + + const resp_ptr = Bun.wasm_exports.scan(input_ptr); + var _bb = new ByteBuffer(this._wasmPtrToSlice(resp_ptr)); + const response = Schema.decodeScanResult(_bb); + Bun.wasm_exports.bun_free(input_ptr); + scratch = bb.data; return response; } } -globalThis.ESDev = ESDev; +globalThis.Bun = Bun; diff --git a/src/api/demo/lib/run.ts b/src/api/demo/lib/run.ts new file mode 100644 index 000000000..8337eb2c9 --- /dev/null +++ b/src/api/demo/lib/run.ts @@ -0,0 +1,70 @@ +import { transform as _transform, initialize } from "esbuild-wasm"; +import initSwc, { transformSync as transformSyncSWC } from "@swc/wasm-web"; +import { Bun } from "./api"; + +export async function start() { + await initialize({ + worker: false, + wasmURL: "/node_modules/esbuild-wasm/esbuild.wasm", + }); + await Bun.init("/bun-wasm.wasm"); + await initSwc("/node_modules/@swc/wasm-web/wasm_bg.wasm"); +} + +const swcOptions = { + sourceMaps: false, + inlineSourcesContent: false, + jsc: { + target: "es2022", + parser: { + jsx: true, + syntax: "typescript", + tsx: false, + decorators: false, + dynamicImport: false, + }, + }, +}; + +export async function transform(contents, file) { + var result = { + timings: { + esbuild: 0, + bun: 0, + swc: 0, + }, + }; + result.timings.esbuild = performance.now(); + result.esbuild = await _transform(contents, { + sourcefile: file, + loader: file.substring(file.lastIndexOf(".") + 1), + }); + result.timings.esbuild = performance.now() - result.timings.esbuild; + + result.timings.bun = performance.now(); + result.bun = Bun.transformSync(contents, file); + result.timings.bun = performance.now() - result.timings.bun; + + if (file.substring(file.lastIndexOf(".") + 1) === "tsx") { + swcOptions.jsc.parser.tsx = true; + swcOptions.jsc.parser.syntax = "typescript"; + } else if (file.substring(file.lastIndexOf(".") + 1) === "jsx") { + swcOptions.jsc.parser.tsx = false; + swcOptions.jsc.parser.jsx = true; + swcOptions.jsc.parser.syntax = "typescript"; + } else { + swcOptions.jsc.parser.tsx = false; + swcOptions.jsc.parser.jsx = false; + swcOptions.jsc.parser.syntax = "javascript"; + } + + result.timings.swc = performance.now(); + result.swc = transformSyncSWC(contents, swcOptions); + result.timings.swc = performance.now() - result.timings.swc; + + console.log("esbuild:", result.timings.esbuild, "ms"); + console.log("Bun:", result.timings.bun, "ms"); + console.log("SWC:", result.timings.swc, "ms"); + + return result; +} diff --git a/src/api/demo/lib/scan.ts b/src/api/demo/lib/scan.ts new file mode 100644 index 000000000..4d16d5b8c --- /dev/null +++ b/src/api/demo/lib/scan.ts @@ -0,0 +1,44 @@ +import { init, parse } from "es-module-lexer"; + +import { Bun } from "./api"; + +export async function start() { + await init; + await Bun.init("/bun-wasm.wasm"); +} + +const swcOptions = { + sourceMaps: false, + inlineSourcesContent: false, + jsc: { + target: "es2022", + parser: { + jsx: true, + syntax: "typescript", + tsx: false, + decorators: false, + dynamicImport: false, + }, + }, +}; + +export async function transform(contents, file) { + var result = { + timings: { + lexer: 0, + bun: 0, + }, + }; + result.timings.lexer = performance.now(); + result.lexer = await parse(contents, file); + result.timings.lexer = performance.now() - result.timings.lexer; + + result.timings.bun = performance.now(); + result.bun = Bun.scan(contents, file); + result.timings.bun = performance.now() - result.timings.bun; + + console.log("lexer:", result.timings.lexer, "ms"); + console.log("Bun:", result.timings.bun, "ms"); + + return result; +} diff --git a/src/api/demo/package.json b/src/api/demo/package.json index e10d0e80d..ac452254a 100644 --- a/src/api/demo/package.json +++ b/src/api/demo/package.json @@ -8,8 +8,13 @@ "start": "next start" }, "dependencies": { - "next": "10.2.0", - "peechy": "^0.4.5", + "@swc/wasm-web": "^1.2.146", + "bun-framework-next": "^12.1.0", + "es-module-loader": "^2.3.0", + "esbuild": "^0.14.23", + "esbuild-wasm": "^0.14.23", + "next": "12", + "peechy": "latest", "react": "17.0.2", "react-dom": "17.0.2", "sucrase": "^3.18.1" @@ -20,4 +25,4 @@ "webpack": "^5.38.1", "webpack-cli": "^4.7.0" } -} +}
\ No newline at end of file diff --git a/src/api/demo/pages/index.tsx b/src/api/demo/pages/index.tsx index 4d60b4084..7274b3d39 100644 --- a/src/api/demo/pages/index.tsx +++ b/src/api/demo/pages/index.tsx @@ -1,70 +1,71 @@ import Head from "next/head"; import Image from "next/image"; import styles from "../styles/Home.module.css"; -import "../lib/api.ts"; -export default function Home() { +import React from "react"; + +if (typeof window !== "undefined") { + globalThis.Run = await import("../lib/run"); + await import("../lib/api.ts"); +} + +export async function getStaticProps(ctx) { + return { + props: { + code: Bun.readFile( + "/Users/jarred/Build/es-module-lexer/test/samples/magic-string.js" + ), + }, + }; +} + +var textDecoder = new TextDecoder(); +export default function Home({ code }) { + const fileNameRef = React.useRef(); + const [esbuildResult, setEsbuildResult] = React.useState(""); + const [bunResult, setBunResult] = React.useState(""); + const [swcResult, setSWCResult] = React.useState(""); + React.useEffect(() => { + globalThis.Run.start(); + }, []); + + const runBuild = React.useCallback( + (event) => { + globalThis.Run.transform( + event.target.value, + fileNameRef.current.value + ).then((result) => { + setEsbuildResult(result.esbuild.code); + setBunResult(textDecoder.decode(result.bun.files[0].data)); + setSWCResult(result.swc.code); + }, console.error); + }, + [fileNameRef, setEsbuildResult, setBunResult, setSWCResult] + ); return ( <div className={styles.container}> <Head> - <title>Create Next App</title> + <title>Next.js</title> <meta name="description" content="Generated by create next app" /> <link rel="icon" href="/favicon.ico" /> </Head> <main className={styles.main}> - <h1 className={styles.title}> - Welcome to <a href="https://nextjs.org">Next.js!</a> - </h1> - - <p className={styles.description}> - Get started by editing{" "} - <code className={styles.code}>pages/index.js</code> - </p> - - <div className={styles.grid}> - <a href="https://nextjs.org/docs" className={styles.card}> - <h2>Documentation →</h2> - <p>Find in-depth information about Next.js features and API.</p> - </a> + <div> + <input + autoComplete="filename" + type="text" + placeholder="filename" + defaultValue="input.tsx" + ref={fileNameRef} + /> + <textarea onChange={runBuild} defaultValue={code}></textarea> - <a href="https://nextjs.org/learn" className={styles.card}> - <h2>Learn →</h2> - <p>Learn about Next.js in an interactive course with quizzes!</p> - </a> - - <a - href="https://github.com/vercel/next.js/tree/master/examples" - className={styles.card} - > - <h2>Examples →</h2> - <p>Discover and deploy boilerplate example Next.js projects.</p> - </a> - - <a - href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" - className={styles.card} - > - <h2>Deploy →</h2> - <p> - Instantly deploy your Next.js site to a public URL with Vercel. - </p> - </a> + <textarea readOnly value={esbuildResult}></textarea> + <textarea readOnly value={bunResult}></textarea> + <textarea readOnly value={swcResult}></textarea> </div> </main> - - <footer className={styles.footer}> - <a - href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" - target="_blank" - rel="noopener noreferrer" - > - Powered by{" "} - <span className={styles.logo}> - <Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} /> - </span> - </a> - </footer> </div> ); } diff --git a/src/api/demo/pages/scan.tsx b/src/api/demo/pages/scan.tsx new file mode 100644 index 000000000..819a597b9 --- /dev/null +++ b/src/api/demo/pages/scan.tsx @@ -0,0 +1,71 @@ +import Head from "next/head"; +import Image from "next/image"; +import styles from "../styles/Home.module.css"; + +import React from "react"; + +if (typeof window !== "undefined") { + globalThis.Scan = await import("../lib/scan"); + await import("../lib/api.ts"); +} + +export async function getStaticProps(ctx) { + return { + props: { + code: Bun.readFile( + "/Users/jarred/Build/es-module-lexer/test/samples/magic-string.js" + ), + defaultFile: "magic-string.js", + }, + }; +} + +var textDecoder = new TextDecoder(); +export default function Home({ code, defaultFile }) { + const fileNameRef = React.useRef(); + const [lexer, setLexer] = React.useState(""); + const [bunResult, setBunResult] = React.useState(""); + const [file, setFile] = React.useState(defaultFile); + React.useEffect(() => { + globalThis.Scan.start(); + }, []); + + const runBuild = React.useCallback( + (event) => { + globalThis.Scan.transform( + event.target.value, + fileNameRef.current.value + ).then((result) => { + setLexer(JSON.stringify(result.lexer, null, 2)); + setBunResult(JSON.stringify(result.bun, null, 2)); + }, console.error); + }, + [fileNameRef, setBunResult, setLexer] + ); + return ( + <div className={styles.container}> + <Head> + <title>Next.js</title> + <meta name="description" content="Generated by create next app" /> + <link rel="icon" href="/favicon.ico" /> + </Head> + + <main className={styles.main}> + <div> + <input + autoComplete="filename" + type="text" + placeholder="filename" + value={file} + onChange={(event) => setFile(event.target.value)} + ref={fileNameRef} + /> + <textarea onChange={runBuild} defaultValue={code}></textarea> + + <textarea readOnly value={bunResult}></textarea> + <textarea readOnly value={lexer}></textarea> + </div> + </main> + </div> + ); +} diff --git a/src/api/demo/schema.d.ts b/src/api/demo/schema.d.ts new file mode 100644 index 000000000..0a7ed3b9b --- /dev/null +++ b/src/api/demo/schema.d.ts @@ -0,0 +1,980 @@ +import type { ByteBuffer } from "peechy"; + +type byte = number; +type float = number; +type int = number; +type alphanumeric = string; +type uint = number; +type int8 = number; +type lowp = number; +type int16 = number; +type int32 = number; +type float32 = number; +type uint16 = number; +type uint32 = number; +export enum Loader { + jsx = 1, + js = 2, + ts = 3, + tsx = 4, + css = 5, + file = 6, + json = 7, + toml = 8, + wasm = 9, +} +export const LoaderKeys = { + 1: "jsx", + jsx: "jsx", + 2: "js", + js: "js", + 3: "ts", + ts: "ts", + 4: "tsx", + tsx: "tsx", + 5: "css", + css: "css", + 6: "file", + file: "file", + 7: "json", + json: "json", + 8: "toml", + toml: "toml", + 9: "wasm", + wasm: "wasm", +}; +export enum FrameworkEntryPointType { + client = 1, + server = 2, + fallback = 3, +} +export const FrameworkEntryPointTypeKeys = { + 1: "client", + client: "client", + 2: "server", + server: "server", + 3: "fallback", + fallback: "fallback", +}; +export enum StackFrameScope { + Eval = 1, + Module = 2, + Function = 3, + Global = 4, + Wasm = 5, + Constructor = 6, +} +export const StackFrameScopeKeys = { + 1: "Eval", + Eval: "Eval", + 2: "Module", + Module: "Module", + 3: "Function", + Function: "Function", + 4: "Global", + Global: "Global", + 5: "Wasm", + Wasm: "Wasm", + 6: "Constructor", + Constructor: "Constructor", +}; +export enum FallbackStep { + ssr_disabled = 1, + create_vm = 2, + configure_router = 3, + configure_defines = 4, + resolve_entry_point = 5, + load_entry_point = 6, + eval_entry_point = 7, + fetch_event_handler = 8, +} +export const FallbackStepKeys = { + 1: "ssr_disabled", + ssr_disabled: "ssr_disabled", + 2: "create_vm", + create_vm: "create_vm", + 3: "configure_router", + configure_router: "configure_router", + 4: "configure_defines", + configure_defines: "configure_defines", + 5: "resolve_entry_point", + resolve_entry_point: "resolve_entry_point", + 6: "load_entry_point", + load_entry_point: "load_entry_point", + 7: "eval_entry_point", + eval_entry_point: "eval_entry_point", + 8: "fetch_event_handler", + fetch_event_handler: "fetch_event_handler", +}; +export enum ResolveMode { + disable = 1, + lazy = 2, + dev = 3, + bundle = 4, +} +export const ResolveModeKeys = { + 1: "disable", + disable: "disable", + 2: "lazy", + lazy: "lazy", + 3: "dev", + dev: "dev", + 4: "bundle", + bundle: "bundle", +}; +export enum Platform { + browser = 1, + node = 2, + bun = 3, + bun_macro = 4, +} +export const PlatformKeys = { + 1: "browser", + browser: "browser", + 2: "node", + node: "node", + 3: "bun", + bun: "bun", + 4: "bun_macro", + bun_macro: "bun_macro", +}; +export enum CSSInJSBehavior { + facade = 1, + facade_onimportcss = 2, + auto_onimportcss = 3, +} +export const CSSInJSBehaviorKeys = { + 1: "facade", + facade: "facade", + 2: "facade_onimportcss", + facade_onimportcss: "facade_onimportcss", + 3: "auto_onimportcss", + auto_onimportcss: "auto_onimportcss", +}; +export enum JSXRuntime { + automatic = 1, + classic = 2, +} +export const JSXRuntimeKeys = { + 1: "automatic", + automatic: "automatic", + 2: "classic", + classic: "classic", +}; +export enum ScanDependencyMode { + app = 1, + all = 2, +} +export const ScanDependencyModeKeys = { + 1: "app", + app: "app", + 2: "all", + all: "all", +}; +export enum ModuleImportType { + import = 1, + require = 2, +} +export const ModuleImportTypeKeys = { + 1: "import", + import: "import", + 2: "require", + require: "require", +}; +export enum DotEnvBehavior { + disable = 1, + prefix = 2, + load_all = 3, +} +export const DotEnvBehaviorKeys = { + 1: "disable", + disable: "disable", + 2: "prefix", + prefix: "prefix", + 3: "load_all", + load_all: "load_all", +}; +export enum ImportKind { + entry_point = 1, + stmt = 2, + require = 3, + dynamic = 4, + require_resolve = 5, + at = 6, + url = 7, + internal = 8, +} +export const ImportKindKeys = { + 1: "entry_point", + entry_point: "entry_point", + 2: "stmt", + stmt: "stmt", + 3: "require", + require: "require", + 4: "dynamic", + dynamic: "dynamic", + 5: "require_resolve", + require_resolve: "require_resolve", + 6: "at", + at: "at", + 7: "url", + url: "url", + 8: "internal", + internal: "internal", +}; +export enum TransformResponseStatus { + success = 1, + fail = 2, +} +export const TransformResponseStatusKeys = { + 1: "success", + success: "success", + 2: "fail", + fail: "fail", +}; +export enum MessageLevel { + err = 1, + warn = 2, + note = 3, + info = 4, + debug = 5, +} +export const MessageLevelKeys = { + 1: "err", + err: "err", + 2: "warn", + warn: "warn", + 3: "note", + note: "note", + 4: "info", + info: "info", + 5: "debug", + debug: "debug", +}; +export enum Reloader { + disable = 1, + live = 2, + fast_refresh = 3, +} +export const ReloaderKeys = { + 1: "disable", + disable: "disable", + 2: "live", + live: "live", + 3: "fast_refresh", + fast_refresh: "fast_refresh", +}; +export enum WebsocketMessageKind { + welcome = 1, + file_change_notification = 2, + build_success = 3, + build_fail = 4, + manifest_success = 5, + manifest_fail = 6, + resolve_file = 7, + file_change_notification_with_hint = 8, +} +export const WebsocketMessageKindKeys = { + 1: "welcome", + welcome: "welcome", + 2: "file_change_notification", + file_change_notification: "file_change_notification", + 3: "build_success", + build_success: "build_success", + 4: "build_fail", + build_fail: "build_fail", + 5: "manifest_success", + manifest_success: "manifest_success", + 6: "manifest_fail", + manifest_fail: "manifest_fail", + 7: "resolve_file", + resolve_file: "resolve_file", + 8: "file_change_notification_with_hint", + file_change_notification_with_hint: "file_change_notification_with_hint", +}; +export enum WebsocketCommandKind { + build = 1, + manifest = 2, + build_with_file_path = 3, +} +export const WebsocketCommandKindKeys = { + 1: "build", + build: "build", + 2: "manifest", + manifest: "manifest", + 3: "build_with_file_path", + build_with_file_path: "build_with_file_path", +}; +export interface StackFrame { + function_name: string; + file: string; + position: StackFramePosition; + scope: StackFrameScope; +} + +export interface StackFramePosition { + source_offset: int32; + line: int32; + line_start: int32; + line_stop: int32; + column_start: int32; + column_stop: int32; + expression_start: int32; + expression_stop: int32; +} + +export interface SourceLine { + line: int32; + text: string; +} + +export interface StackTrace { + source_lines: SourceLine[]; + frames: StackFrame[]; +} + +export interface JSException { + name?: string; + message?: string; + runtime_type?: uint16; + code?: uint8; + stack?: StackTrace; +} + +export interface Problems { + code: uint16; + name: string; + exceptions: JSException[]; + build: Log; +} + +export interface Router { + routes: StringMap; + route: int32; + params: StringMap; +} + +export interface FallbackMessageContainer { + message?: string; + router?: Router; + reason?: FallbackStep; + problems?: Problems; + cwd?: string; +} + +export interface JSX { + factory: string; + runtime: JSXRuntime; + fragment: string; + development: boolean; + import_source: string; + react_fast_refresh: boolean; +} + +export interface StringPointer { + offset: uint32; + length: uint32; +} + +export interface JavascriptBundledModule { + path: StringPointer; + code: StringPointer; + package_id: uint32; + id: uint32; + path_extname_length: byte; +} + +export interface JavascriptBundledPackage { + name: StringPointer; + version: StringPointer; + hash: uint32; + modules_offset: uint32; + modules_length: uint32; +} + +export interface JavascriptBundle { + modules: JavascriptBundledModule[]; + packages: JavascriptBundledPackage[]; + etag: Uint8Array; + generated_at: uint32; + app_package_json_dependencies_hash: Uint8Array; + import_from_name: Uint8Array; + manifest_string: Uint8Array; +} + +export interface JavascriptBundleContainer { + bundle_format_version?: uint32; + routes?: LoadedRouteConfig; + framework?: LoadedFramework; + bundle?: JavascriptBundle; + code_length?: uint32; +} + +export interface ModuleImportRecord { + kind: ModuleImportType; + path: string; + dynamic: boolean; +} + +export interface Module { + path: string; + imports: ModuleImportRecord[]; +} + +export interface StringMap { + keys: string[]; + values: string[]; +} + +export interface LoaderMap { + extensions: string[]; + loaders: Loader[]; +} + +export interface EnvConfig { + prefix?: string; + defaults?: StringMap; +} + +export interface LoadedEnvConfig { + dotenv: DotEnvBehavior; + defaults: StringMap; + prefix: string; +} + +export interface FrameworkConfig { + package?: string; + client?: FrameworkEntryPointMessage; + server?: FrameworkEntryPointMessage; + fallback?: FrameworkEntryPointMessage; + development?: boolean; + client_css_in_js?: CSSInJSBehavior; + display_name?: string; + overrideModules?: StringMap; +} + +export interface FrameworkEntryPoint { + kind: FrameworkEntryPointType; + path: string; + env: LoadedEnvConfig; +} + +export interface FrameworkEntryPointMap { + client?: FrameworkEntryPoint; + server?: FrameworkEntryPoint; + fallback?: FrameworkEntryPoint; +} + +export interface FrameworkEntryPointMessage { + path?: string; + env?: EnvConfig; +} + +export interface LoadedFramework { + package: string; + display_name: string; + development: boolean; + entry_points: FrameworkEntryPointMap; + client_css_in_js: CSSInJSBehavior; + overrideModules: StringMap; +} + +export interface LoadedRouteConfig { + dir: string; + extensions: string[]; + static_dir: string; + asset_prefix: string; +} + +export interface RouteConfig { + dir?: string[]; + extensions?: string[]; + static_dir?: string; + asset_prefix?: string; +} + +export interface TransformOptions { + jsx?: JSX; + tsconfig_override?: string; + resolve?: ResolveMode; + origin?: string; + absolute_working_dir?: string; + define?: StringMap; + preserve_symlinks?: boolean; + entry_points?: string[]; + write?: boolean; + inject?: string[]; + output_dir?: string; + external?: string[]; + loaders?: LoaderMap; + main_fields?: string[]; + platform?: Platform; + serve?: boolean; + extension_order?: string[]; + generate_node_module_bundle?: boolean; + node_modules_bundle_path?: string; + node_modules_bundle_path_server?: string; + framework?: FrameworkConfig; + router?: RouteConfig; + no_summary?: boolean; + disable_hmr?: boolean; + port?: uint16; + logLevel?: MessageLevel; +} + +export interface FileHandle { + path: string; + size: uint; + fd: uint; +} + +export interface Transform { + handle?: FileHandle; + path?: string; + contents?: Uint8Array; + loader?: Loader; + options?: TransformOptions; +} + +export interface Scan { + path?: string; + contents?: Uint8Array; + loader?: Loader; +} + +export interface ScanResult { + exports: string[]; + imports: ScannedImport[]; +} + +export interface ScannedImport { + path: string; + kind: ImportKind; +} + +export interface OutputFile { + data: Uint8Array; + path: string; +} + +export interface TransformResponse { + status: TransformResponseStatus; + files: OutputFile[]; + errors: Message[]; +} + +export interface Location { + file: string; + namespace: string; + line: int32; + column: int32; + line_text: string; + suggestion: string; + offset: uint; +} + +export interface MessageData { + text?: string; + location?: Location; +} + +export interface MessageMeta { + resolve?: string; + build?: boolean; +} + +export interface Message { + level: MessageLevel; + data: MessageData; + notes: MessageData[]; + on: MessageMeta; +} + +export interface Log { + warnings: uint32; + errors: uint32; + msgs: Message[]; +} + +export interface WebsocketMessage { + timestamp: uint32; + kind: WebsocketMessageKind; +} + +export interface WebsocketMessageWelcome { + epoch: uint32; + javascriptReloader: Reloader; + cwd: string; +} + +export interface WebsocketMessageFileChangeNotification { + id: uint32; + loader: Loader; +} + +export interface WebsocketCommand { + kind: WebsocketCommandKind; + timestamp: uint32; +} + +export interface WebsocketCommandBuild { + id: uint32; +} + +export interface WebsocketCommandManifest { + id: uint32; +} + +export interface WebsocketMessageBuildSuccess { + id: uint32; + from_timestamp: uint32; + loader: Loader; + module_path: string; + blob_length: uint32; +} + +export interface WebsocketMessageBuildFailure { + id: uint32; + from_timestamp: uint32; + loader: Loader; + module_path: string; + log: Log; +} + +export interface WebsocketCommandBuildWithFilePath { + id: uint32; + file_path: string; +} + +export interface WebsocketMessageResolveID { + id: uint32; +} + +export interface NPMRegistry { + url: string; + username: string; + password: string; + token: string; +} + +export interface NPMRegistryMap { + scopes: string[]; + registries: NPMRegistry[]; +} + +export interface BunInstall { + default_registry?: NPMRegistry; + scoped?: NPMRegistryMap; + lockfile_path?: string; + save_lockfile_path?: string; + cache_directory?: string; + dry_run?: boolean; + force?: boolean; + save_dev?: boolean; + save_optional?: boolean; + save_peer?: boolean; + save_lockfile?: boolean; + production?: boolean; + save_yarn_lockfile?: boolean; + native_bin_links?: string[]; + disable_cache?: boolean; + disable_manifest_cache?: boolean; + global_dir?: string; + global_bin_dir?: string; +} + +export declare function encodeStackFrame( + message: StackFrame, + bb: ByteBuffer +): void; +export declare function decodeStackFrame(buffer: ByteBuffer): StackFrame; +export declare function encodeStackFramePosition( + message: StackFramePosition, + bb: ByteBuffer +): void; +export declare function decodeStackFramePosition( + buffer: ByteBuffer +): StackFramePosition; +export declare function encodeSourceLine( + message: SourceLine, + bb: ByteBuffer +): void; +export declare function decodeSourceLine(buffer: ByteBuffer): SourceLine; +export declare function encodeStackTrace( + message: StackTrace, + bb: ByteBuffer +): void; +export declare function decodeStackTrace(buffer: ByteBuffer): StackTrace; +export declare function encodeJSException( + message: JSException, + bb: ByteBuffer +): void; +export declare function decodeJSException(buffer: ByteBuffer): JSException; +export declare function encodeProblems(message: Problems, bb: ByteBuffer): void; +export declare function decodeProblems(buffer: ByteBuffer): Problems; +export declare function encodeRouter(message: Router, bb: ByteBuffer): void; +export declare function decodeRouter(buffer: ByteBuffer): Router; +export declare function encodeFallbackMessageContainer( + message: FallbackMessageContainer, + bb: ByteBuffer +): void; +export declare function decodeFallbackMessageContainer( + buffer: ByteBuffer +): FallbackMessageContainer; +export declare function encodeJSX(message: JSX, bb: ByteBuffer): void; +export declare function decodeJSX(buffer: ByteBuffer): JSX; +export declare function encodeStringPointer( + message: StringPointer, + bb: ByteBuffer +): void; +export declare function decodeStringPointer(buffer: ByteBuffer): StringPointer; +export declare function encodeJavascriptBundledModule( + message: JavascriptBundledModule, + bb: ByteBuffer +): void; +export declare function decodeJavascriptBundledModule( + buffer: ByteBuffer +): JavascriptBundledModule; +export declare function encodeJavascriptBundledPackage( + message: JavascriptBundledPackage, + bb: ByteBuffer +): void; +export declare function decodeJavascriptBundledPackage( + buffer: ByteBuffer +): JavascriptBundledPackage; +export declare function encodeJavascriptBundle( + message: JavascriptBundle, + bb: ByteBuffer +): void; +export declare function decodeJavascriptBundle( + buffer: ByteBuffer +): JavascriptBundle; +export declare function encodeJavascriptBundleContainer( + message: JavascriptBundleContainer, + bb: ByteBuffer +): void; +export declare function decodeJavascriptBundleContainer( + buffer: ByteBuffer +): JavascriptBundleContainer; +export declare function encodeModuleImportRecord( + message: ModuleImportRecord, + bb: ByteBuffer +): void; +export declare function decodeModuleImportRecord( + buffer: ByteBuffer +): ModuleImportRecord; +export declare function encodeModule(message: Module, bb: ByteBuffer): void; +export declare function decodeModule(buffer: ByteBuffer): Module; +export declare function encodeStringMap( + message: StringMap, + bb: ByteBuffer +): void; +export declare function decodeStringMap(buffer: ByteBuffer): StringMap; +export declare function encodeLoaderMap( + message: LoaderMap, + bb: ByteBuffer +): void; +export declare function decodeLoaderMap(buffer: ByteBuffer): LoaderMap; +export declare function encodeEnvConfig( + message: EnvConfig, + bb: ByteBuffer +): void; +export declare function decodeEnvConfig(buffer: ByteBuffer): EnvConfig; +export declare function encodeLoadedEnvConfig( + message: LoadedEnvConfig, + bb: ByteBuffer +): void; +export declare function decodeLoadedEnvConfig( + buffer: ByteBuffer +): LoadedEnvConfig; +export declare function encodeFrameworkConfig( + message: FrameworkConfig, + bb: ByteBuffer +): void; +export declare function decodeFrameworkConfig( + buffer: ByteBuffer +): FrameworkConfig; +export declare function encodeFrameworkEntryPoint( + message: FrameworkEntryPoint, + bb: ByteBuffer +): void; +export declare function decodeFrameworkEntryPoint( + buffer: ByteBuffer +): FrameworkEntryPoint; +export declare function encodeFrameworkEntryPointMap( + message: FrameworkEntryPointMap, + bb: ByteBuffer +): void; +export declare function decodeFrameworkEntryPointMap( + buffer: ByteBuffer +): FrameworkEntryPointMap; +export declare function encodeFrameworkEntryPointMessage( + message: FrameworkEntryPointMessage, + bb: ByteBuffer +): void; +export declare function decodeFrameworkEntryPointMessage( + buffer: ByteBuffer +): FrameworkEntryPointMessage; +export declare function encodeLoadedFramework( + message: LoadedFramework, + bb: ByteBuffer +): void; +export declare function decodeLoadedFramework( + buffer: ByteBuffer +): LoadedFramework; +export declare function encodeLoadedRouteConfig( + message: LoadedRouteConfig, + bb: ByteBuffer +): void; +export declare function decodeLoadedRouteConfig( + buffer: ByteBuffer +): LoadedRouteConfig; +export declare function encodeRouteConfig( + message: RouteConfig, + bb: ByteBuffer +): void; +export declare function decodeRouteConfig(buffer: ByteBuffer): RouteConfig; +export declare function encodeTransformOptions( + message: TransformOptions, + bb: ByteBuffer +): void; +export declare function decodeTransformOptions( + buffer: ByteBuffer +): TransformOptions; +export declare function encodeFileHandle( + message: FileHandle, + bb: ByteBuffer +): void; +export declare function decodeFileHandle(buffer: ByteBuffer): FileHandle; +export declare function encodeTransform( + message: Transform, + bb: ByteBuffer +): void; +export declare function decodeTransform(buffer: ByteBuffer): Transform; +export declare function encodeScan(message: Scan, bb: ByteBuffer): void; +export declare function decodeScan(buffer: ByteBuffer): Scan; +export declare function encodeScanResult( + message: ScanResult, + bb: ByteBuffer +): void; +export declare function decodeScanResult(buffer: ByteBuffer): ScanResult; +export declare function encodeScannedImport( + message: ScannedImport, + bb: ByteBuffer +): void; +export declare function decodeScannedImport(buffer: ByteBuffer): ScannedImport; +export declare function encodeOutputFile( + message: OutputFile, + bb: ByteBuffer +): void; +export declare function decodeOutputFile(buffer: ByteBuffer): OutputFile; +export declare function encodeTransformResponse( + message: TransformResponse, + bb: ByteBuffer +): void; +export declare function decodeTransformResponse( + buffer: ByteBuffer +): TransformResponse; +export declare function encodeLocation(message: Location, bb: ByteBuffer): void; +export declare function decodeLocation(buffer: ByteBuffer): Location; +export declare function encodeMessageData( + message: MessageData, + bb: ByteBuffer +): void; +export declare function decodeMessageData(buffer: ByteBuffer): MessageData; +export declare function encodeMessageMeta( + message: MessageMeta, + bb: ByteBuffer +): void; +export declare function decodeMessageMeta(buffer: ByteBuffer): MessageMeta; +export declare function encodeMessage(message: Message, bb: ByteBuffer): void; +export declare function decodeMessage(buffer: ByteBuffer): Message; +export declare function encodeLog(message: Log, bb: ByteBuffer): void; +export declare function decodeLog(buffer: ByteBuffer): Log; +export declare function encodeWebsocketMessage( + message: WebsocketMessage, + bb: ByteBuffer +): void; +export declare function decodeWebsocketMessage( + buffer: ByteBuffer +): WebsocketMessage; +export declare function encodeWebsocketMessageWelcome( + message: WebsocketMessageWelcome, + bb: ByteBuffer +): void; +export declare function decodeWebsocketMessageWelcome( + buffer: ByteBuffer +): WebsocketMessageWelcome; +export declare function encodeWebsocketMessageFileChangeNotification( + message: WebsocketMessageFileChangeNotification, + bb: ByteBuffer +): void; +export declare function decodeWebsocketMessageFileChangeNotification( + buffer: ByteBuffer +): WebsocketMessageFileChangeNotification; +export declare function encodeWebsocketCommand( + message: WebsocketCommand, + bb: ByteBuffer +): void; +export declare function decodeWebsocketCommand( + buffer: ByteBuffer +): WebsocketCommand; +export declare function encodeWebsocketCommandBuild( + message: WebsocketCommandBuild, + bb: ByteBuffer +): void; +export declare function decodeWebsocketCommandBuild( + buffer: ByteBuffer +): WebsocketCommandBuild; +export declare function encodeWebsocketCommandManifest( + message: WebsocketCommandManifest, + bb: ByteBuffer +): void; +export declare function decodeWebsocketCommandManifest( + buffer: ByteBuffer +): WebsocketCommandManifest; +export declare function encodeWebsocketMessageBuildSuccess( + message: WebsocketMessageBuildSuccess, + bb: ByteBuffer +): void; +export declare function decodeWebsocketMessageBuildSuccess( + buffer: ByteBuffer +): WebsocketMessageBuildSuccess; +export declare function encodeWebsocketMessageBuildFailure( + message: WebsocketMessageBuildFailure, + bb: ByteBuffer +): void; +export declare function decodeWebsocketMessageBuildFailure( + buffer: ByteBuffer +): WebsocketMessageBuildFailure; +export declare function encodeWebsocketCommandBuildWithFilePath( + message: WebsocketCommandBuildWithFilePath, + bb: ByteBuffer +): void; +export declare function decodeWebsocketCommandBuildWithFilePath( + buffer: ByteBuffer +): WebsocketCommandBuildWithFilePath; +export declare function encodeWebsocketMessageResolveID( + message: WebsocketMessageResolveID, + bb: ByteBuffer +): void; +export declare function decodeWebsocketMessageResolveID( + buffer: ByteBuffer +): WebsocketMessageResolveID; +export declare function encodeNPMRegistry( + message: NPMRegistry, + bb: ByteBuffer +): void; +export declare function decodeNPMRegistry(buffer: ByteBuffer): NPMRegistry; +export declare function encodeNPMRegistryMap( + message: NPMRegistryMap, + bb: ByteBuffer +): void; +export declare function decodeNPMRegistryMap( + buffer: ByteBuffer +): NPMRegistryMap; +export declare function encodeBunInstall( + message: BunInstall, + bb: ByteBuffer +): void; +export declare function decodeBunInstall(buffer: ByteBuffer): BunInstall; diff --git a/src/api/demo/schema.js b/src/api/demo/schema.js index 01ec08357..b89ed4a08 100644 --- a/src/api/demo/schema.js +++ b/src/api/demo/schema.js @@ -6,6 +6,8 @@ const Loader = { 5: 5, 6: 6, 7: 7, + 8: 8, + 9: 9, jsx: 1, js: 2, ts: 3, @@ -13,6 +15,8 @@ const Loader = { css: 5, file: 6, json: 7, + toml: 8, + wasm: 9, }; const LoaderKeys = { 1: "jsx", @@ -22,6 +26,8 @@ const LoaderKeys = { 5: "css", 6: "file", 7: "json", + 8: "toml", + 9: "wasm", jsx: "jsx", js: "js", ts: "ts", @@ -29,7 +35,489 @@ const LoaderKeys = { css: "css", file: "file", json: "json", + toml: "toml", + wasm: "wasm", }; +const FrameworkEntryPointType = { + 1: 1, + 2: 2, + 3: 3, + client: 1, + server: 2, + fallback: 3, +}; +const FrameworkEntryPointTypeKeys = { + 1: "client", + 2: "server", + 3: "fallback", + client: "client", + server: "server", + fallback: "fallback", +}; +const StackFrameScope = { + 1: 1, + 2: 2, + 3: 3, + 4: 4, + 5: 5, + 6: 6, + Eval: 1, + Module: 2, + Function: 3, + Global: 4, + Wasm: 5, + Constructor: 6, +}; +const StackFrameScopeKeys = { + 1: "Eval", + 2: "Module", + 3: "Function", + 4: "Global", + 5: "Wasm", + 6: "Constructor", + Eval: "Eval", + Module: "Module", + Function: "Function", + Global: "Global", + Wasm: "Wasm", + Constructor: "Constructor", +}; + +function decodeStackFrame(bb) { + var result = {}; + + result["function_name"] = bb.readString(); + result["file"] = bb.readString(); + result["position"] = decodeStackFramePosition(bb); + result["scope"] = StackFrameScope[bb.readByte()]; + return result; +} + +function encodeStackFrame(message, bb) { + var value = message["function_name"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "function_name"'); + } + + var value = message["file"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "file"'); + } + + var value = message["position"]; + if (value != null) { + encodeStackFramePosition(value, bb); + } else { + throw new Error('Missing required field "position"'); + } + + var value = message["scope"]; + if (value != null) { + var encoded = StackFrameScope[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "StackFrameScope"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "scope"'); + } +} + +function decodeStackFramePosition(bb) { + var result = {}; + + result["source_offset"] = bb.readInt32(); + result["line"] = bb.readInt32(); + result["line_start"] = bb.readInt32(); + result["line_stop"] = bb.readInt32(); + result["column_start"] = bb.readInt32(); + result["column_stop"] = bb.readInt32(); + result["expression_start"] = bb.readInt32(); + result["expression_stop"] = bb.readInt32(); + return result; +} + +function encodeStackFramePosition(message, bb) { + var value = message["source_offset"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "source_offset"'); + } + + var value = message["line"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "line"'); + } + + var value = message["line_start"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "line_start"'); + } + + var value = message["line_stop"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "line_stop"'); + } + + var value = message["column_start"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "column_start"'); + } + + var value = message["column_stop"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "column_stop"'); + } + + var value = message["expression_start"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "expression_start"'); + } + + var value = message["expression_stop"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "expression_stop"'); + } +} + +function decodeSourceLine(bb) { + var result = {}; + + result["line"] = bb.readInt32(); + result["text"] = bb.readString(); + return result; +} + +function encodeSourceLine(message, bb) { + var value = message["line"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "line"'); + } + + var value = message["text"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "text"'); + } +} + +function decodeStackTrace(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["source_lines"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeSourceLine(bb); + var length = bb.readVarUint(); + var values = (result["frames"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeStackFrame(bb); + return result; +} + +function encodeStackTrace(message, bb) { + var value = message["source_lines"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeSourceLine(value, bb); + } + } else { + throw new Error('Missing required field "source_lines"'); + } + + var value = message["frames"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeStackFrame(value, bb); + } + } else { + throw new Error('Missing required field "frames"'); + } +} + +function decodeJSException(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["name"] = bb.readString(); + break; + + case 2: + result["message"] = bb.readString(); + break; + + case 3: + result["runtime_type"] = bb.readUint16(); + break; + + case 4: + result["code"] = bb.readByte(); + break; + + case 5: + result["stack"] = decodeStackTrace(bb); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeJSException(message, bb) { + var value = message["name"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["message"]; + if (value != null) { + bb.writeByte(2); + bb.writeString(value); + } + + var value = message["runtime_type"]; + if (value != null) { + bb.writeByte(3); + bb.writeUint16(value); + } + + var value = message["code"]; + if (value != null) { + bb.writeByte(4); + bb.writeByte(value); + } + + var value = message["stack"]; + if (value != null) { + bb.writeByte(5); + encodeStackTrace(value, bb); + } + bb.writeByte(0); +} +const FallbackStep = { + 1: 1, + 2: 2, + 3: 3, + 4: 4, + 5: 5, + 6: 6, + 7: 7, + 8: 8, + ssr_disabled: 1, + create_vm: 2, + configure_router: 3, + configure_defines: 4, + resolve_entry_point: 5, + load_entry_point: 6, + eval_entry_point: 7, + fetch_event_handler: 8, +}; +const FallbackStepKeys = { + 1: "ssr_disabled", + 2: "create_vm", + 3: "configure_router", + 4: "configure_defines", + 5: "resolve_entry_point", + 6: "load_entry_point", + 7: "eval_entry_point", + 8: "fetch_event_handler", + ssr_disabled: "ssr_disabled", + create_vm: "create_vm", + configure_router: "configure_router", + configure_defines: "configure_defines", + resolve_entry_point: "resolve_entry_point", + load_entry_point: "load_entry_point", + eval_entry_point: "eval_entry_point", + fetch_event_handler: "fetch_event_handler", +}; + +function decodeProblems(bb) { + var result = {}; + + result["code"] = bb.readUint16(); + result["name"] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["exceptions"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeJSException(bb); + result["build"] = decodeLog(bb); + return result; +} + +function encodeProblems(message, bb) { + var value = message["code"]; + if (value != null) { + bb.writeUint16(value); + } else { + throw new Error('Missing required field "code"'); + } + + var value = message["name"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "name"'); + } + + var value = message["exceptions"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeJSException(value, bb); + } + } else { + throw new Error('Missing required field "exceptions"'); + } + + var value = message["build"]; + if (value != null) { + encodeLog(value, bb); + } else { + throw new Error('Missing required field "build"'); + } +} + +function decodeRouter(bb) { + var result = {}; + + result["routes"] = decodeStringMap(bb); + result["route"] = bb.readInt32(); + result["params"] = decodeStringMap(bb); + return result; +} + +function encodeRouter(message, bb) { + var value = message["routes"]; + if (value != null) { + encodeStringMap(value, bb); + } else { + throw new Error('Missing required field "routes"'); + } + + var value = message["route"]; + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "route"'); + } + + var value = message["params"]; + if (value != null) { + encodeStringMap(value, bb); + } else { + throw new Error('Missing required field "params"'); + } +} + +function decodeFallbackMessageContainer(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["message"] = bb.readString(); + break; + + case 2: + result["router"] = decodeRouter(bb); + break; + + case 3: + result["reason"] = FallbackStep[bb.readByte()]; + break; + + case 4: + result["problems"] = decodeProblems(bb); + break; + + case 5: + result["cwd"] = bb.readString(); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeFallbackMessageContainer(message, bb) { + var value = message["message"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["router"]; + if (value != null) { + bb.writeByte(2); + encodeRouter(value, bb); + } + + var value = message["reason"]; + if (value != null) { + bb.writeByte(3); + var encoded = FallbackStep[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "FallbackStep"' + ); + bb.writeByte(encoded); + } + + var value = message["problems"]; + if (value != null) { + bb.writeByte(4); + encodeProblems(value, bb); + } + + var value = message["cwd"]; + if (value != null) { + bb.writeByte(5); + bb.writeString(value); + } + bb.writeByte(0); +} const ResolveMode = { 1: 1, 2: 2, @@ -53,14 +541,38 @@ const ResolveModeKeys = { const Platform = { 1: 1, 2: 2, + 3: 3, + 4: 4, browser: 1, node: 2, + bun: 3, + bun_macro: 4, }; const PlatformKeys = { 1: "browser", 2: "node", + 3: "bun", + 4: "bun_macro", browser: "browser", node: "node", + bun: "bun", + bun_macro: "bun_macro", +}; +const CSSInJSBehavior = { + 1: 1, + 2: 2, + 3: 3, + facade: 1, + facade_onimportcss: 2, + auto_onimportcss: 3, +}; +const CSSInJSBehaviorKeys = { + 1: "facade", + 2: "facade_onimportcss", + 3: "auto_onimportcss", + facade: "facade", + facade_onimportcss: "facade_onimportcss", + auto_onimportcss: "auto_onimportcss", }; const JSXRuntime = { 1: 1, @@ -74,8 +586,10 @@ const JSXRuntimeKeys = { automatic: "automatic", classic: "classic", }; + function decodeJSX(bb) { var result = {}; + result["factory"] = bb.readString(); result["runtime"] = JSXRuntime[bb.readByte()]; result["fragment"] = bb.readString(); @@ -84,181 +598,1183 @@ function decodeJSX(bb) { result["react_fast_refresh"] = !!bb.readByte(); return result; } + function encodeJSX(message, bb) { var value = message["factory"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "factory"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "factory"'); + } + var value = message["runtime"]; if (value != null) { var encoded = JSXRuntime[value]; - if (encoded === undefined) + if (encoded === void 0) throw new Error( "Invalid value " + JSON.stringify(value) + ' for enum "JSXRuntime"' ); bb.writeByte(encoded); - } else throw new Error('Missing required field "runtime"'); + } else { + throw new Error('Missing required field "runtime"'); + } + var value = message["fragment"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "fragment"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "fragment"'); + } + var value = message["development"]; - if (value != null) bb.writeByte(value); - else throw new Error('Missing required field "development"'); + if (value != null) { + bb.writeByte(value); + } else { + throw new Error('Missing required field "development"'); + } + var value = message["import_source"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "import_source"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "import_source"'); + } + var value = message["react_fast_refresh"]; - if (value != null) bb.writeByte(value); - else throw new Error('Missing required field "react_fast_refresh"'); + if (value != null) { + bb.writeByte(value); + } else { + throw new Error('Missing required field "react_fast_refresh"'); + } } + +function decodeStringPointer(bb) { + var result = {}; + + result["offset"] = bb.readUint32(); + result["length"] = bb.readUint32(); + return result; +} + +function encodeStringPointer(message, bb) { + var value = message["offset"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "offset"'); + } + + var value = message["length"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "length"'); + } +} + +function decodeJavascriptBundledModule(bb) { + var result = {}; + + result["path"] = decodeStringPointer(bb); + result["code"] = decodeStringPointer(bb); + result["package_id"] = bb.readUint32(); + result["id"] = bb.readUint32(); + result["path_extname_length"] = bb.readByte(); + return result; +} + +function encodeJavascriptBundledModule(message, bb) { + var value = message["path"]; + if (value != null) { + encodeStringPointer(value, bb); + } else { + throw new Error('Missing required field "path"'); + } + + var value = message["code"]; + if (value != null) { + encodeStringPointer(value, bb); + } else { + throw new Error('Missing required field "code"'); + } + + var value = message["package_id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "package_id"'); + } + + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } + + var value = message["path_extname_length"]; + if (value != null) { + bb.writeByte(value); + } else { + throw new Error('Missing required field "path_extname_length"'); + } +} + +function decodeJavascriptBundledPackage(bb) { + var result = {}; + + result["name"] = decodeStringPointer(bb); + result["version"] = decodeStringPointer(bb); + result["hash"] = bb.readUint32(); + result["modules_offset"] = bb.readUint32(); + result["modules_length"] = bb.readUint32(); + return result; +} + +function encodeJavascriptBundledPackage(message, bb) { + var value = message["name"]; + if (value != null) { + encodeStringPointer(value, bb); + } else { + throw new Error('Missing required field "name"'); + } + + var value = message["version"]; + if (value != null) { + encodeStringPointer(value, bb); + } else { + throw new Error('Missing required field "version"'); + } + + var value = message["hash"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "hash"'); + } + + var value = message["modules_offset"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "modules_offset"'); + } + + var value = message["modules_length"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "modules_length"'); + } +} + +function decodeJavascriptBundle(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["modules"] = Array(length)); + for (var i = 0; i < length; i++) + values[i] = decodeJavascriptBundledModule(bb); + var length = bb.readVarUint(); + var values = (result["packages"] = Array(length)); + for (var i = 0; i < length; i++) + values[i] = decodeJavascriptBundledPackage(bb); + result["etag"] = bb.readByteArray(); + result["generated_at"] = bb.readUint32(); + result["app_package_json_dependencies_hash"] = bb.readByteArray(); + result["import_from_name"] = bb.readByteArray(); + result["manifest_string"] = bb.readByteArray(); + return result; +} + +function encodeJavascriptBundle(message, bb) { + var value = message["modules"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeJavascriptBundledModule(value, bb); + } + } else { + throw new Error('Missing required field "modules"'); + } + + var value = message["packages"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeJavascriptBundledPackage(value, bb); + } + } else { + throw new Error('Missing required field "packages"'); + } + + var value = message["etag"]; + if (value != null) { + bb.writeByteArray(value); + } else { + throw new Error('Missing required field "etag"'); + } + + var value = message["generated_at"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "generated_at"'); + } + + var value = message["app_package_json_dependencies_hash"]; + if (value != null) { + bb.writeByteArray(value); + } else { + throw new Error( + 'Missing required field "app_package_json_dependencies_hash"' + ); + } + + var value = message["import_from_name"]; + if (value != null) { + bb.writeByteArray(value); + } else { + throw new Error('Missing required field "import_from_name"'); + } + + var value = message["manifest_string"]; + if (value != null) { + bb.writeByteArray(value); + } else { + throw new Error('Missing required field "manifest_string"'); + } +} + +function decodeJavascriptBundleContainer(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["bundle_format_version"] = bb.readUint32(); + break; + + case 3: + result["routes"] = decodeLoadedRouteConfig(bb); + break; + + case 2: + result["framework"] = decodeLoadedFramework(bb); + break; + + case 4: + result["bundle"] = decodeJavascriptBundle(bb); + break; + + case 5: + result["code_length"] = bb.readUint32(); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeJavascriptBundleContainer(message, bb) { + var value = message["bundle_format_version"]; + if (value != null) { + bb.writeByte(1); + bb.writeUint32(value); + } + + var value = message["routes"]; + if (value != null) { + bb.writeByte(3); + encodeLoadedRouteConfig(value, bb); + } + + var value = message["framework"]; + if (value != null) { + bb.writeByte(2); + encodeLoadedFramework(value, bb); + } + + var value = message["bundle"]; + if (value != null) { + bb.writeByte(4); + encodeJavascriptBundle(value, bb); + } + + var value = message["code_length"]; + if (value != null) { + bb.writeByte(5); + bb.writeUint32(value); + } + bb.writeByte(0); +} +const ScanDependencyMode = { + 1: 1, + 2: 2, + app: 1, + all: 2, +}; +const ScanDependencyModeKeys = { + 1: "app", + 2: "all", + app: "app", + all: "all", +}; +const ModuleImportType = { + 1: 1, + 2: 2, + import: 1, + require: 2, +}; +const ModuleImportTypeKeys = { + 1: "import", + 2: "require", + import: "import", + require: "require", +}; + +function decodeModuleImportRecord(bb) { + var result = {}; + + result["kind"] = ModuleImportType[bb.readByte()]; + result["path"] = bb.readString(); + result["dynamic"] = !!bb.readByte(); + return result; +} + +function encodeModuleImportRecord(message, bb) { + var value = message["kind"]; + if (value != null) { + var encoded = ModuleImportType[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + + JSON.stringify(value) + + ' for enum "ModuleImportType"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "kind"'); + } + + var value = message["path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } + + var value = message["dynamic"]; + if (value != null) { + bb.writeByte(value); + } else { + throw new Error('Missing required field "dynamic"'); + } +} + +function decodeModule(bb) { + var result = {}; + + result["path"] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["imports"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeModuleImportRecord(bb); + return result; +} + +function encodeModule(message, bb) { + var value = message["path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } + + var value = message["imports"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeModuleImportRecord(value, bb); + } + } else { + throw new Error('Missing required field "imports"'); + } +} + +function decodeStringMap(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["keys"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["values"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + return result; +} + +function encodeStringMap(message, bb) { + var value = message["keys"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } else { + throw new Error('Missing required field "keys"'); + } + + var value = message["values"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } else { + throw new Error('Missing required field "values"'); + } +} + +function decodeLoaderMap(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["extensions"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["loaders"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = Loader[bb.readByte()]; + return result; +} + +function encodeLoaderMap(message, bb) { + var value = message["extensions"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } else { + throw new Error('Missing required field "extensions"'); + } + + var value = message["loaders"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + var encoded = Loader[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' + ); + bb.writeByte(encoded); + } + } else { + throw new Error('Missing required field "loaders"'); + } +} +const DotEnvBehavior = { + 1: 1, + 2: 2, + 3: 3, + disable: 1, + prefix: 2, + load_all: 3, +}; +const DotEnvBehaviorKeys = { + 1: "disable", + 2: "prefix", + 3: "load_all", + disable: "disable", + prefix: "prefix", + load_all: "load_all", +}; + +function decodeEnvConfig(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["prefix"] = bb.readString(); + break; + + case 2: + result["defaults"] = decodeStringMap(bb); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeEnvConfig(message, bb) { + var value = message["prefix"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["defaults"]; + if (value != null) { + bb.writeByte(2); + encodeStringMap(value, bb); + } + bb.writeByte(0); +} + +function decodeLoadedEnvConfig(bb) { + var result = {}; + + result["dotenv"] = DotEnvBehavior[bb.readVarUint()]; + result["defaults"] = decodeStringMap(bb); + result["prefix"] = bb.readString(); + return result; +} + +function encodeLoadedEnvConfig(message, bb) { + var value = message["dotenv"]; + if (value != null) { + var encoded = DotEnvBehavior[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "DotEnvBehavior"' + ); + bb.writeVarUint(encoded); + } else { + throw new Error('Missing required field "dotenv"'); + } + + var value = message["defaults"]; + if (value != null) { + encodeStringMap(value, bb); + } else { + throw new Error('Missing required field "defaults"'); + } + + var value = message["prefix"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "prefix"'); + } +} + +function decodeFrameworkConfig(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["package"] = bb.readString(); + break; + + case 2: + result["client"] = decodeFrameworkEntryPointMessage(bb); + break; + + case 3: + result["server"] = decodeFrameworkEntryPointMessage(bb); + break; + + case 4: + result["fallback"] = decodeFrameworkEntryPointMessage(bb); + break; + + case 5: + result["development"] = !!bb.readByte(); + break; + + case 6: + result["client_css_in_js"] = CSSInJSBehavior[bb.readByte()]; + break; + + case 7: + result["display_name"] = bb.readString(); + break; + + case 8: + result["overrideModules"] = decodeStringMap(bb); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeFrameworkConfig(message, bb) { + var value = message["package"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["client"]; + if (value != null) { + bb.writeByte(2); + encodeFrameworkEntryPointMessage(value, bb); + } + + var value = message["server"]; + if (value != null) { + bb.writeByte(3); + encodeFrameworkEntryPointMessage(value, bb); + } + + var value = message["fallback"]; + if (value != null) { + bb.writeByte(4); + encodeFrameworkEntryPointMessage(value, bb); + } + + var value = message["development"]; + if (value != null) { + bb.writeByte(5); + bb.writeByte(value); + } + + var value = message["client_css_in_js"]; + if (value != null) { + bb.writeByte(6); + var encoded = CSSInJSBehavior[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "CSSInJSBehavior"' + ); + bb.writeByte(encoded); + } + + var value = message["display_name"]; + if (value != null) { + bb.writeByte(7); + bb.writeString(value); + } + + var value = message["overrideModules"]; + if (value != null) { + bb.writeByte(8); + encodeStringMap(value, bb); + } + bb.writeByte(0); +} + +function decodeFrameworkEntryPoint(bb) { + var result = {}; + + result["kind"] = FrameworkEntryPointType[bb.readByte()]; + result["path"] = bb.readString(); + result["env"] = decodeLoadedEnvConfig(bb); + return result; +} + +function encodeFrameworkEntryPoint(message, bb) { + var value = message["kind"]; + if (value != null) { + var encoded = FrameworkEntryPointType[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + + JSON.stringify(value) + + ' for enum "FrameworkEntryPointType"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "kind"'); + } + + var value = message["path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } + + var value = message["env"]; + if (value != null) { + encodeLoadedEnvConfig(value, bb); + } else { + throw new Error('Missing required field "env"'); + } +} + +function decodeFrameworkEntryPointMap(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["client"] = decodeFrameworkEntryPoint(bb); + break; + + case 2: + result["server"] = decodeFrameworkEntryPoint(bb); + break; + + case 3: + result["fallback"] = decodeFrameworkEntryPoint(bb); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeFrameworkEntryPointMap(message, bb) { + var value = message["client"]; + if (value != null) { + bb.writeByte(1); + encodeFrameworkEntryPoint(value, bb); + } + + var value = message["server"]; + if (value != null) { + bb.writeByte(2); + encodeFrameworkEntryPoint(value, bb); + } + + var value = message["fallback"]; + if (value != null) { + bb.writeByte(3); + encodeFrameworkEntryPoint(value, bb); + } + bb.writeByte(0); +} + +function decodeFrameworkEntryPointMessage(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["path"] = bb.readString(); + break; + + case 2: + result["env"] = decodeEnvConfig(bb); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeFrameworkEntryPointMessage(message, bb) { + var value = message["path"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["env"]; + if (value != null) { + bb.writeByte(2); + encodeEnvConfig(value, bb); + } + bb.writeByte(0); +} + +function decodeLoadedFramework(bb) { + var result = {}; + + result["package"] = bb.readString(); + result["display_name"] = bb.readString(); + result["development"] = !!bb.readByte(); + result["entry_points"] = decodeFrameworkEntryPointMap(bb); + result["client_css_in_js"] = CSSInJSBehavior[bb.readByte()]; + result["overrideModules"] = decodeStringMap(bb); + return result; +} + +function encodeLoadedFramework(message, bb) { + var value = message["package"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "package"'); + } + + var value = message["display_name"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "display_name"'); + } + + var value = message["development"]; + if (value != null) { + bb.writeByte(value); + } else { + throw new Error('Missing required field "development"'); + } + + var value = message["entry_points"]; + if (value != null) { + encodeFrameworkEntryPointMap(value, bb); + } else { + throw new Error('Missing required field "entry_points"'); + } + + var value = message["client_css_in_js"]; + if (value != null) { + var encoded = CSSInJSBehavior[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "CSSInJSBehavior"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "client_css_in_js"'); + } + + var value = message["overrideModules"]; + if (value != null) { + encodeStringMap(value, bb); + } else { + throw new Error('Missing required field "overrideModules"'); + } +} + +function decodeLoadedRouteConfig(bb) { + var result = {}; + + result["dir"] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["extensions"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + result["static_dir"] = bb.readString(); + result["asset_prefix"] = bb.readString(); + return result; +} + +function encodeLoadedRouteConfig(message, bb) { + var value = message["dir"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "dir"'); + } + + var value = message["extensions"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } else { + throw new Error('Missing required field "extensions"'); + } + + var value = message["static_dir"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "static_dir"'); + } + + var value = message["asset_prefix"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "asset_prefix"'); + } +} + +function decodeRouteConfig(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + var length = bb.readVarUint(); + var values = (result["dir"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + break; + + case 2: + var length = bb.readVarUint(); + var values = (result["extensions"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + break; + + case 3: + result["static_dir"] = bb.readString(); + break; + + case 4: + result["asset_prefix"] = bb.readString(); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeRouteConfig(message, bb) { + var value = message["dir"]; + if (value != null) { + bb.writeByte(1); + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } + + var value = message["extensions"]; + if (value != null) { + bb.writeByte(2); + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } + + var value = message["static_dir"]; + if (value != null) { + bb.writeByte(3); + bb.writeString(value); + } + + var value = message["asset_prefix"]; + if (value != null) { + bb.writeByte(4); + bb.writeString(value); + } + bb.writeByte(0); +} + function decodeTransformOptions(bb) { var result = {}; - while (true) + + while (true) { switch (bb.readByte()) { case 0: return result; + case 1: result["jsx"] = decodeJSX(bb); break; + case 2: result["tsconfig_override"] = bb.readString(); break; + case 3: result["resolve"] = ResolveMode[bb.readByte()]; break; + case 4: result["origin"] = bb.readString(); break; + case 5: result["absolute_working_dir"] = bb.readString(); break; + case 6: - var length = bb.readVarUint(); - var values = (result["define_keys"] = Array(length)); - for (var i = 0; i < length; i++) values[i] = bb.readString(); + result["define"] = decodeStringMap(bb); break; + case 7: - var length = bb.readVarUint(); - var values = (result["define_values"] = Array(length)); - for (var i = 0; i < length; i++) values[i] = bb.readString(); - break; - case 8: result["preserve_symlinks"] = !!bb.readByte(); break; - case 9: + + case 8: var length = bb.readVarUint(); var values = (result["entry_points"] = Array(length)); for (var i = 0; i < length; i++) values[i] = bb.readString(); break; - case 10: + + case 9: result["write"] = !!bb.readByte(); break; - case 11: + + case 10: var length = bb.readVarUint(); var values = (result["inject"] = Array(length)); for (var i = 0; i < length; i++) values[i] = bb.readString(); break; - case 12: + + case 11: result["output_dir"] = bb.readString(); break; - case 13: + + case 12: var length = bb.readVarUint(); var values = (result["external"] = Array(length)); for (var i = 0; i < length; i++) values[i] = bb.readString(); break; + + case 13: + result["loaders"] = decodeLoaderMap(bb); + break; + case 14: var length = bb.readVarUint(); - var values = (result["loader_keys"] = Array(length)); + var values = (result["main_fields"] = Array(length)); for (var i = 0; i < length; i++) values[i] = bb.readString(); break; + case 15: - var length = bb.readVarUint(); - var values = (result["loader_values"] = Array(length)); - for (var i = 0; i < length; i++) values[i] = Loader[bb.readByte()]; + result["platform"] = Platform[bb.readByte()]; break; + case 16: - var length = bb.readVarUint(); - var values = (result["main_fields"] = Array(length)); - for (var i = 0; i < length; i++) values[i] = bb.readString(); + result["serve"] = !!bb.readByte(); break; + case 17: - result["platform"] = Platform[bb.readByte()]; + var length = bb.readVarUint(); + var values = (result["extension_order"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); break; + case 18: - result["serve"] = !!bb.readByte(); + result["generate_node_module_bundle"] = !!bb.readByte(); break; + case 19: - var length = bb.readVarUint(); - var values = (result["extension_order"] = Array(length)); - for (var i = 0; i < length; i++) values[i] = bb.readString(); + result["node_modules_bundle_path"] = bb.readString(); break; + case 20: - result["public_dir"] = bb.readString(); + result["node_modules_bundle_path_server"] = bb.readString(); break; + + case 21: + result["framework"] = decodeFrameworkConfig(bb); + break; + + case 22: + result["router"] = decodeRouteConfig(bb); + break; + + case 23: + result["no_summary"] = !!bb.readByte(); + break; + + case 24: + result["disable_hmr"] = !!bb.readByte(); + break; + + case 25: + result["port"] = bb.readUint16(); + break; + + case 26: + result["logLevel"] = MessageLevel[bb.readVarUint()]; + break; + default: throw new Error("Attempted to parse invalid message"); } + } } + function encodeTransformOptions(message, bb) { var value = message["jsx"]; if (value != null) { bb.writeByte(1); encodeJSX(value, bb); } + var value = message["tsconfig_override"]; if (value != null) { bb.writeByte(2); bb.writeString(value); } + var value = message["resolve"]; if (value != null) { bb.writeByte(3); var encoded = ResolveMode[value]; - if (encoded === undefined) + if (encoded === void 0) throw new Error( "Invalid value " + JSON.stringify(value) + ' for enum "ResolveMode"' ); bb.writeByte(encoded); } + var value = message["origin"]; if (value != null) { bb.writeByte(4); bb.writeString(value); } + var value = message["absolute_working_dir"]; if (value != null) { bb.writeByte(5); bb.writeString(value); } - var value = message["define_keys"]; + + var value = message["define"]; if (value != null) { bb.writeByte(6); - var values = value, - n = values.length; - bb.writeVarUint(n); - for (var i = 0; i < n; i++) { - value = values[i]; - bb.writeString(value); - } - } - var value = message["define_values"]; - if (value != null) { - bb.writeByte(7); - var values = value, - n = values.length; - bb.writeVarUint(n); - for (var i = 0; i < n; i++) { - value = values[i]; - bb.writeString(value); - } + encodeStringMap(value, bb); } + var value = message["preserve_symlinks"]; if (value != null) { - bb.writeByte(8); + bb.writeByte(7); bb.writeByte(value); } + var value = message["entry_points"]; if (value != null) { - bb.writeByte(9); + bb.writeByte(8); var values = value, n = values.length; bb.writeVarUint(n); @@ -267,14 +1783,16 @@ function encodeTransformOptions(message, bb) { bb.writeString(value); } } + var value = message["write"]; if (value != null) { - bb.writeByte(10); + bb.writeByte(9); bb.writeByte(value); } + var value = message["inject"]; if (value != null) { - bb.writeByte(11); + bb.writeByte(10); var values = value, n = values.length; bb.writeVarUint(n); @@ -283,25 +1801,16 @@ function encodeTransformOptions(message, bb) { bb.writeString(value); } } + var value = message["output_dir"]; if (value != null) { - bb.writeByte(12); + bb.writeByte(11); bb.writeString(value); } + var value = message["external"]; if (value != null) { - bb.writeByte(13); - var values = value, - n = values.length; - bb.writeVarUint(n); - for (var i = 0; i < n; i++) { - value = values[i]; - bb.writeString(value); - } - } - var value = message["loader_keys"]; - if (value != null) { - bb.writeByte(14); + bb.writeByte(12); var values = value, n = values.length; bb.writeVarUint(n); @@ -310,25 +1819,16 @@ function encodeTransformOptions(message, bb) { bb.writeString(value); } } - var value = message["loader_values"]; + + var value = message["loaders"]; if (value != null) { - bb.writeByte(15); - var values = value, - n = values.length; - bb.writeVarUint(n); - for (var i = 0; i < n; i++) { - value = values[i]; - var encoded = Loader[value]; - if (encoded === undefined) - throw new Error( - "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' - ); - bb.writeByte(encoded); - } + bb.writeByte(13); + encodeLoaderMap(value, bb); } + var value = message["main_fields"]; if (value != null) { - bb.writeByte(16); + bb.writeByte(14); var values = value, n = values.length; bb.writeVarUint(n); @@ -337,24 +1837,27 @@ function encodeTransformOptions(message, bb) { bb.writeString(value); } } + var value = message["platform"]; if (value != null) { - bb.writeByte(17); + bb.writeByte(15); var encoded = Platform[value]; - if (encoded === undefined) + if (encoded === void 0) throw new Error( "Invalid value " + JSON.stringify(value) + ' for enum "Platform"' ); bb.writeByte(encoded); } + var value = message["serve"]; if (value != null) { - bb.writeByte(18); + bb.writeByte(16); bb.writeByte(value); } + var value = message["extension_order"]; if (value != null) { - bb.writeByte(19); + bb.writeByte(17); var values = value, n = values.length; bb.writeVarUint(n); @@ -363,82 +1866,164 @@ function encodeTransformOptions(message, bb) { bb.writeString(value); } } - var value = message["public_dir"]; + + var value = message["generate_node_module_bundle"]; + if (value != null) { + bb.writeByte(18); + bb.writeByte(value); + } + + var value = message["node_modules_bundle_path"]; + if (value != null) { + bb.writeByte(19); + bb.writeString(value); + } + + var value = message["node_modules_bundle_path_server"]; if (value != null) { bb.writeByte(20); bb.writeString(value); } + + var value = message["framework"]; + if (value != null) { + bb.writeByte(21); + encodeFrameworkConfig(value, bb); + } + + var value = message["router"]; + if (value != null) { + bb.writeByte(22); + encodeRouteConfig(value, bb); + } + + var value = message["no_summary"]; + if (value != null) { + bb.writeByte(23); + bb.writeByte(value); + } + + var value = message["disable_hmr"]; + if (value != null) { + bb.writeByte(24); + bb.writeByte(value); + } + + var value = message["port"]; + if (value != null) { + bb.writeByte(25); + bb.writeUint16(value); + } + + var value = message["logLevel"]; + if (value != null) { + bb.writeByte(26); + var encoded = MessageLevel[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "MessageLevel"' + ); + bb.writeVarUint(encoded); + } bb.writeByte(0); } + function decodeFileHandle(bb) { var result = {}; + result["path"] = bb.readString(); result["size"] = bb.readVarUint(); result["fd"] = bb.readVarUint(); return result; } + function encodeFileHandle(message, bb) { var value = message["path"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "path"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } + var value = message["size"]; - if (value != null) bb.writeVarUint(value); - else throw new Error('Missing required field "size"'); + if (value != null) { + bb.writeVarUint(value); + } else { + throw new Error('Missing required field "size"'); + } + var value = message["fd"]; - if (value != null) bb.writeVarUint(value); - else throw new Error('Missing required field "fd"'); + if (value != null) { + bb.writeVarUint(value); + } else { + throw new Error('Missing required field "fd"'); + } } + function decodeTransform(bb) { var result = {}; - while (true) + + while (true) { switch (bb.readByte()) { case 0: return result; + case 1: result["handle"] = decodeFileHandle(bb); break; + case 2: result["path"] = bb.readString(); break; + case 3: result["contents"] = bb.readByteArray(); break; + case 4: result["loader"] = Loader[bb.readByte()]; break; + case 5: result["options"] = decodeTransformOptions(bb); break; + default: throw new Error("Attempted to parse invalid message"); } + } } + function encodeTransform(message, bb) { var value = message["handle"]; if (value != null) { bb.writeByte(1); encodeFileHandle(value, bb); } + var value = message["path"]; if (value != null) { bb.writeByte(2); bb.writeString(value); } + var value = message["contents"]; if (value != null) { bb.writeByte(3); bb.writeByteArray(value); } + var value = message["loader"]; if (value != null) { bb.writeByte(4); var encoded = Loader[value]; - if (encoded === undefined) + if (encoded === void 0) throw new Error( "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' ); bb.writeByte(encoded); } + var value = message["options"]; if (value != null) { bb.writeByte(5); @@ -446,6 +2031,163 @@ function encodeTransform(message, bb) { } bb.writeByte(0); } + +function decodeScan(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["path"] = bb.readString(); + break; + + case 2: + result["contents"] = bb.readByteArray(); + break; + + case 3: + result["loader"] = Loader[bb.readByte()]; + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeScan(message, bb) { + var value = message["path"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["contents"]; + if (value != null) { + bb.writeByte(2); + bb.writeByteArray(value); + } + + var value = message["loader"]; + if (value != null) { + bb.writeByte(3); + var encoded = Loader[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' + ); + bb.writeByte(encoded); + } + bb.writeByte(0); +} + +function decodeScanResult(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["exports"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["imports"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeScannedImport(bb); + return result; +} + +function encodeScanResult(message, bb) { + var value = message["exports"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } else { + throw new Error('Missing required field "exports"'); + } + + var value = message["imports"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeScannedImport(value, bb); + } + } else { + throw new Error('Missing required field "imports"'); + } +} + +function decodeScannedImport(bb) { + var result = {}; + + result["path"] = bb.readString(); + result["kind"] = ImportKind[bb.readByte()]; + return result; +} + +function encodeScannedImport(message, bb) { + var value = message["path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } + + var value = message["kind"]; + if (value != null) { + var encoded = ImportKind[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "ImportKind"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "kind"'); + } +} +const ImportKind = { + 1: 1, + 2: 2, + 3: 3, + 4: 4, + 5: 5, + 6: 6, + 7: 7, + 8: 8, + entry_point: 1, + stmt: 2, + require: 3, + dynamic: 4, + require_resolve: 5, + at: 6, + url: 7, + internal: 8, +}; +const ImportKindKeys = { + 1: "entry_point", + 2: "stmt", + 3: "require", + 4: "dynamic", + 5: "require_resolve", + 6: "at", + 7: "url", + 8: "internal", + entry_point: "entry_point", + stmt: "stmt", + require: "require", + dynamic: "dynamic", + require_resolve: "require_resolve", + at: "at", + url: "url", + internal: "internal", +}; const TransformResponseStatus = { 1: 1, 2: 2, @@ -458,22 +2200,34 @@ const TransformResponseStatusKeys = { success: "success", fail: "fail", }; + function decodeOutputFile(bb) { var result = {}; + result["data"] = bb.readByteArray(); result["path"] = bb.readString(); return result; } + function encodeOutputFile(message, bb) { var value = message["data"]; - if (value != null) bb.writeByteArray(value); - else throw new Error('Missing required field "data"'); + if (value != null) { + bb.writeByteArray(value); + } else { + throw new Error('Missing required field "data"'); + } + var value = message["path"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "path"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } } + function decodeTransformResponse(bb) { var result = {}; + result["status"] = TransformResponseStatus[bb.readVarUint()]; var length = bb.readVarUint(); var values = (result["files"] = Array(length)); @@ -483,18 +2237,22 @@ function decodeTransformResponse(bb) { for (var i = 0; i < length; i++) values[i] = decodeMessage(bb); return result; } + function encodeTransformResponse(message, bb) { var value = message["status"]; if (value != null) { var encoded = TransformResponseStatus[value]; - if (encoded === undefined) + if (encoded === void 0) throw new Error( "Invalid value " + JSON.stringify(value) + ' for enum "TransformResponseStatus"' ); bb.writeVarUint(encoded); - } else throw new Error('Missing required field "status"'); + } else { + throw new Error('Missing required field "status"'); + } + var value = message["files"]; if (value != null) { var values = value, @@ -504,7 +2262,10 @@ function encodeTransformResponse(message, bb) { value = values[i]; encodeOutputFile(value, bb); } - } else throw new Error('Missing required field "files"'); + } else { + throw new Error('Missing required field "files"'); + } + var value = message["errors"]; if (value != null) { var values = value, @@ -514,30 +2275,38 @@ function encodeTransformResponse(message, bb) { value = values[i]; encodeMessage(value, bb); } - } else throw new Error('Missing required field "errors"'); + } else { + throw new Error('Missing required field "errors"'); + } } -const MessageKind = { +const MessageLevel = { 1: 1, 2: 2, 3: 3, 4: 4, + 5: 5, err: 1, warn: 2, note: 3, - debug: 4, + info: 4, + debug: 5, }; -const MessageKindKeys = { +const MessageLevelKeys = { 1: "err", 2: "warn", 3: "note", - 4: "debug", + 4: "info", + 5: "debug", err: "err", warn: "warn", note: "note", + info: "info", debug: "debug", }; + function decodeLocation(bb) { var result = {}; + result["file"] = bb.readString(); result["namespace"] = bb.readString(); result["line"] = bb.readInt32(); @@ -547,51 +2316,87 @@ function decodeLocation(bb) { result["offset"] = bb.readVarUint(); return result; } + function encodeLocation(message, bb) { var value = message["file"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "file"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "file"'); + } + var value = message["namespace"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "namespace"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "namespace"'); + } + var value = message["line"]; - if (value != null) bb.writeInt32(value); - else throw new Error('Missing required field "line"'); + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "line"'); + } + var value = message["column"]; - if (value != null) bb.writeInt32(value); - else throw new Error('Missing required field "column"'); + if (value != null) { + bb.writeInt32(value); + } else { + throw new Error('Missing required field "column"'); + } + var value = message["line_text"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "line_text"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "line_text"'); + } + var value = message["suggestion"]; - if (value != null) bb.writeString(value); - else throw new Error('Missing required field "suggestion"'); + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "suggestion"'); + } + var value = message["offset"]; - if (value != null) bb.writeVarUint(value); - else throw new Error('Missing required field "offset"'); + if (value != null) { + bb.writeVarUint(value); + } else { + throw new Error('Missing required field "offset"'); + } } + function decodeMessageData(bb) { var result = {}; - while (true) + + while (true) { switch (bb.readByte()) { case 0: return result; + case 1: result["text"] = bb.readString(); break; + case 2: result["location"] = decodeLocation(bb); break; + default: throw new Error("Attempted to parse invalid message"); } + } } + function encodeMessageData(message, bb) { var value = message["text"]; if (value != null) { bb.writeByte(1); bb.writeString(value); } + var value = message["location"]; if (value != null) { bb.writeByte(2); @@ -599,28 +2404,76 @@ function encodeMessageData(message, bb) { } bb.writeByte(0); } + +function decodeMessageMeta(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["resolve"] = bb.readString(); + break; + + case 2: + result["build"] = !!bb.readByte(); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeMessageMeta(message, bb) { + var value = message["resolve"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["build"]; + if (value != null) { + bb.writeByte(2); + bb.writeByte(value); + } + bb.writeByte(0); +} + function decodeMessage(bb) { var result = {}; - result["kind"] = MessageKind[bb.readVarUint()]; + + result["level"] = MessageLevel[bb.readVarUint()]; result["data"] = decodeMessageData(bb); var length = bb.readVarUint(); var values = (result["notes"] = Array(length)); for (var i = 0; i < length; i++) values[i] = decodeMessageData(bb); + result["on"] = decodeMessageMeta(bb); return result; } + function encodeMessage(message, bb) { - var value = message["kind"]; + var value = message["level"]; if (value != null) { - var encoded = MessageKind[value]; - if (encoded === undefined) + var encoded = MessageLevel[value]; + if (encoded === void 0) throw new Error( - "Invalid value " + JSON.stringify(value) + ' for enum "MessageKind"' + "Invalid value " + JSON.stringify(value) + ' for enum "MessageLevel"' ); bb.writeVarUint(encoded); - } else throw new Error('Missing required field "kind"'); + } else { + throw new Error('Missing required field "level"'); + } + var value = message["data"]; - if (value != null) encodeMessageData(value, bb); - else throw new Error('Missing required field "data"'); + if (value != null) { + encodeMessageData(value, bb); + } else { + throw new Error('Missing required field "data"'); + } + var value = message["notes"]; if (value != null) { var values = value, @@ -630,10 +2483,21 @@ function encodeMessage(message, bb) { value = values[i]; encodeMessageData(value, bb); } - } else throw new Error('Missing required field "notes"'); + } else { + throw new Error('Missing required field "notes"'); + } + + var value = message["on"]; + if (value != null) { + encodeMessageMeta(value, bb); + } else { + throw new Error('Missing required field "on"'); + } } + function decodeLog(bb) { var result = {}; + result["warnings"] = bb.readUint32(); result["errors"] = bb.readUint32(); var length = bb.readVarUint(); @@ -641,13 +2505,22 @@ function decodeLog(bb) { for (var i = 0; i < length; i++) values[i] = decodeMessage(bb); return result; } + function encodeLog(message, bb) { var value = message["warnings"]; - if (value != null) bb.writeUint32(value); - else throw new Error('Missing required field "warnings"'); + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "warnings"'); + } + var value = message["errors"]; - if (value != null) bb.writeUint32(value); - else throw new Error('Missing required field "errors"'); + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "errors"'); + } + var value = message["msgs"]; if (value != null) { var values = value, @@ -657,38 +2530,807 @@ function encodeLog(message, bb) { value = values[i]; encodeMessage(value, bb); } - } else throw new Error('Missing required field "msgs"'); + } else { + throw new Error('Missing required field "msgs"'); + } +} +const Reloader = { + 1: 1, + 2: 2, + 3: 3, + disable: 1, + live: 2, + fast_refresh: 3, +}; +const ReloaderKeys = { + 1: "disable", + 2: "live", + 3: "fast_refresh", + disable: "disable", + live: "live", + fast_refresh: "fast_refresh", +}; +const WebsocketMessageKind = { + 1: 1, + 2: 2, + 3: 3, + 4: 4, + 5: 5, + 6: 6, + 7: 7, + 8: 8, + welcome: 1, + file_change_notification: 2, + build_success: 3, + build_fail: 4, + manifest_success: 5, + manifest_fail: 6, + resolve_file: 7, + file_change_notification_with_hint: 8, +}; +const WebsocketMessageKindKeys = { + 1: "welcome", + 2: "file_change_notification", + 3: "build_success", + 4: "build_fail", + 5: "manifest_success", + 6: "manifest_fail", + 7: "resolve_file", + 8: "file_change_notification_with_hint", + welcome: "welcome", + file_change_notification: "file_change_notification", + build_success: "build_success", + build_fail: "build_fail", + manifest_success: "manifest_success", + manifest_fail: "manifest_fail", + resolve_file: "resolve_file", + file_change_notification_with_hint: "file_change_notification_with_hint", +}; +const WebsocketCommandKind = { + 1: 1, + 2: 2, + 3: 3, + build: 1, + manifest: 2, + build_with_file_path: 3, +}; +const WebsocketCommandKindKeys = { + 1: "build", + 2: "manifest", + 3: "build_with_file_path", + build: "build", + manifest: "manifest", + build_with_file_path: "build_with_file_path", +}; + +function decodeWebsocketMessage(bb) { + var result = {}; + + result["timestamp"] = bb.readUint32(); + result["kind"] = WebsocketMessageKind[bb.readByte()]; + return result; +} + +function encodeWebsocketMessage(message, bb) { + var value = message["timestamp"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "timestamp"'); + } + + var value = message["kind"]; + if (value != null) { + var encoded = WebsocketMessageKind[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + + JSON.stringify(value) + + ' for enum "WebsocketMessageKind"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "kind"'); + } +} + +function decodeWebsocketMessageWelcome(bb) { + var result = {}; + + result["epoch"] = bb.readUint32(); + result["javascriptReloader"] = Reloader[bb.readByte()]; + result["cwd"] = bb.readString(); + return result; +} + +function encodeWebsocketMessageWelcome(message, bb) { + var value = message["epoch"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "epoch"'); + } + + var value = message["javascriptReloader"]; + if (value != null) { + var encoded = Reloader[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "Reloader"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "javascriptReloader"'); + } + + var value = message["cwd"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "cwd"'); + } +} + +function decodeWebsocketMessageFileChangeNotification(bb) { + var result = {}; + + result["id"] = bb.readUint32(); + result["loader"] = Loader[bb.readByte()]; + return result; +} + +function encodeWebsocketMessageFileChangeNotification(message, bb) { + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } + + var value = message["loader"]; + if (value != null) { + var encoded = Loader[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "loader"'); + } +} + +function decodeWebsocketCommand(bb) { + var result = {}; + + result["kind"] = WebsocketCommandKind[bb.readByte()]; + result["timestamp"] = bb.readUint32(); + return result; +} + +function encodeWebsocketCommand(message, bb) { + var value = message["kind"]; + if (value != null) { + var encoded = WebsocketCommandKind[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + + JSON.stringify(value) + + ' for enum "WebsocketCommandKind"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "kind"'); + } + + var value = message["timestamp"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "timestamp"'); + } +} + +function decodeWebsocketCommandBuild(bb) { + var result = {}; + + result["id"] = bb.readUint32(); + return result; +} + +function encodeWebsocketCommandBuild(message, bb) { + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } +} + +function decodeWebsocketCommandManifest(bb) { + var result = {}; + + result["id"] = bb.readUint32(); + return result; +} + +function encodeWebsocketCommandManifest(message, bb) { + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } +} + +function decodeWebsocketMessageBuildSuccess(bb) { + var result = {}; + + result["id"] = bb.readUint32(); + result["from_timestamp"] = bb.readUint32(); + result["loader"] = Loader[bb.readByte()]; + result["module_path"] = bb.readString(); + result["blob_length"] = bb.readUint32(); + return result; +} + +function encodeWebsocketMessageBuildSuccess(message, bb) { + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } + + var value = message["from_timestamp"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "from_timestamp"'); + } + + var value = message["loader"]; + if (value != null) { + var encoded = Loader[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "loader"'); + } + + var value = message["module_path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "module_path"'); + } + + var value = message["blob_length"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "blob_length"'); + } +} + +function decodeWebsocketMessageBuildFailure(bb) { + var result = {}; + + result["id"] = bb.readUint32(); + result["from_timestamp"] = bb.readUint32(); + result["loader"] = Loader[bb.readByte()]; + result["module_path"] = bb.readString(); + result["log"] = decodeLog(bb); + return result; +} + +function encodeWebsocketMessageBuildFailure(message, bb) { + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } + + var value = message["from_timestamp"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "from_timestamp"'); + } + + var value = message["loader"]; + if (value != null) { + var encoded = Loader[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "loader"'); + } + + var value = message["module_path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "module_path"'); + } + + var value = message["log"]; + if (value != null) { + encodeLog(value, bb); + } else { + throw new Error('Missing required field "log"'); + } +} + +function decodeWebsocketCommandBuildWithFilePath(bb) { + var result = {}; + + result["id"] = bb.readUint32(); + result["file_path"] = bb.readString(); + return result; +} + +function encodeWebsocketCommandBuildWithFilePath(message, bb) { + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } + + var value = message["file_path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "file_path"'); + } +} + +function decodeWebsocketMessageResolveID(bb) { + var result = {}; + + result["id"] = bb.readUint32(); + return result; +} + +function encodeWebsocketMessageResolveID(message, bb) { + var value = message["id"]; + if (value != null) { + bb.writeUint32(value); + } else { + throw new Error('Missing required field "id"'); + } +} + +function decodeNPMRegistry(bb) { + var result = {}; + + result["url"] = bb.readString(); + result["username"] = bb.readString(); + result["password"] = bb.readString(); + result["token"] = bb.readString(); + return result; +} + +function encodeNPMRegistry(message, bb) { + var value = message["url"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "url"'); + } + + var value = message["username"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "username"'); + } + + var value = message["password"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "password"'); + } + + var value = message["token"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "token"'); + } +} + +function decodeNPMRegistryMap(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["scopes"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["registries"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeNPMRegistry(bb); + return result; +} + +function encodeNPMRegistryMap(message, bb) { + var value = message["scopes"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } else { + throw new Error('Missing required field "scopes"'); + } + + var value = message["registries"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeNPMRegistry(value, bb); + } + } else { + throw new Error('Missing required field "registries"'); + } +} + +function decodeBunInstall(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["default_registry"] = decodeNPMRegistry(bb); + break; + + case 2: + result["scoped"] = decodeNPMRegistryMap(bb); + break; + + case 3: + result["lockfile_path"] = bb.readString(); + break; + + case 4: + result["save_lockfile_path"] = bb.readString(); + break; + + case 5: + result["cache_directory"] = bb.readString(); + break; + + case 6: + result["dry_run"] = !!bb.readByte(); + break; + + case 7: + result["force"] = !!bb.readByte(); + break; + + case 8: + result["save_dev"] = !!bb.readByte(); + break; + + case 9: + result["save_optional"] = !!bb.readByte(); + break; + + case 10: + result["save_peer"] = !!bb.readByte(); + break; + + case 11: + result["save_lockfile"] = !!bb.readByte(); + break; + + case 12: + result["production"] = !!bb.readByte(); + break; + + case 13: + result["save_yarn_lockfile"] = !!bb.readByte(); + break; + + case 14: + var length = bb.readVarUint(); + var values = (result["native_bin_links"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + break; + + case 15: + result["disable_cache"] = !!bb.readByte(); + break; + + case 16: + result["disable_manifest_cache"] = !!bb.readByte(); + break; + + case 17: + result["global_dir"] = bb.readString(); + break; + + case 18: + result["global_bin_dir"] = bb.readString(); + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeBunInstall(message, bb) { + var value = message["default_registry"]; + if (value != null) { + bb.writeByte(1); + encodeNPMRegistry(value, bb); + } + + var value = message["scoped"]; + if (value != null) { + bb.writeByte(2); + encodeNPMRegistryMap(value, bb); + } + + var value = message["lockfile_path"]; + if (value != null) { + bb.writeByte(3); + bb.writeString(value); + } + + var value = message["save_lockfile_path"]; + if (value != null) { + bb.writeByte(4); + bb.writeString(value); + } + + var value = message["cache_directory"]; + if (value != null) { + bb.writeByte(5); + bb.writeString(value); + } + + var value = message["dry_run"]; + if (value != null) { + bb.writeByte(6); + bb.writeByte(value); + } + + var value = message["force"]; + if (value != null) { + bb.writeByte(7); + bb.writeByte(value); + } + + var value = message["save_dev"]; + if (value != null) { + bb.writeByte(8); + bb.writeByte(value); + } + + var value = message["save_optional"]; + if (value != null) { + bb.writeByte(9); + bb.writeByte(value); + } + + var value = message["save_peer"]; + if (value != null) { + bb.writeByte(10); + bb.writeByte(value); + } + + var value = message["save_lockfile"]; + if (value != null) { + bb.writeByte(11); + bb.writeByte(value); + } + + var value = message["production"]; + if (value != null) { + bb.writeByte(12); + bb.writeByte(value); + } + + var value = message["save_yarn_lockfile"]; + if (value != null) { + bb.writeByte(13); + bb.writeByte(value); + } + + var value = message["native_bin_links"]; + if (value != null) { + bb.writeByte(14); + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } + + var value = message["disable_cache"]; + if (value != null) { + bb.writeByte(15); + bb.writeByte(value); + } + + var value = message["disable_manifest_cache"]; + if (value != null) { + bb.writeByte(16); + bb.writeByte(value); + } + + var value = message["global_dir"]; + if (value != null) { + bb.writeByte(17); + bb.writeString(value); + } + + var value = message["global_bin_dir"]; + if (value != null) { + bb.writeByte(18); + bb.writeString(value); + } + bb.writeByte(0); } export { Loader }; export { LoaderKeys }; +export { FrameworkEntryPointType }; +export { FrameworkEntryPointTypeKeys }; +export { StackFrameScope }; +export { StackFrameScopeKeys }; +export { decodeStackFrame }; +export { encodeStackFrame }; +export { decodeStackFramePosition }; +export { encodeStackFramePosition }; +export { decodeSourceLine }; +export { encodeSourceLine }; +export { decodeStackTrace }; +export { encodeStackTrace }; +export { decodeJSException }; +export { encodeJSException }; +export { FallbackStep }; +export { FallbackStepKeys }; +export { decodeProblems }; +export { encodeProblems }; +export { decodeRouter }; +export { encodeRouter }; +export { decodeFallbackMessageContainer }; +export { encodeFallbackMessageContainer }; export { ResolveMode }; export { ResolveModeKeys }; export { Platform }; export { PlatformKeys }; +export { CSSInJSBehavior }; +export { CSSInJSBehaviorKeys }; export { JSXRuntime }; export { JSXRuntimeKeys }; export { decodeJSX }; export { encodeJSX }; +export { decodeStringPointer }; +export { encodeStringPointer }; +export { decodeJavascriptBundledModule }; +export { encodeJavascriptBundledModule }; +export { decodeJavascriptBundledPackage }; +export { encodeJavascriptBundledPackage }; +export { decodeJavascriptBundle }; +export { encodeJavascriptBundle }; +export { decodeJavascriptBundleContainer }; +export { encodeJavascriptBundleContainer }; +export { ScanDependencyMode }; +export { ScanDependencyModeKeys }; +export { ModuleImportType }; +export { ModuleImportTypeKeys }; +export { decodeModuleImportRecord }; +export { encodeModuleImportRecord }; +export { decodeModule }; +export { encodeModule }; +export { decodeStringMap }; +export { encodeStringMap }; +export { decodeLoaderMap }; +export { encodeLoaderMap }; +export { DotEnvBehavior }; +export { DotEnvBehaviorKeys }; +export { decodeEnvConfig }; +export { encodeEnvConfig }; +export { decodeLoadedEnvConfig }; +export { encodeLoadedEnvConfig }; +export { decodeFrameworkConfig }; +export { encodeFrameworkConfig }; +export { decodeFrameworkEntryPoint }; +export { encodeFrameworkEntryPoint }; +export { decodeFrameworkEntryPointMap }; +export { encodeFrameworkEntryPointMap }; +export { decodeFrameworkEntryPointMessage }; +export { encodeFrameworkEntryPointMessage }; +export { decodeLoadedFramework }; +export { encodeLoadedFramework }; +export { decodeLoadedRouteConfig }; +export { encodeLoadedRouteConfig }; +export { decodeRouteConfig }; +export { encodeRouteConfig }; export { decodeTransformOptions }; export { encodeTransformOptions }; export { decodeFileHandle }; export { encodeFileHandle }; export { decodeTransform }; export { encodeTransform }; +export { decodeScan }; +export { encodeScan }; +export { decodeScanResult }; +export { encodeScanResult }; +export { decodeScannedImport }; +export { encodeScannedImport }; +export { ImportKind }; +export { ImportKindKeys }; export { TransformResponseStatus }; export { TransformResponseStatusKeys }; export { decodeOutputFile }; export { encodeOutputFile }; export { decodeTransformResponse }; export { encodeTransformResponse }; -export { MessageKind }; -export { MessageKindKeys }; +export { MessageLevel }; +export { MessageLevelKeys }; export { decodeLocation }; export { encodeLocation }; export { decodeMessageData }; export { encodeMessageData }; +export { decodeMessageMeta }; +export { encodeMessageMeta }; export { decodeMessage }; export { encodeMessage }; export { decodeLog }; export { encodeLog }; +export { Reloader }; +export { ReloaderKeys }; +export { WebsocketMessageKind }; +export { WebsocketMessageKindKeys }; +export { WebsocketCommandKind }; +export { WebsocketCommandKindKeys }; +export { decodeWebsocketMessage }; +export { encodeWebsocketMessage }; +export { decodeWebsocketMessageWelcome }; +export { encodeWebsocketMessageWelcome }; +export { decodeWebsocketMessageFileChangeNotification }; +export { encodeWebsocketMessageFileChangeNotification }; +export { decodeWebsocketCommand }; +export { encodeWebsocketCommand }; +export { decodeWebsocketCommandBuild }; +export { encodeWebsocketCommandBuild }; +export { decodeWebsocketCommandManifest }; +export { encodeWebsocketCommandManifest }; +export { decodeWebsocketMessageBuildSuccess }; +export { encodeWebsocketMessageBuildSuccess }; +export { decodeWebsocketMessageBuildFailure }; +export { encodeWebsocketMessageBuildFailure }; +export { decodeWebsocketCommandBuildWithFilePath }; +export { encodeWebsocketCommandBuildWithFilePath }; +export { decodeWebsocketMessageResolveID }; +export { encodeWebsocketMessageResolveID }; +export { decodeNPMRegistry }; +export { encodeNPMRegistry }; +export { decodeNPMRegistryMap }; +export { encodeNPMRegistryMap }; +export { decodeBunInstall }; +export { encodeBunInstall }; diff --git a/src/api/demo/schema.peechy b/src/api/demo/schema.peechy new file mode 100644 index 000000000..59cb1edf5 --- /dev/null +++ b/src/api/demo/schema.peechy @@ -0,0 +1,553 @@ +package Api; + +smol Loader { + jsx = 1; + js = 2; + ts = 3; + tsx = 4; + css = 5; + file = 6; + json = 7; + toml = 8; + wasm = 9; +} + +smol FrameworkEntryPointType { + client = 1; + server = 2; + fallback = 3; +} + +smol StackFrameScope { + Eval = 1; + Module = 2; + Function = 3; + Global = 4; + Wasm = 5; + Constructor = 6; +} + +struct StackFrame { + string function_name; + string file; + StackFramePosition position; + StackFrameScope scope; +} + +struct StackFramePosition { + int32 source_offset; + int32 line; + int32 line_start; + int32 line_stop; + int32 column_start; + int32 column_stop; + int32 expression_start; + int32 expression_stop; +} + +struct SourceLine { + int32 line; + string text; +} + +struct StackTrace { + SourceLine[] source_lines; + StackFrame[] frames; +} + + +message JSException { + string name = 1; + string message = 2; + + uint16 runtime_type = 3; + uint8 code = 4; + + StackTrace stack = 5; +} + +smol FallbackStep { + ssr_disabled = 1; + create_vm = 2; + configure_router = 3; + configure_defines = 4; + resolve_entry_point = 5; + load_entry_point = 6; + eval_entry_point = 7; + fetch_event_handler = 8; +} + +struct Problems { + uint16 code; + string name; + + JSException[] exceptions; + Log build; +} + +struct Router { + StringMap routes; + int32 route; + StringMap params; +} + +message FallbackMessageContainer { + string message = 1; + Router router = 2; + FallbackStep reason = 3; + Problems problems = 4; + string cwd = 5; +} + + +smol ResolveMode { + disable = 1; + lazy = 2; + dev = 3; + bundle = 4; +} + +smol Platform { + browser = 1; + node = 2; + bun = 3; + bun_macro = 4; +} + +smol CSSInJSBehavior { + facade = 1; + facade_onimportcss = 2; + auto_onimportcss = 3; +} + +smol JSXRuntime { + automatic = 1; + classic = 2; +} + +struct JSX { + string factory; + JSXRuntime runtime; + string fragment; + bool development; + + // Probably react + string import_source; + + bool react_fast_refresh; +} + +struct StringPointer { + uint32 offset; + uint32 length; +} + +struct JavascriptBundledModule { + // package-relative path including file extension + StringPointer path; + + // Source code + StringPointer code; + + // index into JavascriptBundle.packages + uint32 package_id; + + // The ESM export is this id ("$" + number.toString(16)) + uint32 id; + + // This lets us efficiently compare strings ignoring the extension + byte path_extname_length; +} + +struct JavascriptBundledPackage { + StringPointer name; + StringPointer version; + uint32 hash; + + uint32 modules_offset; + uint32 modules_length; +} + +struct JavascriptBundle { + // These are sorted alphabetically so you can do binary search + JavascriptBundledModule[] modules; + JavascriptBundledPackage[] packages; + + // This is ASCII-encoded so you can send it directly over HTTP + byte[] etag; + + uint32 generated_at; + + // generated by hashing all ${name}@${version} in sorted order + byte[] app_package_json_dependencies_hash; + + byte[] import_from_name; + + // This is what StringPointer refers to + byte[] manifest_string; +} + +message JavascriptBundleContainer { + uint32 bundle_format_version = 1; + + // These go first so if we change JavaScriptBundle we can still read these + LoadedRouteConfig routes = 3; + LoadedFramework framework = 2; + + JavascriptBundle bundle = 4; + + // Don't technically need to store this, but it may be helpful as a sanity check + uint32 code_length = 5; +} + +smol ScanDependencyMode { + app = 1; + all = 2; +} + +smol ModuleImportType { + import = 1; + require = 2; +} + +struct ModuleImportRecord { + ModuleImportType kind; + string path; + + bool dynamic; +} + +struct Module { + string path; + ModuleImportRecord[] imports; +} + +struct StringMap { + string[] keys; + string[] values; +} + +struct LoaderMap { + string[] extensions; + Loader[] loaders; +} + +enum DotEnvBehavior { + disable = 1; + prefix = 2; + load_all = 3; +} + +message EnvConfig { + string prefix = 1; + StringMap defaults = 2; +} + +struct LoadedEnvConfig { + DotEnvBehavior dotenv; + + StringMap defaults; + string prefix; +} + +message FrameworkConfig { + string package = 1; + FrameworkEntryPointMessage client = 2; + FrameworkEntryPointMessage server = 3; + FrameworkEntryPointMessage fallback = 4; + bool development = 5; + + CSSInJSBehavior client_css_in_js = 6; + string display_name = 7; + + StringMap overrideModules = 8; +} + +struct FrameworkEntryPoint { + FrameworkEntryPointType kind; + string path; + LoadedEnvConfig env; +} + +message FrameworkEntryPointMap { + FrameworkEntryPoint client = 1; + FrameworkEntryPoint server = 2; + FrameworkEntryPoint fallback = 3; +} + +message FrameworkEntryPointMessage { + string path = 1; + EnvConfig env = 2; +} + +struct LoadedFramework { + string package; + string display_name; + bool development; + FrameworkEntryPointMap entry_points; + CSSInJSBehavior client_css_in_js; + StringMap overrideModules; +} + +struct LoadedRouteConfig { + string dir; + string[] extensions; + string static_dir; + string asset_prefix; +} + +message RouteConfig { + string[] dir = 1; + string[] extensions = 2; + string static_dir = 3; + string asset_prefix = 4; +} + +message TransformOptions { + JSX jsx = 1; + string tsconfig_override = 2; + ResolveMode resolve = 3; + + string origin = 4; + string absolute_working_dir = 5; + + StringMap define = 6; + + bool preserve_symlinks = 7; + + string[] entry_points = 8; + bool write = 9; + + string[] inject = 10; + string output_dir = 11; + + string[] external = 12; + + LoaderMap loaders = 13; + + string[] main_fields = 14; + Platform platform = 15; + + bool serve = 16; + + string[] extension_order = 17; + + bool generate_node_module_bundle = 18; + + string node_modules_bundle_path = 19; + string node_modules_bundle_path_server = 20; + + FrameworkConfig framework = 21; + RouteConfig router = 22; + bool no_summary = 23; + + bool disable_hmr = 24; + + uint16 port = 25; + MessageLevel logLevel = 26; +} + +struct FileHandle { + string path; + uint size; + uint fd; +} + +message Transform { + FileHandle handle = 1; + string path = 2; + byte[] contents = 3; + + Loader loader = 4; + TransformOptions options = 5; +} + +enum TransformResponseStatus { + success = 1; + fail = 2; +} + +struct OutputFile { + byte[] data; + string path; +} + +struct TransformResponse { + TransformResponseStatus status; + OutputFile[] files; + Message[] errors; +} + +enum MessageLevel { + err = 1; + warn =2; + note = 3; + info = 4; + debug = 5; +} + +struct Location { + string file; + string namespace; + int32 line; + int32 column; + string line_text; + string suggestion; + uint offset; +} + +message MessageData { + string text = 1; + Location location = 2; +} + + + +message MessageMeta { + string resolve = 1; + bool build = 2; +} + +struct Message { + MessageLevel level; + MessageData data; + MessageData[] notes; + MessageMeta on; +} + +struct Log { + uint32 warnings; + uint32 errors; + Message[] msgs; +} + + +smol Reloader { + disable = 1; + // equivalent of CMD + R + live = 2; + // React Fast Refresh + fast_refresh = 3; +} + +// The WebSocket protocol +// Server: "hey, this file changed. Does anyone want it?" +// Browser: *checks array* "uhh yeah, ok. rebuild that for me" +// Server: "here u go" +// This makes the client responsible for tracking which files it needs to listen for. +// From a server perspective, this means the filesystem watching thread can send the same WebSocket message +// to every client, which is good for performance. It means if you have 5 tabs open it won't really be different than one tab +// The clients can just ignore files they don't care about +smol WebsocketMessageKind { + welcome = 1; + file_change_notification = 2; + build_success = 3; + build_fail = 4; + manifest_success = 5; + manifest_fail = 6; + resolve_file = 7; + file_change_notification_with_hint = 8; +} + +smol WebsocketCommandKind { + build = 1; + manifest = 2; + build_with_file_path = 3; +} + +// Each websocket message has two messages in it! +// This is the first. +struct WebsocketMessage { + uint32 timestamp; + WebsocketMessageKind kind; +} + +// This is the first. +struct WebsocketMessageWelcome { + uint32 epoch; + Reloader javascriptReloader; + string cwd; +} + +struct WebsocketMessageFileChangeNotification { + uint32 id; + Loader loader; +} + +struct WebsocketCommand { + WebsocketCommandKind kind; + uint32 timestamp; +} + +// The timestamp is used for client-side deduping +struct WebsocketCommandBuild { + uint32 id; +} + +struct WebsocketCommandManifest { + uint32 id; +} + +// We copy the module_path here incase they don't already have it +struct WebsocketMessageBuildSuccess { + uint32 id; + uint32 from_timestamp; + + Loader loader; + string module_path; + + // This is the length of the blob that immediately follows this message. + uint32 blob_length; +} + +struct WebsocketMessageBuildFailure { + uint32 id; + uint32 from_timestamp; + Loader loader; + + string module_path; + Log log; +} + +struct WebsocketCommandBuildWithFilePath { + uint32 id; + string file_path; +} + +struct WebsocketMessageResolveID { + uint32 id; +} + +struct NPMRegistry { + string url; + string username; + string password; + string token; +} + +struct NPMRegistryMap { + string[] scopes; + NPMRegistry[] registries; +} + +message BunInstall { + NPMRegistry default_registry = 1; + NPMRegistryMap scoped = 2; + string lockfile_path = 3; + string save_lockfile_path = 4; + string cache_directory = 5; + bool dry_run = 6; + bool force = 7; + bool save_dev = 8; + bool save_optional = 9; + bool save_peer = 10; + bool save_lockfile = 11; + bool production = 12; + bool save_yarn_lockfile = 13; + string[] native_bin_links = 14; + + bool disable_cache = 15; + bool disable_manifest_cache = 16; + string global_dir = 17; + string global_bin_dir = 18; +}
\ No newline at end of file diff --git a/src/api/demo/schema.zig b/src/api/demo/schema.zig new file mode 100644 index 000000000..61d6b82d1 --- /dev/null +++ b/src/api/demo/schema.zig @@ -0,0 +1,2878 @@ +const std = @import("std"); + +pub const Reader = struct { + const Self = @This(); + pub const ReadError = error{EOF}; + + buf: []u8, + remain: []u8, + allocator: std.mem.Allocator, + + pub fn init(buf: []u8, allocator: std.mem.Allocator) Reader { + return Reader{ + .buf = buf, + .remain = buf, + .allocator = allocator, + }; + } + + pub fn read(this: *Self, count: usize) ![]u8 { + const read_count = @minimum(count, this.remain.len); + if (read_count < count) { + return error.EOF; + } + + var slice = this.remain[0..read_count]; + + this.remain = this.remain[read_count..]; + + return slice; + } + + pub inline fn readAs(this: *Self, comptime T: type) !T { + if (!std.meta.trait.hasUniqueRepresentation(T)) { + @compileError(@typeName(T) ++ " must have unique representation."); + } + + return std.mem.bytesAsValue(T, try this.read(@sizeOf(T))); + } + + pub inline fn readByte(this: *Self) !u8 { + return (try this.read(1))[0]; + } + + pub fn readEnum(this: *Self, comptime Enum: type) !Enum { + const E = error{ + /// An integer was read, but it did not match any of the tags in the supplied enum. + InvalidValue, + }; + const type_info = @typeInfo(Enum).Enum; + const tag = try this.readInt(type_info.tag_type); + + inline for (std.meta.fields(Enum)) |field| { + if (tag == field.value) { + return @field(Enum, field.name); + } + } + + return E.InvalidValue; + } + + pub inline fn readArray(this: *Self, comptime T: type) ![]const T { + const length = try this.readInt(u32); + if (length == 0) { + return &([_]T{}); + } + + switch (comptime T) { + u8 => { + return try this.read(length); + }, + u16, u32, i8, i16, i32 => { + return std.mem.readIntSliceNative(T, this.read(length * @sizeOf(T))); + }, + [:0]const u8, []const u8 => { + var i: u32 = 0; + var array = try this.allocator.alloc(T, length); + while (i < length) : (i += 1) { + array[i] = try this.readArray(u8); + } + return array; + }, + else => { + switch (comptime @typeInfo(T)) { + .Struct => |Struct| { + switch (Struct.layout) { + .Packed => { + const sizeof = @sizeOf(T); + var slice = try this.read(sizeof * length); + return std.mem.bytesAsSlice(T, slice); + }, + else => {}, + } + }, + .Enum => |type_info| { + const enum_values = try this.read(length * @sizeOf(type_info.tag_type)); + return @ptrCast([*]T, enum_values.ptr)[0..length]; + }, + else => {}, + } + + var i: u32 = 0; + var array = try this.allocator.alloc(T, length); + while (i < length) : (i += 1) { + array[i] = try this.readValue(T); + } + + return array; + }, + } + } + + pub inline fn readByteArray(this: *Self) ![]u8 { + const length = try this.readInt(u32); + if (length == 0) { + return &([_]u8{}); + } + + return try this.read(@as(usize, length)); + } + + pub inline fn readInt(this: *Self, comptime T: type) !T { + var slice = try this.read(@sizeOf(T)); + + return std.mem.readIntSliceNative(T, slice); + } + + pub inline fn readBool(this: *Self) !bool { + return (try this.readByte()) > 0; + } + + pub inline fn readValue(this: *Self, comptime T: type) !T { + switch (comptime T) { + bool => { + return try this.readBool(); + }, + u8 => { + return try this.readByte(); + }, + [*:0]const u8, [:0]const u8, []const u8 => { + return try this.readArray(u8); + }, + + []const [:0]const u8, []const [*:0]const u8, []const []const u8 => { + return try this.readArray([]const u8); + }, + []u8, [:0]u8, [*:0]u8 => { + return try this.readArray([]u8); + }, + u16, u32, i8, i16, i32 => { + return std.mem.readIntSliceNative(T, try this.read(@sizeOf(T))); + }, + else => { + switch (comptime @typeInfo(T)) { + .Struct => |Struct| { + switch (Struct.layout) { + .Packed => { + const sizeof = @sizeOf(T); + var slice = try this.read(sizeof); + return @ptrCast(*T, slice[0..sizeof]).*; + }, + else => {}, + } + }, + .Enum => { + return try this.readEnum(T); + }, + else => {}, + } + + return try T.decode(this); + }, + } + + @compileError("Invalid type passed to readValue"); + } +}; + +pub fn Writer(comptime WritableStream: type) type { + return struct { + const Self = @This(); + writable: WritableStream, + + pub fn init(writable: WritableStream) Self { + return Self{ .writable = writable }; + } + + pub inline fn write(this: *Self, bytes: anytype) !void { + _ = try this.writable.write(bytes); + } + + pub inline fn writeByte(this: *Self, byte: u8) !void { + _ = try this.writable.write(&[1]u8{byte}); + } + + pub inline fn writeInt(this: *Self, int: anytype) !void { + try this.write(std.mem.asBytes(&int)); + } + + pub inline fn writeFieldID(this: *Self, comptime id: comptime_int) !void { + try this.writeByte(id); + } + + pub inline fn writeEnum(this: *Self, val: anytype) !void { + try this.writeInt(@enumToInt(val)); + } + + pub fn writeValue(this: *Self, comptime SliceType: type, slice: SliceType) !void { + switch (SliceType) { + []u16, + []u32, + []i16, + []i32, + []i8, + []const u16, + []const u32, + []const i16, + []const i32, + []const i8, + [:0]u16, + [:0]u32, + [:0]i16, + [:0]i32, + [:0]i8, + [:0]const u16, + [:0]const u32, + [:0]const i16, + [:0]const i32, + [:0]const i8, + [*:0]u16, + [*:0]u32, + [*:0]i16, + [*:0]i32, + [*:0]i8, + [*:0]const u16, + [*:0]const u32, + [*:0]const i16, + [*:0]const i32, + [*:0]const i8, + => { + try this.writeArray(SliceType, slice); + }, + + []u8, + []const u8, + [:0]u8, + [:0]const u8, + [*:0]u8, + [*:0]const u8, + => { + try this.writeArray(u8, slice); + }, + + u8 => { + try this.write(slice); + }, + u16, u32, i16, i32, i8 => { + try this.write(std.mem.asBytes(slice)); + }, + + else => { + try slice.encode(this); + }, + } + } + + pub inline fn writeArray(this: *Self, comptime T: type, slice: anytype) !void { + try this.writeInt(@truncate(u32, slice.len)); + + switch (T) { + u8 => { + try this.write(slice); + }, + u16, u32, i16, i32, i8 => { + try this.write(std.mem.asBytes(slice)); + }, + [:0]u8, + []u8, + []u16, + []u32, + []i16, + []i32, + []i8, + []const u8, + [:0]const u8, + []const u16, + []const u32, + []const i16, + []const i32, + []const i8, + [:0]u16, + [:0]u32, + [:0]i16, + [:0]i32, + [:0]i8, + [:0]const u16, + [:0]const u32, + [:0]const i16, + [:0]const i32, + [:0]const i8, + [*:0]u16, + [*:0]u32, + [*:0]i16, + [*:0]i32, + [*:0]i8, + [*:0]const u16, + [*:0]const u32, + [*:0]const i16, + [*:0]const i32, + [*:0]const i8, + => { + for (slice) |num_slice| { + try this.writeArray(std.meta.Child(@TypeOf(num_slice)), num_slice); + } + }, + else => { + for (slice) |val| { + try val.encode(this); + } + }, + } + } + + pub inline fn endMessage(this: *Self) !void { + try this.writeByte(0); + } + }; +} + +pub const ByteWriter = Writer(*std.io.FixedBufferStream([]u8)); +pub const FileWriter = Writer(std.fs.File); + +pub const Api = struct { + pub const Loader = enum(u8) { + _none, + /// jsx + jsx, + + /// js + js, + + /// ts + ts, + + /// tsx + tsx, + + /// css + css, + + /// file + file, + + /// json + json, + + /// toml + toml, + + /// wasm + wasm, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const FrameworkEntryPointType = enum(u8) { + _none, + /// client + client, + + /// server + server, + + /// fallback + fallback, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const StackFrameScope = enum(u8) { + _none, + /// Eval + eval, + + /// Module + module, + + /// Function + function, + + /// Global + global, + + /// Wasm + wasm, + + /// Constructor + constructor, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const StackFrame = struct { + /// function_name + function_name: []const u8, + + /// file + file: []const u8, + + /// position + position: StackFramePosition, + + /// scope + scope: StackFrameScope, + + pub fn decode(reader: anytype) anyerror!StackFrame { + var this = std.mem.zeroes(StackFrame); + + this.function_name = try reader.readValue([]const u8); + this.file = try reader.readValue([]const u8); + this.position = try reader.readValue(StackFramePosition); + this.scope = try reader.readValue(StackFrameScope); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.function_name), this.function_name); + try writer.writeValue(@TypeOf(this.file), this.file); + try writer.writeValue(@TypeOf(this.position), this.position); + try writer.writeEnum(this.scope); + } + }; + + pub const StackFramePosition = packed struct { + /// source_offset + source_offset: i32 = 0, + + /// line + line: i32 = 0, + + /// line_start + line_start: i32 = 0, + + /// line_stop + line_stop: i32 = 0, + + /// column_start + column_start: i32 = 0, + + /// column_stop + column_stop: i32 = 0, + + /// expression_start + expression_start: i32 = 0, + + /// expression_stop + expression_stop: i32 = 0, + + pub fn decode(reader: anytype) anyerror!StackFramePosition { + var this = std.mem.zeroes(StackFramePosition); + + this.source_offset = try reader.readValue(i32); + this.line = try reader.readValue(i32); + this.line_start = try reader.readValue(i32); + this.line_stop = try reader.readValue(i32); + this.column_start = try reader.readValue(i32); + this.column_stop = try reader.readValue(i32); + this.expression_start = try reader.readValue(i32); + this.expression_stop = try reader.readValue(i32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.source_offset); + try writer.writeInt(this.line); + try writer.writeInt(this.line_start); + try writer.writeInt(this.line_stop); + try writer.writeInt(this.column_start); + try writer.writeInt(this.column_stop); + try writer.writeInt(this.expression_start); + try writer.writeInt(this.expression_stop); + } + }; + + pub const SourceLine = struct { + /// line + line: i32 = 0, + + /// text + text: []const u8, + + pub fn decode(reader: anytype) anyerror!SourceLine { + var this = std.mem.zeroes(SourceLine); + + this.line = try reader.readValue(i32); + this.text = try reader.readValue([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.line); + try writer.writeValue(@TypeOf(this.text), this.text); + } + }; + + pub const StackTrace = struct { + /// source_lines + source_lines: []const SourceLine, + + /// frames + frames: []const StackFrame, + + pub fn decode(reader: anytype) anyerror!StackTrace { + var this = std.mem.zeroes(StackTrace); + + this.source_lines = try reader.readArray(SourceLine); + this.frames = try reader.readArray(StackFrame); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray(SourceLine, this.source_lines); + try writer.writeArray(StackFrame, this.frames); + } + }; + + pub const JsException = struct { + /// name + name: ?[]const u8 = null, + + /// message + message: ?[]const u8 = null, + + /// runtime_type + runtime_type: ?u16 = null, + + /// code + code: ?u8 = null, + + /// stack + stack: ?StackTrace = null, + + pub fn decode(reader: anytype) anyerror!JsException { + var this = std.mem.zeroes(JsException); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.name = try reader.readValue([]const u8); + }, + 2 => { + this.message = try reader.readValue([]const u8); + }, + 3 => { + this.runtime_type = try reader.readValue(u16); + }, + 4 => { + this.code = try reader.readValue(u8); + }, + 5 => { + this.stack = try reader.readValue(StackTrace); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.name) |name| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(name), name); + } + if (this.message) |message| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(message), message); + } + if (this.runtime_type) |runtime_type| { + try writer.writeFieldID(3); + try writer.writeInt(runtime_type); + } + if (this.code) |code| { + try writer.writeFieldID(4); + try writer.writeInt(code); + } + if (this.stack) |stack| { + try writer.writeFieldID(5); + try writer.writeValue(@TypeOf(stack), stack); + } + try writer.endMessage(); + } + }; + + pub const FallbackStep = enum(u8) { + _none, + /// ssr_disabled + ssr_disabled, + + /// create_vm + create_vm, + + /// configure_router + configure_router, + + /// configure_defines + configure_defines, + + /// resolve_entry_point + resolve_entry_point, + + /// load_entry_point + load_entry_point, + + /// eval_entry_point + eval_entry_point, + + /// fetch_event_handler + fetch_event_handler, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const Problems = struct { + /// code + code: u16 = 0, + + /// name + name: []const u8, + + /// exceptions + exceptions: []const JsException, + + /// build + build: Log, + + pub fn decode(reader: anytype) anyerror!Problems { + var this = std.mem.zeroes(Problems); + + this.code = try reader.readValue(u16); + this.name = try reader.readValue([]const u8); + this.exceptions = try reader.readArray(JsException); + this.build = try reader.readValue(Log); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.code); + try writer.writeValue(@TypeOf(this.name), this.name); + try writer.writeArray(JsException, this.exceptions); + try writer.writeValue(@TypeOf(this.build), this.build); + } + }; + + pub const Router = struct { + /// routes + routes: StringMap, + + /// route + route: i32 = 0, + + /// params + params: StringMap, + + pub fn decode(reader: anytype) anyerror!Router { + var this = std.mem.zeroes(Router); + + this.routes = try reader.readValue(StringMap); + this.route = try reader.readValue(i32); + this.params = try reader.readValue(StringMap); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.routes), this.routes); + try writer.writeInt(this.route); + try writer.writeValue(@TypeOf(this.params), this.params); + } + }; + + pub const FallbackMessageContainer = struct { + /// message + message: ?[]const u8 = null, + + /// router + router: ?Router = null, + + /// reason + reason: ?FallbackStep = null, + + /// problems + problems: ?Problems = null, + + /// cwd + cwd: ?[]const u8 = null, + + pub fn decode(reader: anytype) anyerror!FallbackMessageContainer { + var this = std.mem.zeroes(FallbackMessageContainer); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.message = try reader.readValue([]const u8); + }, + 2 => { + this.router = try reader.readValue(Router); + }, + 3 => { + this.reason = try reader.readValue(FallbackStep); + }, + 4 => { + this.problems = try reader.readValue(Problems); + }, + 5 => { + this.cwd = try reader.readValue([]const u8); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.message) |message| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(message), message); + } + if (this.router) |router| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(router), router); + } + if (this.reason) |reason| { + try writer.writeFieldID(3); + try writer.writeEnum(reason); + } + if (this.problems) |problems| { + try writer.writeFieldID(4); + try writer.writeValue(@TypeOf(problems), problems); + } + if (this.cwd) |cwd| { + try writer.writeFieldID(5); + try writer.writeValue(@TypeOf(cwd), cwd); + } + try writer.endMessage(); + } + }; + + pub const ResolveMode = enum(u8) { + _none, + /// disable + disable, + + /// lazy + lazy, + + /// dev + dev, + + /// bundle + bundle, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const Platform = enum(u8) { + _none, + /// browser + browser, + + /// node + node, + + /// bun + bun, + + /// bun_macro + bun_macro, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const CssInJsBehavior = enum(u8) { + _none, + /// facade + facade, + + /// facade_onimportcss + facade_onimportcss, + + /// auto_onimportcss + auto_onimportcss, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const JsxRuntime = enum(u8) { + _none, + /// automatic + automatic, + + /// classic + classic, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const Jsx = struct { + /// factory + factory: []const u8, + + /// runtime + runtime: JsxRuntime, + + /// fragment + fragment: []const u8, + + /// development + development: bool = false, + + /// import_source + import_source: []const u8, + + /// react_fast_refresh + react_fast_refresh: bool = false, + + pub fn decode(reader: anytype) anyerror!Jsx { + var this = std.mem.zeroes(Jsx); + + this.factory = try reader.readValue([]const u8); + this.runtime = try reader.readValue(JsxRuntime); + this.fragment = try reader.readValue([]const u8); + this.development = try reader.readValue(bool); + this.import_source = try reader.readValue([]const u8); + this.react_fast_refresh = try reader.readValue(bool); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.factory), this.factory); + try writer.writeEnum(this.runtime); + try writer.writeValue(@TypeOf(this.fragment), this.fragment); + try writer.writeInt(@as(u8, @boolToInt(this.development))); + try writer.writeValue(@TypeOf(this.import_source), this.import_source); + try writer.writeInt(@as(u8, @boolToInt(this.react_fast_refresh))); + } + }; + + pub const StringPointer = packed struct { + /// offset + offset: u32 = 0, + + /// length + length: u32 = 0, + + pub fn decode(reader: anytype) anyerror!StringPointer { + var this = std.mem.zeroes(StringPointer); + + this.offset = try reader.readValue(u32); + this.length = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.offset); + try writer.writeInt(this.length); + } + }; + + pub const JavascriptBundledModule = struct { + /// path + path: StringPointer, + + /// code + code: StringPointer, + + /// package_id + package_id: u32 = 0, + + /// id + id: u32 = 0, + + /// path_extname_length + path_extname_length: u8 = 0, + + pub fn decode(reader: anytype) anyerror!JavascriptBundledModule { + var this = std.mem.zeroes(JavascriptBundledModule); + + this.path = try reader.readValue(StringPointer); + this.code = try reader.readValue(StringPointer); + this.package_id = try reader.readValue(u32); + this.id = try reader.readValue(u32); + this.path_extname_length = try reader.readValue(u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeValue(@TypeOf(this.code), this.code); + try writer.writeInt(this.package_id); + try writer.writeInt(this.id); + try writer.writeInt(this.path_extname_length); + } + }; + + pub const JavascriptBundledPackage = struct { + /// name + name: StringPointer, + + /// version + version: StringPointer, + + /// hash + hash: u32 = 0, + + /// modules_offset + modules_offset: u32 = 0, + + /// modules_length + modules_length: u32 = 0, + + pub fn decode(reader: anytype) anyerror!JavascriptBundledPackage { + var this = std.mem.zeroes(JavascriptBundledPackage); + + this.name = try reader.readValue(StringPointer); + this.version = try reader.readValue(StringPointer); + this.hash = try reader.readValue(u32); + this.modules_offset = try reader.readValue(u32); + this.modules_length = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.name), this.name); + try writer.writeValue(@TypeOf(this.version), this.version); + try writer.writeInt(this.hash); + try writer.writeInt(this.modules_offset); + try writer.writeInt(this.modules_length); + } + }; + + pub const JavascriptBundle = struct { + /// modules + modules: []const JavascriptBundledModule, + + /// packages + packages: []const JavascriptBundledPackage, + + /// etag + etag: []const u8, + + /// generated_at + generated_at: u32 = 0, + + /// app_package_json_dependencies_hash + app_package_json_dependencies_hash: []const u8, + + /// import_from_name + import_from_name: []const u8, + + /// manifest_string + manifest_string: []const u8, + + pub fn decode(reader: anytype) anyerror!JavascriptBundle { + var this = std.mem.zeroes(JavascriptBundle); + + this.modules = try reader.readArray(JavascriptBundledModule); + this.packages = try reader.readArray(JavascriptBundledPackage); + this.etag = try reader.readArray(u8); + this.generated_at = try reader.readValue(u32); + this.app_package_json_dependencies_hash = try reader.readArray(u8); + this.import_from_name = try reader.readArray(u8); + this.manifest_string = try reader.readArray(u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray(JavascriptBundledModule, this.modules); + try writer.writeArray(JavascriptBundledPackage, this.packages); + try writer.writeArray(u8, this.etag); + try writer.writeInt(this.generated_at); + try writer.writeArray(u8, this.app_package_json_dependencies_hash); + try writer.writeArray(u8, this.import_from_name); + try writer.writeArray(u8, this.manifest_string); + } + }; + + pub const JavascriptBundleContainer = struct { + /// bundle_format_version + bundle_format_version: ?u32 = null, + + /// routes + routes: ?LoadedRouteConfig = null, + + /// framework + framework: ?LoadedFramework = null, + + /// bundle + bundle: ?JavascriptBundle = null, + + /// code_length + code_length: ?u32 = null, + + pub fn decode(reader: anytype) anyerror!JavascriptBundleContainer { + var this = std.mem.zeroes(JavascriptBundleContainer); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.bundle_format_version = try reader.readValue(u32); + }, + 2 => { + this.routes = try reader.readValue(LoadedRouteConfig); + }, + 3 => { + this.framework = try reader.readValue(LoadedFramework); + }, + 4 => { + this.bundle = try reader.readValue(JavascriptBundle); + }, + 5 => { + this.code_length = try reader.readValue(u32); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.bundle_format_version) |bundle_format_version| { + try writer.writeFieldID(1); + try writer.writeInt(bundle_format_version); + } + if (this.routes) |routes| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(routes), routes); + } + if (this.framework) |framework| { + try writer.writeFieldID(3); + try writer.writeValue(@TypeOf(framework), framework); + } + if (this.bundle) |bundle| { + try writer.writeFieldID(4); + try writer.writeValue(@TypeOf(bundle), bundle); + } + if (this.code_length) |code_length| { + try writer.writeFieldID(5); + try writer.writeInt(code_length); + } + try writer.endMessage(); + } + }; + + pub const ScanDependencyMode = enum(u8) { + _none, + /// app + app, + + /// all + all, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const ModuleImportType = enum(u8) { + _none, + /// import + import, + + /// require + require, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const ModuleImportRecord = struct { + /// kind + kind: ModuleImportType, + + /// path + path: []const u8, + + /// dynamic + dynamic: bool = false, + + pub fn decode(reader: anytype) anyerror!ModuleImportRecord { + var this = std.mem.zeroes(ModuleImportRecord); + + this.kind = try reader.readValue(ModuleImportType); + this.path = try reader.readValue([]const u8); + this.dynamic = try reader.readValue(bool); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeEnum(this.kind); + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeInt(@as(u8, @boolToInt(this.dynamic))); + } + }; + + pub const Module = struct { + /// path + path: []const u8, + + /// imports + imports: []const ModuleImportRecord, + + pub fn decode(reader: anytype) anyerror!Module { + var this = std.mem.zeroes(Module); + + this.path = try reader.readValue([]const u8); + this.imports = try reader.readArray(ModuleImportRecord); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeArray(ModuleImportRecord, this.imports); + } + }; + + pub const StringMap = struct { + /// keys + keys: []const []const u8, + + /// values + values: []const []const u8, + + pub fn decode(reader: anytype) anyerror!StringMap { + var this = std.mem.zeroes(StringMap); + + this.keys = try reader.readArray([]const u8); + this.values = try reader.readArray([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray([]const u8, this.keys); + try writer.writeArray([]const u8, this.values); + } + }; + + pub const LoaderMap = struct { + /// extensions + extensions: []const []const u8, + + /// loaders + loaders: []const Loader, + + pub fn decode(reader: anytype) anyerror!LoaderMap { + var this = std.mem.zeroes(LoaderMap); + + this.extensions = try reader.readArray([]const u8); + this.loaders = try reader.readArray(Loader); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray([]const u8, this.extensions); + try writer.writeArray(Loader, this.loaders); + } + }; + + pub const DotEnvBehavior = enum(u32) { + _none, + /// disable + disable, + + /// prefix + prefix, + + /// load_all + load_all, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const EnvConfig = struct { + /// prefix + prefix: ?[]const u8 = null, + + /// defaults + defaults: ?StringMap = null, + + pub fn decode(reader: anytype) anyerror!EnvConfig { + var this = std.mem.zeroes(EnvConfig); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.prefix = try reader.readValue([]const u8); + }, + 2 => { + this.defaults = try reader.readValue(StringMap); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.prefix) |prefix| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(prefix), prefix); + } + if (this.defaults) |defaults| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(defaults), defaults); + } + try writer.endMessage(); + } + }; + + pub const LoadedEnvConfig = struct { + /// dotenv + dotenv: DotEnvBehavior, + + /// defaults + defaults: StringMap, + + /// prefix + prefix: []const u8, + + pub fn decode(reader: anytype) anyerror!LoadedEnvConfig { + var this = std.mem.zeroes(LoadedEnvConfig); + + this.dotenv = try reader.readValue(DotEnvBehavior); + this.defaults = try reader.readValue(StringMap); + this.prefix = try reader.readValue([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeEnum(this.dotenv); + try writer.writeValue(@TypeOf(this.defaults), this.defaults); + try writer.writeValue(@TypeOf(this.prefix), this.prefix); + } + }; + + pub const FrameworkConfig = struct { + /// package + package: ?[]const u8 = null, + + /// client + client: ?FrameworkEntryPointMessage = null, + + /// server + server: ?FrameworkEntryPointMessage = null, + + /// fallback + fallback: ?FrameworkEntryPointMessage = null, + + /// development + development: ?bool = null, + + /// client_css_in_js + client_css_in_js: ?CssInJsBehavior = null, + + /// display_name + display_name: ?[]const u8 = null, + + /// overrideModules + override_modules: ?StringMap = null, + + pub fn decode(reader: anytype) anyerror!FrameworkConfig { + var this = std.mem.zeroes(FrameworkConfig); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.package = try reader.readValue([]const u8); + }, + 2 => { + this.client = try reader.readValue(FrameworkEntryPointMessage); + }, + 3 => { + this.server = try reader.readValue(FrameworkEntryPointMessage); + }, + 4 => { + this.fallback = try reader.readValue(FrameworkEntryPointMessage); + }, + 5 => { + this.development = try reader.readValue(bool); + }, + 6 => { + this.client_css_in_js = try reader.readValue(CssInJsBehavior); + }, + 7 => { + this.display_name = try reader.readValue([]const u8); + }, + 8 => { + this.override_modules = try reader.readValue(StringMap); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.package) |package| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(package), package); + } + if (this.client) |client| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(client), client); + } + if (this.server) |server| { + try writer.writeFieldID(3); + try writer.writeValue(@TypeOf(server), server); + } + if (this.fallback) |fallback| { + try writer.writeFieldID(4); + try writer.writeValue(@TypeOf(fallback), fallback); + } + if (this.development) |development| { + try writer.writeFieldID(5); + try writer.writeInt(@as(u8, @boolToInt(development))); + } + if (this.client_css_in_js) |client_css_in_js| { + try writer.writeFieldID(6); + try writer.writeEnum(client_css_in_js); + } + if (this.display_name) |display_name| { + try writer.writeFieldID(7); + try writer.writeValue(@TypeOf(display_name), display_name); + } + if (this.override_modules) |override_modules| { + try writer.writeFieldID(8); + try writer.writeValue(@TypeOf(override_modules), override_modules); + } + try writer.endMessage(); + } + }; + + pub const FrameworkEntryPoint = struct { + /// kind + kind: FrameworkEntryPointType, + + /// path + path: []const u8, + + /// env + env: LoadedEnvConfig, + + pub fn decode(reader: anytype) anyerror!FrameworkEntryPoint { + var this = std.mem.zeroes(FrameworkEntryPoint); + + this.kind = try reader.readValue(FrameworkEntryPointType); + this.path = try reader.readValue([]const u8); + this.env = try reader.readValue(LoadedEnvConfig); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeEnum(this.kind); + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeValue(@TypeOf(this.env), this.env); + } + }; + + pub const FrameworkEntryPointMap = struct { + /// client + client: ?FrameworkEntryPoint = null, + + /// server + server: ?FrameworkEntryPoint = null, + + /// fallback + fallback: ?FrameworkEntryPoint = null, + + pub fn decode(reader: anytype) anyerror!FrameworkEntryPointMap { + var this = std.mem.zeroes(FrameworkEntryPointMap); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.client = try reader.readValue(FrameworkEntryPoint); + }, + 2 => { + this.server = try reader.readValue(FrameworkEntryPoint); + }, + 3 => { + this.fallback = try reader.readValue(FrameworkEntryPoint); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.client) |client| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(client), client); + } + if (this.server) |server| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(server), server); + } + if (this.fallback) |fallback| { + try writer.writeFieldID(3); + try writer.writeValue(@TypeOf(fallback), fallback); + } + try writer.endMessage(); + } + }; + + pub const FrameworkEntryPointMessage = struct { + /// path + path: ?[]const u8 = null, + + /// env + env: ?EnvConfig = null, + + pub fn decode(reader: anytype) anyerror!FrameworkEntryPointMessage { + var this = std.mem.zeroes(FrameworkEntryPointMessage); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.path = try reader.readValue([]const u8); + }, + 2 => { + this.env = try reader.readValue(EnvConfig); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.path) |path| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(path), path); + } + if (this.env) |env| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(env), env); + } + try writer.endMessage(); + } + }; + + pub const LoadedFramework = struct { + /// package + package: []const u8, + + /// display_name + display_name: []const u8, + + /// development + development: bool = false, + + /// entry_points + entry_points: FrameworkEntryPointMap, + + /// client_css_in_js + client_css_in_js: CssInJsBehavior, + + /// overrideModules + override_modules: StringMap, + + pub fn decode(reader: anytype) anyerror!LoadedFramework { + var this = std.mem.zeroes(LoadedFramework); + + this.package = try reader.readValue([]const u8); + this.display_name = try reader.readValue([]const u8); + this.development = try reader.readValue(bool); + this.entry_points = try reader.readValue(FrameworkEntryPointMap); + this.client_css_in_js = try reader.readValue(CssInJsBehavior); + this.override_modules = try reader.readValue(StringMap); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.package), this.package); + try writer.writeValue(@TypeOf(this.display_name), this.display_name); + try writer.writeInt(@as(u8, @boolToInt(this.development))); + try writer.writeValue(@TypeOf(this.entry_points), this.entry_points); + try writer.writeEnum(this.client_css_in_js); + try writer.writeValue(@TypeOf(this.override_modules), this.override_modules); + } + }; + + pub const LoadedRouteConfig = struct { + /// dir + dir: []const u8, + + /// extensions + extensions: []const []const u8, + + /// static_dir + static_dir: []const u8, + + /// asset_prefix + asset_prefix: []const u8, + + pub fn decode(reader: anytype) anyerror!LoadedRouteConfig { + var this = std.mem.zeroes(LoadedRouteConfig); + + this.dir = try reader.readValue([]const u8); + this.extensions = try reader.readArray([]const u8); + this.static_dir = try reader.readValue([]const u8); + this.asset_prefix = try reader.readValue([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.dir), this.dir); + try writer.writeArray([]const u8, this.extensions); + try writer.writeValue(@TypeOf(this.static_dir), this.static_dir); + try writer.writeValue(@TypeOf(this.asset_prefix), this.asset_prefix); + } + }; + + pub const RouteConfig = struct { + /// dir + dir: []const []const u8, + + /// extensions + extensions: []const []const u8, + + /// static_dir + static_dir: ?[]const u8 = null, + + /// asset_prefix + asset_prefix: ?[]const u8 = null, + + pub fn decode(reader: anytype) anyerror!RouteConfig { + var this = std.mem.zeroes(RouteConfig); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.dir = try reader.readArray([]const u8); + }, + 2 => { + this.extensions = try reader.readArray([]const u8); + }, + 3 => { + this.static_dir = try reader.readValue([]const u8); + }, + 4 => { + this.asset_prefix = try reader.readValue([]const u8); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.dir) |dir| { + try writer.writeFieldID(1); + try writer.writeArray([]const u8, dir); + } + if (this.extensions) |extensions| { + try writer.writeFieldID(2); + try writer.writeArray([]const u8, extensions); + } + if (this.static_dir) |static_dir| { + try writer.writeFieldID(3); + try writer.writeValue(@TypeOf(static_dir), static_dir); + } + if (this.asset_prefix) |asset_prefix| { + try writer.writeFieldID(4); + try writer.writeValue(@TypeOf(asset_prefix), asset_prefix); + } + try writer.endMessage(); + } + }; + + pub const TransformOptions = struct { + /// jsx + jsx: ?Jsx = null, + + /// tsconfig_override + tsconfig_override: ?[]const u8 = null, + + /// resolve + resolve: ?ResolveMode = null, + + /// origin + origin: ?[]const u8 = null, + + /// absolute_working_dir + absolute_working_dir: ?[]const u8 = null, + + /// define + define: ?StringMap = null, + + /// preserve_symlinks + preserve_symlinks: ?bool = null, + + /// entry_points + entry_points: []const []const u8, + + /// write + write: ?bool = null, + + /// inject + inject: []const []const u8, + + /// output_dir + output_dir: ?[]const u8 = null, + + /// external + external: []const []const u8, + + /// loaders + loaders: ?LoaderMap = null, + + /// main_fields + main_fields: []const []const u8, + + /// platform + platform: ?Platform = null, + + /// serve + serve: ?bool = null, + + /// extension_order + extension_order: []const []const u8, + + /// generate_node_module_bundle + generate_node_module_bundle: ?bool = null, + + /// node_modules_bundle_path + node_modules_bundle_path: ?[]const u8 = null, + + /// node_modules_bundle_path_server + node_modules_bundle_path_server: ?[]const u8 = null, + + /// framework + framework: ?FrameworkConfig = null, + + /// router + router: ?RouteConfig = null, + + /// no_summary + no_summary: ?bool = null, + + /// disable_hmr + disable_hmr: ?bool = null, + + /// port + port: ?u16 = null, + + /// logLevel + log_level: ?MessageLevel = null, + + pub fn decode(reader: anytype) anyerror!TransformOptions { + var this = std.mem.zeroes(TransformOptions); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.jsx = try reader.readValue(Jsx); + }, + 2 => { + this.tsconfig_override = try reader.readValue([]const u8); + }, + 3 => { + this.resolve = try reader.readValue(ResolveMode); + }, + 4 => { + this.origin = try reader.readValue([]const u8); + }, + 5 => { + this.absolute_working_dir = try reader.readValue([]const u8); + }, + 6 => { + this.define = try reader.readValue(StringMap); + }, + 7 => { + this.preserve_symlinks = try reader.readValue(bool); + }, + 8 => { + this.entry_points = try reader.readArray([]const u8); + }, + 9 => { + this.write = try reader.readValue(bool); + }, + 10 => { + this.inject = try reader.readArray([]const u8); + }, + 11 => { + this.output_dir = try reader.readValue([]const u8); + }, + 12 => { + this.external = try reader.readArray([]const u8); + }, + 13 => { + this.loaders = try reader.readValue(LoaderMap); + }, + 14 => { + this.main_fields = try reader.readArray([]const u8); + }, + 15 => { + this.platform = try reader.readValue(Platform); + }, + 16 => { + this.serve = try reader.readValue(bool); + }, + 17 => { + this.extension_order = try reader.readArray([]const u8); + }, + 18 => { + this.generate_node_module_bundle = try reader.readValue(bool); + }, + 19 => { + this.node_modules_bundle_path = try reader.readValue([]const u8); + }, + 20 => { + this.node_modules_bundle_path_server = try reader.readValue([]const u8); + }, + 21 => { + this.framework = try reader.readValue(FrameworkConfig); + }, + 22 => { + this.router = try reader.readValue(RouteConfig); + }, + 23 => { + this.no_summary = try reader.readValue(bool); + }, + 24 => { + this.disable_hmr = try reader.readValue(bool); + }, + 25 => { + this.port = try reader.readValue(u16); + }, + 26 => { + this.log_level = try reader.readValue(MessageLevel); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.jsx) |jsx| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(jsx), jsx); + } + if (this.tsconfig_override) |tsconfig_override| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(tsconfig_override), tsconfig_override); + } + if (this.resolve) |resolve| { + try writer.writeFieldID(3); + try writer.writeEnum(resolve); + } + if (this.origin) |origin| { + try writer.writeFieldID(4); + try writer.writeValue(@TypeOf(origin), origin); + } + if (this.absolute_working_dir) |absolute_working_dir| { + try writer.writeFieldID(5); + try writer.writeValue(@TypeOf(absolute_working_dir), absolute_working_dir); + } + if (this.define) |define| { + try writer.writeFieldID(6); + try writer.writeValue(@TypeOf(define), define); + } + if (this.preserve_symlinks) |preserve_symlinks| { + try writer.writeFieldID(7); + try writer.writeInt(@as(u8, @boolToInt(preserve_symlinks))); + } + if (this.entry_points) |entry_points| { + try writer.writeFieldID(8); + try writer.writeArray([]const u8, entry_points); + } + if (this.write) |write| { + try writer.writeFieldID(9); + try writer.writeInt(@as(u8, @boolToInt(write))); + } + if (this.inject) |inject| { + try writer.writeFieldID(10); + try writer.writeArray([]const u8, inject); + } + if (this.output_dir) |output_dir| { + try writer.writeFieldID(11); + try writer.writeValue(@TypeOf(output_dir), output_dir); + } + if (this.external) |external| { + try writer.writeFieldID(12); + try writer.writeArray([]const u8, external); + } + if (this.loaders) |loaders| { + try writer.writeFieldID(13); + try writer.writeValue(@TypeOf(loaders), loaders); + } + if (this.main_fields) |main_fields| { + try writer.writeFieldID(14); + try writer.writeArray([]const u8, main_fields); + } + if (this.platform) |platform| { + try writer.writeFieldID(15); + try writer.writeEnum(platform); + } + if (this.serve) |serve| { + try writer.writeFieldID(16); + try writer.writeInt(@as(u8, @boolToInt(serve))); + } + if (this.extension_order) |extension_order| { + try writer.writeFieldID(17); + try writer.writeArray([]const u8, extension_order); + } + if (this.generate_node_module_bundle) |generate_node_module_bundle| { + try writer.writeFieldID(18); + try writer.writeInt(@as(u8, @boolToInt(generate_node_module_bundle))); + } + if (this.node_modules_bundle_path) |node_modules_bundle_path| { + try writer.writeFieldID(19); + try writer.writeValue(@TypeOf(node_modules_bundle_path), node_modules_bundle_path); + } + if (this.node_modules_bundle_path_server) |node_modules_bundle_path_server| { + try writer.writeFieldID(20); + try writer.writeValue(@TypeOf(node_modules_bundle_path_server), node_modules_bundle_path_server); + } + if (this.framework) |framework| { + try writer.writeFieldID(21); + try writer.writeValue(@TypeOf(framework), framework); + } + if (this.router) |router| { + try writer.writeFieldID(22); + try writer.writeValue(@TypeOf(router), router); + } + if (this.no_summary) |no_summary| { + try writer.writeFieldID(23); + try writer.writeInt(@as(u8, @boolToInt(no_summary))); + } + if (this.disable_hmr) |disable_hmr| { + try writer.writeFieldID(24); + try writer.writeInt(@as(u8, @boolToInt(disable_hmr))); + } + if (this.port) |port| { + try writer.writeFieldID(25); + try writer.writeInt(port); + } + if (this.log_level) |log_level| { + try writer.writeFieldID(26); + try writer.writeEnum(log_level); + } + try writer.endMessage(); + } + }; + + pub const FileHandle = struct { + /// path + path: []const u8, + + /// size + size: u32 = 0, + + /// fd + fd: u32 = 0, + + pub fn decode(reader: anytype) anyerror!FileHandle { + var this = std.mem.zeroes(FileHandle); + + this.path = try reader.readValue([]const u8); + this.size = try reader.readValue(u32); + this.fd = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeInt(this.size); + try writer.writeInt(this.fd); + } + }; + + pub const Transform = struct { + /// handle + handle: ?FileHandle = null, + + /// path + path: ?[]const u8 = null, + + /// contents + contents: []const u8, + + /// loader + loader: ?Loader = null, + + /// options + options: ?TransformOptions = null, + + pub fn decode(reader: anytype) anyerror!Transform { + var this = std.mem.zeroes(Transform); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.handle = try reader.readValue(FileHandle); + }, + 2 => { + this.path = try reader.readValue([]const u8); + }, + 3 => { + this.contents = try reader.readArray(u8); + }, + 4 => { + this.loader = try reader.readValue(Loader); + }, + 5 => { + this.options = try reader.readValue(TransformOptions); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.handle) |handle| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(handle), handle); + } + if (this.path) |path| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(path), path); + } + if (this.contents) |contents| { + try writer.writeFieldID(3); + try writer.writeArray(u8, contents); + } + if (this.loader) |loader| { + try writer.writeFieldID(4); + try writer.writeEnum(loader); + } + if (this.options) |options| { + try writer.writeFieldID(5); + try writer.writeValue(@TypeOf(options), options); + } + try writer.endMessage(); + } + }; + + pub const TransformResponseStatus = enum(u32) { + _none, + /// success + success, + + /// fail + fail, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const OutputFile = struct { + /// data + data: []const u8, + + /// path + path: []const u8, + + pub fn decode(reader: anytype) anyerror!OutputFile { + var this = std.mem.zeroes(OutputFile); + + this.data = try reader.readArray(u8); + this.path = try reader.readValue([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray(u8, this.data); + try writer.writeValue(@TypeOf(this.path), this.path); + } + }; + + pub const TransformResponse = struct { + /// status + status: TransformResponseStatus, + + /// files + files: []const OutputFile, + + /// errors + errors: []const Message, + + pub fn decode(reader: anytype) anyerror!TransformResponse { + var this = std.mem.zeroes(TransformResponse); + + this.status = try reader.readValue(TransformResponseStatus); + this.files = try reader.readArray(OutputFile); + this.errors = try reader.readArray(Message); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeEnum(this.status); + try writer.writeArray(OutputFile, this.files); + try writer.writeArray(Message, this.errors); + } + }; + + pub const MessageLevel = enum(u32) { + _none, + /// err + err, + + /// warn + warn, + + /// note + note, + + /// info + info, + + /// debug + debug, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const Location = struct { + /// file + file: []const u8, + + /// namespace + namespace: []const u8, + + /// line + line: i32 = 0, + + /// column + column: i32 = 0, + + /// line_text + line_text: []const u8, + + /// suggestion + suggestion: []const u8, + + /// offset + offset: u32 = 0, + + pub fn decode(reader: anytype) anyerror!Location { + var this = std.mem.zeroes(Location); + + this.file = try reader.readValue([]const u8); + this.namespace = try reader.readValue([]const u8); + this.line = try reader.readValue(i32); + this.column = try reader.readValue(i32); + this.line_text = try reader.readValue([]const u8); + this.suggestion = try reader.readValue([]const u8); + this.offset = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.file), this.file); + try writer.writeValue(@TypeOf(this.namespace), this.namespace); + try writer.writeInt(this.line); + try writer.writeInt(this.column); + try writer.writeValue(@TypeOf(this.line_text), this.line_text); + try writer.writeValue(@TypeOf(this.suggestion), this.suggestion); + try writer.writeInt(this.offset); + } + }; + + pub const MessageData = struct { + /// text + text: ?[]const u8 = null, + + /// location + location: ?Location = null, + + pub fn decode(reader: anytype) anyerror!MessageData { + var this = std.mem.zeroes(MessageData); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.text = try reader.readValue([]const u8); + }, + 2 => { + this.location = try reader.readValue(Location); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.text) |text| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(text), text); + } + if (this.location) |location| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(location), location); + } + try writer.endMessage(); + } + }; + + pub const MessageMeta = struct { + /// resolve + resolve: ?[]const u8 = null, + + /// build + build: ?bool = null, + + pub fn decode(reader: anytype) anyerror!MessageMeta { + var this = std.mem.zeroes(MessageMeta); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.resolve = try reader.readValue([]const u8); + }, + 2 => { + this.build = try reader.readValue(bool); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.resolve) |resolve| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(resolve), resolve); + } + if (this.build) |build| { + try writer.writeFieldID(2); + try writer.writeInt(@as(u8, @boolToInt(build))); + } + try writer.endMessage(); + } + }; + + pub const Message = struct { + /// level + level: MessageLevel, + + /// data + data: MessageData, + + /// notes + notes: []const MessageData, + + /// on + on: MessageMeta, + + pub fn decode(reader: anytype) anyerror!Message { + var this = std.mem.zeroes(Message); + + this.level = try reader.readValue(MessageLevel); + this.data = try reader.readValue(MessageData); + this.notes = try reader.readArray(MessageData); + this.on = try reader.readValue(MessageMeta); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeEnum(this.level); + try writer.writeValue(@TypeOf(this.data), this.data); + try writer.writeArray(MessageData, this.notes); + try writer.writeValue(@TypeOf(this.on), this.on); + } + }; + + pub const Log = struct { + /// warnings + warnings: u32 = 0, + + /// errors + errors: u32 = 0, + + /// msgs + msgs: []const Message, + + pub fn decode(reader: anytype) anyerror!Log { + var this = std.mem.zeroes(Log); + + this.warnings = try reader.readValue(u32); + this.errors = try reader.readValue(u32); + this.msgs = try reader.readArray(Message); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.warnings); + try writer.writeInt(this.errors); + try writer.writeArray(Message, this.msgs); + } + }; + + pub const Reloader = enum(u8) { + _none, + /// disable + disable, + + /// live + live, + + /// fast_refresh + fast_refresh, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const WebsocketMessageKind = enum(u8) { + _none, + /// welcome + welcome, + + /// file_change_notification + file_change_notification, + + /// build_success + build_success, + + /// build_fail + build_fail, + + /// manifest_success + manifest_success, + + /// manifest_fail + manifest_fail, + + /// resolve_file + resolve_file, + + /// file_change_notification_with_hint + file_change_notification_with_hint, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const WebsocketCommandKind = enum(u8) { + _none, + /// build + build, + + /// manifest + manifest, + + /// build_with_file_path + build_with_file_path, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + + pub const WebsocketMessage = struct { + /// timestamp + timestamp: u32 = 0, + + /// kind + kind: WebsocketMessageKind, + + pub fn decode(reader: anytype) anyerror!WebsocketMessage { + var this = std.mem.zeroes(WebsocketMessage); + + this.timestamp = try reader.readValue(u32); + this.kind = try reader.readValue(WebsocketMessageKind); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.timestamp); + try writer.writeEnum(this.kind); + } + }; + + pub const WebsocketMessageWelcome = struct { + /// epoch + epoch: u32 = 0, + + /// javascriptReloader + javascript_reloader: Reloader, + + /// cwd + cwd: []const u8, + + pub fn decode(reader: anytype) anyerror!WebsocketMessageWelcome { + var this = std.mem.zeroes(WebsocketMessageWelcome); + + this.epoch = try reader.readValue(u32); + this.javascript_reloader = try reader.readValue(Reloader); + this.cwd = try reader.readValue([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.epoch); + try writer.writeEnum(this.javascript_reloader); + try writer.writeValue(@TypeOf(this.cwd), this.cwd); + } + }; + + pub const WebsocketMessageFileChangeNotification = struct { + /// id + id: u32 = 0, + + /// loader + loader: Loader, + + pub fn decode(reader: anytype) anyerror!WebsocketMessageFileChangeNotification { + var this = std.mem.zeroes(WebsocketMessageFileChangeNotification); + + this.id = try reader.readValue(u32); + this.loader = try reader.readValue(Loader); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.id); + try writer.writeEnum(this.loader); + } + }; + + pub const WebsocketCommand = struct { + /// kind + kind: WebsocketCommandKind, + + /// timestamp + timestamp: u32 = 0, + + pub fn decode(reader: anytype) anyerror!WebsocketCommand { + var this = std.mem.zeroes(WebsocketCommand); + + this.kind = try reader.readValue(WebsocketCommandKind); + this.timestamp = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeEnum(this.kind); + try writer.writeInt(this.timestamp); + } + }; + + pub const WebsocketCommandBuild = packed struct { + /// id + id: u32 = 0, + + pub fn decode(reader: anytype) anyerror!WebsocketCommandBuild { + var this = std.mem.zeroes(WebsocketCommandBuild); + + this.id = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.id); + } + }; + + pub const WebsocketCommandManifest = packed struct { + /// id + id: u32 = 0, + + pub fn decode(reader: anytype) anyerror!WebsocketCommandManifest { + var this = std.mem.zeroes(WebsocketCommandManifest); + + this.id = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.id); + } + }; + + pub const WebsocketMessageBuildSuccess = struct { + /// id + id: u32 = 0, + + /// from_timestamp + from_timestamp: u32 = 0, + + /// loader + loader: Loader, + + /// module_path + module_path: []const u8, + + /// blob_length + blob_length: u32 = 0, + + pub fn decode(reader: anytype) anyerror!WebsocketMessageBuildSuccess { + var this = std.mem.zeroes(WebsocketMessageBuildSuccess); + + this.id = try reader.readValue(u32); + this.from_timestamp = try reader.readValue(u32); + this.loader = try reader.readValue(Loader); + this.module_path = try reader.readValue([]const u8); + this.blob_length = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.id); + try writer.writeInt(this.from_timestamp); + try writer.writeEnum(this.loader); + try writer.writeValue(@TypeOf(this.module_path), this.module_path); + try writer.writeInt(this.blob_length); + } + }; + + pub const WebsocketMessageBuildFailure = struct { + /// id + id: u32 = 0, + + /// from_timestamp + from_timestamp: u32 = 0, + + /// loader + loader: Loader, + + /// module_path + module_path: []const u8, + + /// log + log: Log, + + pub fn decode(reader: anytype) anyerror!WebsocketMessageBuildFailure { + var this = std.mem.zeroes(WebsocketMessageBuildFailure); + + this.id = try reader.readValue(u32); + this.from_timestamp = try reader.readValue(u32); + this.loader = try reader.readValue(Loader); + this.module_path = try reader.readValue([]const u8); + this.log = try reader.readValue(Log); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.id); + try writer.writeInt(this.from_timestamp); + try writer.writeEnum(this.loader); + try writer.writeValue(@TypeOf(this.module_path), this.module_path); + try writer.writeValue(@TypeOf(this.log), this.log); + } + }; + + pub const WebsocketCommandBuildWithFilePath = struct { + /// id + id: u32 = 0, + + /// file_path + file_path: []const u8, + + pub fn decode(reader: anytype) anyerror!WebsocketCommandBuildWithFilePath { + var this = std.mem.zeroes(WebsocketCommandBuildWithFilePath); + + this.id = try reader.readValue(u32); + this.file_path = try reader.readValue([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.id); + try writer.writeValue(@TypeOf(this.file_path), this.file_path); + } + }; + + pub const WebsocketMessageResolveId = packed struct { + /// id + id: u32 = 0, + + pub fn decode(reader: anytype) anyerror!WebsocketMessageResolveId { + var this = std.mem.zeroes(WebsocketMessageResolveId); + + this.id = try reader.readValue(u32); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeInt(this.id); + } + }; + + pub const NpmRegistry = struct { + /// url + url: []const u8, + + /// username + username: []const u8, + + /// password + password: []const u8, + + /// token + token: []const u8, + + pub fn decode(reader: anytype) anyerror!NpmRegistry { + var this = std.mem.zeroes(NpmRegistry); + + this.url = try reader.readValue([]const u8); + this.username = try reader.readValue([]const u8); + this.password = try reader.readValue([]const u8); + this.token = try reader.readValue([]const u8); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.url), this.url); + try writer.writeValue(@TypeOf(this.username), this.username); + try writer.writeValue(@TypeOf(this.password), this.password); + try writer.writeValue(@TypeOf(this.token), this.token); + } + }; + + pub const NpmRegistryMap = struct { + /// scopes + scopes: []const []const u8, + + /// registries + registries: []const NpmRegistry, + + pub fn decode(reader: anytype) anyerror!NpmRegistryMap { + var this = std.mem.zeroes(NpmRegistryMap); + + this.scopes = try reader.readArray([]const u8); + this.registries = try reader.readArray(NpmRegistry); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray([]const u8, this.scopes); + try writer.writeArray(NpmRegistry, this.registries); + } + }; + + pub const BunInstall = struct { + /// default_registry + default_registry: ?NpmRegistry = null, + + /// scoped + scoped: ?NpmRegistryMap = null, + + /// lockfile_path + lockfile_path: ?[]const u8 = null, + + /// save_lockfile_path + save_lockfile_path: ?[]const u8 = null, + + /// cache_directory + cache_directory: ?[]const u8 = null, + + /// dry_run + dry_run: ?bool = null, + + /// force + force: ?bool = null, + + /// save_dev + save_dev: ?bool = null, + + /// save_optional + save_optional: ?bool = null, + + /// save_peer + save_peer: ?bool = null, + + /// save_lockfile + save_lockfile: ?bool = null, + + /// production + production: ?bool = null, + + /// save_yarn_lockfile + save_yarn_lockfile: ?bool = null, + + /// native_bin_links + native_bin_links: []const []const u8, + + /// disable_cache + disable_cache: ?bool = null, + + /// disable_manifest_cache + disable_manifest_cache: ?bool = null, + + /// global_dir + global_dir: ?[]const u8 = null, + + /// global_bin_dir + global_bin_dir: ?[]const u8 = null, + + pub fn decode(reader: anytype) anyerror!BunInstall { + var this = std.mem.zeroes(BunInstall); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.default_registry = try reader.readValue(NpmRegistry); + }, + 2 => { + this.scoped = try reader.readValue(NpmRegistryMap); + }, + 3 => { + this.lockfile_path = try reader.readValue([]const u8); + }, + 4 => { + this.save_lockfile_path = try reader.readValue([]const u8); + }, + 5 => { + this.cache_directory = try reader.readValue([]const u8); + }, + 6 => { + this.dry_run = try reader.readValue(bool); + }, + 7 => { + this.force = try reader.readValue(bool); + }, + 8 => { + this.save_dev = try reader.readValue(bool); + }, + 9 => { + this.save_optional = try reader.readValue(bool); + }, + 10 => { + this.save_peer = try reader.readValue(bool); + }, + 11 => { + this.save_lockfile = try reader.readValue(bool); + }, + 12 => { + this.production = try reader.readValue(bool); + }, + 13 => { + this.save_yarn_lockfile = try reader.readValue(bool); + }, + 14 => { + this.native_bin_links = try reader.readArray([]const u8); + }, + 15 => { + this.disable_cache = try reader.readValue(bool); + }, + 16 => { + this.disable_manifest_cache = try reader.readValue(bool); + }, + 17 => { + this.global_dir = try reader.readValue([]const u8); + }, + 18 => { + this.global_bin_dir = try reader.readValue([]const u8); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.default_registry) |default_registry| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(default_registry), default_registry); + } + if (this.scoped) |scoped| { + try writer.writeFieldID(2); + try writer.writeValue(@TypeOf(scoped), scoped); + } + if (this.lockfile_path) |lockfile_path| { + try writer.writeFieldID(3); + try writer.writeValue(@TypeOf(lockfile_path), lockfile_path); + } + if (this.save_lockfile_path) |save_lockfile_path| { + try writer.writeFieldID(4); + try writer.writeValue(@TypeOf(save_lockfile_path), save_lockfile_path); + } + if (this.cache_directory) |cache_directory| { + try writer.writeFieldID(5); + try writer.writeValue(@TypeOf(cache_directory), cache_directory); + } + if (this.dry_run) |dry_run| { + try writer.writeFieldID(6); + try writer.writeInt(@as(u8, @boolToInt(dry_run))); + } + if (this.force) |force| { + try writer.writeFieldID(7); + try writer.writeInt(@as(u8, @boolToInt(force))); + } + if (this.save_dev) |save_dev| { + try writer.writeFieldID(8); + try writer.writeInt(@as(u8, @boolToInt(save_dev))); + } + if (this.save_optional) |save_optional| { + try writer.writeFieldID(9); + try writer.writeInt(@as(u8, @boolToInt(save_optional))); + } + if (this.save_peer) |save_peer| { + try writer.writeFieldID(10); + try writer.writeInt(@as(u8, @boolToInt(save_peer))); + } + if (this.save_lockfile) |save_lockfile| { + try writer.writeFieldID(11); + try writer.writeInt(@as(u8, @boolToInt(save_lockfile))); + } + if (this.production) |production| { + try writer.writeFieldID(12); + try writer.writeInt(@as(u8, @boolToInt(production))); + } + if (this.save_yarn_lockfile) |save_yarn_lockfile| { + try writer.writeFieldID(13); + try writer.writeInt(@as(u8, @boolToInt(save_yarn_lockfile))); + } + if (this.native_bin_links) |native_bin_links| { + try writer.writeFieldID(14); + try writer.writeArray([]const u8, native_bin_links); + } + if (this.disable_cache) |disable_cache| { + try writer.writeFieldID(15); + try writer.writeInt(@as(u8, @boolToInt(disable_cache))); + } + if (this.disable_manifest_cache) |disable_manifest_cache| { + try writer.writeFieldID(16); + try writer.writeInt(@as(u8, @boolToInt(disable_manifest_cache))); + } + if (this.global_dir) |global_dir| { + try writer.writeFieldID(17); + try writer.writeValue(@TypeOf(global_dir), global_dir); + } + if (this.global_bin_dir) |global_bin_dir| { + try writer.writeFieldID(18); + try writer.writeValue(@TypeOf(global_bin_dir), global_bin_dir); + } + try writer.endMessage(); + } + }; +}; diff --git a/src/api/schema.d.ts b/src/api/schema.d.ts index d8129fd27..0a7ed3b9b 100644 --- a/src/api/schema.d.ts +++ b/src/api/schema.d.ts @@ -194,6 +194,34 @@ export const DotEnvBehaviorKeys = { 3: "load_all", load_all: "load_all", }; +export enum ImportKind { + entry_point = 1, + stmt = 2, + require = 3, + dynamic = 4, + require_resolve = 5, + at = 6, + url = 7, + internal = 8, +} +export const ImportKindKeys = { + 1: "entry_point", + entry_point: "entry_point", + 2: "stmt", + stmt: "stmt", + 3: "require", + require: "require", + 4: "dynamic", + dynamic: "dynamic", + 5: "require_resolve", + require_resolve: "require_resolve", + 6: "at", + at: "at", + 7: "url", + url: "url", + 8: "internal", + internal: "internal", +}; export enum TransformResponseStatus { success = 1, fail = 2, @@ -508,6 +536,22 @@ export interface Transform { options?: TransformOptions; } +export interface Scan { + path?: string; + contents?: Uint8Array; + loader?: Loader; +} + +export interface ScanResult { + exports: string[]; + imports: ScannedImport[]; +} + +export interface ScannedImport { + path: string; + kind: ImportKind; +} + export interface OutputFile { data: Uint8Array; path: string; @@ -807,6 +851,18 @@ export declare function encodeTransform( bb: ByteBuffer ): void; export declare function decodeTransform(buffer: ByteBuffer): Transform; +export declare function encodeScan(message: Scan, bb: ByteBuffer): void; +export declare function decodeScan(buffer: ByteBuffer): Scan; +export declare function encodeScanResult( + message: ScanResult, + bb: ByteBuffer +): void; +export declare function decodeScanResult(buffer: ByteBuffer): ScanResult; +export declare function encodeScannedImport( + message: ScannedImport, + bb: ByteBuffer +): void; +export declare function decodeScannedImport(buffer: ByteBuffer): ScannedImport; export declare function encodeOutputFile( message: OutputFile, bb: ByteBuffer diff --git a/src/api/schema.js b/src/api/schema.js index f2e9b24a5..b89ed4a08 100644 --- a/src/api/schema.js +++ b/src/api/schema.js @@ -2031,6 +2031,163 @@ function encodeTransform(message, bb) { } bb.writeByte(0); } + +function decodeScan(bb) { + var result = {}; + + while (true) { + switch (bb.readByte()) { + case 0: + return result; + + case 1: + result["path"] = bb.readString(); + break; + + case 2: + result["contents"] = bb.readByteArray(); + break; + + case 3: + result["loader"] = Loader[bb.readByte()]; + break; + + default: + throw new Error("Attempted to parse invalid message"); + } + } +} + +function encodeScan(message, bb) { + var value = message["path"]; + if (value != null) { + bb.writeByte(1); + bb.writeString(value); + } + + var value = message["contents"]; + if (value != null) { + bb.writeByte(2); + bb.writeByteArray(value); + } + + var value = message["loader"]; + if (value != null) { + bb.writeByte(3); + var encoded = Loader[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "Loader"' + ); + bb.writeByte(encoded); + } + bb.writeByte(0); +} + +function decodeScanResult(bb) { + var result = {}; + + var length = bb.readVarUint(); + var values = (result["exports"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = bb.readString(); + var length = bb.readVarUint(); + var values = (result["imports"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeScannedImport(bb); + return result; +} + +function encodeScanResult(message, bb) { + var value = message["exports"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + bb.writeString(value); + } + } else { + throw new Error('Missing required field "exports"'); + } + + var value = message["imports"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeScannedImport(value, bb); + } + } else { + throw new Error('Missing required field "imports"'); + } +} + +function decodeScannedImport(bb) { + var result = {}; + + result["path"] = bb.readString(); + result["kind"] = ImportKind[bb.readByte()]; + return result; +} + +function encodeScannedImport(message, bb) { + var value = message["path"]; + if (value != null) { + bb.writeString(value); + } else { + throw new Error('Missing required field "path"'); + } + + var value = message["kind"]; + if (value != null) { + var encoded = ImportKind[value]; + if (encoded === void 0) + throw new Error( + "Invalid value " + JSON.stringify(value) + ' for enum "ImportKind"' + ); + bb.writeByte(encoded); + } else { + throw new Error('Missing required field "kind"'); + } +} +const ImportKind = { + 1: 1, + 2: 2, + 3: 3, + 4: 4, + 5: 5, + 6: 6, + 7: 7, + 8: 8, + entry_point: 1, + stmt: 2, + require: 3, + dynamic: 4, + require_resolve: 5, + at: 6, + url: 7, + internal: 8, +}; +const ImportKindKeys = { + 1: "entry_point", + 2: "stmt", + 3: "require", + 4: "dynamic", + 5: "require_resolve", + 6: "at", + 7: "url", + 8: "internal", + entry_point: "entry_point", + stmt: "stmt", + require: "require", + dynamic: "dynamic", + require_resolve: "require_resolve", + at: "at", + url: "url", + internal: "internal", +}; const TransformResponseStatus = { 1: 1, 2: 2, @@ -3119,6 +3276,14 @@ export { decodeFileHandle }; export { encodeFileHandle }; export { decodeTransform }; export { encodeTransform }; +export { decodeScan }; +export { encodeScan }; +export { decodeScanResult }; +export { encodeScanResult }; +export { decodeScannedImport }; +export { encodeScannedImport }; +export { ImportKind }; +export { ImportKindKeys }; export { TransformResponseStatus }; export { TransformResponseStatusKeys }; export { decodeOutputFile }; diff --git a/src/api/schema.peechy b/src/api/schema.peechy index 59cb1edf5..cf954cc4c 100644 --- a/src/api/schema.peechy +++ b/src/api/schema.peechy @@ -362,6 +362,34 @@ message Transform { TransformOptions options = 5; } +message Scan { + string path = 1; + byte[] contents = 2; + Loader loader = 3; +} + +struct ScanResult { + string[] exports; + ScannedImport[] imports; +} + +struct ScannedImport { + string path; + ImportKind kind; +} + +smol ImportKind { + entry_point = 1; + stmt = 2; + require = 3; + dynamic = 4; + require_resolve = 5; + at = 6; + url = 7; + internal = 8; +} + + enum TransformResponseStatus { success = 1; fail = 2; diff --git a/src/api/schema.zig b/src/api/schema.zig index 61d6b82d1..5f4532522 100644 --- a/src/api/schema.zig +++ b/src/api/schema.zig @@ -2047,6 +2047,134 @@ pub const Api = struct { } }; + pub const Scan = struct { + /// path + path: ?[]const u8 = null, + + /// contents + contents: []const u8, + + /// loader + loader: ?Loader = null, + + pub fn decode(reader: anytype) anyerror!Scan { + var this = std.mem.zeroes(Scan); + + while (true) { + switch (try reader.readByte()) { + 0 => { + return this; + }, + + 1 => { + this.path = try reader.readValue([]const u8); + }, + 2 => { + this.contents = try reader.readArray(u8); + }, + 3 => { + this.loader = try reader.readValue(Loader); + }, + else => { + return error.InvalidMessage; + }, + } + } + unreachable; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + if (this.path) |path| { + try writer.writeFieldID(1); + try writer.writeValue(@TypeOf(path), path); + } + if (this.contents) |contents| { + try writer.writeFieldID(2); + try writer.writeArray(u8, contents); + } + if (this.loader) |loader| { + try writer.writeFieldID(3); + try writer.writeEnum(loader); + } + try writer.endMessage(); + } + }; + + pub const ScanResult = struct { + /// exports + exports: []const []const u8, + + /// imports + imports: []const ScannedImport, + + pub fn decode(reader: anytype) anyerror!ScanResult { + var this = std.mem.zeroes(ScanResult); + + this.exports = try reader.readArray([]const u8); + this.imports = try reader.readArray(ScannedImport); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeArray([]const u8, this.exports); + try writer.writeArray(ScannedImport, this.imports); + } + }; + + pub const ScannedImport = struct { + /// path + path: []const u8, + + /// kind + kind: ImportKind, + + pub fn decode(reader: anytype) anyerror!ScannedImport { + var this = std.mem.zeroes(ScannedImport); + + this.path = try reader.readValue([]const u8); + this.kind = try reader.readValue(ImportKind); + return this; + } + + pub fn encode(this: *const @This(), writer: anytype) anyerror!void { + try writer.writeValue(@TypeOf(this.path), this.path); + try writer.writeEnum(this.kind); + } + }; + + pub const ImportKind = enum(u8) { + _none, + /// entry_point + entry_point, + + /// stmt + stmt, + + /// require + require, + + /// dynamic + dynamic, + + /// require_resolve + require_resolve, + + /// at + at, + + /// url + url, + + /// internal + internal, + + _, + + pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void { + return try std.json.stringify(@tagName(self), opts, o); + } + }; + pub const TransformResponseStatus = enum(u32) { _none, /// success diff --git a/src/bun_js.zig b/src/bun_js.zig index b712c8a19..5f673fb06 100644 --- a/src/bun_js.zig +++ b/src/bun_js.zig @@ -28,7 +28,7 @@ const bundler = @import("bundler.zig"); const NodeModuleBundle = @import("node_module_bundle.zig").NodeModuleBundle; const DotEnv = @import("env_loader.zig"); const which = @import("which.zig").which; -const VirtualMachine = @import("./javascript/jsc/javascript.zig").VirtualMachine; +const VirtualMachine = @import("javascript_core").VirtualMachine; const JSC = @import("javascript_core"); const OpaqueWrap = JSC.OpaqueWrap; diff --git a/src/bundler.zig b/src/bundler.zig index f2582e2d4..6c28e81d8 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -411,7 +411,7 @@ pub const Bundler = struct { // So it is not fast! Unless it's already cached. var paths = [_]string{std.mem.trimLeft(u8, this.options.entry_points[0], "./")}; if (std.mem.indexOfScalar(u8, paths[0], '.') == null) { - var pages_dir_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var pages_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var entry = this.fs.absBuf(&paths, &pages_dir_buf); if (std.fs.path.extension(entry).len == 0) { @@ -1503,7 +1503,7 @@ pub const Bundler = struct { }; const json_parse_string = "parse"; var json_ast_symbols_list = std.mem.span(&json_ast_symbols); - threadlocal var override_file_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + threadlocal var override_file_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn appendToModuleList( this: *GenerateNodeModuleBundle, @@ -2879,9 +2879,9 @@ pub const Bundler = struct { } // This is public so it can be used by the HTTP handler when matching against public dir. - pub threadlocal var tmp_buildfile_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - threadlocal var tmp_buildfile_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; - threadlocal var tmp_buildfile_buf3: [std.fs.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var tmp_buildfile_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + threadlocal var tmp_buildfile_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; + threadlocal var tmp_buildfile_buf3: [_global.MAX_PATH_BYTES]u8 = undefined; // We try to be mostly stateless when serving // This means we need a slightly different resolver setup diff --git a/src/bundler/entry_points.zig b/src/bundler/entry_points.zig index 38ae29878..d49f4363a 100644 --- a/src/bundler/entry_points.zig +++ b/src/bundler/entry_points.zig @@ -8,7 +8,7 @@ const Bundler = @import("../bundler.zig").Bundler; const strings = _global.strings; pub const FallbackEntryPoint = struct { code_buffer: [8096]u8 = undefined, - path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined, + path_buffer: [_global.MAX_PATH_BYTES]u8 = undefined, source: logger.Source = undefined, built_code: string = "", @@ -74,7 +74,7 @@ pub const FallbackEntryPoint = struct { pub const ClientEntryPoint = struct { code_buffer: [8096]u8 = undefined, - path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined, + path_buffer: [_global.MAX_PATH_BYTES]u8 = undefined, source: logger.Source = undefined, pub fn isEntryPointPath(extname: string) bool { @@ -157,8 +157,8 @@ pub const ClientEntryPoint = struct { }; pub const ServerEntryPoint = struct { - code_buffer: [std.fs.MAX_PATH_BYTES * 2 + 500]u8 = undefined, - output_code_buffer: [std.fs.MAX_PATH_BYTES * 8 + 500]u8 = undefined, + code_buffer: [_global.MAX_PATH_BYTES * 2 + 500]u8 = undefined, + output_code_buffer: [_global.MAX_PATH_BYTES * 8 + 500]u8 = undefined, source: logger.Source = undefined, pub fn generate( @@ -209,8 +209,8 @@ pub const ServerEntryPoint = struct { // protected. This is mostly a workaround for being unable to call ESM exported // functions from C++. When that is resolved, we should remove this. pub const MacroEntryPoint = struct { - code_buffer: [std.fs.MAX_PATH_BYTES * 2 + 500]u8 = undefined, - output_code_buffer: [std.fs.MAX_PATH_BYTES * 8 + 500]u8 = undefined, + code_buffer: [_global.MAX_PATH_BYTES * 2 + 500]u8 = undefined, + output_code_buffer: [_global.MAX_PATH_BYTES * 8 + 500]u8 = undefined, source: logger.Source = undefined, pub fn generateID(entry_path: string, function_name: string, buf: []u8, len: *u32) i32 { diff --git a/src/cli.zig b/src/cli.zig index f50cbb9ad..152661eff 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -240,7 +240,7 @@ pub const Arguments = struct { try Bunfig.parse(allocator, logger.Source.initPathString(std.mem.span(config_path), contents), ctx, cmd); } - fn getHomeConfigPath(buf: *[std.fs.MAX_PATH_BYTES]u8) ?[:0]const u8 { + fn getHomeConfigPath(buf: *[_global.MAX_PATH_BYTES]u8) ?[:0]const u8 { if (std.os.getenvZ("XDG_CONFIG_HOME") orelse std.os.getenvZ("HOME")) |data_dir| { var paths = [_]string{".bunfig.toml"}; var outbuf = resolve_path.joinAbsStringBuf(data_dir, buf, &paths, .auto); @@ -252,7 +252,7 @@ pub const Arguments = struct { } pub fn loadConfig(allocator: std.mem.Allocator, user_config_path_: ?string, ctx: *Command.Context, comptime cmd: Command.Tag) !void { - var config_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var config_buf: [_global.MAX_PATH_BYTES]u8 = undefined; if (comptime cmd.readGlobalConfig()) { if (getHomeConfigPath(&config_buf)) |path| { try loadConfigPath(allocator, true, path, ctx, comptime cmd); @@ -278,7 +278,7 @@ pub const Arguments = struct { config_path = config_buf[0..config_path_.len :0]; } else { if (ctx.args.absolute_working_dir == null) { - var secondbuf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var secondbuf: [_global.MAX_PATH_BYTES]u8 = undefined; var cwd = std.os.getcwd(&secondbuf) catch return; ctx.args.absolute_working_dir = try allocator.dupe(u8, cwd); } @@ -689,7 +689,7 @@ pub const PrintBundleCommand = struct { @setCold(true); const entry_point = ctx.args.entry_points[0]; - var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; var stdout = std.io.getStdOut(); var input = try std.fs.openFileAbsolute(try std.os.realpath(entry_point, &out_buffer), .{ .read = true }); @@ -712,7 +712,7 @@ pub const PrintBundleCommand = struct { }; pub const Command = struct { - var script_name_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var script_name_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub const DebugOptions = struct { dump_environment_variables: bool = false, @@ -1098,7 +1098,7 @@ pub const Command = struct { break :brk std.fs.cwd().openFileZ(file_pathZ, .{ .read = true }); } else { - var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; const cwd = std.os.getcwd(&path_buf) catch break :possibly_open_with_bun_js; path_buf[cwd.len] = std.fs.path.sep; var parts = [_]string{script_name_to_search}; diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index 3d9f49ca0..86376fdd9 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -92,7 +92,7 @@ pub const BuildCommand = struct { // So don't do that unless we actually need to. // const do_we_need_to_close = !FeatureFlags.store_file_descriptors or (@intCast(usize, root_dir.fd) + open_file_limit) < result.output_files.len; - var filepath_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var filepath_buf: [_global.MAX_PATH_BYTES]u8 = undefined; filepath_buf[0] = '.'; filepath_buf[1] = '/'; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index 008ed2ef2..3e39ae1b3 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -42,7 +42,7 @@ const clap = @import("clap"); const Lock = @import("../lock.zig").Lock; const Headers = @import("http").Headers; const CopyFile = @import("../copy_file.zig"); -var bun_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; +var bun_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; const Futex = @import("../futex.zig"); const target_nextjs_version = "12.1.0"; @@ -244,7 +244,7 @@ const CreateOptions = struct { }; const BUN_CREATE_DIR = ".bun-create"; -var home_dir_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; +var home_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub const CreateCommand = struct { pub fn exec(ctx: Command.Context, _: []const []const u8) !void { @setCold(true); diff --git a/src/cli/install_completions_command.zig b/src/cli/install_completions_command.zig index b64b31ebd..23b9a9a34 100644 --- a/src/cli/install_completions_command.zig +++ b/src/cli/install_completions_command.zig @@ -75,7 +75,7 @@ pub const InstallCompletionsCommand = struct { var completions_dir: string = ""; var output_dir: std.fs.Dir = found: { - var cwd_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var cwd = std.os.getcwd(&cwd_buf) catch { Output.prettyErrorln("<r><red>error<r>: Could not get current working directory", .{}); Output.flush(); @@ -285,9 +285,9 @@ pub const InstallCompletionsCommand = struct { // Check if they need to load the zsh completions file into their .zshrc if (shell == .zsh) { - var completions_absolute_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var completions_absolute_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var completions_path = std.os.getFdPath(output_file.handle, &completions_absolute_path_buf) catch unreachable; - var zshrc_filepath: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var zshrc_filepath: [_global.MAX_PATH_BYTES]u8 = undefined; const needs_to_tell_them_to_add_completions_file = brk: { var dot_zshrc: std.fs.File = zshrc: { first: { diff --git a/src/cli/package_manager_command.zig b/src/cli/package_manager_command.zig index cd330493c..26af4c5b1 100644 --- a/src/cli/package_manager_command.zig +++ b/src/cli/package_manager_command.zig @@ -7,12 +7,12 @@ const Global = @import("../global.zig").Global; const Output = @import("../global.zig").Output; const Fs = @import("../fs.zig"); const Path = @import("../resolver/resolve_path.zig"); - +const _global = @import("../global.zig"); pub const PackageManagerCommand = struct { pub fn printHelp(_: std.mem.Allocator) void {} pub fn printHash(ctx: Command.Context, lockfile_: []const u8) !void { @setCold(true); - var lockfile_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var lockfile_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; @memcpy(&lockfile_buffer, lockfile_.ptr, lockfile_.len); lockfile_buffer[lockfile_.len] = 0; var lockfile = lockfile_buffer[0..lockfile_.len :0]; diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 62f9b88e6..15040f69c 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -30,8 +30,8 @@ const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle; const DotEnv = @import("../env_loader.zig"); const which = @import("../which.zig").which; const Run = @import("../bun_js.zig").Run; -var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -var path_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; +var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; const NpmArgs = struct { // https://github.com/npm/rfcs/blob/main/implemented/0021-reduce-lifecycle-script-environment.md#detailed-explanation pub const package_name: string = "npm_package_name"; diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 72affc77d..98d5f6313 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -31,8 +31,8 @@ const NodeModuleBundle = @import("../node_module_bundle.zig").NodeModuleBundle; const DotEnv = @import("../env_loader.zig"); const which = @import("../which.zig").which; const Run = @import("../bun_js.zig").Run; -var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -var path_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; +var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; const PathString = _global.PathString; const JSC = @import("javascript_core"); @@ -104,8 +104,8 @@ const Scanner = struct { dirs_to_scan: Fifo, results: std.ArrayList(_global.PathString), fs: *FileSystem, - open_dir_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, - scan_dir_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, + open_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined, + scan_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined, options: *options.BundleOptions, has_iterated: bool = false, diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index 5995be9c2..d6e2527fe 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -120,10 +120,10 @@ pub const UpgradeCheckerThread = struct { pub const UpgradeCommand = struct { pub const timeout: u32 = 30000; const default_github_headers: string = "Acceptapplication/vnd.github.v3+json"; - var github_repository_url_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var current_executable_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var unzip_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var tmpdir_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var github_repository_url_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var current_executable_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var unzip_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var tmpdir_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn getLatestVersion( allocator: std.mem.Allocator, diff --git a/src/emcc_main.c b/src/emcc_main.c new file mode 100644 index 000000000..feb99b58a --- /dev/null +++ b/src/emcc_main.c @@ -0,0 +1,22 @@ +#define STBI_ASSERT(x) +#include <stdint.h>out.w + +#include <stdlib.h> + +extern void console_error(uint64_t slice); +extern void console_log(uint64_t slice); +extern void console_warn(uint64_t slice); +extern void console_info(uint64_t slice); + +// Zig compiles C code with -fstack-protector-strong which requires the +// following two symbols which don't seem to be provided by the emscripten +// toolchain(?) +uintptr_t __stack_chk_guard = 0xABBABABA; +_Noreturn void __stack_chk_fail(void) { abort(); }; + +// emsc_main() is the Zig entry function in pacman.zig +extern void emsc_main(void); +int main() { + emsc_main(); + return 0; +}
\ No newline at end of file diff --git a/src/env.zig b/src/env.zig index 0c6f69213..9801966c0 100644 --- a/src/env.zig +++ b/src/env.zig @@ -3,9 +3,7 @@ const builtin = @import("builtin"); pub const BuildTarget = enum { native, wasm, wasi }; pub const build_target: BuildTarget = brk: { - if (@import("builtin").target.isWasm() and @import("builtin").target.getOsTag() == .wasi) { - break :brk BuildTarget.wasi; - } else if (@import("builtin").target.isWasm()) { + if (@import("builtin").target.isWasm()) { break :brk BuildTarget.wasm; } else { break :brk BuildTarget.native; diff --git a/src/feature_flags.zig b/src/feature_flags.zig index 679ce2831..d61decd06 100644 --- a/src/feature_flags.zig +++ b/src/feature_flags.zig @@ -58,7 +58,7 @@ pub const CSSInJSImportBehavior = enum { pub const remote_inspector = false; pub const auto_import_buffer = false; -pub const is_macro_enabled = true; +pub const is_macro_enabled = !env.isWasm and !env.isWasi; // pretend everything is always the macro environment // useful for debugging the macro's JSX transform diff --git a/src/fs.zig b/src/fs.zig index 7218f7987..98874ff11 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -80,7 +80,7 @@ pub const FileSystem = struct { top_level_dir: string = "/", // used on subsequent updates - top_level_dir_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, + top_level_dir_buf: [_global.MAX_PATH_BYTES]u8 = undefined, fs: Implementation, @@ -503,7 +503,7 @@ pub const FileSystem = struct { file_limit: usize = 32, file_quota: usize = 32, - pub var tmpdir_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + pub var tmpdir_buf: [_global.MAX_PATH_BYTES]u8 = undefined; const PLATFORM_TMP_DIR: string = switch (@import("builtin").target.os.tag) { .windows => "TMPDIR", @@ -927,7 +927,7 @@ pub const FileSystem = struct { pub fn kind(fs: *RealFS, _dir: string, base: string, existing_fd: StoredFileDescriptorType) !Entry.Cache { var dir = _dir; var combo = [2]string{ dir, base }; - var outpath: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var outpath: [_global.MAX_PATH_BYTES]u8 = undefined; var entry_path = path_handler.joinAbsStringBuf(fs.cwd, &outpath, &combo, .auto); outpath[entry_path.len + 1] = 0; diff --git a/src/global.zig b/src/global.zig index 6ca2e0813..074652823 100644 --- a/src/global.zig +++ b/src/global.zig @@ -41,7 +41,14 @@ pub const Output = struct { // return @TypeOf(std.io.bufferedWriter(stdout.writer())); } }; - pub const BufferedStream: type = std.io.BufferedWriter(4096, @typeInfo(std.meta.declarationInfo(StreamType, "writer").data.Fn.fn_type).Fn.return_type.?); + pub const BufferedStream: type = struct { + fn getBufferedStream() type { + if (comptime Environment.isWasm) + return StreamType; + + return std.io.BufferedWriter(4096, @typeInfo(std.meta.declarationInfo(StreamType, "writer").data.Fn.fn_type).Fn.return_type.?); + } + }.getBufferedStream(); buffered_stream: BufferedStream, buffered_error_stream: BufferedStream, @@ -68,8 +75,14 @@ pub const Output = struct { return Source{ .stream = stream, .error_stream = err, - .buffered_stream = BufferedStream{ .unbuffered_writer = stream.writer() }, - .buffered_error_stream = BufferedStream{ .unbuffered_writer = err.writer() }, + .buffered_stream = if (Environment.isNative) + BufferedStream{ .unbuffered_writer = stream.writer() } + else + stream, + .buffered_error_stream = if (Environment.isNative) + BufferedStream{ .unbuffered_writer = err.writer() } + else + err, }; } @@ -112,33 +125,33 @@ pub const Output = struct { source = _source.*; source_set = true; - if (!stdout_stream_set) { stdout_stream_set = true; + if (comptime Environment.isNative) { + var is_color_terminal: ?bool = null; + if (_source.stream.isTty()) { + stdout_descriptor_type = OutputStreamDescriptor.terminal; + is_color_terminal = is_color_terminal orelse isColorTerminal(); + enable_ansi_colors_stdout = is_color_terminal.?; + } else if (isForceColor()) |val| { + enable_ansi_colors_stdout = val; + } else { + enable_ansi_colors_stdout = false; + } - var is_color_terminal: ?bool = null; - if (_source.stream.isTty()) { - stdout_descriptor_type = OutputStreamDescriptor.terminal; - is_color_terminal = is_color_terminal orelse isColorTerminal(); - enable_ansi_colors_stdout = is_color_terminal.?; - } else if (isForceColor()) |val| { - enable_ansi_colors_stdout = val; - } else { - enable_ansi_colors_stdout = false; - } + if (_source.error_stream.isTty()) { + stderr_descriptor_type = OutputStreamDescriptor.terminal; + is_color_terminal = is_color_terminal orelse isColorTerminal(); + enable_ansi_colors_stderr = is_color_terminal.?; + } else if (isForceColor()) |val| { + enable_ansi_colors_stderr = val; + } else { + enable_ansi_colors_stderr = false; + } - if (_source.error_stream.isTty()) { - stderr_descriptor_type = OutputStreamDescriptor.terminal; - is_color_terminal = is_color_terminal orelse isColorTerminal(); - enable_ansi_colors_stderr = is_color_terminal.?; - } else if (isForceColor()) |val| { - enable_ansi_colors_stderr = val; - } else { - enable_ansi_colors_stderr = false; + enable_ansi_colors = enable_ansi_colors_stderr or enable_ansi_colors_stdout; } - enable_ansi_colors = enable_ansi_colors_stderr or enable_ansi_colors_stdout; - stdout_stream = _source.stream; stderr_stream = _source.error_stream; } @@ -155,7 +168,7 @@ pub const Output = struct { pub var enable_ansi_colors = Environment.isNative; pub var enable_ansi_colors_stderr = Environment.isNative; pub var enable_ansi_colors_stdout = Environment.isNative; - pub var enable_buffering = true; + pub var enable_buffering = Environment.isNative; pub var stderr_descriptor_type = OutputStreamDescriptor.unknown; pub var stdout_descriptor_type = OutputStreamDescriptor.unknown; @@ -175,12 +188,12 @@ pub const Output = struct { Output.Source.set(&_source_for_test); } pub fn enableBuffering() void { - enable_buffering = true; + if (comptime Environment.isNative) enable_buffering = true; } pub fn disableBuffering() void { Output.flush(); - enable_buffering = false; + if (comptime Environment.isNative) enable_buffering = false; } pub fn panic(comptime fmt: string, args: anytype) noreturn { @@ -284,7 +297,7 @@ pub const Output = struct { if (comptime Environment.isWasm) { try source.stream.seekTo(0); try source.stream.writer().print(fmt, args); - root.console_log(root.Uint8Array.fromSlice(source.out_buffer[0..source.stream.pos])); + root.console_error(root.Uint8Array.fromSlice(source.stream.buffer[0..source.stream.pos])); } else { std.fmt.format(source.stream.writer(), fmt, args) catch unreachable; } @@ -313,14 +326,13 @@ pub const Output = struct { } pub fn print(comptime fmt: string, args: anytype) void { - std.debug.assert(source_set); - if (comptime Environment.isWasm) { - source.stream.seekTo(0) catch return; - source.stream.writer().print(fmt, args) catch return; - - root.console_log(root.Uint8Array.fromSlice(source.out_buffer[0..source.stream.pos])); + source.stream.pos = 0; + std.fmt.format(source.stream.writer(), fmt, args) catch unreachable; + root.console_log(root.Uint8Array.fromSlice(source.stream.buffer[0..source.stream.pos])); } else { + std.debug.assert(source_set); + if (enable_buffering) { std.fmt.format(source.buffered_stream.writer(), fmt, args) catch unreachable; } else { @@ -656,3 +668,5 @@ pub const MutableString = @import("string_mutable.zig").MutableString; pub inline fn constStrToU8(s: []const u8) []u8 { return @intToPtr([*]u8, @ptrToInt(s.ptr))[0..s.len]; } + +pub const MAX_PATH_BYTES: usize = if (Environment.isWasm) 1024 else std.fs.MAX_PATH_BYTES; diff --git a/src/http.zig b/src/http.zig index 58176df6c..634d9f1f4 100644 --- a/src/http.zig +++ b/src/http.zig @@ -768,7 +768,7 @@ pub const RequestContext = struct { }; threadlocal var file_chunk_buf: [chunk_preamble_len + 2]u8 = undefined; - threadlocal var symlink_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + threadlocal var symlink_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; threadlocal var weak_etag_buffer: [100]u8 = undefined; threadlocal var strong_etag_buffer: [100]u8 = undefined; threadlocal var weak_etag_tmp_buffer: [100]u8 = undefined; @@ -1763,7 +1763,7 @@ pub const RequestContext = struct { // Output.prettyErrorln("<r><green>101<r><d> Hot Module Reloading connected.<r>", .{}); // Output.flush(); Analytics.Features.hot_module_reloading = true; - var build_file_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var build_file_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var cmd: Api.WebsocketCommand = undefined; var msg: Api.WebsocketMessage = .{ @@ -1772,7 +1772,7 @@ pub const RequestContext = struct { }; var cmd_reader: ApiReader = undefined; { - var byte_buf: [32 + std.fs.MAX_PATH_BYTES]u8 = undefined; + var byte_buf: [32 + _global.MAX_PATH_BYTES]u8 = undefined; var fbs = std.io.fixedBufferStream(&byte_buf); var writer = ByteApiWriter.init(&fbs); @@ -3040,7 +3040,7 @@ pub const Server = struct { var opened = try tmpdir.openFile(basename, .{}); defer opened.close(); - var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; try editor_.open( Server.editor_path, try std.os.getFdPath(opened.handle, &path_buf), @@ -3051,7 +3051,7 @@ pub const Server = struct { } pub fn detectEditor(env: *DotEnv.Loader) void { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var out: string = ""; // first: choose from user preference @@ -3130,7 +3130,7 @@ pub const Server = struct { } } - var _on_file_update_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var _on_file_update_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; fn _onFileUpdate( ctx: *Server, events: []watcher.WatchEvent, diff --git a/src/http/async_socket.zig b/src/http/async_socket.zig index d841d1b0c..dcdeb8b62 100644 --- a/src/http/async_socket.zig +++ b/src/http/async_socket.zig @@ -9,7 +9,7 @@ const KeepAlive = @import("../http_client_async.zig").KeepAlive; const Output = @import("../global.zig").Output; const NetworkThread = @import("../network_thread.zig"); const Environment = @import("../global.zig").Environment; - +const _global = @import("../global.zig"); const extremely_verbose = @import("../http_client_async.zig").extremely_verbose; const SOCKET_FLAGS: u32 = @import("../http_client_async.zig").SOCKET_FLAGS; const getAllocator = @import("../http_client_async.zig").getAllocator; @@ -330,7 +330,7 @@ pub const SSL = struct { send_frame: Yield(SSL.send) = Yield(SSL.send){}, read_frame: Yield(SSL.read) = Yield(SSL.read){}, - hostname: [std.fs.MAX_PATH_BYTES]u8 = undefined, + hostname: [_global.MAX_PATH_BYTES]u8 = undefined, is_ssl: bool = false, handshake_state: HandshakeState = HandshakeState.none, diff --git a/src/import_record.zig b/src/import_record.zig index 31ad8185f..3ec2f82eb 100644 --- a/src/import_record.zig +++ b/src/import_record.zig @@ -2,6 +2,7 @@ const fs = @import("fs.zig"); const logger = @import("logger.zig"); const std = @import("std"); const Ref = @import("ast/base.zig").Ref; +const Api = @import("./api/schema.zig").Api; pub const ImportKind = enum(u8) { @@ -62,6 +63,19 @@ pub const ImportKind = enum(u8) { pub fn isFromCSS(k: ImportKind) bool { return k == .at_conditional or k == .at or k == .url; } + + pub fn toAPI(k: ImportKind) Api.ImportKind { + return switch (k) { + ImportKind.entry_point => Api.ImportKind.entry_point, + ImportKind.stmt => Api.ImportKind.stmt, + ImportKind.require => Api.ImportKind.require, + ImportKind.dynamic => Api.ImportKind.dynamic, + ImportKind.require_resolve => Api.ImportKind.require_resolve, + ImportKind.at => Api.ImportKind.at, + ImportKind.url => Api.ImportKind.url, + else => Api.ImportKind.internal, + }; + } }; pub const ImportRecord = struct { diff --git a/src/install/bin.zig b/src/install/bin.zig index f3f64f0d7..d3703f871 100644 --- a/src/install/bin.zig +++ b/src/install/bin.zig @@ -10,7 +10,7 @@ const C = @import("../c.zig"); const Fs = @import("../fs.zig"); const stringZ = @import("../global.zig").stringZ; const Resolution = @import("./resolution.zig").Resolution; - +const _global = @import("../global.zig"); /// Normalized `bin` field in [package.json](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin) /// Can be a: /// - file path (relative to the package root) @@ -149,7 +149,7 @@ pub const Bin = extern struct { dir_iterator: ?std.fs.Dir.Iterator = null, package_name: String, package_installed_node_modules: std.fs.Dir = std.fs.Dir{ .fd = std.math.maxInt(std.os.fd_t) }, - buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, + buf: [_global.MAX_PATH_BYTES]u8 = undefined, string_buffer: []const u8, extern_string_buf: []const ExternalString, @@ -263,8 +263,8 @@ pub const Bin = extern struct { // That way, if you move your node_modules folder around, the symlinks in .bin still work // If we used absolute paths for the symlinks, you'd end up with broken symlinks pub fn link(this: *Linker, link_global: bool) void { - var target_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var dest_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var target_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var dest_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var from_remain: []u8 = &target_buf; var remain: []u8 = &dest_buf; diff --git a/src/install/extract_tarball.zig b/src/install/extract_tarball.zig index 1ece844b9..6b2e11f70 100644 --- a/src/install/extract_tarball.zig +++ b/src/install/extract_tarball.zig @@ -12,7 +12,7 @@ const Npm = @import("./npm.zig"); const ExtractTarball = @This(); const default_allocator = @import("../global.zig").default_allocator; const Global = @import("../global.zig").Global; - +const _global = @import("../global.zig"); name: strings.StringOrTinyString, resolution: Resolution, registry: string, @@ -140,8 +140,8 @@ pub fn buildURLWithPrinter( } } -threadlocal var abs_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var abs_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; +threadlocal var abs_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var abs_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; fn extract(this: *const ExtractTarball, tgz_bytes: []const u8) !string { var tmpdir = this.temp_dir; diff --git a/src/install/install.zig b/src/install/install.zig index 377844990..842a44b40 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -35,8 +35,8 @@ const HeaderBuilder = @import("http").HeaderBuilder; const Fs = @import("../fs.zig"); const FileSystem = Fs.FileSystem; const Lock = @import("../lock.zig").Lock; -var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -var path_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; +var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; const URL = @import("../query_string_map.zig").URL; const AsyncHTTP = @import("http").AsyncHTTP; const HTTPChannel = @import("http").HTTPChannel; @@ -587,8 +587,8 @@ const PackageInstall = struct { var this: *PackageInstall.Task = @fieldParentPtr(PackageInstall.Task, "task", task); var ctx = this.ctx; - var destination_dir_subpath_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var cache_dir_subpath_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var destination_dir_subpath_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var cache_dir_subpath_buf: [_global.MAX_PATH_BYTES]u8 = undefined; const name = ctx.names[this.package_id].slice(ctx.string_buf); const resolution = ctx.resolutions[this.package_id]; std.mem.copy(u8, &destination_dir_subpath_buf, name); @@ -811,7 +811,7 @@ const PackageInstall = struct { walker: *Walker, ) !u32 { var real_file_count: u32 = 0; - var stackpath: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var stackpath: [_global.MAX_PATH_BYTES]u8 = undefined; while (try walker.next()) |entry| { switch (entry.kind) { .Directory => std.os.mkdirat(destination_dir_.fd, entry.path, 0o755) catch {}, @@ -1284,7 +1284,7 @@ pub const PackageManager = struct { } } - var cached_package_folder_name_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var cached_package_folder_name_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub inline fn getCacheDirectory(this: *PackageManager) std.fs.Dir { return this.cache_directory_ orelse brk: { @@ -2562,14 +2562,14 @@ pub const PackageManager = struct { } if (std.os.getenvZ("BUN_INSTALL")) |home_dir| { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var parts = [_]string{ "install", "global" }; var path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto); return try std.fs.cwd().makeOpenPath(path, .{ .iterate = true }); } if (std.os.getenvZ("XDG_CACHE_HOME") orelse std.os.getenvZ("HOME")) |home_dir| { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var parts = [_]string{ ".bun", "install", "global" }; var path = Path.joinAbsStringBuf(home_dir, &buf, &parts, .auto); return try std.fs.cwd().makeOpenPath(path, .{ .iterate = true }); @@ -2592,7 +2592,7 @@ pub const PackageManager = struct { } if (std.os.getenvZ("BUN_INSTALL")) |home_dir| { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var parts = [_]string{ "bin", }; @@ -2601,7 +2601,7 @@ pub const PackageManager = struct { } if (std.os.getenvZ("XDG_CACHE_HOME") orelse std.os.getenvZ("HOME")) |home_dir| { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var parts = [_]string{ ".bun", "bin", @@ -3460,8 +3460,8 @@ pub const PackageManager = struct { } if (args.option("--cwd")) |cwd_| { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var buf2: [_global.MAX_PATH_BYTES]u8 = undefined; var final_path: [:0]u8 = undefined; if (cwd_.len > 0 and cwd_[0] == '.') { var cwd = try std.os.getcwd(&buf); @@ -3956,7 +3956,7 @@ pub const PackageManager = struct { if (op == .remove) { var cwd = std.fs.cwd(); // This is not exactly correct - var node_modules_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var node_modules_buf: [_global.MAX_PATH_BYTES]u8 = undefined; std.mem.copy(u8, &node_modules_buf, "node_modules" ++ std.fs.path.sep_str); var offset_buf: []u8 = node_modules_buf["node_modules/".len..]; const name_hashes = manager.lockfile.packages.items(.name_hash); @@ -4003,8 +4003,8 @@ pub const PackageManager = struct { } } - var cwd_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var package_json_cwd_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var cwd_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var package_json_cwd_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub inline fn install( ctx: Command.Context, @@ -4051,8 +4051,8 @@ pub const PackageManager = struct { node: *Progress.Node, has_created_bin: bool = false, global_bin_dir: std.fs.Dir, - destination_dir_subpath_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, - folder_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, + destination_dir_subpath_buf: [_global.MAX_PATH_BYTES]u8 = undefined, + folder_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined, install_count: usize = 0, successfully_installed: Bitset, @@ -4523,7 +4523,7 @@ pub const PackageManager = struct { pub fn setupGlobalDir(manager: *PackageManager, ctx: *const Command.Context) !void { manager.options.global_bin_dir = try Options.openGlobalBinDir(ctx.install); - var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; var result = try std.os.getFdPath(manager.options.global_bin_dir.fd, &out_buffer); out_buffer[result.len] = 0; var result_: [:0]u8 = out_buffer[0..result.len :0]; diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index 85e82e5a9..e4f9bda78 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -35,8 +35,8 @@ const HeaderBuilder = @import("http").HeaderBuilder; const Fs = @import("../fs.zig"); const FileSystem = Fs.FileSystem; const Lock = @import("../lock.zig").Lock; -var path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -var path_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; +var path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +var path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; const URL = @import("../query_string_map.zig").URL; const AsyncHTTP = @import("http").AsyncHTTP; const HTTPChannel = @import("http").HTTPChannel; @@ -222,13 +222,13 @@ pub const Tree = struct { package_ids: []const PackageID, names: []const String, tree_id: Id = 0, - path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, + path_buf: [_global.MAX_PATH_BYTES]u8 = undefined, path_buf_len: usize = 0, last_parent: Id = invalid_id, string_buf: string, // max number of node_modules folders - depth_stack: [(std.fs.MAX_PATH_BYTES / "node_modules".len) + 1]Id = undefined, + depth_stack: [(_global.MAX_PATH_BYTES / "node_modules".len) + 1]Id = undefined, pub fn init( trees: []const Tree, @@ -842,8 +842,8 @@ pub const Printer = struct { pub const Format = enum { yarn }; - var lockfile_path_buf1: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var lockfile_path_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var lockfile_path_buf1: [_global.MAX_PATH_BYTES]u8 = undefined; + var lockfile_path_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn print( allocator: std.mem.Allocator, @@ -2282,7 +2282,7 @@ pub const Package = extern struct { // If it's a folder, pessimistically assume we will need a maximum path if (Dependency.Version.Tag.infer(value) == .folder) { - string_builder.cap += std.fs.MAX_PATH_BYTES; + string_builder.cap += _global.MAX_PATH_BYTES; } } total_dependencies_count += @truncate(u32, dependencies_q.expr.data.e_object.properties.len); @@ -2911,7 +2911,7 @@ pub const Serializer = struct { load_workspace: { const workspace_path_len = reader.readIntLittle(u64) catch break :load_workspace; - if (workspace_path_len > 0 and workspace_path_len < std.fs.MAX_PATH_BYTES) { + if (workspace_path_len > 0 and workspace_path_len < _global.MAX_PATH_BYTES) { var workspace_path = try allocator.alloc(u8, workspace_path_len); const len = reader.readAll(workspace_path) catch break :load_workspace; lockfile.workspace_path = workspace_path[0..len]; diff --git a/src/install/resolvers/folder_resolver.zig b/src/install/resolvers/folder_resolver.zig index 9d92a5b30..d988dc05a 100644 --- a/src/install/resolvers/folder_resolver.zig +++ b/src/install/resolvers/folder_resolver.zig @@ -12,7 +12,7 @@ const IdentityContext = @import("../../identity_context.zig").IdentityContext; const strings = @import("strings"); const Resolution = @import("../resolution.zig").Resolution; const String = @import("../semver.zig").String; - +const _global = @import("../../global.zig"); pub const FolderResolution = union(Tag) { package_id: PackageID, new_package_id: PackageID, @@ -51,11 +51,11 @@ pub const FolderResolution = union(Tag) { // We consider it valid if there is a package.json in the folder const normalized = std.mem.trimRight(u8, normalize(non_normalized_path), std.fs.path.sep_str); - var joined: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var joined: [_global.MAX_PATH_BYTES]u8 = undefined; var abs: string = ""; var rel: string = ""; if (strings.startsWithChar(normalized, '.')) { - var tempcat: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var tempcat: [_global.MAX_PATH_BYTES]u8 = undefined; std.mem.copy(u8, &tempcat, normalized); tempcat[normalized.len] = std.fs.path.sep; diff --git a/src/io/io_stub.zig b/src/io/io_stub.zig new file mode 100644 index 000000000..b1f6d3f57 --- /dev/null +++ b/src/io/io_stub.zig @@ -0,0 +1,11 @@ +const std = @import("std"); +const IO = struct { + buffer: i32 = 0, +}; + +pub fn init(_: anytype, _: anytype) anyerror!void {} + +pub var global: IO = undefined; +pub var global_loaded: bool = false; + +fn buffer_limit(_: usize) usize {} diff --git a/src/javascript/jsc/api/router.zig b/src/javascript/jsc/api/router.zig index e8ef4dc09..8e80fefa5 100644 --- a/src/javascript/jsc/api/router.zig +++ b/src/javascript/jsc/api/router.zig @@ -7,7 +7,7 @@ const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap; const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner; const _global = @import("../../../global.zig"); const string = _global.string; -const JSC = @import("javascript_core"); +const JSC = @import("../../../jsc.zig"); const js = JSC.C; const WebCore = @import("../webcore/response.zig"); const Router = @This(); @@ -360,7 +360,7 @@ pub fn createQueryObject(ctx: js.JSContextRef, map: *QueryStringMap, _: js.Excep return value.asRef(); } -threadlocal var entry_point_tempbuf: [std.fs.MAX_PATH_BYTES]u8 = undefined; +threadlocal var entry_point_tempbuf: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn getScriptSrcString( comptime Writer: type, writer: Writer, diff --git a/src/javascript/jsc/api/transpiler.zig b/src/javascript/jsc/api/transpiler.zig index 004b670cb..3993768f3 100644 --- a/src/javascript/jsc/api/transpiler.zig +++ b/src/javascript/jsc/api/transpiler.zig @@ -7,7 +7,7 @@ const QueryStringMap = @import("../../../query_string_map.zig").QueryStringMap; const CombinedScanner = @import("../../../query_string_map.zig").CombinedScanner; const _global = @import("../../../global.zig"); const string = _global.string; -const JSC = @import("javascript_core"); +const JSC = @import("../../../jsc.zig"); const js = JSC.C; const WebCore = @import("../webcore/response.zig"); const Bundler = @import("../../../bundler.zig"); diff --git a/src/javascript/jsc/bindings/bindings.zig b/src/javascript/jsc/bindings/bindings.zig index 6fabeeb17..9c0d4488b 100644 --- a/src/javascript/jsc/bindings/bindings.zig +++ b/src/javascript/jsc/bindings/bindings.zig @@ -247,7 +247,7 @@ pub const ZigString = extern struct { }; } - pub fn sliceZBuf(this: ZigString, buf: *[std.fs.MAX_PATH_BYTES]u8) ![:0]const u8 { + pub fn sliceZBuf(this: ZigString, buf: *[_global.MAX_PATH_BYTES]u8) ![:0]const u8 { return try std.fmt.bufPrintZ(buf, "{}", .{this}); } diff --git a/src/javascript/jsc/bindings/exports.zig b/src/javascript/jsc/bindings/exports.zig index c7e98077c..da0a8cb73 100644 --- a/src/javascript/jsc/bindings/exports.zig +++ b/src/javascript/jsc/bindings/exports.zig @@ -1,6 +1,6 @@ const JSC = @import("../../../jsc.zig"); const Fs = @import("../../../fs.zig"); -const CAPI = @import("../../../jsc.zig").C; +const CAPI = JSC.C; const JS = @import("../javascript.zig"); const JSBase = @import("../base.zig"); const ZigURL = @import("../../../query_string_map.zig").URL; diff --git a/src/javascript/jsc/javascript.zig b/src/javascript/jsc/javascript.zig index 648653332..727ac9654 100644 --- a/src/javascript/jsc/javascript.zig +++ b/src/javascript/jsc/javascript.zig @@ -586,7 +586,7 @@ pub const Bun = struct { arguments: []const js.JSValueRef, exception: js.ExceptionRef, ) js.JSValueRef { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; const path = getFilePath(ctx, arguments, &buf, exception) orelse return null; buf[path.len] = 0; @@ -603,7 +603,7 @@ pub const Bun = struct { arguments: []const js.JSValueRef, exception: js.ExceptionRef, ) js.JSValueRef { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; const path = getFilePath(ctx, arguments, &buf, exception) orelse return null; buf[path.len] = 0; @@ -728,7 +728,7 @@ pub const Bun = struct { return out.toValueGC(ctx.ptr()).asObjectRef(); } - var public_path_temp_str: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var public_path_temp_str: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn getPublicPathJS( _: void, @@ -760,7 +760,7 @@ pub const Bun = struct { // if (arguments.len == 0) return ZigString.Empty.toValue(ctx.ptr()).asObjectRef(); // var zig_str: ZigString = ZigString.Empty; // JSValue.toZigString(JSValue.fromRef(arguments[0]), &zig_str, ctx.ptr()); - // var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + // var buf: [_global.MAX_PATH_BYTES]u8 = undefined; // var stack = std.heap.stackFallback(32 * @sizeOf(string), VirtualMachine.vm.allocator); // var allocator = stack.get(); // var parts = allocator.alloc(string, arguments.len) catch {}; diff --git a/src/javascript/jsc/node/node_fs.zig b/src/javascript/jsc/node/node_fs.zig index a53c7d172..59cc2dfa9 100644 --- a/src/javascript/jsc/node/node_fs.zig +++ b/src/javascript/jsc/node/node_fs.zig @@ -2417,7 +2417,7 @@ pub const NodeFS = struct { /// We want to avoid allocating a new path buffer for every error message so that JSC can clone + GC it. /// That means a stack-allocated buffer won't suffice. Instead, we re-use /// the heap allocated buffer on the NodefS struct - sync_error_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined, + sync_error_buf: [_global.MAX_PATH_BYTES]u8 = undefined, pub const ReturnType = Return; @@ -2506,8 +2506,8 @@ pub const NodeFS = struct { switch (comptime flavor) { .sync => { - var src_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var dest_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var src_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var dest_buf: [_global.MAX_PATH_BYTES]u8 = undefined; var src = args.src.sliceZ(&src_buf); var dest = args.dest.sliceZ(&dest_buf); @@ -2776,7 +2776,7 @@ pub const NodeFS = struct { return Maybe(Return.Lchown).todo; } pub fn link(this: *NodeFS, args: Arguments.Link, comptime flavor: Flavor) Maybe(Return.Link) { - var new_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var new_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; const from = args.old_path.sliceZ(&this.sync_error_buf); const to = args.new_path.sliceZ(&new_path_buf); @@ -2846,7 +2846,7 @@ pub const NodeFS = struct { switch (comptime flavor) { // The sync version does no allocation except when returning the path .sync => { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; const path = args.path.sliceZWithForceCopy(&buf, true); const len = @truncate(u16, path.len); @@ -3393,7 +3393,7 @@ pub const NodeFS = struct { } pub fn readlink(this: *NodeFS, args: Arguments.Readlink, comptime flavor: Flavor) Maybe(Return.Readlink) { - var outbuf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var outbuf: [_global.MAX_PATH_BYTES]u8 = undefined; var inbuf = &this.sync_error_buf; switch (comptime flavor) { .sync => { @@ -3426,7 +3426,7 @@ pub const NodeFS = struct { return Maybe(Return.Readlink).todo; } pub fn realpath(this: *NodeFS, args: Arguments.Realpath, comptime flavor: Flavor) Maybe(Return.Realpath) { - var outbuf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var outbuf: [_global.MAX_PATH_BYTES]u8 = undefined; var inbuf = &this.sync_error_buf; if (comptime Environment.allow_assert) std.debug.assert(FileSystem.instance_loaded); @@ -3491,7 +3491,7 @@ pub const NodeFS = struct { // } pub fn rename(this: *NodeFS, args: Arguments.Rename, comptime flavor: Flavor) Maybe(Return.Rename) { var from_buf = &this.sync_error_buf; - var to_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var to_buf: [_global.MAX_PATH_BYTES]u8 = undefined; switch (comptime flavor) { .sync => { @@ -3550,7 +3550,7 @@ pub const NodeFS = struct { } pub fn symlink(this: *NodeFS, args: Arguments.Symlink, comptime flavor: Flavor) Maybe(Return.Symlink) { - var to_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var to_buf: [_global.MAX_PATH_BYTES]u8 = undefined; switch (comptime flavor) { .sync => { diff --git a/src/javascript/jsc/node/syscall.zig b/src/javascript/jsc/node/syscall.zig index 7dee85736..aa181b75f 100644 --- a/src/javascript/jsc/node/syscall.zig +++ b/src/javascript/jsc/node/syscall.zig @@ -10,8 +10,9 @@ const default_allocator = @import("../../../global.zig").default_allocator; const JSC = @import("../../../jsc.zig"); const SystemError = JSC.SystemError; const darwin = os.darwin; -const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES; -const fd_t = std.os.fd_t; +const _global = @import("../../../global.zig"); +const MAX_PATH_BYTES = _global.MAX_PATH_BYTES; +const fd_t = _global.FileDescriptorType; const C = @import("../../../global.zig").C; const linux = os.linux; const Maybe = JSC.Node.Maybe; @@ -77,12 +78,12 @@ else const mem = std.mem; -pub fn getcwd(buf: *[std.fs.MAX_PATH_BYTES]u8) Maybe([]const u8) { +pub fn getcwd(buf: *[_global.MAX_PATH_BYTES]u8) Maybe([]const u8) { const Result = Maybe([]const u8); buf[0] = 0; - const rc = std.c.getcwd(buf, std.fs.MAX_PATH_BYTES); + const rc = std.c.getcwd(buf, _global.MAX_PATH_BYTES); return if (rc != null) - Result{ .result = std.mem.sliceTo(rc.?[0..std.fs.MAX_PATH_BYTES], 0) } + Result{ .result = std.mem.sliceTo(rc.?[0.._global.MAX_PATH_BYTES], 0) } else Result.errnoSys(0, .getcwd).?; } diff --git a/src/javascript/jsc/node/types.zig b/src/javascript/jsc/node/types.zig index 6ee9bd293..a02645853 100644 --- a/src/javascript/jsc/node/types.zig +++ b/src/javascript/jsc/node/types.zig @@ -250,7 +250,7 @@ pub const PathLike = union(Tag) { }; } - pub fn sliceZWithForceCopy(this: PathLike, buf: *[std.fs.MAX_PATH_BYTES]u8, comptime force: bool) [:0]const u8 { + pub fn sliceZWithForceCopy(this: PathLike, buf: *[_global.MAX_PATH_BYTES]u8, comptime force: bool) [:0]const u8 { var sliced = this.slice(); if (sliced.len == 0) return ""; @@ -267,7 +267,7 @@ pub const PathLike = union(Tag) { return buf[0..sliced.len :0]; } - pub inline fn sliceZ(this: PathLike, buf: *[std.fs.MAX_PATH_BYTES]u8) [:0]const u8 { + pub inline fn sliceZ(this: PathLike, buf: *[_global.MAX_PATH_BYTES]u8) [:0]const u8 { return sliceZWithForceCopy(this, buf, false); } @@ -345,11 +345,11 @@ pub const Valid = struct { JSC.throwInvalidArguments("Invalid path string: can't be empty", .{}, ctx, exception); return false; }, - 1...std.fs.MAX_PATH_BYTES => return true, + 1..._global.MAX_PATH_BYTES => return true, else => { // TODO: should this be an EINVAL? JSC.throwInvalidArguments( - comptime std.fmt.comptimePrint("Invalid path string: path is too long (max: {d})", .{std.fs.MAX_PATH_BYTES}), + comptime std.fmt.comptimePrint("Invalid path string: path is too long (max: {d})", .{_global.MAX_PATH_BYTES}), .{}, ctx, exception, @@ -373,14 +373,14 @@ pub const Valid = struct { // TODO: should this be an EINVAL? JSC.throwInvalidArguments( - comptime std.fmt.comptimePrint("Invalid path buffer: path is too long (max: {d})", .{std.fs.MAX_PATH_BYTES}), + comptime std.fmt.comptimePrint("Invalid path buffer: path is too long (max: {d})", .{_global.MAX_PATH_BYTES}), .{}, ctx, exception, ); return false; }, - 1...std.fs.MAX_PATH_BYTES => return true, + 1..._global.MAX_PATH_BYTES => return true, } unreachable; @@ -2198,7 +2198,7 @@ pub const Path = struct { var arena = std.heap.ArenaAllocator.init(heap_allocator); var arena_allocator = arena.allocator(); defer arena.deinit(); - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var to_join = allocator.alloc(string, args_len) catch unreachable; var possibly_utf16 = false; for (args_ptr[0..args_len]) |arg, i| { @@ -2231,7 +2231,7 @@ pub const Path = struct { var zig_str: JSC.ZigString = args_ptr[0].getZigString(globalThis); if (zig_str.len == 0) return JSC.ZigString.init("").toValue(globalThis); - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var str_slice = zig_str.toSlice(heap_allocator); defer str_slice.deinit(); var str = str_slice.slice(); @@ -2322,7 +2322,7 @@ pub const Path = struct { heap_allocator, ); var allocator = stack_fallback_allocator.get(); - var out_buf: [std.fs.MAX_PATH_BYTES * 2]u8 = undefined; + var out_buf: [_global.MAX_PATH_BYTES * 2]u8 = undefined; var parts = allocator.alloc(string, args_len) catch unreachable; defer allocator.free(parts); @@ -2447,7 +2447,7 @@ pub const Process = struct { } pub fn getCwd(globalObject: *JSC.JSGlobalObject) callconv(.C) JSC.JSValue { - var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buffer: [_global.MAX_PATH_BYTES]u8 = undefined; switch (Syscall.getcwd(&buffer)) { .err => |err| { return err.toJSC(globalObject); @@ -2467,7 +2467,7 @@ pub const Process = struct { return JSC.toInvalidArguments("path is required", .{}, globalObject.ref()); } - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; const slice = to.sliceZBuf(&buf) catch { return JSC.toInvalidArguments("Invalid path", .{}, globalObject.ref()); }; diff --git a/src/js_ast.zig b/src/js_ast.zig index 668c232d2..630335dfd 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -4606,7 +4606,7 @@ pub fn printmem(comptime format: string, args: anytype) void { } pub const Macro = struct { - const JavaScript = @import("./javascript/jsc/javascript.zig"); + const JavaScript = @import("javascript_core"); const JSCBase = @import("./javascript/jsc/base.zig"); const Resolver = @import("./resolver/resolver.zig").Resolver; const isPackagePath = @import("./resolver/resolver.zig").isPackagePath; diff --git a/src/js_lexer.zig b/src/js_lexer.zig index f0c997e67..6d33e256b 100644 --- a/src/js_lexer.zig +++ b/src/js_lexer.zig @@ -2806,8 +2806,20 @@ fn NewLexer_( pub const Lexer = NewLexer(.{}); const JSIdentifier = @import("./js_lexer/identifier.zig"); -pub const isIdentifierStart = JSIdentifier.Bitset.isIdentifierStart; -pub const isIdentifierContinue = JSIdentifier.Bitset.isIdentifierPart; +pub inline fn isIdentifierStart(codepoint: i32) bool { + if (comptime Environment.isWasm) { + return JSIdentifier.JumpTable.isIdentifierStart(codepoint); + } + + return JSIdentifier.Bitset.isIdentifierStart(codepoint); +} +pub inline fn isIdentifierContinue(codepoint: i32) bool { + if (comptime Environment.isWasm) { + return JSIdentifier.JumpTable.isIdentifierPart(codepoint); + } + + return JSIdentifier.Bitset.isIdentifierPart(codepoint); +} pub fn isWhitespace(codepoint: CodePoint) bool { return switch (codepoint) { diff --git a/src/js_lexer/identifier.zig b/src/js_lexer/identifier.zig index 7ca14063e..d399a5b0e 100644 --- a/src/js_lexer/identifier.zig +++ b/src/js_lexer/identifier.zig @@ -46,104 +46,105 @@ pub const Bitset = struct { } }; -// pub const JumpTable = struct { -// const minInt = @import("std").math.minInt; -// const maxInt = @import("std").math.maxInt; -// const max_codepoint = 0x10FFFF; -// noinline fn isIdentifierPartSlow(codepoint: i32) bool { -// @setCold(true); -// return switch (codepoint) { -// // explicitly tell LLVM's optimizer about values we know will not be in the range of this switch statement -// 0xaa...0xffd7 => isIdentifierPartSlow16(@intCast(u16, codepoint)), -// (0xffd7 + 1)...0xe01ef => isIdentifierPartSlow32(codepoint), -// else => false, -// }; -// } +/// In WASM, we use the JumpTable version +pub const JumpTable = struct { + const minInt = @import("std").math.minInt; + const maxInt = @import("std").math.maxInt; + const max_codepoint = 0x10FFFF; + noinline fn isIdentifierPartSlow(codepoint: i32) bool { + @setCold(true); + return switch (codepoint) { + // explicitly tell LLVM's optimizer about values we know will not be in the range of this switch statement + 0xaa...0xffd7 => isIdentifierPartSlow16(@intCast(u16, codepoint)), + (0xffd7 + 1)...0xe01ef => isIdentifierPartSlow32(codepoint), + else => false, + }; + } -// fn isIdentifierPartSlow16(codepoint: u16) bool { -// return switch (codepoint) { -// minInt(u16)...(0xaa - 1) => unreachable, -// 0xaa...0xaa, 0xb5...0xb5, 0xb7...0xb7, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x300...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x483...0x487, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x591...0x5bd, 0x5bf...0x5bf, 0x5c1...0x5c2, 0x5c4...0x5c5, 0x5c7...0x5c7, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x610...0x61a, 0x620...0x669, 0x66e...0x6d3, 0x6d5...0x6dc, 0x6df...0x6e8, 0x6ea...0x6fc, 0x6ff...0x6ff, 0x710...0x74a, 0x74d...0x7b1, 0x7c0...0x7f5, 0x7fa...0x7fa, 0x7fd...0x7fd, 0x800...0x82d, 0x840...0x85b, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x8d3...0x8e1, 0x8e3...0x963, 0x966...0x96f, 0x971...0x983, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bc...0x9c4, 0x9c7...0x9c8, 0x9cb...0x9ce, 0x9d7...0x9d7, 0x9dc...0x9dd, 0x9df...0x9e3, 0x9e6...0x9f1, 0x9fc...0x9fc, 0x9fe...0x9fe, 0xa01...0xa03, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa3c...0xa3c, 0xa3e...0xa42, 0xa47...0xa48, 0xa4b...0xa4d, 0xa51...0xa51, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa66...0xa75, 0xa81...0xa83, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabc...0xac5, 0xac7...0xac9, 0xacb...0xacd, 0xad0...0xad0, 0xae0...0xae3, 0xae6...0xaef, 0xaf9...0xaff, 0xb01...0xb03, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3c...0xb44, 0xb47...0xb48, 0xb4b...0xb4d, 0xb55...0xb57, 0xb5c...0xb5d, 0xb5f...0xb63, 0xb66...0xb6f, 0xb71...0xb71, 0xb82...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbbe...0xbc2, 0xbc6...0xbc8, 0xbca...0xbcd, 0xbd0...0xbd0, 0xbd7...0xbd7, 0xbe6...0xbef, 0xc00...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc44, 0xc46...0xc48, 0xc4a...0xc4d, 0xc55...0xc56, 0xc58...0xc5a, 0xc60...0xc63, 0xc66...0xc6f, 0xc80...0xc83, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbc...0xcc4, 0xcc6...0xcc8, 0xcca...0xccd, 0xcd5...0xcd6, 0xcde...0xcde, 0xce0...0xce3, 0xce6...0xcef, 0xcf1...0xcf2, 0xd00...0xd0c, 0xd0e...0xd10, 0xd12...0xd44, 0xd46...0xd48, 0xd4a...0xd4e, 0xd54...0xd57, 0xd5f...0xd63, 0xd66...0xd6f, 0xd7a...0xd7f, 0xd81...0xd83, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xdca...0xdca, 0xdcf...0xdd4, 0xdd6...0xdd6, 0xdd8...0xddf, 0xde6...0xdef, 0xdf2...0xdf3, 0xe01...0xe3a, 0xe40...0xe4e, 0xe50...0xe59, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xec8...0xecd, 0xed0...0xed9, 0xedc...0xedf, 0xf00...0xf00, 0xf18...0xf19, 0xf20...0xf29, 0xf35...0xf35, 0xf37...0xf37, 0xf39...0xf39, 0xf3e...0xf47, 0xf49...0xf6c, 0xf71...0xf84, 0xf86...0xf97, 0xf99...0xfbc, 0xfc6...0xfc6, 0x1000...0x1049, 0x1050...0x109d, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x135d...0x135f, 0x1369...0x1371, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1714, 0x1720...0x1734, 0x1740...0x1753, 0x1760...0x176c, 0x176e...0x1770, 0x1772...0x1773, 0x1780...0x17d3, 0x17d7...0x17d7, 0x17dc...0x17dd, 0x17e0...0x17e9, 0x180b...0x180d, 0x1810...0x1819, 0x1820...0x1878, 0x1880...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1920...0x192b, 0x1930...0x193b, 0x1946...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x19d0...0x19da, 0x1a00...0x1a1b, 0x1a20...0x1a5e, 0x1a60...0x1a7c, 0x1a7f...0x1a89, 0x1a90...0x1a99, 0x1aa7...0x1aa7, 0x1ab0...0x1abd, 0x1abf...0x1ac0, 0x1b00...0x1b4b, 0x1b50...0x1b59, 0x1b6b...0x1b73, 0x1b80...0x1bf3, 0x1c00...0x1c37, 0x1c40...0x1c49, 0x1c4d...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1cd0...0x1cd2, 0x1cd4...0x1cfa, 0x1d00...0x1df9, 0x1dfb...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x203f...0x2040, 0x2054...0x2054, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x20d0...0x20dc, 0x20e1...0x20e1, 0x20e5...0x20f0, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d7f...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x2de0...0x2dff, 0x3005...0x3007, 0x3021...0x302f, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x3099...0x309f, 0x30a1...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa62b, 0xa640...0xa66f, 0xa674...0xa67d, 0xa67f...0xa6f1, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa827, 0xa82c...0xa82c, 0xa840...0xa873, 0xa880...0xa8c5, 0xa8d0...0xa8d9, 0xa8e0...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa92d, 0xa930...0xa953, 0xa960...0xa97c, 0xa980...0xa9c0, 0xa9cf...0xa9d9, 0xa9e0...0xa9fe, 0xaa00...0xaa36, 0xaa40...0xaa4d, 0xaa50...0xaa59, 0xaa60...0xaa76, 0xaa7a...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaef, 0xaaf2...0xaaf6, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabea, 0xabec...0xabed, 0xabf0...0xabf9, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7, 0xfdf0...0xfdfb, 0xfe00...0xfe0f, 0xfe20...0xfe2f, 0xfe33...0xfe34, 0xfe4d...0xfe4f, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff10...0xff19, 0xff21...0xff3a, 0xff3f...0xff3f, 0xff41...0xff5a, 0xff65...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7 => true, -// else => false, -// }; -// } + fn isIdentifierPartSlow16(codepoint: u16) bool { + return switch (codepoint) { + minInt(u16)...(0xaa - 1) => unreachable, + 0xaa...0xaa, 0xb5...0xb5, 0xb7...0xb7, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x300...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x483...0x487, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x591...0x5bd, 0x5bf...0x5bf, 0x5c1...0x5c2, 0x5c4...0x5c5, 0x5c7...0x5c7, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x610...0x61a, 0x620...0x669, 0x66e...0x6d3, 0x6d5...0x6dc, 0x6df...0x6e8, 0x6ea...0x6fc, 0x6ff...0x6ff, 0x710...0x74a, 0x74d...0x7b1, 0x7c0...0x7f5, 0x7fa...0x7fa, 0x7fd...0x7fd, 0x800...0x82d, 0x840...0x85b, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x8d3...0x8e1, 0x8e3...0x963, 0x966...0x96f, 0x971...0x983, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bc...0x9c4, 0x9c7...0x9c8, 0x9cb...0x9ce, 0x9d7...0x9d7, 0x9dc...0x9dd, 0x9df...0x9e3, 0x9e6...0x9f1, 0x9fc...0x9fc, 0x9fe...0x9fe, 0xa01...0xa03, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa3c...0xa3c, 0xa3e...0xa42, 0xa47...0xa48, 0xa4b...0xa4d, 0xa51...0xa51, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa66...0xa75, 0xa81...0xa83, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabc...0xac5, 0xac7...0xac9, 0xacb...0xacd, 0xad0...0xad0, 0xae0...0xae3, 0xae6...0xaef, 0xaf9...0xaff, 0xb01...0xb03, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3c...0xb44, 0xb47...0xb48, 0xb4b...0xb4d, 0xb55...0xb57, 0xb5c...0xb5d, 0xb5f...0xb63, 0xb66...0xb6f, 0xb71...0xb71, 0xb82...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbbe...0xbc2, 0xbc6...0xbc8, 0xbca...0xbcd, 0xbd0...0xbd0, 0xbd7...0xbd7, 0xbe6...0xbef, 0xc00...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc44, 0xc46...0xc48, 0xc4a...0xc4d, 0xc55...0xc56, 0xc58...0xc5a, 0xc60...0xc63, 0xc66...0xc6f, 0xc80...0xc83, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbc...0xcc4, 0xcc6...0xcc8, 0xcca...0xccd, 0xcd5...0xcd6, 0xcde...0xcde, 0xce0...0xce3, 0xce6...0xcef, 0xcf1...0xcf2, 0xd00...0xd0c, 0xd0e...0xd10, 0xd12...0xd44, 0xd46...0xd48, 0xd4a...0xd4e, 0xd54...0xd57, 0xd5f...0xd63, 0xd66...0xd6f, 0xd7a...0xd7f, 0xd81...0xd83, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xdca...0xdca, 0xdcf...0xdd4, 0xdd6...0xdd6, 0xdd8...0xddf, 0xde6...0xdef, 0xdf2...0xdf3, 0xe01...0xe3a, 0xe40...0xe4e, 0xe50...0xe59, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xec8...0xecd, 0xed0...0xed9, 0xedc...0xedf, 0xf00...0xf00, 0xf18...0xf19, 0xf20...0xf29, 0xf35...0xf35, 0xf37...0xf37, 0xf39...0xf39, 0xf3e...0xf47, 0xf49...0xf6c, 0xf71...0xf84, 0xf86...0xf97, 0xf99...0xfbc, 0xfc6...0xfc6, 0x1000...0x1049, 0x1050...0x109d, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x135d...0x135f, 0x1369...0x1371, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1714, 0x1720...0x1734, 0x1740...0x1753, 0x1760...0x176c, 0x176e...0x1770, 0x1772...0x1773, 0x1780...0x17d3, 0x17d7...0x17d7, 0x17dc...0x17dd, 0x17e0...0x17e9, 0x180b...0x180d, 0x1810...0x1819, 0x1820...0x1878, 0x1880...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1920...0x192b, 0x1930...0x193b, 0x1946...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x19d0...0x19da, 0x1a00...0x1a1b, 0x1a20...0x1a5e, 0x1a60...0x1a7c, 0x1a7f...0x1a89, 0x1a90...0x1a99, 0x1aa7...0x1aa7, 0x1ab0...0x1abd, 0x1abf...0x1ac0, 0x1b00...0x1b4b, 0x1b50...0x1b59, 0x1b6b...0x1b73, 0x1b80...0x1bf3, 0x1c00...0x1c37, 0x1c40...0x1c49, 0x1c4d...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1cd0...0x1cd2, 0x1cd4...0x1cfa, 0x1d00...0x1df9, 0x1dfb...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x203f...0x2040, 0x2054...0x2054, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x20d0...0x20dc, 0x20e1...0x20e1, 0x20e5...0x20f0, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d7f...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x2de0...0x2dff, 0x3005...0x3007, 0x3021...0x302f, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x3099...0x309f, 0x30a1...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa62b, 0xa640...0xa66f, 0xa674...0xa67d, 0xa67f...0xa6f1, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa827, 0xa82c...0xa82c, 0xa840...0xa873, 0xa880...0xa8c5, 0xa8d0...0xa8d9, 0xa8e0...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa92d, 0xa930...0xa953, 0xa960...0xa97c, 0xa980...0xa9c0, 0xa9cf...0xa9d9, 0xa9e0...0xa9fe, 0xaa00...0xaa36, 0xaa40...0xaa4d, 0xaa50...0xaa59, 0xaa60...0xaa76, 0xaa7a...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaef, 0xaaf2...0xaaf6, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabea, 0xabec...0xabed, 0xabf0...0xabf9, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7, 0xfdf0...0xfdfb, 0xfe00...0xfe0f, 0xfe20...0xfe2f, 0xfe33...0xfe34, 0xfe4d...0xfe4f, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff10...0xff19, 0xff21...0xff3a, 0xff3f...0xff3f, 0xff41...0xff5a, 0xff65...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7 => true, + else => false, + }; + } -// fn isIdentifierPartSlow32(codepoint: i32) bool { -// return switch (codepoint) { -// 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x101fd...0x101fd, 0x10280...0x1029c, 0x102a0...0x102d0, 0x102e0...0x102e0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x1037a, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104a0...0x104a9, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a03, 0x10a05...0x10a06, 0x10a0c...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a38...0x10a3a, 0x10a3f...0x10a3f, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae6, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d27, 0x10d30...0x10d39, 0x10e80...0x10ea9, 0x10eab...0x10eac, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f50, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11000...0x11046, 0x11066...0x1106f, 0x1107f...0x110ba, 0x110d0...0x110e8, 0x110f0...0x110f9, 0x11100...0x11134, 0x11136...0x1113f, 0x11144...0x11147, 0x11150...0x11173, 0x11176...0x11176, 0x11180...0x111c4, 0x111c9...0x111cc, 0x111ce...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x11237, 0x1123e...0x1123e, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112ea, 0x112f0...0x112f9, 0x11300...0x11303, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133b...0x11344, 0x11347...0x11348, 0x1134b...0x1134d, 0x11350...0x11350, 0x11357...0x11357, 0x1135d...0x11363, 0x11366...0x1136c, 0x11370...0x11374, 0x11400...0x1144a, 0x11450...0x11459, 0x1145e...0x11461, 0x11480...0x114c5, 0x114c7...0x114c7, 0x114d0...0x114d9, 0x11580...0x115b5, 0x115b8...0x115c0, 0x115d8...0x115dd, 0x11600...0x11640, 0x11644...0x11644, 0x11650...0x11659, 0x11680...0x116b8, 0x116c0...0x116c9, 0x11700...0x1171a, 0x1171d...0x1172b, 0x11730...0x11739, 0x11800...0x1183a, 0x118a0...0x118e9, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x11935, 0x11937...0x11938, 0x1193b...0x11943, 0x11950...0x11959, 0x119a0...0x119a7, 0x119aa...0x119d7, 0x119da...0x119e1, 0x119e3...0x119e4, 0x11a00...0x11a3e, 0x11a47...0x11a47, 0x11a50...0x11a99, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c36, 0x11c38...0x11c40, 0x11c50...0x11c59, 0x11c72...0x11c8f, 0x11c92...0x11ca7, 0x11ca9...0x11cb6, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d36, 0x11d3a...0x11d3a, 0x11d3c...0x11d3d, 0x11d3f...0x11d47, 0x11d50...0x11d59, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d8e, 0x11d90...0x11d91, 0x11d93...0x11d98, 0x11da0...0x11da9, 0x11ee0...0x11ef6, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16a60...0x16a69, 0x16ad0...0x16aed, 0x16af0...0x16af4, 0x16b00...0x16b36, 0x16b40...0x16b43, 0x16b50...0x16b59, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f4f...0x16f87, 0x16f8f...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe4, 0x16ff0...0x16ff1, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1bc9d...0x1bc9e, 0x1d165...0x1d169, 0x1d16d...0x1d172, 0x1d17b...0x1d182, 0x1d185...0x1d18b, 0x1d1aa...0x1d1ad, 0x1d242...0x1d244, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1d7ce...0x1d7ff, 0x1da00...0x1da36, 0x1da3b...0x1da6c, 0x1da75...0x1da75, 0x1da84...0x1da84, 0x1da9b...0x1da9f, 0x1daa1...0x1daaf, 0x1e000...0x1e006, 0x1e008...0x1e018, 0x1e01b...0x1e021, 0x1e023...0x1e024, 0x1e026...0x1e02a, 0x1e100...0x1e12c, 0x1e130...0x1e13d, 0x1e140...0x1e149, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2f9, 0x1e800...0x1e8c4, 0x1e8d0...0x1e8d6, 0x1e900...0x1e94b, 0x1e950...0x1e959, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x1fbf0...0x1fbf9, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a, 0xe0100...0xe01ef => true, -// else => false, -// }; -// } + fn isIdentifierPartSlow32(codepoint: i32) bool { + return switch (codepoint) { + 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x101fd...0x101fd, 0x10280...0x1029c, 0x102a0...0x102d0, 0x102e0...0x102e0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x1037a, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104a0...0x104a9, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a03, 0x10a05...0x10a06, 0x10a0c...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a38...0x10a3a, 0x10a3f...0x10a3f, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae6, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d27, 0x10d30...0x10d39, 0x10e80...0x10ea9, 0x10eab...0x10eac, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f50, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11000...0x11046, 0x11066...0x1106f, 0x1107f...0x110ba, 0x110d0...0x110e8, 0x110f0...0x110f9, 0x11100...0x11134, 0x11136...0x1113f, 0x11144...0x11147, 0x11150...0x11173, 0x11176...0x11176, 0x11180...0x111c4, 0x111c9...0x111cc, 0x111ce...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x11237, 0x1123e...0x1123e, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112ea, 0x112f0...0x112f9, 0x11300...0x11303, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133b...0x11344, 0x11347...0x11348, 0x1134b...0x1134d, 0x11350...0x11350, 0x11357...0x11357, 0x1135d...0x11363, 0x11366...0x1136c, 0x11370...0x11374, 0x11400...0x1144a, 0x11450...0x11459, 0x1145e...0x11461, 0x11480...0x114c5, 0x114c7...0x114c7, 0x114d0...0x114d9, 0x11580...0x115b5, 0x115b8...0x115c0, 0x115d8...0x115dd, 0x11600...0x11640, 0x11644...0x11644, 0x11650...0x11659, 0x11680...0x116b8, 0x116c0...0x116c9, 0x11700...0x1171a, 0x1171d...0x1172b, 0x11730...0x11739, 0x11800...0x1183a, 0x118a0...0x118e9, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x11935, 0x11937...0x11938, 0x1193b...0x11943, 0x11950...0x11959, 0x119a0...0x119a7, 0x119aa...0x119d7, 0x119da...0x119e1, 0x119e3...0x119e4, 0x11a00...0x11a3e, 0x11a47...0x11a47, 0x11a50...0x11a99, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c36, 0x11c38...0x11c40, 0x11c50...0x11c59, 0x11c72...0x11c8f, 0x11c92...0x11ca7, 0x11ca9...0x11cb6, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d36, 0x11d3a...0x11d3a, 0x11d3c...0x11d3d, 0x11d3f...0x11d47, 0x11d50...0x11d59, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d8e, 0x11d90...0x11d91, 0x11d93...0x11d98, 0x11da0...0x11da9, 0x11ee0...0x11ef6, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16a60...0x16a69, 0x16ad0...0x16aed, 0x16af0...0x16af4, 0x16b00...0x16b36, 0x16b40...0x16b43, 0x16b50...0x16b59, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f4f...0x16f87, 0x16f8f...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe4, 0x16ff0...0x16ff1, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1bc9d...0x1bc9e, 0x1d165...0x1d169, 0x1d16d...0x1d172, 0x1d17b...0x1d182, 0x1d185...0x1d18b, 0x1d1aa...0x1d1ad, 0x1d242...0x1d244, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1d7ce...0x1d7ff, 0x1da00...0x1da36, 0x1da3b...0x1da6c, 0x1da75...0x1da75, 0x1da84...0x1da84, 0x1da9b...0x1da9f, 0x1daa1...0x1daaf, 0x1e000...0x1e006, 0x1e008...0x1e018, 0x1e01b...0x1e021, 0x1e023...0x1e024, 0x1e026...0x1e02a, 0x1e100...0x1e12c, 0x1e130...0x1e13d, 0x1e140...0x1e149, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2f9, 0x1e800...0x1e8c4, 0x1e8d0...0x1e8d6, 0x1e900...0x1e94b, 0x1e950...0x1e959, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x1fbf0...0x1fbf9, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a, 0xe0100...0xe01ef => true, + else => false, + }; + } -// fn isIdentifierStartSlow16(codepoint: u16) bool { -// return switch (codepoint) { -// 0xaa...0xaa, 0xb5...0xb5, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x370...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x386, 0x388...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x620...0x64a, 0x66e...0x66f, 0x671...0x6d3, 0x6d5...0x6d5, 0x6e5...0x6e6, 0x6ee...0x6ef, 0x6fa...0x6fc, 0x6ff...0x6ff, 0x710...0x710, 0x712...0x72f, 0x74d...0x7a5, 0x7b1...0x7b1, 0x7ca...0x7ea, 0x7f4...0x7f5, 0x7fa...0x7fa, 0x800...0x815, 0x81a...0x81a, 0x824...0x824, 0x828...0x828, 0x840...0x858, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x904...0x939, 0x93d...0x93d, 0x950...0x950, 0x958...0x961, 0x971...0x980, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bd...0x9bd, 0x9ce...0x9ce, 0x9dc...0x9dd, 0x9df...0x9e1, 0x9f0...0x9f1, 0x9fc...0x9fc, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa72...0xa74, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabd...0xabd, 0xad0...0xad0, 0xae0...0xae1, 0xaf9...0xaf9, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3d...0xb3d, 0xb5c...0xb5d, 0xb5f...0xb61, 0xb71...0xb71, 0xb83...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbd0...0xbd0, 0xc05...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc3d, 0xc58...0xc5a, 0xc60...0xc61, 0xc80...0xc80, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbd...0xcbd, 0xcde...0xcde, 0xce0...0xce1, 0xcf1...0xcf2, 0xd04...0xd0c, 0xd0e...0xd10, 0xd12...0xd3a, 0xd3d...0xd3d, 0xd4e...0xd4e, 0xd54...0xd56, 0xd5f...0xd61, 0xd7a...0xd7f, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xe01...0xe30, 0xe32...0xe33, 0xe40...0xe46, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xeb0, 0xeb2...0xeb3, 0xebd...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xedc...0xedf, 0xf00...0xf00, 0xf40...0xf47, 0xf49...0xf6c, 0xf88...0xf8c, 0x1000...0x102a, 0x103f...0x103f, 0x1050...0x1055, 0x105a...0x105d, 0x1061...0x1061, 0x1065...0x1066, 0x106e...0x1070, 0x1075...0x1081, 0x108e...0x108e, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1711, 0x1720...0x1731, 0x1740...0x1751, 0x1760...0x176c, 0x176e...0x1770, 0x1780...0x17b3, 0x17d7...0x17d7, 0x17dc...0x17dc, 0x1820...0x1878, 0x1880...0x18a8, 0x18aa...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1950...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x1a00...0x1a16, 0x1a20...0x1a54, 0x1aa7...0x1aa7, 0x1b05...0x1b33, 0x1b45...0x1b4b, 0x1b83...0x1ba0, 0x1bae...0x1baf, 0x1bba...0x1be5, 0x1c00...0x1c23, 0x1c4d...0x1c4f, 0x1c5a...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1ce9...0x1cec, 0x1cee...0x1cf3, 0x1cf5...0x1cf6, 0x1cfa...0x1cfa, 0x1d00...0x1dbf, 0x1e00...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cee, 0x2cf2...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d80...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x3005...0x3007, 0x3021...0x3029, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x309b...0x309f, 0x30a1...0x30fa, 0x30fc...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa61f, 0xa62a...0xa62b, 0xa640...0xa66e, 0xa67f...0xa69d, 0xa6a0...0xa6ef, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa801, 0xa803...0xa805, 0xa807...0xa80a, 0xa80c...0xa822, 0xa840...0xa873, 0xa882...0xa8b3, 0xa8f2...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa8fe, 0xa90a...0xa925, 0xa930...0xa946, 0xa960...0xa97c, 0xa984...0xa9b2, 0xa9cf...0xa9cf, 0xa9e0...0xa9e4, 0xa9e6...0xa9ef, 0xa9fa...0xa9fe, 0xaa00...0xaa28, 0xaa40...0xaa42, 0xaa44...0xaa4b, 0xaa60...0xaa76, 0xaa7a...0xaa7a, 0xaa7e...0xaaaf, 0xaab1...0xaab1, 0xaab5...0xaab6, 0xaab9...0xaabd, 0xaac0...0xaac0, 0xaac2...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaea, 0xaaf2...0xaaf4, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabe2, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb1d, 0xfb1f...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7 => true, -// else => false, -// }; -// } + fn isIdentifierStartSlow16(codepoint: u16) bool { + return switch (codepoint) { + 0xaa...0xaa, 0xb5...0xb5, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x370...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x386, 0x388...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x620...0x64a, 0x66e...0x66f, 0x671...0x6d3, 0x6d5...0x6d5, 0x6e5...0x6e6, 0x6ee...0x6ef, 0x6fa...0x6fc, 0x6ff...0x6ff, 0x710...0x710, 0x712...0x72f, 0x74d...0x7a5, 0x7b1...0x7b1, 0x7ca...0x7ea, 0x7f4...0x7f5, 0x7fa...0x7fa, 0x800...0x815, 0x81a...0x81a, 0x824...0x824, 0x828...0x828, 0x840...0x858, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x904...0x939, 0x93d...0x93d, 0x950...0x950, 0x958...0x961, 0x971...0x980, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bd...0x9bd, 0x9ce...0x9ce, 0x9dc...0x9dd, 0x9df...0x9e1, 0x9f0...0x9f1, 0x9fc...0x9fc, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa72...0xa74, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabd...0xabd, 0xad0...0xad0, 0xae0...0xae1, 0xaf9...0xaf9, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3d...0xb3d, 0xb5c...0xb5d, 0xb5f...0xb61, 0xb71...0xb71, 0xb83...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbd0...0xbd0, 0xc05...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc3d, 0xc58...0xc5a, 0xc60...0xc61, 0xc80...0xc80, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbd...0xcbd, 0xcde...0xcde, 0xce0...0xce1, 0xcf1...0xcf2, 0xd04...0xd0c, 0xd0e...0xd10, 0xd12...0xd3a, 0xd3d...0xd3d, 0xd4e...0xd4e, 0xd54...0xd56, 0xd5f...0xd61, 0xd7a...0xd7f, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xe01...0xe30, 0xe32...0xe33, 0xe40...0xe46, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xeb0, 0xeb2...0xeb3, 0xebd...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xedc...0xedf, 0xf00...0xf00, 0xf40...0xf47, 0xf49...0xf6c, 0xf88...0xf8c, 0x1000...0x102a, 0x103f...0x103f, 0x1050...0x1055, 0x105a...0x105d, 0x1061...0x1061, 0x1065...0x1066, 0x106e...0x1070, 0x1075...0x1081, 0x108e...0x108e, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1711, 0x1720...0x1731, 0x1740...0x1751, 0x1760...0x176c, 0x176e...0x1770, 0x1780...0x17b3, 0x17d7...0x17d7, 0x17dc...0x17dc, 0x1820...0x1878, 0x1880...0x18a8, 0x18aa...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1950...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x1a00...0x1a16, 0x1a20...0x1a54, 0x1aa7...0x1aa7, 0x1b05...0x1b33, 0x1b45...0x1b4b, 0x1b83...0x1ba0, 0x1bae...0x1baf, 0x1bba...0x1be5, 0x1c00...0x1c23, 0x1c4d...0x1c4f, 0x1c5a...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1ce9...0x1cec, 0x1cee...0x1cf3, 0x1cf5...0x1cf6, 0x1cfa...0x1cfa, 0x1d00...0x1dbf, 0x1e00...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cee, 0x2cf2...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d80...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x3005...0x3007, 0x3021...0x3029, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x309b...0x309f, 0x30a1...0x30fa, 0x30fc...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa61f, 0xa62a...0xa62b, 0xa640...0xa66e, 0xa67f...0xa69d, 0xa6a0...0xa6ef, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa801, 0xa803...0xa805, 0xa807...0xa80a, 0xa80c...0xa822, 0xa840...0xa873, 0xa882...0xa8b3, 0xa8f2...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa8fe, 0xa90a...0xa925, 0xa930...0xa946, 0xa960...0xa97c, 0xa984...0xa9b2, 0xa9cf...0xa9cf, 0xa9e0...0xa9e4, 0xa9e6...0xa9ef, 0xa9fa...0xa9fe, 0xaa00...0xaa28, 0xaa40...0xaa42, 0xaa44...0xaa4b, 0xaa60...0xaa76, 0xaa7a...0xaa7a, 0xaa7e...0xaaaf, 0xaab1...0xaab1, 0xaab5...0xaab6, 0xaab9...0xaabd, 0xaac0...0xaac0, 0xaac2...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaea, 0xaaf2...0xaaf4, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabe2, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb1d, 0xfb1f...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7 => true, + else => false, + }; + } -// fn isIdentifierStartSlow32(codepoint: i32) bool { -// return switch (codepoint) { -// 0xfdf0...0xfdfb, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff21...0xff3a, 0xff41...0xff5a, 0xff66...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7, 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x10280...0x1029c, 0x102a0...0x102d0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x10375, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a00, 0x10a10...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae4, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d23, 0x10e80...0x10ea9, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f45, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11003...0x11037, 0x11083...0x110af, 0x110d0...0x110e8, 0x11103...0x11126, 0x11144...0x11144, 0x11147...0x11147, 0x11150...0x11172, 0x11176...0x11176, 0x11183...0x111b2, 0x111c1...0x111c4, 0x111da...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x1122b, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112de, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133d...0x1133d, 0x11350...0x11350, 0x1135d...0x11361, 0x11400...0x11434, 0x11447...0x1144a, 0x1145f...0x11461, 0x11480...0x114af, 0x114c4...0x114c5, 0x114c7...0x114c7, 0x11580...0x115ae, 0x115d8...0x115db, 0x11600...0x1162f, 0x11644...0x11644, 0x11680...0x116aa, 0x116b8...0x116b8, 0x11700...0x1171a, 0x11800...0x1182b, 0x118a0...0x118df, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x1192f, 0x1193f...0x1193f, 0x11941...0x11941, 0x119a0...0x119a7, 0x119aa...0x119d0, 0x119e1...0x119e1, 0x119e3...0x119e3, 0x11a00...0x11a00, 0x11a0b...0x11a32, 0x11a3a...0x11a3a, 0x11a50...0x11a50, 0x11a5c...0x11a89, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c2e, 0x11c40...0x11c40, 0x11c72...0x11c8f, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d30, 0x11d46...0x11d46, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d89, 0x11d98...0x11d98, 0x11ee0...0x11ef2, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16ad0...0x16aed, 0x16b00...0x16b2f, 0x16b40...0x16b43, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f50...0x16f50, 0x16f93...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe3, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1e100...0x1e12c, 0x1e137...0x1e13d, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2eb, 0x1e800...0x1e8c4, 0x1e900...0x1e943, 0x1e94b...0x1e94b, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a => true, -// else => false, -// }; -// } + fn isIdentifierStartSlow32(codepoint: i32) bool { + return switch (codepoint) { + 0xfdf0...0xfdfb, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff21...0xff3a, 0xff41...0xff5a, 0xff66...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7, 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x10280...0x1029c, 0x102a0...0x102d0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x10375, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a00, 0x10a10...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae4, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d23, 0x10e80...0x10ea9, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f45, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11003...0x11037, 0x11083...0x110af, 0x110d0...0x110e8, 0x11103...0x11126, 0x11144...0x11144, 0x11147...0x11147, 0x11150...0x11172, 0x11176...0x11176, 0x11183...0x111b2, 0x111c1...0x111c4, 0x111da...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x1122b, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112de, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133d...0x1133d, 0x11350...0x11350, 0x1135d...0x11361, 0x11400...0x11434, 0x11447...0x1144a, 0x1145f...0x11461, 0x11480...0x114af, 0x114c4...0x114c5, 0x114c7...0x114c7, 0x11580...0x115ae, 0x115d8...0x115db, 0x11600...0x1162f, 0x11644...0x11644, 0x11680...0x116aa, 0x116b8...0x116b8, 0x11700...0x1171a, 0x11800...0x1182b, 0x118a0...0x118df, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x1192f, 0x1193f...0x1193f, 0x11941...0x11941, 0x119a0...0x119a7, 0x119aa...0x119d0, 0x119e1...0x119e1, 0x119e3...0x119e3, 0x11a00...0x11a00, 0x11a0b...0x11a32, 0x11a3a...0x11a3a, 0x11a50...0x11a50, 0x11a5c...0x11a89, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c2e, 0x11c40...0x11c40, 0x11c72...0x11c8f, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d30, 0x11d46...0x11d46, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d89, 0x11d98...0x11d98, 0x11ee0...0x11ef2, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16ad0...0x16aed, 0x16b00...0x16b2f, 0x16b40...0x16b43, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f50...0x16f50, 0x16f93...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe3, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1e100...0x1e12c, 0x1e137...0x1e13d, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2eb, 0x1e800...0x1e8c4, 0x1e900...0x1e943, 0x1e94b...0x1e94b, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a => true, + else => false, + }; + } -// noinline fn isIdentifierStartSlow(codepoint: i32) bool { -// @setCold(true); -// return switch (codepoint) { -// // explicitly tell LLVM's optimizer about values we know will not be in the range of this switch statement + noinline fn isIdentifierStartSlow(codepoint: i32) bool { + @setCold(true); + return switch (codepoint) { + // explicitly tell LLVM's optimizer about values we know will not be in the range of this switch statement -// (max_codepoint + 1)...maxInt(i32), minInt(i32)...127 => unreachable, -// 128...0xfdc7 => isIdentifierStartSlow16(@intCast(u16, codepoint)), -// 0xfdf0...0x3134a => isIdentifierStartSlow32(codepoint), -// else => false, -// }; -// } + (max_codepoint + 1)...maxInt(i32), minInt(i32)...127 => unreachable, + 128...0xfdc7 => isIdentifierStartSlow16(@intCast(u16, codepoint)), + 0xfdf0...0x3134a => isIdentifierStartSlow32(codepoint), + else => false, + }; + } -// pub inline fn isIdentifierStart(codepoint: i32) bool { -// return switch (codepoint) { -// 'A'...'Z', 'a'...'z', '$', '_' => true, -// else => if (codepoint < 128) -// return false -// else -// return isIdentifierStartSlow(codepoint), -// }; -// } + pub inline fn isIdentifierStart(codepoint: i32) bool { + return switch (codepoint) { + 'A'...'Z', 'a'...'z', '$', '_' => true, + else => if (codepoint < 128) + return false + else + return isIdentifierStartSlow(codepoint), + }; + } -// pub inline fn isIdentifierPart(codepoint: i32) bool { -// return switch (codepoint) { -// 'A'...'Z', 'a'...'z', '0'...'9', '$', '_' => true, -// else => if (codepoint < 128) -// return false -// else -// return isIdentifierPartSlow(codepoint), -// }; -// } -// }; + pub inline fn isIdentifierPart(codepoint: i32) bool { + return switch (codepoint) { + 'A'...'Z', 'a'...'z', '0'...'9', '$', '_' => true, + else => if (codepoint < 128) + return false + else + return isIdentifierPartSlow(codepoint), + }; + } +}; -// pub const JumpTableInline = struct { -// pub inline fn isIdentifierStart(codepoint: i32) bool { -// return switch (codepoint) { -// 'A'...'Z', 'a'...'z', '$', '_' => true, +pub const JumpTableInline = struct { + pub inline fn isIdentifierStart(codepoint: i32) bool { + return switch (codepoint) { + 'A'...'Z', 'a'...'z', '$', '_' => true, -// else => switch (codepoint) { -// 0x41...0x5a, 0x61...0x7a, 0xaa...0xaa, 0xb5...0xb5, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x370...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x386, 0x388...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x620...0x64a, 0x66e...0x66f, 0x671...0x6d3, 0x6d5...0x6d5, 0x6e5...0x6e6, 0x6ee...0x6ef, 0x6fa...0x6fc, 0x6ff...0x6ff, 0x710...0x710, 0x712...0x72f, 0x74d...0x7a5, 0x7b1...0x7b1, 0x7ca...0x7ea, 0x7f4...0x7f5, 0x7fa...0x7fa, 0x800...0x815, 0x81a...0x81a, 0x824...0x824, 0x828...0x828, 0x840...0x858, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x904...0x939, 0x93d...0x93d, 0x950...0x950, 0x958...0x961, 0x971...0x980, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bd...0x9bd, 0x9ce...0x9ce, 0x9dc...0x9dd, 0x9df...0x9e1, 0x9f0...0x9f1, 0x9fc...0x9fc, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa72...0xa74, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabd...0xabd, 0xad0...0xad0, 0xae0...0xae1, 0xaf9...0xaf9, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3d...0xb3d, 0xb5c...0xb5d, 0xb5f...0xb61, 0xb71...0xb71, 0xb83...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbd0...0xbd0, 0xc05...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc3d, 0xc58...0xc5a, 0xc60...0xc61, 0xc80...0xc80, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbd...0xcbd, 0xcde...0xcde, 0xce0...0xce1, 0xcf1...0xcf2, 0xd04...0xd0c, 0xd0e...0xd10, 0xd12...0xd3a, 0xd3d...0xd3d, 0xd4e...0xd4e, 0xd54...0xd56, 0xd5f...0xd61, 0xd7a...0xd7f, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xe01...0xe30, 0xe32...0xe33, 0xe40...0xe46, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xeb0, 0xeb2...0xeb3, 0xebd...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xedc...0xedf, 0xf00...0xf00, 0xf40...0xf47, 0xf49...0xf6c, 0xf88...0xf8c, 0x1000...0x102a, 0x103f...0x103f, 0x1050...0x1055, 0x105a...0x105d, 0x1061...0x1061, 0x1065...0x1066, 0x106e...0x1070, 0x1075...0x1081, 0x108e...0x108e, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1711, 0x1720...0x1731, 0x1740...0x1751, 0x1760...0x176c, 0x176e...0x1770, 0x1780...0x17b3, 0x17d7...0x17d7, 0x17dc...0x17dc, 0x1820...0x1878, 0x1880...0x18a8, 0x18aa...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1950...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x1a00...0x1a16, 0x1a20...0x1a54, 0x1aa7...0x1aa7, 0x1b05...0x1b33, 0x1b45...0x1b4b, 0x1b83...0x1ba0, 0x1bae...0x1baf, 0x1bba...0x1be5, 0x1c00...0x1c23, 0x1c4d...0x1c4f, 0x1c5a...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1ce9...0x1cec, 0x1cee...0x1cf3, 0x1cf5...0x1cf6, 0x1cfa...0x1cfa, 0x1d00...0x1dbf, 0x1e00...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cee, 0x2cf2...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d80...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x3005...0x3007, 0x3021...0x3029, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x309b...0x309f, 0x30a1...0x30fa, 0x30fc...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa61f, 0xa62a...0xa62b, 0xa640...0xa66e, 0xa67f...0xa69d, 0xa6a0...0xa6ef, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa801, 0xa803...0xa805, 0xa807...0xa80a, 0xa80c...0xa822, 0xa840...0xa873, 0xa882...0xa8b3, 0xa8f2...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa8fe, 0xa90a...0xa925, 0xa930...0xa946, 0xa960...0xa97c, 0xa984...0xa9b2, 0xa9cf...0xa9cf, 0xa9e0...0xa9e4, 0xa9e6...0xa9ef, 0xa9fa...0xa9fe, 0xaa00...0xaa28, 0xaa40...0xaa42, 0xaa44...0xaa4b, 0xaa60...0xaa76, 0xaa7a...0xaa7a, 0xaa7e...0xaaaf, 0xaab1...0xaab1, 0xaab5...0xaab6, 0xaab9...0xaabd, 0xaac0...0xaac0, 0xaac2...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaea, 0xaaf2...0xaaf4, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabe2, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb1d, 0xfb1f...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7, 0xfdf0...0xfdfb, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff21...0xff3a, 0xff41...0xff5a, 0xff66...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7, 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x10280...0x1029c, 0x102a0...0x102d0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x10375, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a00, 0x10a10...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae4, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d23, 0x10e80...0x10ea9, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f45, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11003...0x11037, 0x11083...0x110af, 0x110d0...0x110e8, 0x11103...0x11126, 0x11144...0x11144, 0x11147...0x11147, 0x11150...0x11172, 0x11176...0x11176, 0x11183...0x111b2, 0x111c1...0x111c4, 0x111da...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x1122b, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112de, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133d...0x1133d, 0x11350...0x11350, 0x1135d...0x11361, 0x11400...0x11434, 0x11447...0x1144a, 0x1145f...0x11461, 0x11480...0x114af, 0x114c4...0x114c5, 0x114c7...0x114c7, 0x11580...0x115ae, 0x115d8...0x115db, 0x11600...0x1162f, 0x11644...0x11644, 0x11680...0x116aa, 0x116b8...0x116b8, 0x11700...0x1171a, 0x11800...0x1182b, 0x118a0...0x118df, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x1192f, 0x1193f...0x1193f, 0x11941...0x11941, 0x119a0...0x119a7, 0x119aa...0x119d0, 0x119e1...0x119e1, 0x119e3...0x119e3, 0x11a00...0x11a00, 0x11a0b...0x11a32, 0x11a3a...0x11a3a, 0x11a50...0x11a50, 0x11a5c...0x11a89, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c2e, 0x11c40...0x11c40, 0x11c72...0x11c8f, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d30, 0x11d46...0x11d46, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d89, 0x11d98...0x11d98, 0x11ee0...0x11ef2, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16ad0...0x16aed, 0x16b00...0x16b2f, 0x16b40...0x16b43, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f50...0x16f50, 0x16f93...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe3, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1e100...0x1e12c, 0x1e137...0x1e13d, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2eb, 0x1e800...0x1e8c4, 0x1e900...0x1e943, 0x1e94b...0x1e94b, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a => true, -// else => false, -// }, -// }; -// } + else => switch (codepoint) { + 0x41...0x5a, 0x61...0x7a, 0xaa...0xaa, 0xb5...0xb5, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x370...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x386, 0x388...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x620...0x64a, 0x66e...0x66f, 0x671...0x6d3, 0x6d5...0x6d5, 0x6e5...0x6e6, 0x6ee...0x6ef, 0x6fa...0x6fc, 0x6ff...0x6ff, 0x710...0x710, 0x712...0x72f, 0x74d...0x7a5, 0x7b1...0x7b1, 0x7ca...0x7ea, 0x7f4...0x7f5, 0x7fa...0x7fa, 0x800...0x815, 0x81a...0x81a, 0x824...0x824, 0x828...0x828, 0x840...0x858, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x904...0x939, 0x93d...0x93d, 0x950...0x950, 0x958...0x961, 0x971...0x980, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bd...0x9bd, 0x9ce...0x9ce, 0x9dc...0x9dd, 0x9df...0x9e1, 0x9f0...0x9f1, 0x9fc...0x9fc, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa72...0xa74, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabd...0xabd, 0xad0...0xad0, 0xae0...0xae1, 0xaf9...0xaf9, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3d...0xb3d, 0xb5c...0xb5d, 0xb5f...0xb61, 0xb71...0xb71, 0xb83...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbd0...0xbd0, 0xc05...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc3d, 0xc58...0xc5a, 0xc60...0xc61, 0xc80...0xc80, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbd...0xcbd, 0xcde...0xcde, 0xce0...0xce1, 0xcf1...0xcf2, 0xd04...0xd0c, 0xd0e...0xd10, 0xd12...0xd3a, 0xd3d...0xd3d, 0xd4e...0xd4e, 0xd54...0xd56, 0xd5f...0xd61, 0xd7a...0xd7f, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xe01...0xe30, 0xe32...0xe33, 0xe40...0xe46, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xeb0, 0xeb2...0xeb3, 0xebd...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xedc...0xedf, 0xf00...0xf00, 0xf40...0xf47, 0xf49...0xf6c, 0xf88...0xf8c, 0x1000...0x102a, 0x103f...0x103f, 0x1050...0x1055, 0x105a...0x105d, 0x1061...0x1061, 0x1065...0x1066, 0x106e...0x1070, 0x1075...0x1081, 0x108e...0x108e, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1711, 0x1720...0x1731, 0x1740...0x1751, 0x1760...0x176c, 0x176e...0x1770, 0x1780...0x17b3, 0x17d7...0x17d7, 0x17dc...0x17dc, 0x1820...0x1878, 0x1880...0x18a8, 0x18aa...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1950...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x1a00...0x1a16, 0x1a20...0x1a54, 0x1aa7...0x1aa7, 0x1b05...0x1b33, 0x1b45...0x1b4b, 0x1b83...0x1ba0, 0x1bae...0x1baf, 0x1bba...0x1be5, 0x1c00...0x1c23, 0x1c4d...0x1c4f, 0x1c5a...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1ce9...0x1cec, 0x1cee...0x1cf3, 0x1cf5...0x1cf6, 0x1cfa...0x1cfa, 0x1d00...0x1dbf, 0x1e00...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cee, 0x2cf2...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d80...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x3005...0x3007, 0x3021...0x3029, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x309b...0x309f, 0x30a1...0x30fa, 0x30fc...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa61f, 0xa62a...0xa62b, 0xa640...0xa66e, 0xa67f...0xa69d, 0xa6a0...0xa6ef, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa801, 0xa803...0xa805, 0xa807...0xa80a, 0xa80c...0xa822, 0xa840...0xa873, 0xa882...0xa8b3, 0xa8f2...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa8fe, 0xa90a...0xa925, 0xa930...0xa946, 0xa960...0xa97c, 0xa984...0xa9b2, 0xa9cf...0xa9cf, 0xa9e0...0xa9e4, 0xa9e6...0xa9ef, 0xa9fa...0xa9fe, 0xaa00...0xaa28, 0xaa40...0xaa42, 0xaa44...0xaa4b, 0xaa60...0xaa76, 0xaa7a...0xaa7a, 0xaa7e...0xaaaf, 0xaab1...0xaab1, 0xaab5...0xaab6, 0xaab9...0xaabd, 0xaac0...0xaac0, 0xaac2...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaea, 0xaaf2...0xaaf4, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabe2, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb1d, 0xfb1f...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7, 0xfdf0...0xfdfb, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff21...0xff3a, 0xff41...0xff5a, 0xff66...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7, 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x10280...0x1029c, 0x102a0...0x102d0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x10375, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a00, 0x10a10...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae4, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d23, 0x10e80...0x10ea9, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f45, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11003...0x11037, 0x11083...0x110af, 0x110d0...0x110e8, 0x11103...0x11126, 0x11144...0x11144, 0x11147...0x11147, 0x11150...0x11172, 0x11176...0x11176, 0x11183...0x111b2, 0x111c1...0x111c4, 0x111da...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x1122b, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112de, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133d...0x1133d, 0x11350...0x11350, 0x1135d...0x11361, 0x11400...0x11434, 0x11447...0x1144a, 0x1145f...0x11461, 0x11480...0x114af, 0x114c4...0x114c5, 0x114c7...0x114c7, 0x11580...0x115ae, 0x115d8...0x115db, 0x11600...0x1162f, 0x11644...0x11644, 0x11680...0x116aa, 0x116b8...0x116b8, 0x11700...0x1171a, 0x11800...0x1182b, 0x118a0...0x118df, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x1192f, 0x1193f...0x1193f, 0x11941...0x11941, 0x119a0...0x119a7, 0x119aa...0x119d0, 0x119e1...0x119e1, 0x119e3...0x119e3, 0x11a00...0x11a00, 0x11a0b...0x11a32, 0x11a3a...0x11a3a, 0x11a50...0x11a50, 0x11a5c...0x11a89, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c2e, 0x11c40...0x11c40, 0x11c72...0x11c8f, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d30, 0x11d46...0x11d46, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d89, 0x11d98...0x11d98, 0x11ee0...0x11ef2, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16ad0...0x16aed, 0x16b00...0x16b2f, 0x16b40...0x16b43, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f50...0x16f50, 0x16f93...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe3, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1e100...0x1e12c, 0x1e137...0x1e13d, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2eb, 0x1e800...0x1e8c4, 0x1e900...0x1e943, 0x1e94b...0x1e94b, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a => true, + else => false, + }, + }; + } -// pub inline fn isIdentifierPart(codepoint: i32) bool { -// return switch (codepoint) { -// 'A'...'Z', 'a'...'z', '0'...'9', '$', '_' => true, -// else => switch (codepoint) { -// 0x30...0x39, 0x41...0x5a, 0x5f...0x5f, 0x61...0x7a, 0xaa...0xaa, 0xb5...0xb5, 0xb7...0xb7, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x300...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x483...0x487, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x591...0x5bd, 0x5bf...0x5bf, 0x5c1...0x5c2, 0x5c4...0x5c5, 0x5c7...0x5c7, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x610...0x61a, 0x620...0x669, 0x66e...0x6d3, 0x6d5...0x6dc, 0x6df...0x6e8, 0x6ea...0x6fc, 0x6ff...0x6ff, 0x710...0x74a, 0x74d...0x7b1, 0x7c0...0x7f5, 0x7fa...0x7fa, 0x7fd...0x7fd, 0x800...0x82d, 0x840...0x85b, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x8d3...0x8e1, 0x8e3...0x963, 0x966...0x96f, 0x971...0x983, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bc...0x9c4, 0x9c7...0x9c8, 0x9cb...0x9ce, 0x9d7...0x9d7, 0x9dc...0x9dd, 0x9df...0x9e3, 0x9e6...0x9f1, 0x9fc...0x9fc, 0x9fe...0x9fe, 0xa01...0xa03, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa3c...0xa3c, 0xa3e...0xa42, 0xa47...0xa48, 0xa4b...0xa4d, 0xa51...0xa51, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa66...0xa75, 0xa81...0xa83, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabc...0xac5, 0xac7...0xac9, 0xacb...0xacd, 0xad0...0xad0, 0xae0...0xae3, 0xae6...0xaef, 0xaf9...0xaff, 0xb01...0xb03, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3c...0xb44, 0xb47...0xb48, 0xb4b...0xb4d, 0xb55...0xb57, 0xb5c...0xb5d, 0xb5f...0xb63, 0xb66...0xb6f, 0xb71...0xb71, 0xb82...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbbe...0xbc2, 0xbc6...0xbc8, 0xbca...0xbcd, 0xbd0...0xbd0, 0xbd7...0xbd7, 0xbe6...0xbef, 0xc00...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc44, 0xc46...0xc48, 0xc4a...0xc4d, 0xc55...0xc56, 0xc58...0xc5a, 0xc60...0xc63, 0xc66...0xc6f, 0xc80...0xc83, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbc...0xcc4, 0xcc6...0xcc8, 0xcca...0xccd, 0xcd5...0xcd6, 0xcde...0xcde, 0xce0...0xce3, 0xce6...0xcef, 0xcf1...0xcf2, 0xd00...0xd0c, 0xd0e...0xd10, 0xd12...0xd44, 0xd46...0xd48, 0xd4a...0xd4e, 0xd54...0xd57, 0xd5f...0xd63, 0xd66...0xd6f, 0xd7a...0xd7f, 0xd81...0xd83, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xdca...0xdca, 0xdcf...0xdd4, 0xdd6...0xdd6, 0xdd8...0xddf, 0xde6...0xdef, 0xdf2...0xdf3, 0xe01...0xe3a, 0xe40...0xe4e, 0xe50...0xe59, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xec8...0xecd, 0xed0...0xed9, 0xedc...0xedf, 0xf00...0xf00, 0xf18...0xf19, 0xf20...0xf29, 0xf35...0xf35, 0xf37...0xf37, 0xf39...0xf39, 0xf3e...0xf47, 0xf49...0xf6c, 0xf71...0xf84, 0xf86...0xf97, 0xf99...0xfbc, 0xfc6...0xfc6, 0x1000...0x1049, 0x1050...0x109d, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x135d...0x135f, 0x1369...0x1371, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1714, 0x1720...0x1734, 0x1740...0x1753, 0x1760...0x176c, 0x176e...0x1770, 0x1772...0x1773, 0x1780...0x17d3, 0x17d7...0x17d7, 0x17dc...0x17dd, 0x17e0...0x17e9, 0x180b...0x180d, 0x1810...0x1819, 0x1820...0x1878, 0x1880...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1920...0x192b, 0x1930...0x193b, 0x1946...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x19d0...0x19da, 0x1a00...0x1a1b, 0x1a20...0x1a5e, 0x1a60...0x1a7c, 0x1a7f...0x1a89, 0x1a90...0x1a99, 0x1aa7...0x1aa7, 0x1ab0...0x1abd, 0x1abf...0x1ac0, 0x1b00...0x1b4b, 0x1b50...0x1b59, 0x1b6b...0x1b73, 0x1b80...0x1bf3, 0x1c00...0x1c37, 0x1c40...0x1c49, 0x1c4d...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1cd0...0x1cd2, 0x1cd4...0x1cfa, 0x1d00...0x1df9, 0x1dfb...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x203f...0x2040, 0x2054...0x2054, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x20d0...0x20dc, 0x20e1...0x20e1, 0x20e5...0x20f0, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d7f...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x2de0...0x2dff, 0x3005...0x3007, 0x3021...0x302f, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x3099...0x309f, 0x30a1...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa62b, 0xa640...0xa66f, 0xa674...0xa67d, 0xa67f...0xa6f1, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa827, 0xa82c...0xa82c, 0xa840...0xa873, 0xa880...0xa8c5, 0xa8d0...0xa8d9, 0xa8e0...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa92d, 0xa930...0xa953, 0xa960...0xa97c, 0xa980...0xa9c0, 0xa9cf...0xa9d9, 0xa9e0...0xa9fe, 0xaa00...0xaa36, 0xaa40...0xaa4d, 0xaa50...0xaa59, 0xaa60...0xaa76, 0xaa7a...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaef, 0xaaf2...0xaaf6, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabea, 0xabec...0xabed, 0xabf0...0xabf9, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7, 0xfdf0...0xfdfb, 0xfe00...0xfe0f, 0xfe20...0xfe2f, 0xfe33...0xfe34, 0xfe4d...0xfe4f, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff10...0xff19, 0xff21...0xff3a, 0xff3f...0xff3f, 0xff41...0xff5a, 0xff65...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7, 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x101fd...0x101fd, 0x10280...0x1029c, 0x102a0...0x102d0, 0x102e0...0x102e0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x1037a, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104a0...0x104a9, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a03, 0x10a05...0x10a06, 0x10a0c...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a38...0x10a3a, 0x10a3f...0x10a3f, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae6, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d27, 0x10d30...0x10d39, 0x10e80...0x10ea9, 0x10eab...0x10eac, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f50, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11000...0x11046, 0x11066...0x1106f, 0x1107f...0x110ba, 0x110d0...0x110e8, 0x110f0...0x110f9, 0x11100...0x11134, 0x11136...0x1113f, 0x11144...0x11147, 0x11150...0x11173, 0x11176...0x11176, 0x11180...0x111c4, 0x111c9...0x111cc, 0x111ce...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x11237, 0x1123e...0x1123e, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112ea, 0x112f0...0x112f9, 0x11300...0x11303, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133b...0x11344, 0x11347...0x11348, 0x1134b...0x1134d, 0x11350...0x11350, 0x11357...0x11357, 0x1135d...0x11363, 0x11366...0x1136c, 0x11370...0x11374, 0x11400...0x1144a, 0x11450...0x11459, 0x1145e...0x11461, 0x11480...0x114c5, 0x114c7...0x114c7, 0x114d0...0x114d9, 0x11580...0x115b5, 0x115b8...0x115c0, 0x115d8...0x115dd, 0x11600...0x11640, 0x11644...0x11644, 0x11650...0x11659, 0x11680...0x116b8, 0x116c0...0x116c9, 0x11700...0x1171a, 0x1171d...0x1172b, 0x11730...0x11739, 0x11800...0x1183a, 0x118a0...0x118e9, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x11935, 0x11937...0x11938, 0x1193b...0x11943, 0x11950...0x11959, 0x119a0...0x119a7, 0x119aa...0x119d7, 0x119da...0x119e1, 0x119e3...0x119e4, 0x11a00...0x11a3e, 0x11a47...0x11a47, 0x11a50...0x11a99, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c36, 0x11c38...0x11c40, 0x11c50...0x11c59, 0x11c72...0x11c8f, 0x11c92...0x11ca7, 0x11ca9...0x11cb6, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d36, 0x11d3a...0x11d3a, 0x11d3c...0x11d3d, 0x11d3f...0x11d47, 0x11d50...0x11d59, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d8e, 0x11d90...0x11d91, 0x11d93...0x11d98, 0x11da0...0x11da9, 0x11ee0...0x11ef6, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16a60...0x16a69, 0x16ad0...0x16aed, 0x16af0...0x16af4, 0x16b00...0x16b36, 0x16b40...0x16b43, 0x16b50...0x16b59, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f4f...0x16f87, 0x16f8f...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe4, 0x16ff0...0x16ff1, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1bc9d...0x1bc9e, 0x1d165...0x1d169, 0x1d16d...0x1d172, 0x1d17b...0x1d182, 0x1d185...0x1d18b, 0x1d1aa...0x1d1ad, 0x1d242...0x1d244, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1d7ce...0x1d7ff, 0x1da00...0x1da36, 0x1da3b...0x1da6c, 0x1da75...0x1da75, 0x1da84...0x1da84, 0x1da9b...0x1da9f, 0x1daa1...0x1daaf, 0x1e000...0x1e006, 0x1e008...0x1e018, 0x1e01b...0x1e021, 0x1e023...0x1e024, 0x1e026...0x1e02a, 0x1e100...0x1e12c, 0x1e130...0x1e13d, 0x1e140...0x1e149, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2f9, 0x1e800...0x1e8c4, 0x1e8d0...0x1e8d6, 0x1e900...0x1e94b, 0x1e950...0x1e959, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x1fbf0...0x1fbf9, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a, 0xe0100...0xe01ef => true, -// else => false, -// }, -// }; -// } -// }; + pub inline fn isIdentifierPart(codepoint: i32) bool { + return switch (codepoint) { + 'A'...'Z', 'a'...'z', '0'...'9', '$', '_' => true, + else => switch (codepoint) { + 0x30...0x39, 0x41...0x5a, 0x5f...0x5f, 0x61...0x7a, 0xaa...0xaa, 0xb5...0xb5, 0xb7...0xb7, 0xba...0xba, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0x2c1, 0x2c6...0x2d1, 0x2e0...0x2e4, 0x2ec...0x2ec, 0x2ee...0x2ee, 0x300...0x374, 0x376...0x377, 0x37a...0x37d, 0x37f...0x37f, 0x386...0x38a, 0x38c...0x38c, 0x38e...0x3a1, 0x3a3...0x3f5, 0x3f7...0x481, 0x483...0x487, 0x48a...0x52f, 0x531...0x556, 0x559...0x559, 0x560...0x588, 0x591...0x5bd, 0x5bf...0x5bf, 0x5c1...0x5c2, 0x5c4...0x5c5, 0x5c7...0x5c7, 0x5d0...0x5ea, 0x5ef...0x5f2, 0x610...0x61a, 0x620...0x669, 0x66e...0x6d3, 0x6d5...0x6dc, 0x6df...0x6e8, 0x6ea...0x6fc, 0x6ff...0x6ff, 0x710...0x74a, 0x74d...0x7b1, 0x7c0...0x7f5, 0x7fa...0x7fa, 0x7fd...0x7fd, 0x800...0x82d, 0x840...0x85b, 0x860...0x86a, 0x8a0...0x8b4, 0x8b6...0x8c7, 0x8d3...0x8e1, 0x8e3...0x963, 0x966...0x96f, 0x971...0x983, 0x985...0x98c, 0x98f...0x990, 0x993...0x9a8, 0x9aa...0x9b0, 0x9b2...0x9b2, 0x9b6...0x9b9, 0x9bc...0x9c4, 0x9c7...0x9c8, 0x9cb...0x9ce, 0x9d7...0x9d7, 0x9dc...0x9dd, 0x9df...0x9e3, 0x9e6...0x9f1, 0x9fc...0x9fc, 0x9fe...0x9fe, 0xa01...0xa03, 0xa05...0xa0a, 0xa0f...0xa10, 0xa13...0xa28, 0xa2a...0xa30, 0xa32...0xa33, 0xa35...0xa36, 0xa38...0xa39, 0xa3c...0xa3c, 0xa3e...0xa42, 0xa47...0xa48, 0xa4b...0xa4d, 0xa51...0xa51, 0xa59...0xa5c, 0xa5e...0xa5e, 0xa66...0xa75, 0xa81...0xa83, 0xa85...0xa8d, 0xa8f...0xa91, 0xa93...0xaa8, 0xaaa...0xab0, 0xab2...0xab3, 0xab5...0xab9, 0xabc...0xac5, 0xac7...0xac9, 0xacb...0xacd, 0xad0...0xad0, 0xae0...0xae3, 0xae6...0xaef, 0xaf9...0xaff, 0xb01...0xb03, 0xb05...0xb0c, 0xb0f...0xb10, 0xb13...0xb28, 0xb2a...0xb30, 0xb32...0xb33, 0xb35...0xb39, 0xb3c...0xb44, 0xb47...0xb48, 0xb4b...0xb4d, 0xb55...0xb57, 0xb5c...0xb5d, 0xb5f...0xb63, 0xb66...0xb6f, 0xb71...0xb71, 0xb82...0xb83, 0xb85...0xb8a, 0xb8e...0xb90, 0xb92...0xb95, 0xb99...0xb9a, 0xb9c...0xb9c, 0xb9e...0xb9f, 0xba3...0xba4, 0xba8...0xbaa, 0xbae...0xbb9, 0xbbe...0xbc2, 0xbc6...0xbc8, 0xbca...0xbcd, 0xbd0...0xbd0, 0xbd7...0xbd7, 0xbe6...0xbef, 0xc00...0xc0c, 0xc0e...0xc10, 0xc12...0xc28, 0xc2a...0xc39, 0xc3d...0xc44, 0xc46...0xc48, 0xc4a...0xc4d, 0xc55...0xc56, 0xc58...0xc5a, 0xc60...0xc63, 0xc66...0xc6f, 0xc80...0xc83, 0xc85...0xc8c, 0xc8e...0xc90, 0xc92...0xca8, 0xcaa...0xcb3, 0xcb5...0xcb9, 0xcbc...0xcc4, 0xcc6...0xcc8, 0xcca...0xccd, 0xcd5...0xcd6, 0xcde...0xcde, 0xce0...0xce3, 0xce6...0xcef, 0xcf1...0xcf2, 0xd00...0xd0c, 0xd0e...0xd10, 0xd12...0xd44, 0xd46...0xd48, 0xd4a...0xd4e, 0xd54...0xd57, 0xd5f...0xd63, 0xd66...0xd6f, 0xd7a...0xd7f, 0xd81...0xd83, 0xd85...0xd96, 0xd9a...0xdb1, 0xdb3...0xdbb, 0xdbd...0xdbd, 0xdc0...0xdc6, 0xdca...0xdca, 0xdcf...0xdd4, 0xdd6...0xdd6, 0xdd8...0xddf, 0xde6...0xdef, 0xdf2...0xdf3, 0xe01...0xe3a, 0xe40...0xe4e, 0xe50...0xe59, 0xe81...0xe82, 0xe84...0xe84, 0xe86...0xe8a, 0xe8c...0xea3, 0xea5...0xea5, 0xea7...0xebd, 0xec0...0xec4, 0xec6...0xec6, 0xec8...0xecd, 0xed0...0xed9, 0xedc...0xedf, 0xf00...0xf00, 0xf18...0xf19, 0xf20...0xf29, 0xf35...0xf35, 0xf37...0xf37, 0xf39...0xf39, 0xf3e...0xf47, 0xf49...0xf6c, 0xf71...0xf84, 0xf86...0xf97, 0xf99...0xfbc, 0xfc6...0xfc6, 0x1000...0x1049, 0x1050...0x109d, 0x10a0...0x10c5, 0x10c7...0x10c7, 0x10cd...0x10cd, 0x10d0...0x10fa, 0x10fc...0x1248, 0x124a...0x124d, 0x1250...0x1256, 0x1258...0x1258, 0x125a...0x125d, 0x1260...0x1288, 0x128a...0x128d, 0x1290...0x12b0, 0x12b2...0x12b5, 0x12b8...0x12be, 0x12c0...0x12c0, 0x12c2...0x12c5, 0x12c8...0x12d6, 0x12d8...0x1310, 0x1312...0x1315, 0x1318...0x135a, 0x135d...0x135f, 0x1369...0x1371, 0x1380...0x138f, 0x13a0...0x13f5, 0x13f8...0x13fd, 0x1401...0x166c, 0x166f...0x167f, 0x1681...0x169a, 0x16a0...0x16ea, 0x16ee...0x16f8, 0x1700...0x170c, 0x170e...0x1714, 0x1720...0x1734, 0x1740...0x1753, 0x1760...0x176c, 0x176e...0x1770, 0x1772...0x1773, 0x1780...0x17d3, 0x17d7...0x17d7, 0x17dc...0x17dd, 0x17e0...0x17e9, 0x180b...0x180d, 0x1810...0x1819, 0x1820...0x1878, 0x1880...0x18aa, 0x18b0...0x18f5, 0x1900...0x191e, 0x1920...0x192b, 0x1930...0x193b, 0x1946...0x196d, 0x1970...0x1974, 0x1980...0x19ab, 0x19b0...0x19c9, 0x19d0...0x19da, 0x1a00...0x1a1b, 0x1a20...0x1a5e, 0x1a60...0x1a7c, 0x1a7f...0x1a89, 0x1a90...0x1a99, 0x1aa7...0x1aa7, 0x1ab0...0x1abd, 0x1abf...0x1ac0, 0x1b00...0x1b4b, 0x1b50...0x1b59, 0x1b6b...0x1b73, 0x1b80...0x1bf3, 0x1c00...0x1c37, 0x1c40...0x1c49, 0x1c4d...0x1c7d, 0x1c80...0x1c88, 0x1c90...0x1cba, 0x1cbd...0x1cbf, 0x1cd0...0x1cd2, 0x1cd4...0x1cfa, 0x1d00...0x1df9, 0x1dfb...0x1f15, 0x1f18...0x1f1d, 0x1f20...0x1f45, 0x1f48...0x1f4d, 0x1f50...0x1f57, 0x1f59...0x1f59, 0x1f5b...0x1f5b, 0x1f5d...0x1f5d, 0x1f5f...0x1f7d, 0x1f80...0x1fb4, 0x1fb6...0x1fbc, 0x1fbe...0x1fbe, 0x1fc2...0x1fc4, 0x1fc6...0x1fcc, 0x1fd0...0x1fd3, 0x1fd6...0x1fdb, 0x1fe0...0x1fec, 0x1ff2...0x1ff4, 0x1ff6...0x1ffc, 0x203f...0x2040, 0x2054...0x2054, 0x2071...0x2071, 0x207f...0x207f, 0x2090...0x209c, 0x20d0...0x20dc, 0x20e1...0x20e1, 0x20e5...0x20f0, 0x2102...0x2102, 0x2107...0x2107, 0x210a...0x2113, 0x2115...0x2115, 0x2118...0x211d, 0x2124...0x2124, 0x2126...0x2126, 0x2128...0x2128, 0x212a...0x2139, 0x213c...0x213f, 0x2145...0x2149, 0x214e...0x214e, 0x2160...0x2188, 0x2c00...0x2c2e, 0x2c30...0x2c5e, 0x2c60...0x2ce4, 0x2ceb...0x2cf3, 0x2d00...0x2d25, 0x2d27...0x2d27, 0x2d2d...0x2d2d, 0x2d30...0x2d67, 0x2d6f...0x2d6f, 0x2d7f...0x2d96, 0x2da0...0x2da6, 0x2da8...0x2dae, 0x2db0...0x2db6, 0x2db8...0x2dbe, 0x2dc0...0x2dc6, 0x2dc8...0x2dce, 0x2dd0...0x2dd6, 0x2dd8...0x2dde, 0x2de0...0x2dff, 0x3005...0x3007, 0x3021...0x302f, 0x3031...0x3035, 0x3038...0x303c, 0x3041...0x3096, 0x3099...0x309f, 0x30a1...0x30ff, 0x3105...0x312f, 0x3131...0x318e, 0x31a0...0x31bf, 0x31f0...0x31ff, 0x3400...0x4dbf, 0x4e00...0x9ffc, 0xa000...0xa48c, 0xa4d0...0xa4fd, 0xa500...0xa60c, 0xa610...0xa62b, 0xa640...0xa66f, 0xa674...0xa67d, 0xa67f...0xa6f1, 0xa717...0xa71f, 0xa722...0xa788, 0xa78b...0xa7bf, 0xa7c2...0xa7ca, 0xa7f5...0xa827, 0xa82c...0xa82c, 0xa840...0xa873, 0xa880...0xa8c5, 0xa8d0...0xa8d9, 0xa8e0...0xa8f7, 0xa8fb...0xa8fb, 0xa8fd...0xa92d, 0xa930...0xa953, 0xa960...0xa97c, 0xa980...0xa9c0, 0xa9cf...0xa9d9, 0xa9e0...0xa9fe, 0xaa00...0xaa36, 0xaa40...0xaa4d, 0xaa50...0xaa59, 0xaa60...0xaa76, 0xaa7a...0xaac2, 0xaadb...0xaadd, 0xaae0...0xaaef, 0xaaf2...0xaaf6, 0xab01...0xab06, 0xab09...0xab0e, 0xab11...0xab16, 0xab20...0xab26, 0xab28...0xab2e, 0xab30...0xab5a, 0xab5c...0xab69, 0xab70...0xabea, 0xabec...0xabed, 0xabf0...0xabf9, 0xac00...0xd7a3, 0xd7b0...0xd7c6, 0xd7cb...0xd7fb, 0xf900...0xfa6d, 0xfa70...0xfad9, 0xfb00...0xfb06, 0xfb13...0xfb17, 0xfb1d...0xfb28, 0xfb2a...0xfb36, 0xfb38...0xfb3c, 0xfb3e...0xfb3e, 0xfb40...0xfb41, 0xfb43...0xfb44, 0xfb46...0xfbb1, 0xfbd3...0xfd3d, 0xfd50...0xfd8f, 0xfd92...0xfdc7, 0xfdf0...0xfdfb, 0xfe00...0xfe0f, 0xfe20...0xfe2f, 0xfe33...0xfe34, 0xfe4d...0xfe4f, 0xfe70...0xfe74, 0xfe76...0xfefc, 0xff10...0xff19, 0xff21...0xff3a, 0xff3f...0xff3f, 0xff41...0xff5a, 0xff65...0xffbe, 0xffc2...0xffc7, 0xffca...0xffcf, 0xffd2...0xffd7, 0xffda...0xffdc, 0x10000...0x1000b, 0x1000d...0x10026, 0x10028...0x1003a, 0x1003c...0x1003d, 0x1003f...0x1004d, 0x10050...0x1005d, 0x10080...0x100fa, 0x10140...0x10174, 0x101fd...0x101fd, 0x10280...0x1029c, 0x102a0...0x102d0, 0x102e0...0x102e0, 0x10300...0x1031f, 0x1032d...0x1034a, 0x10350...0x1037a, 0x10380...0x1039d, 0x103a0...0x103c3, 0x103c8...0x103cf, 0x103d1...0x103d5, 0x10400...0x1049d, 0x104a0...0x104a9, 0x104b0...0x104d3, 0x104d8...0x104fb, 0x10500...0x10527, 0x10530...0x10563, 0x10600...0x10736, 0x10740...0x10755, 0x10760...0x10767, 0x10800...0x10805, 0x10808...0x10808, 0x1080a...0x10835, 0x10837...0x10838, 0x1083c...0x1083c, 0x1083f...0x10855, 0x10860...0x10876, 0x10880...0x1089e, 0x108e0...0x108f2, 0x108f4...0x108f5, 0x10900...0x10915, 0x10920...0x10939, 0x10980...0x109b7, 0x109be...0x109bf, 0x10a00...0x10a03, 0x10a05...0x10a06, 0x10a0c...0x10a13, 0x10a15...0x10a17, 0x10a19...0x10a35, 0x10a38...0x10a3a, 0x10a3f...0x10a3f, 0x10a60...0x10a7c, 0x10a80...0x10a9c, 0x10ac0...0x10ac7, 0x10ac9...0x10ae6, 0x10b00...0x10b35, 0x10b40...0x10b55, 0x10b60...0x10b72, 0x10b80...0x10b91, 0x10c00...0x10c48, 0x10c80...0x10cb2, 0x10cc0...0x10cf2, 0x10d00...0x10d27, 0x10d30...0x10d39, 0x10e80...0x10ea9, 0x10eab...0x10eac, 0x10eb0...0x10eb1, 0x10f00...0x10f1c, 0x10f27...0x10f27, 0x10f30...0x10f50, 0x10fb0...0x10fc4, 0x10fe0...0x10ff6, 0x11000...0x11046, 0x11066...0x1106f, 0x1107f...0x110ba, 0x110d0...0x110e8, 0x110f0...0x110f9, 0x11100...0x11134, 0x11136...0x1113f, 0x11144...0x11147, 0x11150...0x11173, 0x11176...0x11176, 0x11180...0x111c4, 0x111c9...0x111cc, 0x111ce...0x111da, 0x111dc...0x111dc, 0x11200...0x11211, 0x11213...0x11237, 0x1123e...0x1123e, 0x11280...0x11286, 0x11288...0x11288, 0x1128a...0x1128d, 0x1128f...0x1129d, 0x1129f...0x112a8, 0x112b0...0x112ea, 0x112f0...0x112f9, 0x11300...0x11303, 0x11305...0x1130c, 0x1130f...0x11310, 0x11313...0x11328, 0x1132a...0x11330, 0x11332...0x11333, 0x11335...0x11339, 0x1133b...0x11344, 0x11347...0x11348, 0x1134b...0x1134d, 0x11350...0x11350, 0x11357...0x11357, 0x1135d...0x11363, 0x11366...0x1136c, 0x11370...0x11374, 0x11400...0x1144a, 0x11450...0x11459, 0x1145e...0x11461, 0x11480...0x114c5, 0x114c7...0x114c7, 0x114d0...0x114d9, 0x11580...0x115b5, 0x115b8...0x115c0, 0x115d8...0x115dd, 0x11600...0x11640, 0x11644...0x11644, 0x11650...0x11659, 0x11680...0x116b8, 0x116c0...0x116c9, 0x11700...0x1171a, 0x1171d...0x1172b, 0x11730...0x11739, 0x11800...0x1183a, 0x118a0...0x118e9, 0x118ff...0x11906, 0x11909...0x11909, 0x1190c...0x11913, 0x11915...0x11916, 0x11918...0x11935, 0x11937...0x11938, 0x1193b...0x11943, 0x11950...0x11959, 0x119a0...0x119a7, 0x119aa...0x119d7, 0x119da...0x119e1, 0x119e3...0x119e4, 0x11a00...0x11a3e, 0x11a47...0x11a47, 0x11a50...0x11a99, 0x11a9d...0x11a9d, 0x11ac0...0x11af8, 0x11c00...0x11c08, 0x11c0a...0x11c36, 0x11c38...0x11c40, 0x11c50...0x11c59, 0x11c72...0x11c8f, 0x11c92...0x11ca7, 0x11ca9...0x11cb6, 0x11d00...0x11d06, 0x11d08...0x11d09, 0x11d0b...0x11d36, 0x11d3a...0x11d3a, 0x11d3c...0x11d3d, 0x11d3f...0x11d47, 0x11d50...0x11d59, 0x11d60...0x11d65, 0x11d67...0x11d68, 0x11d6a...0x11d8e, 0x11d90...0x11d91, 0x11d93...0x11d98, 0x11da0...0x11da9, 0x11ee0...0x11ef6, 0x11fb0...0x11fb0, 0x12000...0x12399, 0x12400...0x1246e, 0x12480...0x12543, 0x13000...0x1342e, 0x14400...0x14646, 0x16800...0x16a38, 0x16a40...0x16a5e, 0x16a60...0x16a69, 0x16ad0...0x16aed, 0x16af0...0x16af4, 0x16b00...0x16b36, 0x16b40...0x16b43, 0x16b50...0x16b59, 0x16b63...0x16b77, 0x16b7d...0x16b8f, 0x16e40...0x16e7f, 0x16f00...0x16f4a, 0x16f4f...0x16f87, 0x16f8f...0x16f9f, 0x16fe0...0x16fe1, 0x16fe3...0x16fe4, 0x16ff0...0x16ff1, 0x17000...0x187f7, 0x18800...0x18cd5, 0x18d00...0x18d08, 0x1b000...0x1b11e, 0x1b150...0x1b152, 0x1b164...0x1b167, 0x1b170...0x1b2fb, 0x1bc00...0x1bc6a, 0x1bc70...0x1bc7c, 0x1bc80...0x1bc88, 0x1bc90...0x1bc99, 0x1bc9d...0x1bc9e, 0x1d165...0x1d169, 0x1d16d...0x1d172, 0x1d17b...0x1d182, 0x1d185...0x1d18b, 0x1d1aa...0x1d1ad, 0x1d242...0x1d244, 0x1d400...0x1d454, 0x1d456...0x1d49c, 0x1d49e...0x1d49f, 0x1d4a2...0x1d4a2, 0x1d4a5...0x1d4a6, 0x1d4a9...0x1d4ac, 0x1d4ae...0x1d4b9, 0x1d4bb...0x1d4bb, 0x1d4bd...0x1d4c3, 0x1d4c5...0x1d505, 0x1d507...0x1d50a, 0x1d50d...0x1d514, 0x1d516...0x1d51c, 0x1d51e...0x1d539, 0x1d53b...0x1d53e, 0x1d540...0x1d544, 0x1d546...0x1d546, 0x1d54a...0x1d550, 0x1d552...0x1d6a5, 0x1d6a8...0x1d6c0, 0x1d6c2...0x1d6da, 0x1d6dc...0x1d6fa, 0x1d6fc...0x1d714, 0x1d716...0x1d734, 0x1d736...0x1d74e, 0x1d750...0x1d76e, 0x1d770...0x1d788, 0x1d78a...0x1d7a8, 0x1d7aa...0x1d7c2, 0x1d7c4...0x1d7cb, 0x1d7ce...0x1d7ff, 0x1da00...0x1da36, 0x1da3b...0x1da6c, 0x1da75...0x1da75, 0x1da84...0x1da84, 0x1da9b...0x1da9f, 0x1daa1...0x1daaf, 0x1e000...0x1e006, 0x1e008...0x1e018, 0x1e01b...0x1e021, 0x1e023...0x1e024, 0x1e026...0x1e02a, 0x1e100...0x1e12c, 0x1e130...0x1e13d, 0x1e140...0x1e149, 0x1e14e...0x1e14e, 0x1e2c0...0x1e2f9, 0x1e800...0x1e8c4, 0x1e8d0...0x1e8d6, 0x1e900...0x1e94b, 0x1e950...0x1e959, 0x1ee00...0x1ee03, 0x1ee05...0x1ee1f, 0x1ee21...0x1ee22, 0x1ee24...0x1ee24, 0x1ee27...0x1ee27, 0x1ee29...0x1ee32, 0x1ee34...0x1ee37, 0x1ee39...0x1ee39, 0x1ee3b...0x1ee3b, 0x1ee42...0x1ee42, 0x1ee47...0x1ee47, 0x1ee49...0x1ee49, 0x1ee4b...0x1ee4b, 0x1ee4d...0x1ee4f, 0x1ee51...0x1ee52, 0x1ee54...0x1ee54, 0x1ee57...0x1ee57, 0x1ee59...0x1ee59, 0x1ee5b...0x1ee5b, 0x1ee5d...0x1ee5d, 0x1ee5f...0x1ee5f, 0x1ee61...0x1ee62, 0x1ee64...0x1ee64, 0x1ee67...0x1ee6a, 0x1ee6c...0x1ee72, 0x1ee74...0x1ee77, 0x1ee79...0x1ee7c, 0x1ee7e...0x1ee7e, 0x1ee80...0x1ee89, 0x1ee8b...0x1ee9b, 0x1eea1...0x1eea3, 0x1eea5...0x1eea9, 0x1eeab...0x1eebb, 0x1fbf0...0x1fbf9, 0x20000...0x2a6dd, 0x2a700...0x2b734, 0x2b740...0x2b81d, 0x2b820...0x2cea1, 0x2ceb0...0x2ebe0, 0x2f800...0x2fa1d, 0x30000...0x3134a, 0xe0100...0xe01ef => true, + else => false, + }, + }; + } +}; // test "isIdentifier" { // Bitset.init(); diff --git a/src/jsc_stub.zig b/src/jsc_stub.zig new file mode 100644 index 000000000..34069b04a --- /dev/null +++ b/src/jsc_stub.zig @@ -0,0 +1,10 @@ +// For WASM builds +pub const C = struct {}; +pub const WebCore = struct {}; +pub const Jest = struct {}; +pub const API = struct { + pub const Transpiler = struct {}; +}; +pub const Node = struct {}; + +pub const VirtualMachine = struct {}; diff --git a/src/logger.zig b/src/logger.zig index 2607241bf..63590fcda 100644 --- a/src/logger.zig +++ b/src/logger.zig @@ -1,6 +1,6 @@ const std = @import("std"); const Api = @import("./api/schema.zig").Api; -const js = @import("./jsc.zig"); +const js = @import("javascript_core"); const ImportKind = @import("./import_record.zig").ImportKind; const _global = @import("./global.zig"); const string = _global.string; @@ -12,7 +12,7 @@ const MutableString = _global.MutableString; const stringZ = _global.stringZ; const default_allocator = _global.default_allocator; const C = _global.C; -const JSC = @import("./jsc.zig"); +const JSC = @import("javascript_core"); const fs = @import("fs.zig"); const unicode = std.unicode; diff --git a/src/main_wasm.zig b/src/main_wasm.zig new file mode 100644 index 000000000..257e56461 --- /dev/null +++ b/src/main_wasm.zig @@ -0,0 +1,348 @@ +const JSParser = @import("./js_parser/js_parser.zig"); +const JSPrinter = @import("./js_printer.zig"); +const JSAst = @import("./js_ast.zig"); +const Api = @import("./api/schema.zig").Api; +const Logger = @import("./logger.zig"); +const global = @import("./global.zig"); +const default_allocator = global.default_allocator; +const std = @import("std"); +const Define = @import("./defines.zig"); +const Options = @import("./options.zig"); +const ApiWriter = @import("./api/schema.zig").Writer; +const ApiReader = @import("./api/schema.zig").Reader; +const ImportKind = @import("./import_record.zig").ImportKind; +const Output = global.Output; + +export var code_buffer_ptr: ?[*]const u8 = null; +pub const bindgen = true; +const Main = @This(); +pub const os = struct { + pub const c = Main.system; + pub const system = Main.system; +}; + +pub extern fn console_error(slice: u64) void; +pub extern fn console_log(slice: u64) void; +pub extern fn console_warn(slice: u64) void; +pub extern fn console_info(slice: u64) void; +pub const Uint8Array = extern struct { + ptr: ?[*]const u8 = null, + len: usize = 0, + + pub fn fromSlice(slice: []const u8) u64 { + return @bitCast(u64, [2]u32{ + @ptrToInt(slice.ptr), + slice.len, + }); + } + + pub fn fromJS(data: u64) []u8 { + const ptrs = @bitCast([2]u32, data); + return @intToPtr([*]u8, ptrs[0])[0..ptrs[1]]; + } +}; + +pub const system = struct { + pub const fd_t = i32; + pub const sockaddr = fd_t; + pub const mode_t = fd_t; + pub const E = enum(u8) { + SUCCESS = 0, + EPERM = 1, + ENOENT = 2, + ESRCH = 3, + EINTR = 4, + EIO = 5, + ENXIO = 6, + E2BIG = 7, + ENOEXEC = 8, + EBADF = 9, + ECHILD = 10, + EDEADLK = 11, + ENOMEM = 12, + EACCES = 13, + EFAULT = 14, + ENOTBLK = 15, + EBUSY = 16, + EEXIST = 17, + EXDEV = 18, + ENODEV = 19, + ENOTDIR = 20, + EISDIR = 21, + EINVAL = 22, + ENFILE = 23, + EMFILE = 24, + ENOTTY = 25, + ETXTBSY = 26, + EFBIG = 27, + ENOSPC = 28, + ESPIPE = 29, + EROFS = 30, + EMLINK = 31, + EPIPE = 32, + EDOM = 33, + ERANGE = 34, + EAGAIN = 35, + EINPROGRESS = 36, + EALREADY = 37, + ENOTSOCK = 38, + EDESTADDRREQ = 39, + EMSGSIZE = 40, + EPROTOTYPE = 41, + ENOPROTOOPT = 42, + EPROTONOSUPPORT = 43, + ESOCKTNOSUPPORT = 44, + ENOTSUP = 45, + EPFNOSUPPORT = 46, + EAFNOSUPPORT = 47, + EADDRINUSE = 48, + EADDRNOTAVAIL = 49, + ENETDOWN = 50, + ENETUNREACH = 51, + ENETRESET = 52, + ECONNABORTED = 53, + ECONNRESET = 54, + ENOBUFS = 55, + EISCONN = 56, + ENOTCONN = 57, + ESHUTDOWN = 58, + ETOOMANYREFS = 59, + ETIMEDOUT = 60, + ECONNREFUSED = 61, + ELOOP = 62, + ENAMETOOLONG = 63, + EHOSTDOWN = 64, + EHOSTUNREACH = 65, + ENOTEMPTY = 66, + EPROCLIM = 67, + EUSERS = 68, + EDQUOT = 69, + ESTALE = 70, + EREMOTE = 71, + EBADRPC = 72, + ERPCMISMATCH = 73, + EPROGUNAVAIL = 74, + EPROGMISMATCH = 75, + EPROCUNAVAIL = 76, + ENOLCK = 77, + ENOSYS = 78, + EFTYPE = 79, + EAUTH = 80, + ENEEDAUTH = 81, + EPWROFF = 82, + EDEVERR = 83, + EOVERFLOW = 84, + EBADEXEC = 85, + EBADARCH = 86, + ESHLIBVERS = 87, + EBADMACHO = 88, + ECANCELED = 89, + EIDRM = 90, + ENOMSG = 91, + EILSEQ = 92, + ENOATTR = 93, + EBADMSG = 94, + EMULTIHOP = 95, + ENODATA = 96, + ENOLINK = 97, + ENOSR = 98, + ENOSTR = 99, + EPROTO = 100, + ETIME = 101, + EOPNOTSUPP = 102, + ENOPOLICY = 103, + ENOTRECOVERABLE = 104, + EOWNERDEAD = 105, + EQFULL = 106, + }; +}; + +export fn cycleStart() void {} +export fn cycleEnd() void {} + +var transform_response: Api.TransformResponse = std.mem.zeroes(Api.TransformResponse); +var output_files: [1]Api.OutputFile = undefined; +var buffer_writer: JSPrinter.BufferWriter = undefined; +var writer: JSPrinter.BufferPrinter = undefined; +var define: *Define.Define = undefined; +export fn bun_malloc(size: usize) u64 { + return @bitCast(u64, [2]u32{ + @ptrToInt((default_allocator.alloc(u8, size) catch unreachable).ptr), + size, + }); +} + +export fn bun_free(bytes: u64) void { + default_allocator.free(Uint8Array.fromJS(bytes)); +} + +var output_stream_buf: [16384]u8 = undefined; +var output_stream = std.io.fixedBufferStream(&output_stream_buf); +var error_stream_buf: [16384]u8 = undefined; +var error_stream = std.io.fixedBufferStream(&error_stream_buf); +var output_source: global.Output.Source = undefined; +export fn init() void { + const Mimalloc = @import("./allocators/mimalloc.zig"); + // reserve 256 MB upfront + Mimalloc.mi_option_set(Mimalloc.mi_option_t.allow_decommit, 0); + Mimalloc.mi_option_set(Mimalloc.mi_option_t.limit_os_alloc, 1); + _ = Mimalloc.mi_reserve_os_memory(2.56e+8, false, true); + + output_source = global.Output.Source.init(output_stream, error_stream); + global.Output.Source.set(&output_source); + JSAst.Stmt.Data.Store.create(default_allocator); + JSAst.Expr.Data.Store.create(default_allocator); + buffer_writer = JSPrinter.BufferWriter.init(default_allocator) catch unreachable; + buffer_writer.buffer.growBy(1024) catch unreachable; + writer = JSPrinter.BufferPrinter.init(buffer_writer); + define = Define.Define.init(default_allocator, null, null) catch unreachable; +} +const Arena = @import("./mimalloc_arena.zig").Arena; + +var log: Logger.Log = undefined; + +export fn transform(opts_array: u64) u64 { + // var arena = std.heap.ArenaAllocator.init(default_allocator); + var arena = Arena.init() catch unreachable; + var allocator = arena.allocator(); + defer arena.deinit(); + log = Logger.Log.init(allocator); + + var reader = ApiReader.init(Uint8Array.fromJS(opts_array), allocator); + var opts = Api.Transform.decode(&reader) catch unreachable; + const loader_ = opts.loader orelse Api.Loader.tsx; + + defer { + JSAst.Stmt.Data.Store.reset(); + JSAst.Expr.Data.Store.reset(); + } + const loader: Options.Loader = switch (loader_) { + .jsx => Options.Loader.jsx, + .js => Options.Loader.js, + .ts => Options.Loader.ts, + .tsx => Options.Loader.tsx, + else => .file, + }; + const path = opts.path orelse loader.stdinName(); + var code = Logger.Source.initPathString(path, opts.contents); + code.contents_is_recycled = true; + + var parser = JSParser.Parser.init(.{ + .jsx = .{}, + }, &log, &code, define, allocator) catch unreachable; + parser.options.jsx.parse = loader.isJSX(); + parser.options.ts = loader.isTypeScript(); + parser.options.features.top_level_await = true; + const result = parser.parse() catch unreachable; + if (result.ok) { + var symbols: [][]JSAst.Symbol = &([_][]JSAst.Symbol{result.ast.symbols}); + + _ = JSPrinter.printAst( + @TypeOf(&writer), + &writer, + result.ast, + JSAst.Symbol.Map.initList(symbols), + &code, + false, + .{}, + void, + null, + ) catch 0; + + output_files[0] = .{ .data = writer.ctx.written, .path = path }; + writer.ctx.reset(); + writer.written = 0; + buffer_writer = writer.ctx; + } else { + output_files[0] = .{ .data = "", .path = path }; + } + + transform_response = Api.TransformResponse{ + .status = if (result.ok) Api.TransformResponseStatus.success else Api.TransformResponseStatus.fail, + .files = &output_files, + .errors = &[_]Api.Message{}, //(log.toAPI(allocator) catch unreachable).msgs, + }; + + var output = std.ArrayList(u8).init(default_allocator); + var output_writer = output.writer(); + const Encoder = ApiWriter(@TypeOf(output_writer)); + var encoder = Encoder.init(output_writer); + transform_response.encode(&encoder) catch unreachable; + return @bitCast(u64, [2]u32{ @ptrToInt(output.items.ptr), output.items.len }); +} + +export fn scan(opts_array: u64) u64 { + // var arena = std.heap.ArenaAllocator.init(default_allocator); + var arena = Arena.init() catch unreachable; + var allocator = arena.allocator(); + defer arena.deinit(); + log = Logger.Log.init(allocator); + + var reader = ApiReader.init(Uint8Array.fromJS(opts_array), allocator); + var opts = Api.Scan.decode(&reader) catch unreachable; + const loader_ = opts.loader orelse Api.Loader.tsx; + + defer { + JSAst.Stmt.Data.Store.reset(); + JSAst.Expr.Data.Store.reset(); + } + const loader: Options.Loader = switch (loader_) { + .jsx => Options.Loader.jsx, + .js => Options.Loader.js, + .ts => Options.Loader.ts, + .tsx => Options.Loader.tsx, + else => .file, + }; + const path = opts.path orelse loader.stdinName(); + var code = Logger.Source.initPathString(path, opts.contents); + code.contents_is_recycled = true; + + var parser = JSParser.Parser.init(.{ + .jsx = .{}, + }, &log, &code, define, allocator) catch unreachable; + parser.options.jsx.parse = loader.isJSX(); + parser.options.ts = loader.isTypeScript(); + parser.options.features.top_level_await = true; + const result = parser.parse() catch unreachable; + var scan_result = std.mem.zeroes(Api.ScanResult); + var output = std.ArrayList(u8).init(default_allocator); + var output_writer = output.writer(); + const Encoder = ApiWriter(@TypeOf(output_writer)); + + if (result.ok) { + var scanned_imports = allocator.alloc(Api.ScannedImport, result.ast.import_records.len) catch unreachable; + var scanned_i: usize = 0; + for (result.ast.import_records) |import_record| { + if (import_record.kind == .internal) continue; + scanned_imports[scanned_i] = Api.ScannedImport{ .path = import_record.path.text, .kind = import_record.kind.toAPI() }; + scanned_i += 1; + } + + scan_result = Api.ScanResult{ .exports = result.ast.named_exports.keys(), .imports = scanned_imports[0..scanned_i] }; + } + + var encoder = Encoder.init(output_writer); + scan_result.encode(&encoder) catch unreachable; + return @bitCast(u64, [2]u32{ @ptrToInt(output.items.ptr), output.items.len }); +} + +// pub fn main() anyerror!void {} + +export fn emsc_main() void { + _ = emsc_main; + _ = cycleEnd; + _ = cycleStart; + _ = transform; + _ = bun_free; + _ = bun_malloc; +} + +comptime { + _ = emsc_main; + _ = cycleEnd; + _ = cycleStart; + _ = transform; + _ = bun_free; + _ = scan; + _ = bun_malloc; +} diff --git a/src/mdx/mdx_parser.zig b/src/mdx/mdx_parser.zig new file mode 100644 index 000000000..cecc8e57f --- /dev/null +++ b/src/mdx/mdx_parser.zig @@ -0,0 +1,1836 @@ +const std = @import("std"); +const logger = @import("../logger.zig"); +const mdx_lexer = @import("./mdx_lexer.zig"); +const Lexer = mdx_lexer.Lexer; +const importRecord = @import("../import_record.zig"); +const js_ast = @import("../js_ast.zig"); +const JSParser = @import("../js_parser/js_parser.zig").MDXParser; +const ParseStatementOptions = @import("../js_parser/js_parser.zig").ParseStatementOptions; + +const options = @import("../options.zig"); + +const fs = @import("../fs.zig"); +const _global = @import("../global.zig"); +const string = _global.string; +const Output = _global.Output; +const Global = _global.Global; +const Environment = _global.Environment; +const strings = _global.strings; +const MutableString = _global.MutableString; +const stringZ = _global.stringZ; +const default_allocator = _global.default_allocator; +const C = _global.C; +const expect = std.testing.expect; +const ImportKind = importRecord.ImportKind; +const BindingNodeIndex = js_ast.BindingNodeIndex; +const Define = @import("../defines.zig").Define; +const js_lexer = @import("../js_lexer.zig"); +const StmtNodeIndex = js_ast.StmtNodeIndex; +const ExprNodeIndex = js_ast.ExprNodeIndex; +const ExprNodeList = js_ast.ExprNodeList; +const StmtNodeList = js_ast.StmtNodeList; +const BindingNodeList = js_ast.BindingNodeList; +const ParserOptions = @import("../js_parser/js_parser.zig").Parser.Options; +const runVisitPassAndFinish = @import("../js_parser/js_parser.zig").Parser.runVisitPassAndFinish; +const Ref = @import("../ast/base.zig").Ref; +const assert = std.debug.assert; +const BabyList = js_ast.BabyList; + +const LocRef = js_ast.LocRef; +const S = js_ast.S; +const B = js_ast.B; +const G = js_ast.G; +const T = mdx_lexer.T; +const E = js_ast.E; +const Stmt = js_ast.Stmt; +const Expr = js_ast.Expr; +const Binding = js_ast.Binding; +const Symbol = js_ast.Symbol; +const Level = js_ast.Op.Level; +const Op = js_ast.Op; +const Scope = js_ast.Scope; +const Range = logger.Range; + +pub const Container = struct { + ch: u8 = 0, + is_loose: bool = false, + is_task: bool = false, + start: u32 = 0, + mark_indent: u32 = 0, + contents_indent: u32 = 0, + block_index: u32 = 0, + task_mark_off: u32 = 0, +}; + +pub const Block = struct { + tag: Tag = Tag.html, + flags: Block.Flags.Set = Block.Flags.Set{}, + data: u32 = 0, + /// Leaf blocks: Count of lines (MD_LINE or MD_VERBATIMLINE) on the block. + /// LI: Task mark offset in the input doc. + /// OL: Start item number. + /// + line_count: u32 = 0, + line_offset: u32 = 0, + detail: Block.Detail = Block.Detail{ .none = .{} }, + + pub inline fn lines(this: Block, lines_: BabyList(Line)) []Line { + return lines_.ptr[this.line_offset .. this.line_offset + this.line_count]; + } + + pub inline fn verbatimLines(this: Block, lines_: BabyList(Line.Verbatim)) []Line.Verbatim { + return lines_.ptr[this.line_offset .. this.line_offset + this.line_count]; + } + + pub const Data = u32; + + pub const Flags = enum(u3) { + container_opener = 0, + container_closer = 1, + loose_list = 2, + setext_header = 3, + + pub const Set = std.enums.EnumSet(Block.Flags); + }; + + pub inline fn isContainer(this: Block) bool { + return this.flags.contains(.container_opener) or this.flags.contains(.container_closer); + } + + pub const Tag = enum { + /// <body>...</body> + doc, + + /// <blockquote>...</blockquote> + quote, + + /// <ul>...</ul> + ///Detail: Structure ul_detail. + ul, + + /// <ol>...</ol> + ///Detail: Structure ol_detail. + ol, + + /// <li>...</li> + ///Detail: Structure li_detail. + li, + + /// <hr> + hr, + + /// <h1>...</h1> (for levels up to 6) + ///Detail: Structure h_detail. + h, + + /// <pre><code>...</code></pre> + ///Note the text lines within code blocks are terminated with '\n' + ///instead of explicit MD_TEXT_BR. + code, + + /// Raw HTML block. This itself does not correspond to any particular HTML + ///tag. The contents of it _is_ raw HTML source intended to be put + ///in verbatim form to the HTML output. + html, + + /// <p>...</p> + p, + + /// <table>...</table> and its contents. + ///Detail: Structure table_detail (for table), + /// structure td_detail (for th and td) + ///Note all of these are used only if extension MD_FLAG_TABLES is enabled. + table, + thead, + tbody, + tr, + th, + td, + }; + + pub const UL = struct { + tight: bool = false, + mark: u8 = '*', + }; + + pub const OL = struct { + start: u32 = 0, + tight: bool = false, + mark: u8 = '*', + }; + + pub const LI = struct { + /// Can be non-zero only with MD_FLAG_TASKLISTS + task: bool = false, + /// is_task, then one of 'x', 'X' or ' '. Undefined otherwise. + task_mark: u8 = 'x', + /// If is_task, then offset in the input of the char between '[' and ']'. + task_mark_off: u32 = 0, + }; + + pub const Header = u4; + + pub const Code = struct { + info: Attribute = .{}, + lang: Attribute = .{}, + /// character used for fenced code block; or zero for indented code block. * + fence: u8 = '`', + }; + + pub const Table = struct { + /// Count of columns in the table. + column_count: u32 = 0, + /// Count of rows in the table header (currently always 1) + head_row_count: u32 = 1, + /// Count of rows in the table body + body_row_count: u32 = 0, + }; + + pub const Detail = union { + none: void, + ul: UL, + ol: OL, + li: LI, + }; + + pub const TD = struct { + alignment: Align = Align.default, + }; +}; +pub const Span = struct { + pub const Tag = enum { + /// <em>...</em> + em, + + /// <strong>...</strong> + strong, + + /// <a href="xxx">...</a> + /// Detail: Structure a_detail. + a, + + /// <img src="xxx">...</a> + /// Detail: Structure img_detail. + /// Note: Image text can contain nested spans and even nested images. + /// If rendered into ALT attribute of HTML <IMG> tag, it's responsibility + /// of the parser to deal with it. + img, + + /// <code>...</code> + code, + + /// <del>...</del> + /// Note: Recognized only when MD_FLAG_STRIKETHROUGH is enabled. + del, + + /// For recognizing inline ($) and display ($$) equations + /// Note: Recognized only when MD_FLAG_LATEXMATHSPANS is enabled. + latexmath, + latexmath_display, + + /// Wiki links + /// Note: Recognized only when MD_FLAG_WIKILINKS is enabled. + wikilink, + + /// <u>...</u> + /// Note: Recognized only when MD_FLAG_UNDERLINE is enabled. + u, + }; + + pub const Link = struct { + src: Attribute = .{}, + title: Attribute = .{}, + }; + + pub const Image = Link; + + pub const Wikilink = struct { + target: Attribute = .{}, + }; +}; + +pub const Text = enum { + /// Normal text. + normal, + /// NULL character. CommonMark requires replacing NULL character with + /// the replacement char U+FFFD, so this allows caller to do that easily. + nullchar, + /// Line breaks. + /// Note these are not sent from blocks with verbatim output (MD_BLOCK_CODE + /// or MD_BLOCK_HTML). In such cases, '\n' is part of the text itself. + /// <br> (hard break) + br, + /// '\n' in source text where it is not semantically meaningful (soft break) + softbr, + /// Entity. + /// (a) Named entity, e.g. + /// (Note MD4C does not have a list of known entities. + /// Anything matching the regexp /&[A-Za-z][A-Za-z0-9]{1,47};/ is + /// treated as a named entity.) + /// (b) Numerical entity, e.g. Ӓ + /// (c) Hexadecimal entity, e.g. ካ + /// + /// As MD4C is mostly encoding agnostic, application gets the verbatim + /// entity text into the MD_PARSER::text_callback(). + entity, + /// Text in a code block (inside MD_BLOCK_CODE) or inlined code (`code`). + /// If it is inside MD_BLOCK_CODE, it includes spaces for indentation and + /// '\n' for new lines. br and softbr are not sent for this + /// kind of text. + code, + /// Text is a raw HTML. If it is contents of a raw HTML block (i.e. not + /// an inline raw HTML), then br and softbr are not used. + /// The text contains verbatim '\n' for the new lines. + html, + /// Text is inside an equation. This is processed the same way as inlined code + /// spans (`code`). + latexmath, +}; +pub const Align = enum(u3) { + default = 0, + left = 1, + center = 2, + right = 3, +}; + +/// String attribute. +/// +/// This wraps strings which are outside of a normal text flow and which are +/// propagated within various detailed structures, but which still may contain +/// string portions of different types like e.g. entities. +/// +/// So, for example, lets consider this image: +/// +///  +/// +/// The image alt text is propagated as a normal text via the MD_PARSER::text() +/// callback. However, the image title ('foo " bar') is propagated as +/// MD_ATTRIBUTE in MD_SPAN_IMG_DETAIL::title. +/// +/// Then the attribute MD_SPAN_IMG_DETAIL::title shall provide the following: +/// -- [0]: "foo " (substr_types[0] == MD_TEXT_NORMAL; substr_offsets[0] == 0) +/// -- [1]: """ (substr_types[1] == MD_TEXT_ENTITY; substr_offsets[1] == 4) +/// -- [2]: " bar" (substr_types[2] == MD_TEXT_NORMAL; substr_offsets[2] == 10) +/// -- [3]: (n/a) (n/a ; substr_offsets[3] == 14) +/// +/// Note that these invariants are always guaranteed: +/// -- substr_offsets[0] == 0 +/// -- substr_offsets[LAST+1] == size +/// -- Currently, only MD_TEXT_NORMAL, MD_TEXT_ENTITY, MD_TEXT_NULLCHAR +/// substrings can appear. This could change only of the specification +/// changes. +/// +pub const Attribute = struct { + text: []const u8 = "", + substring: Substring.List = .{}, +}; +pub const Substring = struct { + offset: u32, + tag: Text, + + pub const List = std.MultiArrayList(Substring); + pub const ListPool = ObjectPool(List); +}; + +pub const Mark = struct { + position: Ref = Ref.None, + prev: u32 = std.math.maxInt(u32), + next: u32 = std.math.maxInt(u32), + ch: u8 = 0, + flags: u16 = 0, + + /// Maybe closer. + pub const potential_closer = 0x02; + /// Maybe opener. + pub const potential_opener = 0x01; + /// Definitely opener. + pub const opener = 0x04; + /// Definitely closer. + pub const closer = 0x08; + /// Resolved in any definite way. + pub const resolved = 0x10; + + /// Helper for the "rule of 3". */ + pub const emph_intraword = 0x20; + pub const emph_mod3_0 = 0x40; + pub const emph_mod3_1 = 0x80; + pub const emph_mod3_2 = (0x40 | 0x80); + pub const emph_mod3_mask = (0x40 | 0x80); + /// Distinguisher for '<', '>'. */ + pub const autolink = 0x20; + /// For permissive autolinks. */ + pub const validpermissiveautolink = 0x20; + /// For '[' to rule out invalid link labels early */ + pub const hasnestedbrackets = 0x20; + + /// During analyzes of inline marks, we need to manage some "mark chains", + /// of (yet unresolved) openers. This structure holds start/end of the chain. + /// The chain internals are then realized through MD_MARK::prev and ::next. + pub const Chain = struct { + head: u32 = std.math.maxInt(u32), + tail: u32 = std.math.maxInt(u32), + + pub const List = struct { + data: [13]Chain = [13]Chain{ .{}, .{}, .{}, .{}, .{}, .{}, .{}, .{}, .{}, .{}, .{}, .{} }, + pub inline fn ptr_chain(this: *List) *Chain { + return &this.data[0]; + } + pub inline fn tablecellboundaries(this: *List) *Chain { + return &this.data[1]; + } + pub inline fn asterisk_openers_extraword_mod3_0(this: *List) *Chain { + return &this.data[2]; + } + pub inline fn asterisk_openers_extraword_mod3_1(this: *List) *Chain { + return &this.data[3]; + } + pub inline fn asterisk_openers_extraword_mod3_2(this: *List) *Chain { + return &this.data[4]; + } + pub inline fn asterisk_openers_intraword_mod3_0(this: *List) *Chain { + return &this.data[5]; + } + pub inline fn asterisk_openers_intraword_mod3_1(this: *List) *Chain { + return &this.data[6]; + } + pub inline fn asterisk_openers_intraword_mod3_2(this: *List) *Chain { + return &this.data[7]; + } + pub inline fn underscore_openers(this: *List) *Chain { + return &this.data[8]; + } + pub inline fn tilde_openers_1(this: *List) *Chain { + return &this.data[9]; + } + pub inline fn tilde_openers_2(this: *List) *Chain { + return &this.data[10]; + } + pub inline fn bracket_openers(this: *List) *Chain { + return &this.data[11]; + } + pub inline fn dollar_openers(this: *List) *Chain { + return &this.data[12]; + } + }; + }; +}; + +pub const Line = struct { + beg: u32 = 0, + end: u32 = 0, + + pub const Tag = enum(u32) { + blank, + hr, + atx_header, + setext_header, + setext_underline, + indented_code, + fenced_code, + html, + text, + table, + table_underline, + }; + pub const Analysis = packed struct { + tag: Tag = Tag.blank, + beg: u32 = 0, + end: u32 = 0, + indent: u32 = 0, + data: u32 = 0, + + pub const blank = Analysis{}; + pub fn eql(a: Analysis, b: Analysis) bool { + return strings.eqlLong(std.mem.asBytes(&a), std.mem.asBytes(&b), false); + } + }; + + pub const Verbatim = struct { + line: Line = Line{}, + indent: u32 = 0, + }; +}; + +pub const MDParser = struct { + marks: BabyList(Mark) = .{}, + chain: Mark.Chain.List = .{}, + source: logger.Source, + flags: Flags.Set = Flags.commonmark, + allocator: std.mem.Allocator, + mdx: *MDX, + mark_char_map: [255]u1 = undefined, + doc_ends_with_newline: bool = false, + size: u32 = 0, + + lines: BabyList(Line) = .{}, + verbatim_lines: BabyList(Line.Verbatim) = .{}, + + containers: BabyList(Container) = .{}, + blocks: BabyList(Block) = .{}, + current_block: ?*Block = null, + current_block_index: u32 = 0, + + code_fence_length: u32 = 0, + code_indent_offset: u32 = std.math.maxInt(u32), + last_line_has_list_loosening_effect: bool = false, + last_list_item_starts_with_two_blank_lines: bool = false, + + pub const Flags = enum { + /// In MD_TEXT_NORMAL, collapse non-trivial whitespace into single ' ' + collapse_whitespace, + /// Do not require space in ATX headers ( ###header ) + permissive_atxheaders, + /// Recognize URLs as autolinks even without '<', '>' + permissive_url_autolinks, + /// Recognize e-mails as autolinks even without '<', '>' and 'mailto:' + permissive_email_autolinks, + /// Disable indented code blocks. (Only fenced code works.) + noindented_codeblocks, + /// Disable raw HTML blocks. + no_html_blocks, + /// Disable raw HTML (inline). + no_html_spans, + /// Enable tables extension. + tables, + /// Enable strikethrough extension. + strikethrough, + /// Enable WWW autolinks (even without any scheme prefix, if they begin with 'www.') + permissive_www_autolinks, + /// Enable task list extension. + tasklists, + /// Enable $ and $$ containing LaTeX equations. + latex_mathspans, + /// Enable wiki links extension. + wikilinks, + /// Enable underline extension (and disables '_' for normal emphasis). + underline, + + pub const Set = std.enums.EnumSet(Flags); + pub const permissive_autolinks = Set.init(.{ .permissive_email_autolinks = true, .permissive_url_autolinks = true }); + pub const no_email = Set.init(.{ .no_html_blocks = true, .no_html_spans = true }); + pub const github = Set.init(.{ .tables = true, .permissive_autolinks = true, .strikethrough = true, .tasklists = true }); + pub const commonmark: i32 = Set{}; + }; + + fn buildCharMap(this: *MDParser) void { + @memset(&this.mark_char_map, 0, this.mark_char_map.len); + + this.mark_char_map['\\'] = 1; + this.mark_char_map['*'] = 1; + this.mark_char_map['_'] = 1; + this.mark_char_map['`'] = 1; + this.mark_char_map['&'] = 1; + this.mark_char_map[';'] = 1; + this.mark_char_map['<'] = 1; + this.mark_char_map['>'] = 1; + this.mark_char_map['['] = 1; + this.mark_char_map['!'] = 1; + this.mark_char_map[']'] = 1; + this.mark_char_map[0] = 1; + + // whitespace + this.mark_char_map[' '] = 1; + this.mark_char_map['\t'] = 1; + this.mark_char_map['\r'] = 1; + this.mark_char_map['\n'] = 1; + + // form feed + this.mark_char_map[0xC] = 1; + // vertical tab + this.mark_char_map[0xB] = 1; + + if (this.flags.contains(.strikethrough)) { + this.mark_char_map['~'] = 1; + } + + if (this.flags.contains(.latex_mathspans)) { + this.mark_char_map['$'] = 1; + } + + if (this.flags.contains(.permissive_email_autolinks)) { + this.mark_char_map['@'] = 1; + } + + if (this.flags.contains(.permissive_url_autolinks)) { + this.mark_char_map[':'] = 1; + } + + if (this.flags.contains(.permissive_www_autolinks)) { + this.mark_char_map['.'] = 1; + } + + if (this.flags.contains(.tables)) { + this.mark_char_map['.'] = 1; + } + } + pub fn init(allocator: std.mem.Allocator, source: logger.Source, flags: Flags.Set, mdx: *MDX) MDParser { + var parser = MDParser{ + .allocator = allocator, + .source = source, + .flags = flags, + .mdx = mdx, + .size = @truncate(u32, source.contents.len), + }; + parser.buildCharMap(); + parser.doc_ends_with_newline = source.contents.len.len > 0 and source.contents[source.contents.len - 1] == '\n'; + return parser; + } + + fn startNewBlock(this: *MDParser, line: *const Line.Analysis) !void { + try this.blocks.push( + this.allocator, + Block{ + .tag = switch (line.tag) { + .hr => Block.Tag.hr, + .atx_header, .setext_header => Block.Tag.h, + .fenced_code, .indented_code => Block.Tag.code, + .text => Block.Tag.p, + .html => Block.Tag.html, + else => unreachable, + }, + .data = line.data, + .line_count = 0, + .line_offset = switch (line.tag) { + .indented_code, .html, .fenced_code => this.verbatim_lines.len, + else => this.lines.len, + }, + }, + ); + } + + inline fn charAt(this: *const MDParser, index: u32) u8 { + return this.source.contents[index]; + } + + inline fn isNewline(this: *const MDParser, index: u32) bool { + return switch (this.charAt(index)) { + '\n', '\r' => true, + else => false, + }; + } + + inline fn isAnyOf2(this: *const MDParser, index: u32, comptime first: u8, comptime second: u8) bool { + return isAnyOf2_(this.charAt(index), first, second); + } + + inline fn isAnyOf2_(char: u8, comptime first: u8, comptime second: u8) bool { + return switch (char) { + first, second => true, + else => false, + }; + } + + inline fn isAnyOf(this: *const MDParser, index: u32, comptime values: []const u8) bool { + return isCharAnyOf(this.charAt(index), values); + } + + inline fn isCharAnyOf(char: u8, comptime values: []const u8) bool { + inline for (values) |val| { + if (val == char) return true; + } + return false; + } + + inline fn isBlank(char: u8) bool { + return isCharAnyOf(char, &[_]u8{ ' ', '\t' }); + } + + inline fn isWhitespace(char: u8) bool { + return isCharAnyOf(char, &[_]u8{ ' ', '\t', 0xC, 0xB }); + } + + pub fn getIndent(this: *MDParser, total_indent: u32, beg: u32, end: *u32) u32 { + var off = beg; + var indent = total_indent; + while (off < this.size and isBlank(this.charAt(off))) { + if (this.charAt(off) == '\t') { + indent = (indent + 4) & ~3; + } else { + indent += 1; + } + off += 1; + } + end.* = off; + return indent - total_indent; + } + + pub fn isContainerMark(this: *MDParser, indent: u32, beg: u32, end: *u32, container: *Container) bool { + var off = beg; + var max_end: u32 = undefined; + + if (off >= this.size or indent >= this.code_indent_offset) + return false; + + if (this.charAt(off) == '>') { + off += 1; + container.ch = '>'; + container.is_loose = false; + container.is_task = false; + container.mark_indent = indent; + container.contents_indent = indent + 1; + end.* = off; + return true; + } + + // Check for list item bullet mark. + if (this.isAnyOf(off, "-+*") and (off + 1 >= this.size or isBlank(this.charAt(off + 1)) or this.isNewline(off + 1))) { + container.ch = this.charAt(off); + container.is_loose = false; + container.is_task = false; + container.mark_indent = indent; + container.contents_indent = indent + 1; + end.* = off + 1; + return true; + } + + // Check for ordered list item marks + max_end = @minimum(off + 9, this.size); + container.start = 0; + while (off < max_end and std.ascii.isDigit(this.charAt(off))) { + container.start = container.start * 10 + (this.charAt(off) - '0'); + off += 1; + } + + if (off > beg and + off < this.size and + (this.isAnyOf2(off, '.', ')')) and + (off + 1 >= this.size or + this.isBlank(this.charAt(off + 1) or + this.isNewline(off + 1)))) + { + container.ch = this.charAt(off); + container.is_loose = false; + container.is_task = false; + container.mark_indent = indent; + container.contents_indent = indent + off - beg + 1; + end.* = off + 1; + return true; + } + + return false; + } + + fn analyzeLine(this: *MDParser, beg: u32, end: *u32, pivot_line: *const Line.Analysis, line: *Line.Analysis) !void { + _ = this; + _ = beg; + _ = end; + _ = pivot_line; + _ = line; + var off = beg; + var hr_killer: u32 = 0; + var prev_line_has_list_loosening_effect = this.last_line_has_list_loosening_effect; + var container = Container{}; + _ = hr_killer; + _ = prev_line_has_list_loosening_effect; + _ = container; + var total_indent: u32 = 0; + var n_parents: u32 = 0; + var n_brothers: u32 = 0; + var n_children: u32 = 0; + + // Given the indentation and block quote marks '>', determine how many of + // the current containers are our parents. + while (n_parents < this.containers.len) { + var c: *Container = this.containers.ptr + n_parents; + + if (c.ch == '>' and line.indent < this.code_indent_offset and off < this.size and this.charAt(off) == '>') { + off += 1; + total_indent += 1; + line.indent = this.getIndent(total_indent, off, &off); + total_indent += line.indent; + + // The optional 1st space after '>' is part of the block quote mark. + line.indent -|= line.indent; + line.beg = off; + } else if (c.ch != '>' and line.indent >= c.contents_indent) { + line.indent -|= c.contents_indent; + } else { + break; + } + + n_parents += 1; + } + + if (off >= this.size or this.isNewline(off)) { + // Blank line does not need any real indentation to be nested inside a list + if (n_brothers + n_children == 0) { + while (n_parents < this.containers.len and this.containers.ptr[n_parents].ch == '>') { + n_parents += 1; + } + } + } + + while (true) { + switch (pivot_line.tag) { + .fencedcode => { + // Check whether we are fenced code continuation. + line.beg = off; + + // We are another MD_LINE_FENCEDCODE unless we are closing fence + // which we transform into MD_LINE_BLANK. + if (line.indent < this.code_indent_offset) { + if (this.isClosingCodeFence(this.charAt(pivot_line.beg), off, &off)) { + line.tag = .blank; + this.last_line_has_list_loosening_effect = false; + break; + } + } + + // Change indentation accordingly to the initial code fence. + if (n_parents == this.containers.len) { + line.indent -|= pivot_line.indent; + line.tag = .fenced_code; + break; + } + }, + + .indentedcode => {}, + .text => {}, + + .html => {}, + else => {}, + } + + // Check for blank line. + if (off >= this.size or this.isNewline(off)) { + if (pivot_line.tag == .indented_code and n_parents == this.containers.len) { + line.tag = .indented_code; + line.indent -|= this.code_indent_offset; + this.last_line_has_list_loosening_effect = false; + } else { + line.tag = .blank; + this.last_line_has_list_loosening_effect = n_parents > 0 and + n_brothers + n_children == 0 and + this.containers.ptr[n_parents - 1].ch != '>'; + + // See https://github.com/mity/md4c/issues/6 + // + // This ugly checking tests we are in (yet empty) list item but + // not its very first line (i.e. not the line with the list + // item mark). + // + // If we are such a blank line, then any following non-blank + // line which would be part of the list item actually has to + // end the list because according to the specification, "a list + // item can begin with at most one blank line." + // + if (n_parents > 0 and this.containers.ptr[n_parents - 1].ch != '>' and n_brothers + n_children == 0 and this.current_block == null and this.blocks.len > 0) { + var top_block = this.blocks.last().?; + if (top_block.tag == .li) { + this.last_list_item_starts_with_two_blank_lines = true; + } + } + } + break; + } else { + // This is the 2nd half of the hack. If the flag is set (i.e. there + // was a 2nd blank line at the beginning of the list item) and if + // we would otherwise still belong to the list item, we enforce + // the end of the list. + this.last_line_has_list_loosening_effect = false; + if (this.last_list_item_starts_with_two_blank_lines) { + if (n_parents > 0 and + this.containers.ptr[n_parents - 1].ch != '>' and + n_brothers + n_children == 0 and + this.current_block == null and this.blocks.len > 1) + { + var top = this.blocks.last().?; + if (top.tag == .li) { + n_parents -|= 1; + } + } + this.last_line_has_list_loosening_effect = true; + } + } + + // Check whether we are Setext underline. + if (line.indent < this.code_indent_offset and + pivot_line.tag == .text and + off < this.size and + this.isAnyOf2(off, '=', '-') and + n_parents == this.containers.len) + { + var level: u4 = 0; + if (this.isSetextUnderline(off, &off, &level)) { + line.tag = .setext_underline; + line.data = level; + break; + } + } + + // Check for a thematic break line + if (line.indent < this.code_indent_offset and off < this.size and off >= hr_killer and this.isAnyOf(off, "-_*")) { + if (this.isHRLine(off, &off, &hr_killer)) { + line.tag = .hr; + break; + } + } + + // Check for "brother" container. I.e. whether we are another list item + //in already started list. + if (n_parents < this.containers.len and n_brothers + n_children == 0) { + var tmp: u32 = undefined; + + if (this.isContainerMark(line.indent, off, &tmp, &container) and + isContainerCompatible(&this.containers.ptr[n_parents], &container)) + { + pivot_line.* = Line.Analysis.blank; + off = tmp; + + total_indent += container.contents_indent - container.mark_indent; + line.indent = this.getIndent(total_indent, off, &off); + total_indent += line.indent; + line.beg = off; + + // Some of the following whitespace actually still belongs to the mark. + if (off >= this.size or this.isNewline(off)) { + container.contents_indent += 1; + } else if (line.indent <= this.code_indent_offset) { + container.contents_indent += line.indent; + line.indent = 0; + } else { + container.contents_indent += 1; + line.indent -= 1; + } + + this.containers.ptr[n_parents].mark_indent = container.mark_indent; + this.containers.ptr[n_parents].contents_indent = container.contents_indent; + n_brothers += 1; + continue; + } + } + + // Check for indented code + // Note: indented code block cannot interrupt a paragrpah + if (line.indent >= this.code_indent_offset and + (pivot_line.tag == .blank or + pivot_line.tag == .indented_code)) + { + line.tag = .indented_code; + std.debug.assert(line.indent >= this.code_indent_offset); + line.indent -|= this.code_indent_offset; + line.data = 0; + break; + } + + // Check for start of a new container block + if (line.indent < this.code_indent_offset and + this.isContainerMark(line.indent, off, &off, &container)) + { + if (pivot_line.tag == .text and + n_parents == this.n_containers and + (off >= this.size or this.isNewline(off)) and + container.ch != '>') + { + // Noop. List mark followed by a blank line cannot interrupt a paragraph. + } else if (pivot_line.tag == .text and + n_parents == this.containers.len and + isAnyOf2_(container.ch, '.', ')')) + { + // Noop. Ordered list cannot interrupt a paragraph unless the start index is 1. + } else { + total_indent += container.contents_indent - container.mark_indent; + line.indent = this.getIndent(total_indent, off, &off); + total_indent += line.indent; + + line.beg = off; + line.data = container.ch; + + // Some of the following whitespace actually still belongs to the mark. + if (off >= this.size or this.isNewline(off)) { + container.contents_indent += 1; + } else if (line.indent <= this.code_indent_offset) { + container.contents_indent += line.indent; + line.indent = 0; + } else { + container.contents_indent += 1; + line.indent -= 1; + } + + if (n_brothers + n_children == 0) { + pivot_line.* = Line.Analysis.blank; + } + + if (n_children == 0) { + try this.leaveChildContainers(n_parents + n_brothers); + } + + n_children += 1; + try this.pushContainer(container); + continue; + } + } + + // heck whether we are table continuation. + if (pivot_line.tag == .table and n_parents == this.n_containers) { + line.tag = .table; + break; + } + + // heck for ATX header. + if (line.indent < this.code_indent_offset and off < this.size and this.isAnyOf(off, '#')) { + var level: u4 = 0; + if (this.isATXHeaderLine(off, &line.beg, &off, &level)) { + line.tag = .atx_header; + line.data = level; + break; + } + } + + // Check whether we are starting code fence. + if (off < this.size and this.isAnyOf2(off, '`', '~')) { + if (this.isOpeningCodeFence(off, &off)) { + line.tag = .fenced_code; + line.data = 1; + break; + } + } + + // Check for start of raw HTML block. + if (off < this.size and !this.flags.contains(.no_html_blocks) and this.charAt(off) == '<') {} + + // Check for table underline. + if (this.flags.contains(.tables) and pivot_line.tag == .text and off < this.size and this.isAnyOf(off, "|-:") and n_parents == this.containers.len) { + var col_count: u32 = undefined; + + if (this.current_block != null and this.current_block.?.line_count == 1 and this.isTableUnderline(off, &off, &col_count)) { + line.data = col_count; + line.tag = .table_underline; + break; + } + } + + // By default, we are normal text line. + line.tag = .text; + if (pivot_line.tag == .text and n_brothers + n_children == 0) { + // lazy continuation + n_parents = this.containers.len; + } + + // Check for task mark. + if (this.flags.contains(.tasklists) and + n_brothers + n_children > 0 and + off < this.size and + isCharAnyOf(this.containers.last().?.ch, "-+*.)")) + { + var tmp: u32 = off; + + while (tmp < this.size and tmp < off + 3 and isBlank(tmp)) { + tmp += 1; + } + + if ((tmp + 2 < this.size and + this.charAt(tmp) == '[' and + this.isAnyOf(tmp + 1, "xX ") and + this.charAt(tmp + 2) == ']') and + (tmp + 3 == this.size or + isBlank(this.charAt(tmp + 3)) or + this.isNewline(tmp + 3))) + { + var task_container: *Container = if (n_children > 0) this.containers.last().? else &container; + task_container.is_task = true; + task_container.task_mark_off = tmp + 1; + off = tmp + 3; + while (off < this.size and isWhitespace(this.charAt(off))) { + off += 1; + } + if (off == this.size) break; + line.beg = off; + } + } + + break; + } + + // Scan for end of the line. + while (off + 3 < this.size and + !(strings.eqlComptimeIgnoreLen(this.source.contents.ptr[off..][0..4], "\n\n\n\n") or + strings.eqlComptimeIgnoreLen(this.source.contents.ptr[off..][0..4], "\r\n\r\n"))) + { + off += 4; + } + + while (off < this.size and !this.isNewline(off)) { + off += 1; + } + + // Set end of line + line.end = off; + + // ut for ATX header, we should exclude the optional trailing mark. + if (line.type == .atx_header) { + var tmp = line.end; + while (tmp > line.beg and this.charAt(tmp - 1) == ' ') { + tmp -= 1; + } + + while (tmp > line.beg and this.charAt(tmp - 1) == '#') { + tmp -= 1; + } + + if (tmp == line.beg or this.charAt(tmp - 1) == ' ' or this.flags.contains(.permissive_atxheaders)) { + line.end = tmp; + } + } + + // Trim trailing spaces. + switch (line.tag) { + .indented_code, .fenced_code => {}, + else => { + while (line.end > line.beg and this.charAt(line.end - 1) == ' ') { + line.end -= 1; + } + }, + } + + // Eat also the new line + if (off < this.size and this.charAt(off) == '\r') { + off += 1; + } + + if (off < this.size and this.charAt(off) == '\n') { + off += 1; + } + + end.* = off; + + // If we belong to a list after seeing a blank line, the list is loose. + if (prev_line_has_list_loosening_effect and line.tag != .blank and n_parents + n_brothers > 0) { + var c: *Container = this.containers.ptr[n_parents + n_brothers - 1]; + if (c.ch != '>') { + var block: *Block = this.blocks.ptr[c.block_index]; + block.flags.insert(.loose_list); + } + } + + // Leave any containers we are not part of anymore. + if (n_children == 0 and n_parents + n_brothers < this.containers.len) { + try this.leaveChildContainers(n_parents + n_brothers); + } + + // Enter any container we found a mark for + if (n_brothers > 0) { + std.debug.assert(n_brothers == 0); + try this.pushContainerBytes( + Block.Tag.li, + this.containers.ptr[n_parents].task_mark_off, + if (this.containers.ptr[n_parents].is_task) this.charAt(this.containers.ptr[n_parents].task_mark_off) else 0, + Block.Flags.container_closer, + ); + try this.pushContainerBytes( + Block.Tag.li, + container.task_mark_off, + if (container.is_task) this.charAt(container.task_mark_off) else 0, + Block.Flags.container_opener, + ); + this.containers.ptr[n_parents].is_task = container.is_task; + this.containers.ptr[n_parents].task_mark_off = container.task_mark_off; + } + + if (n_children > 0) { + try this.enterChildContainers(n_children); + } + } + fn processLine(this: *MDParser, p_pivot_line: **const Line.Analysis, line: *Line.Analysis) !void { + var pivot_line = p_pivot_line.*; + + switch (line.tag) { + .blank => { + // Blank line ends current leaf block. + try this.endCurrentBlock(); + p_pivot_line.* = Line.Analysis.blank; + }, + .hr, .atx_header => { + try this.endCurrentBlock(); + + // Add our single-line block + try this.startNewBlock(line); + try this.addLineIntoCurrentBlock(line); + try this.endCurrentBlock(); + p_pivot_line.* = &Line.Analysis.blank; + }, + .setext_underline => { + this.current_block.?.tag = .table; + this.current_block.?.data = line.data; + this.current_block.?.flags.insert(.setext_header); + try this.addLineIntoCurrentBlock(line); + try this.endCurrentBlock(); + if (this.current_block == null) { + p_pivot_line.* = &Line.Analysis.blank; + } else { + // This happens if we have consumed all the body as link ref. defs. + //and downgraded the underline into start of a new paragraph block. + line.tag = .text; + p_pivot_line.* = line; + } + }, + // MD_LINE_TABLEUNDERLINE changes meaning of the current block. + .table_underline => { + var current_block = this.current_block.?; + std.debug.assert(current_block.line_count == 1); + current_block.tag = .table; + current_block.data = line.data; + std.debug.assert(pivot_line != &Line.Analysis.blank); + @intToPtr(*Line.Analysis, @ptrToInt(p_pivot_line.*)).tag = .table; + try this.addLineIntoCurrentBlock(line); + }, + else => { + // The current block also ends if the line has different type. + if (line.tag != pivot_line.tag) { + try this.endCurrentBlock(); + } + + // The current line may start a new block. + if (this.current_block == null) { + try this.startNewBlock(line); + p_pivot_line.* = line; + } + + // In all other cases the line is just a continuation of the current block. + try this.addLineIntoCurrentBlock(line); + }, + } + } + fn consumeLinkReferenceDefinitions(this: *MDParser) !void { + _ = this; + } + fn addLineIntoCurrentBlock(this: *MDParser, analysis: *const Line.Analysis) !void { + var current_block = this.current_block.?; + + switch (current_block.tag) { + .code, .html => { + if (current_block.line_count > 0) + std.debug.assert( + this.verbatim_lines.len == current_block.line_count + current_block.line_offset, + ); + if (current_block.line_count == 0) { + current_block.line_offset = this.verbatim_lines.len; + } + + try this.verbatim_lines.push(this.allocator, Line.Verbatim{ + .indent = analysis.indent, + .line = .{ + .beg = analysis.beg, + .end = analysis.end, + }, + }); + }, + else => { + if (current_block.line_count > 0) + std.debug.assert( + this.lines.len == current_block.line_count + current_block.line_offset, + ); + if (current_block.line_count == 0) { + current_block.line_offset = this.lines.len; + } + this.lines.push(this.allocator, .{ .beg = analysis.beg, .end = analysis.end }); + }, + } + + current_block.line_count += 1; + } + fn endCurrentBlock(this: *MDParser) !void { + _ = this; + + var block = this.current_block orelse return; + // Check whether there is a reference definition. (We do this here instead + // of in md_analyze_line() because reference definition can take multiple + // lines.) */ + if ((block.tag == .p or block.tag == .h) and block.flags.contains(.setext_header)) { + var lines = block.lines(this.lines); + if (lines[0].beg == '[') { + try this.consumeLinkReferenceDefinitions(); + block = this.current_block orelse return; + } + } + + if (block.tag == .h and block.flags.contains(.setext_header)) { + var n_lines = block.line_count; + if (n_lines > 1) { + // get rid of the underline + if (this.lines.len == block.line_count + block.line_offset) { + this.lines.len -= 1; + } + block.line_count -= 1; + } else { + // Only the underline has left after eating the ref. defs. + // Keep the line as beginning of a new ordinary paragraph. */ + block.tag = .p; + } + } + + // Mark we are not building any block anymore. + this.current_block = null; + this.current_block_index -|= 1; + } + fn buildRefDefHashTable(this: *MDParser) !void { + _ = this; + } + fn leaveChildContainers(this: *MDParser, keep: u32) !void { + _ = this; + while (this.containers.len > keep) { + var c = this.containers.last().?; + var is_ordered_list = false; + switch (c.ch) { + ')', '.' => { + is_ordered_list = true; + }, + '-', '+', '*' => { + try this.pushContainerBytes( + Block.Tag.li, + c.task_mark_off, + if (c.is_task) this.charAt(c.task_mark_off) else 0, + Block.Flags.container_closer, + ); + try this.pushContainerBytes( + if (is_ordered_list) Block.Tag.ol else Block.Tag.ul, + c.ch, + if (c.is_task) this.charAt(c.task_mark_off) else 0, + Block.Flags.container_closer, + ); + }, + '>' => { + try this.pushContainerBytes( + Block.Tag.quote, + 0, + 0, + Block.Flags.container_closer, + ); + }, + else => unreachable, + } + + this.containers.len -= 1; + } + } + fn enterChildContainers(this: *MDParser, keep: u32) !void { + _ = this; + var i: u32 = this.containers.len - keep; + while (i < this.containers.len) : (i += 1) { + var c: *Container = this.containers.ptr[i]; + var is_ordered_list = false; + + switch (c.ch) { + ')', '.' => { + is_ordered_list = true; + }, + '-', '+', '*' => { + // Remember offset in ctx.block_bytes so we can revisit the + // block if we detect it is a loose list. + try this.endCurrentBlock(); + c.block_index = this.blocks.len; + + try this.pushContainerBytes( + if (is_ordered_list) Block.Tag.ol else Block.Tag.ul, + c.start, + c.ch, + Block.Flags.container_opener, + ); + try this.pushContainerBytes( + Block.Tag.li, + c.task_mark_off, + if (c.is_task) this.charAt(c.task_mark_off) else 0, + Block.Flags.container_opener, + ); + }, + '>' => { + try this.pushContainerBytes( + Block.Tag.quote, + 0, + 0, + Block.Flags.container_opener, + ); + }, + else => unreachable, + } + } + } + fn pushContainer(this: *MDParser, container: Container) !void { + try this.containers.push(this.allocator, container); + } + + fn processLeafBlock(this: *MDParser, comptime tag: Block.Tag, block: *Block) anyerror!void { + const BlockDetailType = comptime switch (tag) { + Block.Tag.h => Block.Header, + Block.Tag.code => Block.Code, + Block.Tag.table => Block.Table, + }; + + const is_in_tight_list = if (this.containers.len == 0) + false + else + !this.containers.ptr[this.containers.len - 1].is_loose; + + const detail: BlockDetailType = switch (comptime tag) { + Block.Tag.h => @truncate(Block.Header, block.data), + Block.Tag.code => try this.setupFencedCodeDetail(block), + Block.Tag.table => .{ + .col_count = block.data, + .head_row_count = 1, + .body_row_count = block.line_count -| 2, + }, + else => void{}, + }; + + if (!is_in_tight_list or comptime tag != .p) { + try this.mdx.onEnterBlock(block.tag, BlockDetailType, detail); + } + + defer { + if (comptime tag == Block.Tag.code) {} + } + } + + fn pushContainerBytes(this: *MDParser, block_type: Block.Tag, start: u32, data: u32, flag: Block.Flags) !void { + try this.endCurrentBlock(); + var block = Block{ + .tag = block_type, + .line_count = start, + .data = data, + }; + block.flags.insert(flag); + var prev_block: ?Block = null; + if (this.current_block) |curr| { + prev_block = curr.*; + } + + try this.blocks.push(this.allocator, block); + if (prev_block != null) { + this.current_block = this.blocks.ptr[this.current_block_index]; + } + } + fn processBlock(this: *MDParser, comptime tag: Block.Tag, block: *Block) !void { + const detail: Block.Detail = + switch (comptime tag) { + .ul => Block.Detail{ + .ul = .{ + .is_tight = !block.flags.contains(.loose_list), + .mark = @truncate(u8, block.data), + }, + }, + .ol => Block.Detail{ + .ol = .{ + .start = block.line_count, + .is_tight = !block.flags.contains(.loose_list), + .mark_delimiter = @truncate(u8, block.data), + }, + }, + .li => Block.Detail{ + .li = .{ + .is_task = block.data != 0, + .task_mark = @truncate(u8, block.data), + .task_mark_offset = @intCast(u32, block.line_count), + }, + }, + else => Block.Detail{ .none = .{} }, + }; + + if (block.flags.contains(.container)) { + if (block.flags.contains(.container_closer)) { + switch (block.tag) { + .li => try this.mdx.onLeaveBlock(tag, Block.LI, detail.li), + .ul => try this.mdx.onLeaveBlock(tag, Block.UL, detail.ul), + .ol => try this.mdx.onLeaveBlock(tag, Block.OL, detail.ol), + else => try this.mdx.onLeaveBlock(block.tag, void, void{}), + } + this.containers.len -|= switch (block.tag) { + .ul, .ol, .blockquote => 1, + else => 0, + }; + } + + if (block.flags.contains(.container_opener)) { + switch (comptime tag) { + .li => try this.mdx.onEnterBlock(tag, Block.LI, detail.li), + .ul => try this.mdx.onEnterBlock(tag, Block.UL, detail.ul), + .ol => try this.mdx.onEnterBlock(tag, Block.OL, detail.ol), + else => try this.mdx.onEnterBlock(block.tag, void, void{}), + } + + switch (comptime tag) { + .ul, .ol => { + this.containers.ptr[this.containers.len].is_loose = block.flags.contains(.loose_list); + this.containers.len += 1; + }, + .blockquote => { + // This causes that any text in a block quote, even if + // nested inside a tight list item, is wrapped with + // <p>...</p>. */ + this.containers.ptr[this.containers.len].is_loose = true; + this.containers.len += 1; + }, + else => {}, + } + } + } else { + try this.processLeafBlock(tag, block); + } + } + fn processAllBlocks(this: *MDParser) !void { + _ = this; + + // ctx->containers now is not needed for detection of lists and list items + // so we reuse it for tracking what lists are loose or tight. We rely + // on the fact the vector is large enough to hold the deepest nesting + // level of lists. + this.containers.len = 0; + var blocks = this.blocks.slice(); + for (blocks) |*block| {} + } + fn isContainerCompatible(pivot: *const Container, container: *const Container) bool { + // Block quote has no "items" like lists. + if (container.ch == '>') return false; + + if (container.ch != pivot.ch) + return false; + + if (container.mark_indent > pivot.contents_indent) + return false; + return true; + } + + fn isHRLine(this: *MDParser, beg: u32, end: *u32, hr_killer: *u32) bool { + var off = beg + 1; + var n: u32 = 1; + + while (off < this.size and (this.charAt(off) == this.charAt(beg) or this.charAt(off) == ' ' or this.charAt(off) == '\t')) { + if (this.charAt(off) == this.charAt(beg)) + n += 1; + off += 1; + } + + if (n < 3) { + hr_killer.* = off; + return false; + } + + // Nothing else can be present on the line. */ + if (off < this.size and !this.isNewline(off)) { + hr_killer.* = off; + return false; + } + + end.* = off; + return true; + } + + fn isSetextUnderline(this: *MDParser, beg: u32, end: *u32, level: *u4) bool { + var off = beg + 1; + while (off < this.size and this.charAt(off) == this.charAt(beg)) + off += 1; + + // Optionally, space(s) can follow. */ + while (off < this.size and this.charAt(off) == ' ') + off += 1; + + // But nothing more is allowed on the line. + if (off < this.size and !this.isNewline(off)) + return false; + level.* = if (this.charAt(beg) == '=') 1 else 2; + end.* = off; + return true; + } + + fn isATXHeaderLine(this: *MDParser, beg: u32, p_beg: *u32, end: *u32, level: *u4) bool { + var n: i32 = undefined; + var off: u32 = beg + 1; + + while (off < this.size and this.charAt(off) == '#' and off - beg < 7) { + off += 1; + } + n = off - beg; + + if (n > 6) + return false; + level.* = @intCast(u4, n); + + if (!(this.flags.contains(.permissive_atxheaders)) and off < this.size and + this.charAt(off) != ' ' and this.charAt(off) != '\t' and !this.isNewline(off)) + return false; + + while (off < this.size and this.charAt(off) == ' ') { + off += 1; + } + + p_beg.* = off; + end.* = off; + + return true; + } + + fn isTableUnderline(this: *MDParser, beg: u32, end: *u32, column_column: *u32) bool { + _ = this; + _ = end; + _ = column_column; + + var off = beg; + var found_pipe = false; + var col_count: u32 = 0; + + if (off < this.size and this.charAt(off) == '|') { + found_pipe = true; + off += 1; + while (off < this.size and isWhitespace(this.charAt(off))) { + off += 1; + } + } + + while (true) { + var delimited = false; + + // Cell underline ("-----", ":----", "----:" or ":----:")if(off < this.size and this.charAt(off) == _T(':')) + off += 1; + if (off >= this.size or this.charAt(off) != '-') + return false; + while (off < this.size and this.charAt(off) == '-') + off += 1; + if (off < this.size and this.charAt(off) == ':') + off += 1; + + col_count += 1; + + // Pipe delimiter (optional at the end of line). */ + while (off < this.size and isWhitespace(this.charAt(off))) + off += 1; + if (off < this.size and this.charAt(off) == '|') { + delimited = true; + found_pipe = true; + off += 1; + while (off < this.size and isWhitespace(this.charAt(off))) + off += 1; + } + + // Success, if we reach end of line. + if (off >= this.size or this.isNewline(off)) + break; + + if (!delimited) + return false; + } + + if (!found_pipe) + return false; + + column_column.* = col_count; + end.* = off; + return true; + } + + fn isOpeningCodeFence(this: *MDParser, beg: u8, end: *u32) bool { + var off = beg; + const first = this.charAt(beg); + + while (off < this.size and this.charAt(off) == first) { + off += 1; + } + + // Fence must have at least three characters. + if (off - beg < 3) + return false; + + // Optionally, space(s) can follow + while (off < this.size and this.charAt(off) == ' ') { + off += 1; + } + + // Optionally, an info string can follow. + while (off < this.size and !this.isNewline(this.charAt(off))) { + // Backtick-based fence must not contain '`' in the info string. + if (first == '`' and this.charAt(off) == '`') + return false; + off += 1; + } + + end.* = off; + return true; + } + + fn isClosingCodeFence(this: *MDParser, ch: u8, beg: u8, end: *u32) bool { + var off = beg; + + defer { + end.* = off; + } + + while (off < this.size and this.charAt(off) == ch) { + off += 1; + } + + if (off - beg < this.code_fence_length) { + return false; + } + + // Optionally, space(s) can follow + while (off < this.size and this.charAt(off) == ' ') { + off += 1; + } + + // But nothing more is allowed on the line. + if (off < this.size and !this.isNewline(this.charAt(off))) + return false; + + return true; + } + + pub fn parse(this: *MDParser) anyerror!void { + var pivot_line = &Line.Analysis.blank; + var line_buf: [2]Line.Analysis = undefined; + var line = &line_buf[0]; + var offset: u32 = 0; + + try this.mdx.onEnterBlock(.doc, void, void{}); + + const len: u32 = this.size; + while (offset < len) { + if (line == pivot_line) { + line = if (line == &line_buf[0]) &line_buf[1] else &line_buf[0]; + } + + try this.analyzeLine(offset, &offset, pivot_line, line); + try this.processLine(&pivot_line, line); + } + + this.endCurrentBlock(); + + try this.buildRefDefHashTable(); + + this.leaveChildContainers(0); + this.processAllBlocks(); + try this.mdx.onLeaveBlock(.doc, void, void{}); + } +}; + +pub const MDX = struct { + parser: JSParser, + log: *logger.Log, + allocator: std.mem.Allocator, + stmts: std.ArrayListUnmanaged(js_ast.Stmt) = .{}, + + pub const Options = struct {}; + + pub fn onEnterBlock(this: *MDX, tag: Block.Tag, comptime Detail: type, detail: Detail) anyerror!void { + _ = tag; + _ = detail; + _ = this; + } + + pub fn onLeaveBlock(this: *MDX, tag: Block.Tag, comptime Detail: type, detail: Detail) anyerror!void { + _ = tag; + _ = detail; + _ = this; + } + + pub fn onEnterSpan(this: *MDX, tag: Span.Tag, comptime Detail: type, detail: Detail) anyerror!void { + _ = tag; + _ = detail; + _ = this; + } + + pub fn onLeaveSpan(this: *MDX, tag: Span.Tag, comptime Detail: type, detail: Detail) anyerror!void { + _ = tag; + _ = detail; + _ = this; + } + + pub fn onText(this: *MDX, tag: Text, text: []const u8) anyerror!void { + _ = tag; + _ = text; + _ = this; + } + + pub inline fn source(p: *const MDX) *const logger.Source { + return &p.lexer.source; + } + + pub fn e(_: *MDX, t: anytype, loc: logger.Loc) Expr { + const Type = @TypeOf(t); + if (@typeInfo(Type) == .Pointer) { + return Expr.init(std.meta.Child(Type), t.*, loc); + } else { + return Expr.init(Type, t, loc); + } + } + + pub fn s(_: *MDX, t: anytype, loc: logger.Loc) Stmt { + const Type = @TypeOf(t); + if (@typeInfo(Type) == .Pointer) { + return Stmt.init(std.meta.Child(Type), t.*, loc); + } else { + return Stmt.alloc(Type, t, loc); + } + } + + pub fn setup( + this: *MDX, + _options: ParserOptions, + log: *logger.Log, + source_: *const logger.Source, + define: *Define, + allocator: std.mem.Allocator, + ) !void { + try JSParser.init( + allocator, + log, + source_, + define, + js_lexer.Lexer.initNoAutoStep(log, source_.*, allocator), + _options, + &this.parser, + ); + this.lexer = try Lexer.init(&this.parser.lexer); + this.allocator = allocator; + this.log = log; + this.stmts = .{}; + } + + pub fn parse(this: *MDX) !js_ast.Result { + try this._parse(); + return try runVisitPassAndFinish(JSParser, &this.parser, this.stmts.toOwnedSlice(this.allocator)); + } + + fn run(this: *MDX) anyerror!logger.Loc { + _ = this; + return logger.Loc.Empty; + } + + fn _parse(this: *MDX) anyerror!void { + var root_children = std.ArrayListUnmanaged(Expr){}; + var first_loc = try run(this, &root_children); + + first_loc.start = @maximum(first_loc.start, 0); + const args_loc = first_loc; + first_loc.start += 1; + const body_loc = first_loc; + + // We need to simulate a function that was parsed + _ = try this.parser.pushScopeForParsePass(.function_args, args_loc); + + _ = try this.parser.pushScopeForParsePass(.function_body, body_loc); + + const root = this.e(E.JSXElement{ + .tag = this.e(E.JSXElement.Tag.map.get(E.JSXElement.Tag.main), body_loc), + .children = ExprNodeList.fromList(root_children), + }, body_loc); + + var root_stmts = try this.allocator.alloc(Stmt, 1); + root_stmts[0] = this.s(S.Return{ .value = root }, body_loc); + + try this.stmts.append( + this.allocator, + + this.s(S.ExportDefault{ + .default_name = try this.parser.createDefaultName(args_loc), + .value = .{ + .expr = this.e(E.Arrow{ + .body = G.FnBody{ + .stmts = root_stmts, + .loc = body_loc, + }, + .args = &[_]G.Arg{}, + .prefer_expr = true, + }, args_loc), + }, + }, args_loc), + ); + } +}; diff --git a/src/memory_allocator.zig b/src/memory_allocator.zig index c7e42ae87..6797661de 100644 --- a/src/memory_allocator.zig +++ b/src/memory_allocator.zig @@ -32,12 +32,6 @@ const c = struct { const Allocator = mem.Allocator; const assert = std.debug.assert; const CAllocator = struct { - comptime { - if (!@import("builtin").link_libc) { - @compileError("C allocator is only available when linking against libc"); - } - } - usingnamespace if (@hasDecl(c, "malloc_size")) struct { pub const supports_malloc_size = true; @@ -161,12 +155,6 @@ const c_allocator_vtable = Allocator.VTable{ // This is a memory allocator which always writes zero instead of undefined const ZAllocator = struct { - comptime { - if (!@import("builtin").link_libc) { - @compileError("C allocator is only available when linking against libc"); - } - } - usingnamespace if (@hasDecl(c, "malloc_size")) struct { pub const supports_malloc_size = true; diff --git a/src/open.zig b/src/open.zig index 509e92f40..b73bc282e 100644 --- a/src/open.zig +++ b/src/open.zig @@ -89,7 +89,7 @@ pub const Editor = enum(u8) { } const which = @import("./which.zig").which; - pub fn byPATH(env: *DotEnv.Loader, buf: *[std.fs.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor { + pub fn byPATH(env: *DotEnv.Loader, buf: *[_global.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor { const PATH = env.get("PATH") orelse return null; inline for (default_preference_list) |editor| { @@ -104,7 +104,7 @@ pub const Editor = enum(u8) { return null; } - pub fn byPATHForEditor(env: *DotEnv.Loader, editor: Editor, buf: *[std.fs.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) bool { + pub fn byPATHForEditor(env: *DotEnv.Loader, editor: Editor, buf: *[_global.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) bool { const PATH = env.get("PATH") orelse return false; if (bin_name.get(editor)) |path| { @@ -135,7 +135,7 @@ pub const Editor = enum(u8) { return false; } - pub fn byFallback(env: *DotEnv.Loader, buf: *[std.fs.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor { + pub fn byFallback(env: *DotEnv.Loader, buf: *[_global.MAX_PATH_BYTES]u8, cwd: string, out: *[]const u8) ?Editor { inline for (default_preference_list) |editor| { if (byPATHForEditor(env, editor, buf, cwd, out)) { return editor; @@ -220,7 +220,7 @@ pub const Editor = enum(u8) { column: ?string, allocator: std.mem.Allocator, ) !void { - var file_path_buf: [std.fs.MAX_PATH_BYTES + 1024]u8 = undefined; + var file_path_buf: [_global.MAX_PATH_BYTES + 1024]u8 = undefined; var file_path_buf_stream = std.io.fixedBufferStream(&file_path_buf); var file_path_buf_writer = file_path_buf_stream.writer(); var args_buf: [10]string = undefined; diff --git a/src/options.zig b/src/options.zig index f1ba76ad2..aea7d13d1 100644 --- a/src/options.zig +++ b/src/options.zig @@ -24,7 +24,7 @@ const stringZ = _global.stringZ; const default_allocator = _global.default_allocator; const C = _global.C; const StoredFileDescriptorType = _global.StoredFileDescriptorType; -const JSC = @import("./jsc.zig"); +const JSC = @import("javascript_core"); const Analytics = @import("./analytics/analytics_thread.zig"); const MacroRemap = @import("./resolver/package_json.zig").MacroMap; @@ -1076,6 +1076,8 @@ pub fn loadersFromTransformOptions(allocator: std.mem.Allocator, _loaders: ?Api. return loaders; } +const Dir = std.fs.Dir; + /// BundleOptions is used when ResolveMode is not set to "disable". /// BundleOptions is effectively webpack + babel pub const BundleOptions = struct { @@ -1089,7 +1091,7 @@ pub const BundleOptions = struct { hot_module_reloading: bool = false, inject: ?[]string = null, origin: URL = URL{}, - output_dir_handle: ?std.fs.Dir = null, + output_dir_handle: ?Dir = null, output_dir: string = "out", node_modules_bundle_url: string = "", @@ -1510,7 +1512,7 @@ pub const BundleOptions = struct { if (!opts.routes.single_page_app_routing and should_try_to_find_a_index_html_file) { attempt: { - var abs_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var abs_buf: [_global.MAX_PATH_BYTES]u8 = undefined; // If it's not in static-dir/index.html, check if it's in top level dir/index.html var parts = [_]string{"index.html"}; var full_path = resolve_path.joinAbsStringBuf(fs.top_level_dir, &abs_buf, &parts, .auto); diff --git a/src/report.zig b/src/report.zig index 075e2fc90..0a368b733 100644 --- a/src/report.zig +++ b/src/report.zig @@ -20,9 +20,10 @@ const CrashReporter = @import("crash_reporter"); const Report = @This(); var crash_report_writer: CrashReportWriter = CrashReportWriter{ .file = null }; +const CrashWritable = if (Environment.isWasm) std.io.fixedBufferStream([2048]u8) else std.fs.File.Writer; var crash_reporter_path: [1024]u8 = undefined; pub const CrashReportWriter = struct { - file: ?std.io.BufferedWriter(4096, std.fs.File.Writer) = null, + file: ?std.io.BufferedWriter(4096, CrashWritable) = null, file_path: []const u8 = "", pub fn printFrame(_: ?*anyopaque, frame: CrashReporter.StackFrame) void { @@ -32,11 +33,13 @@ pub const CrashReportWriter = struct { } pub fn dump() void { - CrashReporter.print(); + if (comptime !Environment.isWasm) + CrashReporter.print(); } pub fn done() void { - CrashReporter.print(); + if (comptime !Environment.isWasm) + CrashReporter.print(); } pub fn print(this: *CrashReportWriter, comptime fmt: string, args: anytype) void { diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index d9e2515de..13f0b5467 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -1069,7 +1069,7 @@ pub const ESModule = struct { "%5C", }; - threadlocal var resolved_path_buf_percent: [std.fs.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolved_path_buf_percent: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn resolve(r: *const ESModule, package_url: string, subpath: string, exports: ExportsMap.Entry) Resolution { var result = r.resolveExports(package_url, subpath, exports); @@ -1239,8 +1239,8 @@ pub const ESModule = struct { }; } - threadlocal var resolve_target_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - threadlocal var resolve_target_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolve_target_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolve_target_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; fn resolveTarget( r: *const ESModule, package_url: string, @@ -1505,8 +1505,8 @@ pub const ESModule = struct { } } - threadlocal var resolve_target_reverse_prefix_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - threadlocal var resolve_target_reverse_prefix_buf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolve_target_reverse_prefix_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + threadlocal var resolve_target_reverse_prefix_buf2: [_global.MAX_PATH_BYTES]u8 = undefined; fn resolveTargetReverse( r: *const ESModule, diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index a2366b50a..c731aff6b 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -3,7 +3,7 @@ const std = @import("std"); const strings = @import("../string_immutable.zig"); const FeatureFlags = @import("../feature_flags.zig"); const default_allocator = @import("../memory_allocator.zig").c_allocator; - +const _global = @import("../global.zig"); threadlocal var parser_join_input_buffer: [4096]u8 = undefined; threadlocal var parser_buffer: [1024]u8 = undefined; @@ -716,7 +716,7 @@ pub fn joinAbsStringBufZ(_cwd: []const u8, buf: []u8, _parts: anytype, comptime inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: type, _cwd: []const u8, buf: []u8, _parts: anytype, comptime _platform: Platform) ReturnType { var parts: []const []const u8 = _parts; - var temp_buf: [std.fs.MAX_PATH_BYTES * 2]u8 = undefined; + var temp_buf: [_global.MAX_PATH_BYTES * 2]u8 = undefined; if (parts.len == 0) { if (comptime is_sentinel) { unreachable; diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index f153db65a..f05cbb6f1 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -56,8 +56,8 @@ pub const TemporaryBuffer = struct { pub threadlocal var ExtensionPathBuf: [512]u8 = undefined; pub threadlocal var TSConfigMatchStarBuf: [512]u8 = undefined; pub threadlocal var TSConfigMatchPathBuf: [512]u8 = undefined; - pub threadlocal var TSConfigMatchFullBuf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - pub threadlocal var TSConfigMatchFullBuf2: [std.fs.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var TSConfigMatchFullBuf: [_global.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var TSConfigMatchFullBuf2: [_global.MAX_PATH_BYTES]u8 = undefined; }; pub const PathPair = struct { @@ -212,21 +212,21 @@ pub const DirEntryResolveQueueItem = struct { threadlocal var _dir_entry_paths_to_resolve: [256]DirEntryResolveQueueItem = undefined; threadlocal var _open_dirs: [256]std.fs.Dir = undefined; -threadlocal var resolve_without_remapping_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var index_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var dir_info_uncached_filename_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var node_bin_path: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var dir_info_uncached_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var tsconfig_base_url_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var relative_abs_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var load_as_file_or_directory_via_tsconfig_base_path: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var node_modules_check_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var field_abs_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var tsconfig_path_abs_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var check_browser_map_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var remap_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var load_as_file_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; -threadlocal var remap_path_trailing_slash: [std.fs.MAX_PATH_BYTES]u8 = undefined; +threadlocal var resolve_without_remapping_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var index_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var dir_info_uncached_filename_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var node_bin_path: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var dir_info_uncached_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var tsconfig_base_url_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var relative_abs_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var load_as_file_or_directory_via_tsconfig_base_path: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var node_modules_check_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var field_abs_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var tsconfig_path_abs_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var check_browser_map_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var remap_path_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var load_as_file_buf: [_global.MAX_PATH_BYTES]u8 = undefined; +threadlocal var remap_path_trailing_slash: [_global.MAX_PATH_BYTES]u8 = undefined; pub const DebugLogs = struct { what: string = "", @@ -511,7 +511,7 @@ pub const Resolver = struct { pkg.loadFrameworkWithPreference(pair, json, r.allocator, load_defines, preference); const dir = pkg.source.path.sourceDir(); - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; pair.framework.resolved_dir = pkg.source.path.sourceDir(); @@ -716,7 +716,7 @@ pub const Resolver = struct { } } else if (dir.abs_real_path.len > 0) { var parts = [_]string{ dir.abs_real_path, query.entry.base() }; - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var out = r.fs.absBuf(&parts, &buf); @@ -1161,8 +1161,8 @@ pub const Resolver = struct { } threadlocal var esm_subpath_buf: [512]u8 = undefined; - threadlocal var esm_absolute_package_path: [std.fs.MAX_PATH_BYTES]u8 = undefined; - threadlocal var esm_absolute_package_path_joined: [std.fs.MAX_PATH_BYTES]u8 = undefined; + threadlocal var esm_absolute_package_path: [_global.MAX_PATH_BYTES]u8 = undefined; + threadlocal var esm_absolute_package_path_joined: [_global.MAX_PATH_BYTES]u8 = undefined; pub fn loadNodeModules(r: *ThisResolver, import_path: string, kind: ast.ImportKind, _dir_info: *DirInfo) ?MatchResult { var dir_info = _dir_info; if (r.debug_logs) |*debug| { @@ -1814,7 +1814,7 @@ pub const Resolver = struct { extension_order: []const string, map: BrowserMap, - pub threadlocal var abs_to_rel_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + pub threadlocal var abs_to_rel_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub const Kind = enum { PackagePath, AbsolutePath }; diff --git a/src/router.zig b/src/router.zig index 73a7d9987..cad7d182b 100644 --- a/src/router.zig +++ b/src/router.zig @@ -536,8 +536,8 @@ pub const Route = struct { pub const Ptr = TinyPtr; pub const index_route_name: string = "/"; - var route_file_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - var second_route_file_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var route_file_buf: [_global.MAX_PATH_BYTES]u8 = undefined; + var second_route_file_buf: [_global.MAX_PATH_BYTES]u8 = undefined; pub const Sorter = struct { const sort_table: [std.math.maxInt(u8)]u8 = brk: { diff --git a/src/runtime.version b/src/runtime.version index 2dbb44452..f63c71b22 100644 --- a/src/runtime.version +++ b/src/runtime.version @@ -1 +1 @@ -ca1cb170bea8ecef
\ No newline at end of file +fcef2b20a766d0b8
\ No newline at end of file diff --git a/src/runtime.zig b/src/runtime.zig index a5acd7e68..627615799 100644 --- a/src/runtime.zig +++ b/src/runtime.zig @@ -28,7 +28,7 @@ pub const ErrorCSS = struct { pub inline fn sourceContent() string { if (comptime Environment.isDebug) { - var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; var dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable; var paths = [_]string{ dirname, BUN_ROOT, ErrorCSSPathDev }; const file = std.fs.cwd().openFile( @@ -54,7 +54,7 @@ pub const ErrorJS = struct { pub inline fn sourceContent() string { if (comptime Environment.isDebug) { - var out_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var out_buffer: [_global.MAX_PATH_BYTES]u8 = undefined; var dirname = std.fs.selfExeDirPath(&out_buffer) catch unreachable; var paths = [_]string{ dirname, BUN_ROOT, ErrorJSPath }; const file = std.fs.cwd().openFile( diff --git a/src/string_types.zig b/src/string_types.zig index 9aa0ff414..df435ee89 100644 --- a/src/string_types.zig +++ b/src/string_types.zig @@ -3,19 +3,19 @@ pub const string = []const u8; pub const stringZ = [:0]const u8; pub const stringMutable = []u8; pub const CodePoint = i32; - +const _global = @import("./global.zig"); // macOS sets file path limit to 1024 // Since a pointer on x64 is 64 bits and only 46 bits are used // We can safely store the entire path slice in a single u64. pub const PathString = packed struct { - const PathIntLen = std.math.IntFittingRange(0, std.fs.MAX_PATH_BYTES); + const PathIntLen = std.math.IntFittingRange(0, _global.MAX_PATH_BYTES); pub const use_small_path_string = @bitSizeOf(usize) - @bitSizeOf(PathIntLen) >= 53; pub const PathInt = if (use_small_path_string) PathIntLen else usize; pub const PointerIntType = if (use_small_path_string) u53 else usize; ptr: PointerIntType = 0, len: PathInt = 0, - const JSC = @import("./jsc.zig"); + const JSC = @import("javascript_core"); pub fn fromJS(value: JSC.JSValue, global: *JSC.JSGlobalObject, exception: JSC.C.ExceptionRef) PathString { if (!value.jsType().isStringLike()) { JSC.JSError(JSC.getAllocator(global.ref()), "Only path strings are supported for now", .{}, global.ref(), exception); @@ -63,10 +63,12 @@ pub const PathString = packed struct { pub const empty = @This(){ .ptr = 0, .len = 0 }; comptime { - if (use_small_path_string and @bitSizeOf(@This()) != 64) { - @compileError("PathString must be 64 bits"); - } else if (!use_small_path_string and @bitSizeOf(@This()) != 128) { - @compileError("PathString must be 128 bits"); + if (!_global.Environment.isWasm) { + if (use_small_path_string and @bitSizeOf(@This()) != 64) { + @compileError("PathString must be 64 bits"); + } else if (!use_small_path_string and @bitSizeOf(@This()) != 128) { + @compileError("PathString must be 128 bits"); + } } } }; diff --git a/src/typegen.zig b/src/typegen.zig new file mode 100644 index 000000000..0f2222bff --- /dev/null +++ b/src/typegen.zig @@ -0,0 +1,5 @@ +pub const bindgen = true; + +pub fn main() anyerror!void { + return try @import("javascript/jsc/typescript.zig").main(); +} diff --git a/src/watcher.zig b/src/watcher.zig index 35606f697..a5775071b 100644 --- a/src/watcher.zig +++ b/src/watcher.zig @@ -79,7 +79,7 @@ pub const INotify = struct { pub var inotify_fd: EventListIndex = 0; pub var loaded_inotify = false; - const EventListBuffer = [@sizeOf([128]INotifyEvent) + (128 * std.fs.MAX_PATH_BYTES)]u8; + const EventListBuffer = [@sizeOf([128]INotifyEvent) + (128 * _global.MAX_PATH_BYTES)]u8; var eventlist: EventListBuffer = undefined; var eventlist_ptrs: [128]*const INotifyEvent = undefined; @@ -193,12 +193,19 @@ const DarwinWatcher = struct { } }; +pub const Placeholder = struct { + pub const EventListIndex = u32; + + pub var eventlist: [WATCHER_MAX_LIST]EventListIndex = undefined; + pub var eventlist_index: EventListIndex = 0; +}; + const PlatformWatcher = if (Environment.isMac) DarwinWatcher else if (Environment.isLinux) INotify else - void; + Placeholder; pub const WatchItem = struct { file_path: string, @@ -599,7 +606,7 @@ pub fn NewWatcher(comptime ContextType: type) type { ); } else if (comptime Environment.isLinux) { // var file_path_to_use_ = std.mem.trimRight(u8, file_path_, "/"); - // var buf: [std.fs.MAX_PATH_BYTES+1]u8 = undefined; + // var buf: [_global.MAX_PATH_BYTES+1]u8 = undefined; // std.mem.copy(u8, &buf, file_path_to_use_); // buf[file_path_to_use_.len] = 0; var buf = file_path_.ptr; @@ -683,7 +690,7 @@ pub fn NewWatcher(comptime ContextType: type) type { ); } else if (Environment.isLinux) { var file_path_to_use_ = std.mem.trimRight(u8, file_path_, "/"); - var buf: [std.fs.MAX_PATH_BYTES + 1]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES + 1]u8 = undefined; std.mem.copy(u8, &buf, file_path_to_use_); buf[file_path_to_use_.len] = 0; var slice: [:0]u8 = buf[0..file_path_to_use_.len :0]; diff --git a/src/which.zig b/src/which.zig index 558abc389..a6009200c 100644 --- a/src/which.zig +++ b/src/which.zig @@ -1,6 +1,6 @@ const std = @import("std"); - -fn isValid(buf: *[std.fs.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8) ?u16 { +const _global = @import("./global.zig"); +fn isValid(buf: *[_global.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8) ?u16 { std.mem.copy(u8, buf, segment); buf[segment.len] = std.fs.path.sep; std.mem.copy(u8, buf[segment.len + 1 ..], bin); @@ -14,7 +14,7 @@ fn isValid(buf: *[std.fs.MAX_PATH_BYTES]u8, segment: []const u8, bin: []const u8 // Like /usr/bin/which but without needing to exec a child process // Remember to resolve the symlink if necessary -pub fn which(buf: *[std.fs.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8, bin: []const u8) ?[:0]const u8 { +pub fn which(buf: *[_global.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8, bin: []const u8) ?[:0]const u8 { if (isValid(buf, std.mem.trimRight(u8, cwd, std.fs.path.sep_str), bin)) |len| { return buf[0..len :0]; } @@ -30,7 +30,7 @@ pub fn which(buf: *[std.fs.MAX_PATH_BYTES]u8, path: []const u8, cwd: []const u8, } test "which" { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + var buf: [_global.MAX_PATH_BYTES]u8 = undefined; var realpath = std.os.getenv("PATH") orelse unreachable; var whichbin = which(&buf, realpath, try std.process.getCwdAlloc(std.heap.c_allocator), "which"); try std.testing.expectEqualStrings(whichbin orelse return std.debug.assert(false), "/usr/bin/which"); |