diff options
author | 2023-08-24 18:39:28 -0300 | |
---|---|---|
committer | 2023-08-24 14:39:28 -0700 | |
commit | 55eb4ffe8fc8708d5a44c53fe75026a03f0a4de8 (patch) | |
tree | b807c9eb1819e28eb991e583e4c7550b996a0ff2 /src | |
parent | a051a6f62014b740702594527b19464ce24ba32b (diff) | |
download | bun-55eb4ffe8fc8708d5a44c53fe75026a03f0a4de8.tar.gz bun-55eb4ffe8fc8708d5a44c53fe75026a03f0a4de8.tar.zst bun-55eb4ffe8fc8708d5a44c53fe75026a03f0a4de8.zip |
Update bun-polyfills & bun-wasm (#4246)
* automate Bun.version & revision polyfills
* polyfill Bun.gc
* bun:jsc module initial polyfills
* update peechy schema
* bun-polyfills: fix some project configs
* bun-wasm: lots of fixes
* bun-polyfills: Bun.Transpiler impl.
* revision hash update
Diffstat (limited to 'src')
-rw-r--r-- | src/api/schema.d.ts | 1 | ||||
-rw-r--r-- | src/api/schema.js | 16 | ||||
-rw-r--r-- | src/api/schema.peechy | 3 | ||||
-rw-r--r-- | src/api/schema.zig | 5 | ||||
-rw-r--r-- | src/main_wasm.zig | 50 |
5 files changed, 58 insertions, 17 deletions
diff --git a/src/api/schema.d.ts b/src/api/schema.d.ts index f1d5b5f62..3ec03e213 100644 --- a/src/api/schema.d.ts +++ b/src/api/schema.d.ts @@ -579,6 +579,7 @@ export interface Scan { export interface ScanResult { exports: string[]; imports: ScannedImport[]; + errors: Message[]; } export interface ScannedImport { diff --git a/src/api/schema.js b/src/api/schema.js index 4931cd716..6fb4b1d8d 100644 --- a/src/api/schema.js +++ b/src/api/schema.js @@ -2058,6 +2058,9 @@ function decodeScanResult(bb) { var length = bb.readVarUint(); var values = (result["imports"] = Array(length)); for (var i = 0; i < length; i++) values[i] = decodeScannedImport(bb); + var length = bb.readVarUint(); + var values = (result["errors"] = Array(length)); + for (var i = 0; i < length; i++) values[i] = decodeMessage(bb); return result; } @@ -2087,6 +2090,19 @@ function encodeScanResult(message, bb) { } else { throw new Error('Missing required field "imports"'); } + + var value = message["errors"]; + if (value != null) { + var values = value, + n = values.length; + bb.writeVarUint(n); + for (var i = 0; i < n; i++) { + value = values[i]; + encodeMessage(value, bb); + } + } else { + throw new Error('Missing required field "errors"'); + } } function decodeScannedImport(bb) { diff --git a/src/api/schema.peechy b/src/api/schema.peechy index dc8e312a5..8185733c9 100644 --- a/src/api/schema.peechy +++ b/src/api/schema.peechy @@ -377,6 +377,7 @@ message Scan { struct ScanResult { string[] exports; ScannedImport[] imports; + Message[] errors; } struct ScannedImport { @@ -414,7 +415,7 @@ struct TransformResponse { enum MessageLevel { err = 1; - warn =2; + warn = 2; note = 3; info = 4; debug = 5; diff --git a/src/api/schema.zig b/src/api/schema.zig index 93b526d47..ae63af87a 100644 --- a/src/api/schema.zig +++ b/src/api/schema.zig @@ -2117,17 +2117,22 @@ pub const Api = struct { /// imports imports: []const ScannedImport, + /// errors + errors: []const Message, + 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); + this.errors = try reader.readArray(Message); 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); + try writer.writeArray(Message, this.errors); } }; diff --git a/src/main_wasm.zig b/src/main_wasm.zig index e7fd55d80..6d3ba2466 100644 --- a/src/main_wasm.zig +++ b/src/main_wasm.zig @@ -604,26 +604,44 @@ export fn scan(opts_array: u64) u64 { 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 (log.errors == 0) { + 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 == .ast) { + var scanned_imports = allocator.alloc(Api.ScannedImport, result.ast.import_records.len) catch unreachable; + var scanned_i: usize = 0; + for (result.ast.import_records.slice()) |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; + } - if (result == .ast) { - var scanned_imports = allocator.alloc(Api.ScannedImport, result.ast.import_records.len) catch unreachable; - var scanned_i: usize = 0; - for (result.ast.import_records.slice()) |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], + .errors = (log.toAPI(allocator) catch unreachable).msgs, + }; } - 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 @as(u64, @bitCast([2]u32{ @intFromPtr(output.items.ptr), output.items.len })); + } else { + var output = std.ArrayList(u8).init(default_allocator); + var output_writer = output.writer(); + const Encoder = ApiWriter(@TypeOf(output_writer)); + var scan_result = Api.ScanResult{ + .exports = &.{}, + .imports = &.{}, + .errors = (log.toAPI(allocator) catch unreachable).msgs, + }; + var encoder = Encoder.init(output_writer); + scan_result.encode(&encoder) catch unreachable; + return @as(u64, @bitCast([2]u32{ @intFromPtr(output.items.ptr), output.items.len })); } - - var encoder = Encoder.init(output_writer); - scan_result.encode(&encoder) catch unreachable; - return @as(u64, @bitCast([2]u32{ @intFromPtr(output.items.ptr), output.items.len })); } // pub fn main() anyerror!void {} |