mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
feat(repl): implement native Zig REPL for bun repl
This implements a new REPL in Zig that replaces the previous bunx-based REPL. The new REPL provides: - Interactive line editing with cursor movement and history navigation - Syntax highlighting using QuickAndDirtyJavaScriptSyntaxHighlighter - Multi-line input with bracket matching detection - REPL commands (.help, .exit, .clear, .load, .save, .editor, .timing) - JavaScript evaluation using the global eval() function - Pretty-printed output for evaluated expressions - Support for both TTY (interactive) and non-TTY (piped) input The REPL properly initializes the JSC VirtualMachine with the API lock held, enabling safe JavaScript execution. It uses Bun's transpiler infrastructure and output formatting. TODO: - Implement REPL transforms for variable persistence across lines - Integrate package installation - Add shell mode integration - Implement JSC-based autocomplete Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -92,6 +92,7 @@ pub const AuditCommand = @import("./cli/audit_command.zig").AuditCommand;
|
||||
pub const InitCommand = @import("./cli/init_command.zig").InitCommand;
|
||||
pub const WhyCommand = @import("./cli/why_command.zig").WhyCommand;
|
||||
pub const FuzzilliCommand = @import("./cli/fuzzilli_command.zig").FuzzilliCommand;
|
||||
pub const ReplCommand = @import("./cli/repl_command.zig");
|
||||
|
||||
pub const Arguments = @import("./cli/Arguments.zig");
|
||||
|
||||
@@ -826,12 +827,8 @@ pub const Command = struct {
|
||||
return;
|
||||
},
|
||||
.ReplCommand => {
|
||||
// TODO: Put this in native code.
|
||||
var ctx = try Command.init(allocator, log, .BunxCommand);
|
||||
ctx.debug.run_in_bun = true; // force the same version of bun used. fixes bun-debug for example
|
||||
var args = bun.argv[0..];
|
||||
args[1] = "bun-repl";
|
||||
try BunxCommand.exec(ctx, args);
|
||||
const ctx = try Command.init(allocator, log, .ReplCommand);
|
||||
try ReplCommand.exec(ctx);
|
||||
return;
|
||||
},
|
||||
.RemoveCommand => {
|
||||
|
||||
1260
src/cli/repl_command.zig
Normal file
1260
src/cli/repl_command.zig
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user