Repository navigation
Conversation
Each example on docs/runtime/repl.mdx is now the screen of a pty session on a build of main (0c864a0). The examples show the `❯` prompt, the value that a declaration prints, strings in double quotes, the stack frames of an error, and the four lines that `-p "{ a: 1, b: 2 }"` prints. Three examples printed a long or changing result: the star count of the repository, a Response object, and the exports of zod. Lines with a short, fixed result replace them. These statements did not hold on main and are corrected or scoped: - `__dirname` and `__filename` are "" and "[repl]". They do not resolve from the working directory. `require` resolves from the directory that the REPL starts in. - `_` keeps its value after a result of `undefined`. `_error` changes when an input throws. - An unclosed quote also continues the input. `.editor` buffers the lines that end with Enter. - `.history` prints the last 20 entries. `.copy` writes an OSC 52 escape sequence. - Ctrl+T swaps the character before the cursor with the character at the cursor. Ctrl+D does not exit at a `...` prompt. - The REPL saves the history on `.exit`, Ctrl+D and Ctrl+C. A signal or `process.exit()` loses the history of the session. - `bun repl -e` exits with code 1 when the script throws or when a promise that it awaits at the top level rejects.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Updated 1:15 AM PT - Oct 21st, 2026
✅ @robobun, your commit 5ad8958d2eeff13f93a10d6ba3cbd085280ad086 passed in 🧪 To try this PR locally: bunx bun-pr 46308That installs a local version of the PR into your bun-46308 --bun |
|
Status Reproduced on main ( printf 'const greeting = "Hello, Bun!"\ngreeting\n.exit\n' | NO_COLOR=1 bun repl
# the page on main: undefined, then 'Hello, Bun!'
# bun repl: "Hello, Bun!", then "Hello, Bun!"
bun repl -p "{ a: 1, b: 2 }"
# the page on main: { a: 1, b: 2 }
# bun repl: four lines, one property on each line
printf '__dirname\n__filename\n.exit\n' | NO_COLOR=1 bun repl
# the page on main: both resolve from the working directory
# bun repl: "" and "[repl]"With this PR, each of the 9 examples on the page equals the screen of a pty session on that build, line for line. |
Problem
docs/runtime/repl.mdxare never whatbun replprints. Four showundefinedafter a declaration or an import. The others show single-quoted strings and a one-line{ a: 1, b: 2 }.>where a terminal shows❯. The banner (v1.3.3) is older than the native REPL (v1.3.10).__dirnameis"",Ctrl+Tswaps around the cursor, and a signal loses the history.Fix
1.4.4-canary.1+0c864a07c).Response, the zod exports. Lines with a short, fixed result replace them.Background
❯in a terminal with colors. It is>withNO_COLOR=1or without a terminal.Notes
How the page was checked
1.4.4-canary.1+0c864a07c.src/runtime/cli/repl.rs,repl_command.rsandsrc/js_parser/repl_transforms.rsare the same at the head of this branch. A build of367d939d9(1.4.3) prints the same text, except the version in the banner.bun replin a pty (TERM=xterm-256color,NO_COLORnot set), one fresh session and one emptyHOMEfor each block. The rendered screen must equal the block, line for line.-eand-pexamples: run throughsh, with stdout compared to the#lines.prettier --check.Example lines that changed, and what the binary prints
bun replWelcome to Bun v1.3.3Welcome to Bun v1.4.4> const greeting = "Hello, Bun!"givesundefined"Hello, Bun!"> greetinggives'Hello, Bun!'"Hello, Bun!"JSON.parse("oops")gives one lineatlines, and an empty line8123496328on the day of the checkconst response = await fetch(...)givesundefinedResponse, 31 lines with dates and request idsimport { z } from "zod"givesundefinedconst path = require("path")givesundefinedpathmodule, 37 lines'/tmp/file.txt'"/tmp/file.txt".save ./my-session.txtgives no outputSession saved to ./my-session.txt-p "{ a: 1, b: 2 }"gives{ a: 1, b: 2 }Statements that changed, and the run behind each one
__dirnameand__filenameare "resolved relative to your current working directory", asrequireandmoduleare__dirnameprints""and__filenameprints"[repl]". Afterprocess.chdir(),require("./x.js")still loads the file of the directory that the REPL started in._does not change after a result ofundefined._errordoes not change after an input that does not throw._is "the result of the last expression"5, thenundefined, then_prints5._erroris "the last error that was thrown"setTimeoutcallback and a rejection that nothing awaits print an error and leave_error.',"or backtick..editor"buffers all input" untilCtrl+DEnteris not evaluated. It stays on the next prompt..historyprints "the command history".copycopies to the clipboardESC ] 52 ; c ; <base64> BEL. The terminal does the rest.Ctrl+Dexits "if line is empty"...line it does nothing. In editor mode it evaluates.Ctrl+Tswaps "the two characters before the cursor"he█llobecomeshle█lo. At the end of the line it swaps the last two..exit,Ctrl+D, andCtrl+Ctwice. Not saved after SIGTERM, SIGHUP, SIGINT, SIGKILL, orprocess.exit(0). The limit holds: a file of 1500 lines plus one new entry leaves 1000 lines.1"await. Exit 0 forPromise.reject(new Error("x"))that nothing awaits, and for anasyncfunction that rejects and that nothing awaits.Sentences that are new
let a = 1, b = 2prints2.const { p } = { p: 1 }prints the object.NO_COLOR=1, or when standard input or standard output is not a terminal, the prompt is>." Each of the three conditions was run on its own.Corner cases that the page does not describe
They are defects or limits of the REPL. None makes a sentence of the new page false in the plain case.
<T>(x: T) => xand<number>5are syntax errors, and<T,>(x: T) => xworks. This belongs to line 32.{and is not an object literal runs without the REPL transform.{ 40 + 2 }prints42and leaves_. Anawaitin it is a syntax error.bun repl -p "{ console.log(1) } 42"exits 1. repl: evaluate input the REPL transform does not take through each caller's result path (-e/-pexit code,.copy,_) #45267 covers this path..is read as a REPL command, also on a...line:.5 + 1printsUnknown command: .5.Ctrl+Con a...line andCtrl+Din editor mode leave the text of the current line on the next prompt (repl: clear the typed line on Ctrl+C in every mode, evaluate it on Ctrl+D in editor mode #46083).Tab,Right,End,Ctrl+EandCtrl+Faccept it.importorrequirereturns the module that is already loaded, also after the file changed.Other open PRs that edit this page
>andWelcome to Bun v1.3.3. For repl: read non-terminal stdin as lines of text and take bracketed pastes as text #46248 the>is correct: the block shows piped input.await. The twoatlines in the special variables example come from that wrapper.Hosts
The fetch examples use
https://bun.com, as 7 other examples indocs/do.https://example.comdoes not resolve in the environment where the examples were run, so a line with that host could not be run as written.no test proof · iteration 0 · docs-only change; test-proof not applicable