2025-07-14
James Diacono
james@diacono.com.au
I present Replete, a JavaScript REPL for web professionals. By integrating with a variety of text editors and supporting all major browsers and JavaScript runtimes, Replete makes REPL-driven development accessible to a large audience. Crucially, it supports the evaluation of import statements and other module syntax, permitting the evaluation of deep module structures rather than the self-contained fragments expected by prompt-based REPLs.
Extensive use of Replete revealed a new design pattern, Whole Modules, which was found to enhance the maintainability and reliability of a commercial software system used in the Olympics.
Two junior programmers introduced to Replete were able to use it effectively with minimal instruction, both to learn JavaScript and to produce well-tested user interface components.
The benefits of REPL-driven development are well known within the Lisp community, yet they are virtually unheard of in the much larger JavaScript community. This is surprising given the semantic similarities of JavaScript and Scheme. There are a few plausible explanations.
Firstly, existing JavaScript REPLs are mostly prompt-based. These include the command line REPL bundled with Node.js and the REPL in Chrome’s DevTools console. Such REPLs are cumbersome to use and do not support JavaScript’s module syntax, making them unsuitable for REPL-driven development, which demands the frequent evaluation of large bodies of code.
Secondly, web professionals are generally required to write code that works across multiple browsers or runtimes. This makes any REPL coupled to a particular browser or runtime much less attractive, due to the additional testing that must be performed outside of the REPL.
Lastly, JavaScript’s standard module syntax was not universally supported by browsers and runtimes until somewhat recently. Historically there were two workarounds for this problem:
<script> tag in the HTML). The
inability to statically analyze the imports and exports of JavaScript files
would have made it difficult for a REPL to resolve the necessary
dependencies of evaluated code.require function from Node.js). Such a lack of
uniformity would have limited the utility of a REPL coupled to any
particular module system.Upon learning about REPL-driven development from a Clojure educator, I wished to apply it to my work but could not find a capable JavaScript REPL. I set out to make one satisfying the following design goals, listed in decreasing order of importance:
import statements.I named the tool Replete and open sourced it, regrettably unaware that a Clojure REPL with the same name already existed.
In using Replete I have found REPL-driven development to be not only applicable to, but remarkably effective for commercial web development. I will now describe the features of Replete and the lessons I have learned from using it.
Emacs users are familiar with the keybinding Control + x, Control + e that evaluates the Emacs Lisp S-expression immediately preceding the cursor. The resulting value appears in the minibuffer at the bottom of the window.
Replete deviates from this tradition in two minor ways.
Firstly, the code to be evaluated is selected textually, not by its syntactic structure. The following video demonstrates the VSCode Replete extension.
Emacs offers several keybindings to control how much code is evaluated, whereas Replete does not. (This relieves the text editor plugin of the burden of parsing JavaScript, which turns out to be impractical in most cases. For example, Neovim plugins are written in Lua yet there are no JavaScript parsers written in Lua, and even if there were, it is unlikely that they would be capable of parsing the entire JavaScript language or that they would remain up-to-date as JavaScript evolves.) This lack of convenience is alleviated in two ways: by making text editor plugins evaluate the current line when no text is selected, and by using the standard keybinding for selecting all text in the file. Experience shows that these two cases, single line and whole file, together account for the majority of evaluations, making manual selection using the mouse relatively uncommon.
Secondly, the choice of keybinding dictates the environment in which code is evaluated. For example, different keybindings are used for Deno and the browser.
The fact that each environment has a dedicated keybinding is yet another reason to avoid dedicated keybindings for evaluating different regions of code, as this would lead to a proliferation of unmemorable keybindings.
Text editor integration is made straightforward by virtue of a dedicated Replete process doing most of the work, with the text editor plugins only responsible for spawning the process, sending it JSON commands on stdin, and displaying the JSON results from stdout to the user:
COMMAND {platform: "deno", source: "console.log(0 / 0, 1 / 0)"}
RESULT {out: "NaN Infinity\n"}
RESULT {evaluation: "undefined"}
This separation of concerns means text editor plugins themselves can be very simple, as little as 100 lines of code. In this way Replete embodies the Worse is Better design philosophy that is purported to promote viral adoption.
When necessary, a debugger can be attached to step through evaluated code. In Chrome, for example, this is as simple as opening the Source pane of the DevTools. In Node.js or Deno it is necessary to attach a debugger to the REPL process via the V8 debugger protocol, although this is just standard practice for debugging such runtimes.
Though Replete is primarily designed to be used from a native text editor, it can also be used, without installation, in the web-based playground. Unlike the text editor plugins, the playground has a “watch” mode that causes the file to reevaluate whenever it is changed. Intriguing though watch mode is, it has not proven useful enough to justify its inclusion in the text editor plugins. Indeed, it could pose a danger if used with runtimes that can write to disk or perform other destructive operations, owing to the inadvertent evaluation of incomplete code. Within the browser’s sandbox, however, it seems safe enough.
Nontrivial yet reliable web applications can be efficiently developed with just a text editor, a linter, and Replete, as evidenced by the fact that the playground was developed in itself in just over two weeks.
As I began using Replete I noticed that having tests in the same file as the implementation was very convenient, because the tests could be run simply by evaluating the entire file.
Notice that the tests in the example above execute only when
import.meta.main is true, which happens to be the
case for all code evaluated by Replete. This gives the module a kind of
duality: on one hand, it is a module that can be imported without side effects.
On the other hand, it is a program that demonstrates its own correctness. For
want of an existing term, I am calling this pattern “whole modules”
and have described the idea more thoroughly elsewhere.
An especially interesting application of whole modules is user interface components, where a demonstration of correctness is not as simple as a pass or fail. More useful is a “demo” that renders the component in a random configuration, by providing randomized parameters and simulating failures and delays. Thoroughly exercising a component in isolation uncovers bugs surprisingly quickly. This in itself is not novel, with popular tools like Storybook providing a framework to write, test, and browse components in isolation, but it is worth noting that basically equivalent functionality falls out of Replete, which weighs in at 8,227 lines of code (including dependencies) compared to Storybook’s 129,436 lines of code (not including dependencies).
I say “falls out” because Replete is a general tool that concerns
itself only with evaluating code. It contains no affordances for managing a
library of components or even running tests or demos, because these are just
special cases of running code. Furthermore, whole modules are not even tied to
Replete: they can be executed as standalone applications by browsers or
runtimes directly, though they may require bundling to do so. Contrast this to
components developed using Storybook, which rely on the presence of a large
framework in order for their demos to run. Whole modules are highly
self-sufficient because they explicitly import all the
functionality they need to demonstrate themselves in isolation.
overlays_picker_ui demo.Code is evaluated simultaneously in all connected browser tabs, making cross browser testing straightforward. This even includes mobile browsers when Replete has been exposed to the local area network.
Working within a single file for extended periods is more conducive to flow state than when working across multiple files, where frequent context switching makes it more difficult to maintain focus.
The whole module pattern has been consistently applied at Equimaps, my company, since 2021. We make CrossCountry, a cross platform equestrian mapping app used by officials and gold medal competitors of the Olympic Games since 2012. Though no metrics have been gathered, it is my impression that the reliability of our software has improved due to the growing proportion of well-tested whole modules it contains. Certainly maintenance is easier and more pleasant. The two videos above demonstrate just a few of the whole modules used in production today. These components coexist with older components that do not yet have demos, suggesting that incremental adoption of whole modules into an existing codebase is a viable strategy.
This section describes my experience using Replete as an educational tool. Note that most of my observations apply to REPL-driven development in general and so are presumably well known to practitioners in that area.
In recent years, two junior programmers interned with Equimaps, both in their final year at university. Despite their lack of exposure to JavaScript, they were tasked with implementing nontrivial user interface components, necessitating a rapid introduction to JavaScript’s syntax, data structures, and concepts (such as event handling).
Each week, a programmer and I would meet either in person or over video call. First they would present their progress to me. Usually this involved them demonstrating their component, walking me through their code, and describing any difficulties. Then I would attempt to fill any relevant gaps I had observed in the programmer’s knowledge. Occasionally I would draw diagrams on paper, but most often I would use Replete to evaluate small, self-contained code fragments. (In many cases a prompt-based REPL would have been sufficient, but not when demonstrating imported functionality such as libraries.) This experience was not unlike using a blackboard, with the added benefit that I could point to a scribble and bring it to life.
reduce array method.Prior to each evaluation I would orally quiz the programmer on the expected behavior, resulting in an experience reminiscent of The Little Schemer. These interactions afforded me a near-infallible means of detecting misunderstandings, which could be cleared up immediately before continuing. I would also use my voice to introduce and reinforce the correct terminology.
These lessons seemed to stick with the programmers, only rarely requiring reinforcement. I can only surmise that visually coupling code with its behavior, in small digestible pieces, made the meaning of the code difficult to unsee.
Replete was also used by the programmers themselves. By developing their components in isolation, as whole modules, they were able to ignore the complexity of the application into which their component would eventually be integrated. Our top-down design, bottom-up implementation style worked well in practice, with both programmers delivering well tested and production ready components within their allotted time frame.
In order to minimize code size, Replete offers no built in support for transpiled languages, such as TypeScript or JSX, which are commonly used in web development. It can, however, evaluate and import code in transpiled languages given some configuration. For example, the minimal configuration for evaluating and importing TypeScript can be found here.
A major limitation of such configurations is that they can not be composed together, so support for multiple transpiled languages entails a bespoke configuration effort. This could be overcome by extending Replete to support “language plugins”, which could then be installed side-by-side with ease.
There is currently no way to control the verbosity of output. If a large
object or array is evaluated, say window, this can flood the
output pane of the editor with too much information. Limiting the depth of
expansion mitigates this problem, but occasionally renders useful information
inaccessible. An obvious improvement would be for text editor plugins to let
users collapse or expand values as necessary, as is common in more
sophisticated REPLs. Seeing as Replete already stores the most recent
evaluation in a special variable, $value, a text editor plugin
could simply issue evaluation commands to stash it away in a unique variable
like $value_1751402155863 and subsequently query it.
Another feature missing from Replete is autocomplete. Dynamic autocomplete, a
feature in many REPLs, allows the user to browse object properties in a running
system. This can be useful when static autocomplete is inaccurate, or when
object properties change during execution. A text editor plugin could achieve
dynamic autocomplete by issuing evaluation commands that enumerate object
properties (including the module’s top level identifiers, which are stored
as properties in the special $scope object). Some text editors
permit the comingling of dynamic and static autocomplete suggestions, making it
possible to get the best of both worlds.
Lastly, Replete does not offer a way to interrupt long running evaluations. It is not clear how to implement such a feature, given the single threaded nature of JavaScript, but the user can always restart Replete (using a keybinding) to interrupt an infinite loop.
REPL-driven development is a long established practice in the world of Lisp, with well known benefits. The task of adapting it to professional web development is complicated by the numerous JavaScript environments in which code runs, but Replete shows that a multi-environment JavaScript REPL is technically achievable and can indeed be easy to use.