Compare commits

...

2 Commits

Author SHA1 Message Date
Jarred Sumner
e459ee472f WIP 2022-02-06 00:25:35 -08:00
Jarred Sumner
a6ee900aaf Update bun-flavored-toml.md 2022-02-05 23:48:51 -08:00
4 changed files with 168 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
# Bun-flavored TOML
This document is incomplete.
[TOML](https://toml.io/) is a minimal configuration file format designed to be easy for humans to read.
Bun implements a TOML parser with a few tweaks designed for better interopability with INI files and with JavaScript.

View File

@@ -89,6 +89,16 @@ pub const ZigString = extern struct {
pub const shim = Shimmer("", "ZigString", @This());
pub fn hash(this: ZigString) u64 {
if (this.len == 0) return 0;
if (this.is16Bit()) {
return std.hash.Wyhash.hash(0, std.mem.sliceAsBytes(this.utf16Slice()));
}
return std.hash.Wyhash.hash(0, this.slice());
}
pub const Slice = struct {
allocator: std.mem.Allocator,
ptr: [*]const u8,
@@ -1713,6 +1723,22 @@ pub const JSValue = enum(i64) {
});
}
pub fn indexOfMatchingRegexPtr(list: [*]const JSValue, list_len: usize, globalThis: *JSGlobalObject, zig_str: *const ZigString) i32 {
return cppFn("indexOfMatchingRegexPtr", .{
list,
list_len,
globalThis,
zig_str,
});
}
pub fn indexOfMatchingRegExp(list: []const JSValue, globalThis: *JSGlobalObject, zig_str: ZigString) ?usize {
return switch (indexOfMatchingRegexPtr(list.ptr, list.len, globalThis, &zig_str)) {
-1 => null,
0...std.math.maxInt(i32) => |val| @intCast(usize, val),
};
}
pub inline fn arrayIterator(this: JSValue, global: *JSGlobalObject) JSArrayIterator {
return JSArrayIterator.init(this, global);
}
@@ -1998,7 +2024,7 @@ pub const JSValue = enum(i64) {
return @intToPtr(*anyopaque, @bitCast(u64, @enumToInt(this)));
}
pub const Extern = [_][]const u8{ "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isUndefined", "isNull", "isUndefinedOrNull", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
pub const Extern = [_][]const u8{ "indexOfMatchingRegex", "createInternalPromise", "asInternalPromise", "asArrayBuffer_", "getReadableStreamState", "getWritableStreamState", "fromEntries", "createTypeError", "createRangeError", "createObject2", "getIfPropertyExistsImpl", "jsType", "jsonStringify", "kind_", "isTerminationException", "isSameValue", "getLengthOfArray", "toZigString", "createStringArray", "createEmptyObject", "putRecord", "asPromise", "isClass", "getNameProperty", "getClassName", "getErrorsProperty", "toInt32", "toBoolean", "isInt32", "isIterable", "forEach", "isAggregateError", "toZigException", "isException", "toWTFString", "hasProperty", "getPropertyNames", "getDirect", "putDirect", "getIfExists", "asString", "asObject", "asNumber", "isError", "jsNull", "jsUndefined", "jsTDZValue", "jsBoolean", "jsDoubleNumber", "jsNumberFromDouble", "jsNumberFromChar", "jsNumberFromU16", "jsNumberFromInt32", "jsNumberFromInt64", "jsNumberFromUint64", "isUndefined", "isNull", "isUndefinedOrNull", "isBoolean", "isAnyInt", "isUInt32AsAnyInt", "isInt32AsAnyInt", "isNumber", "isString", "isBigInt", "isHeapBigInt", "isBigInt32", "isSymbol", "isPrimitive", "isGetterSetter", "isCustomGetterSetter", "isObject", "isCell", "asCell", "toString", "toStringOrNull", "toPropertyKey", "toPropertyKeyValue", "toObject", "toString", "getPrototype", "getPropertyByPropertyName", "eqlValue", "eqlCell", "isCallable" };
};
extern "c" fn Microtask__run(*Microtask, *JSGlobalObject) void;

View File

@@ -0,0 +1,134 @@
const std = @import("std");
const Api = @import("../../../api/schema.zig").Api;
const RequestContext = @import("../../../http.zig").RequestContext;
const MimeType = @import("../../../http.zig").MimeType;
const ZigURL = @import("../../../query_string_map.zig").URL;
const HTTPClient = @import("http");
const NetworkThread = HTTPClient.NetworkThread;
const strings = @import("../../../global.zig").strings;
const string = @import("../../../global.zig").string;
const default_allocator = @import("../../../global.zig").default_allocator;
const FeatureFlags = @import("../../../global.zig").FeatureFlags;
const Path = @import("../../../fs.zig").Path;
const logger = @import("../../../logger.zig");
const JSC = @import("../../../jsc.zig");
const Bundler = @import("../../../bundler.zig").Bundler;
const Resolver = @import("../../../bundler.zig").Resolver;
const js = JSC.C;
pub const Plugin = struct {
name: string,
pub const Registry = struct {
bundler: *Bundler,
resolver: *Resolver,
allocator: std.mem.Allocator,
load: LoadCallback.Map,
resolve: ResolveCallback.Map,
pub const Class = JSC.NewClass(
Registry,
.{ .name = "Registry" },
.{
.onLoad = .{
.rfn = handleOnLoad,
},
.onResolve = .{
.rfn = handleOnResolve,
},
.onStart = .{
.rfn = handleOnStart,
},
.onEnd = .{
.rfn = handleOnEnd,
},
.resolve = .{
.rfn = handleResolve,
},
},
.{},
);
pub fn addLoadCallback(this: *Registry, namespace_: string, callback: LoadCallback) void {
var entry = this.load.getOrPut(this.allocator, namespace_) catch unreachable;
}
pub fn handleOnLoad(
this: *Registry,
ctx: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
args_: []const js.JSValueRef,
exception: js.ExceptionRef,
) js.JSValueRef {
const args: []const JSC.JSValue = @ptrCast([*]const JSC.JSValue, args_.ptr)[0..args_.len];
if (args.len < 2) {
JSC.throwInvalidArguments("onLoad expects a filter object and a callback", .{}, ctx, exception);
return null;
}
const object = args[0];
if (!object.jsType().isObject()) {
JSC.throwInvalidArguments("onLoad expects an object with \"filter\"", .{}, ctx, exception);
return null;
}
var namespace_slice = JSC.ZigString.init("file").toSlice(this.allocator);
if (object.get(ctx.ptr(), "namespace")) |namespace_prop| {
namespace_slice = namespace_prop.toSlice(ctx.ptr(), this.allocator);
}
if (object.get(ctx.ptr(), "filter")) |filter_prop| {
switch (filter_prop.jsType()) {
JSC.JSValue.JSType.RegExpObject => {
},
}
}
}
pub fn noop(
_: *Registry,
_: js.JSContextRef,
_: js.JSObjectRef,
_: js.JSObjectRef,
_: []const js.JSValueRef,
_: js.ExceptionRef,
) js.JSValueRef {
return JSC.JSValue.jsUndefined();
}
const handleOnResolve = noop;
const handleOnStart = noop;
const handleOnEnd = noop;
const handleResolve = noop;
};
};
pub const LoadCallback = struct {
plugin: *Plugin,
javascript_function: JSC.JSValue,
filter: FilterList,
pub const List = std.MultiArrayList(LoadCallback);
pub const Map = std.AutoHashMapUnmanaged(u64, List);
pub const Context = struct {
registry:
log: *logger.Log,
namespace: string,
import_path: string,
};
};
pub const ResolveCallback = struct {
plugin: *Plugin,
javascript_function: JSC.JSValue,
filter: FilterList,
pub const List = std.MultiArrayList(ResolveCallback);
pub const Map = std.AutoHashMapUnmanaged(u64, List);
};
pub const FilterList = []const JSC.JSValue;

View File

@@ -433,7 +433,7 @@ pub fn eqlCaseInsensitiveASCII(a: string, comptime b: anytype, comptime check_le
return true;
}
pub fn eqlLong(a_: string, b: string, comptime check_len: bool) bool {
pub fn eqlLongWithType(comptime Type: type, a_: Type, b: Type, comptime check_len: bool) bool {
if (comptime check_len) {
if (a_.len == 0) {
return b.len == 0;
@@ -483,6 +483,10 @@ pub fn eqlLong(a_: string, b: string, comptime check_len: bool) bool {
return true;
}
pub fn eqlLong(a_: string, b: string, comptime check_len: bool) bool {
return eqlLongWithType(string, a_, b, check_len);
}
pub inline fn append(allocator: std.mem.Allocator, self: string, other: string) !string {
return std.fmt.allocPrint(allocator, "{s}{s}", .{ self, other });
}