esupgrade
Keeping your JavaScript and TypeScript code up to date with full browser compatibility.
Sponsors

Usage
esupgrade is safe and meant to be used automatically on your codebase.
We recommend integrating it into your development workflow using pre-commit, husky, or as an agent skill.
CLI
To try it out on a repository without writing changes, run:
npx -y esupgrade $(git ls-files | grep -E -i -w '.*\.(t|j)sx?')
To transform code from standard input, pass - as the input path:
echo 'var x = 1;' | npx esupgrade -
For help with available options:
npx esupgrade --help
pre-commit
uvx pre-commit install
# .pre-commit-config.yaml
repos:
- repo: https://github.com/codingjoe/esupgrade
rev: 2025.0.2 # Use the latest version
hooks:
- id: esupgrade
pre-commit run esupgrade --all-files
Husky
Assuming Husky is already initialized and .husky/pre-commit already contains set -e, append:
echo "git diff --cached --name-only --diff-filter=ACMR -z -- '*.js' '*.jsx' '*.ts' '*.tsx' '*.mjs' '*.cjs' | xargs -0 sh -c 'test \"\$#\" -eq 0 && exit 0; npx -y esupgrade -- \"\$@\"' sh" >> .husky/pre-commit
echo "git diff --cached --name-only --diff-filter=ACMR -z -- '*.js' '*.jsx' '*.ts' '*.tsx' '*.mjs' '*.cjs' | xargs -0 sh -c 'test \"\$#\" -eq 0 && exit 0; git add -- \"\$@\"' sh" >> .husky/pre-commit
Agent Skill
esupgrade is available as a skill in Claude Code. The plugin is distributed via the codingjoe/claude-plugins marketplace. To use it:
- Run
/plugin marketplace add codingjoe/claude-plugins
- Run
/plugin install esupgrade@codingjoe
The skill will analyze your selected code and suggest transformations based on the Baseline browser support policy.
Browser Support & Baseline
All transformations are based on Web Platform Baseline features. Baseline tracks which web platform features are safe to use across browsers.
By default, esupgrade uses widely available features, meaning they work in all major browsers (Chrome, Edge, Safari, Firefox) for at least 30 months. This ensures full compatibility while keeping your code modern.
You can opt into newly available features (available in all browsers for 0-30 months) with:
npx esupgrade --baseline newly-available <files>
For more information about Baseline browser support, visit web.dev/baseline.
Supported File Types & Languages
.js - JavaScript
.jsx - React/JSX
.ts - TypeScript
.tsx - TypeScript with JSX
.d.ts - TypeScript declaration files
.mjs - ES Modules
.cjs - CommonJS
Transformations
[!NOTE]
A transformation applies to code with a statically verifiable type. Code that shadows a
global such as Array, or that accesses a method through a computed member such as
array[method](), stays unchanged.
using and await using declarations are never rewritten, because the replacement would
drop the resource disposal.
Widely available
-var x = 1;
-var y = 2;
-y = 3;
+const x = 1;
+let y = 2;
+y = 3;
Declarations keep var when:
- A reference leaves the block that would own the narrowed binding
- A reference precedes the declaration
- A call above the declaration runs a function that reads the binding
- Another declaration of the shared
var binding cannot narrow
- A direct
eval call leaves the binding out of reach
// Not transformed - `error` is read after the block
function f(flag) {
if (flag) {
var error = 1;
}
return error;
}
-const greeting = 'Hello ' + name + '!';
-const message = 'You have ' + count + ' items';
+const greeting = `Hello ${name}!`;
+const message = `You have ${count} items`;
Special handling for escape sequences and formatting:
Escape sequences: \r (carriage return) is preserved, while \n (newline) is converted to actual newlines
-const text = "Line 1\n" + "Line 2";
+const text = `Line 1
+Line 2`;
Multiline concatenation: Visual structure is preserved with line continuation backslashes
-const longText = "First part " +
- "second part";
+const longText = `First part \
+second part`;
-for (let i = 0; i < items.length; i++) {
- const item = items[i];
- console.log(item);
-}
+for (const item of items) {
+ console.log(item);
+}
Transformations are limited to loops that start at 0, increment by 1, and where the index variable is not used in the loop body.
-Array.from(items).forEach(item => {
- console.log(item);
-});
+for (const item of items) {
+ console.log(item);
+}
-document.querySelectorAll('.item').forEach(item => {
- item.classList.add('active');
-});
+for (const item of document.querySelectorAll('.item')) {
+ item.classList.add('active');
+}
Supports:
document.querySelectorAll()
document.getElementsByTagName()
document.getElementsByClassName()
document.getElementsByName()
window.frames
Transformations limited to inline arrow or function expressions with block statement bodies.
Callbacks with index parameters or expression bodies are not transformed.
-const doubled = Array.from(numbers).map(n => n * 2);
-const filtered = Array.from(items).filter(x => x > 5);
-const arr = Array.from(iterable);
+const doubled = [...numbers].map(n => n * 2);
+const filtered = [...items].filter(x => x > 5);
+const arr = [...iterable];
Array.from() with a mapping function or thisArg is not converted.
-const obj = Object.assign({}, obj1, obj2);
-const copy = Object.assign({}, original);
+const obj = { ...obj1, ...obj2 };
+const copy = { ...original };
[!NOTE]
TypeScript does not support generic object spread yet:
https://github.com/Microsoft/TypeScript/issues/10727
You might need to manually adjust the type after transformation:
const object_with_generic_type: object = { ...(myGenericObject as object) }
-const combined = arr1.concat(arr2, arr3);
-const withItem = array.concat([item]);
+const combined = [...arr1, ...arr2, ...arr3];
+const withItem = [...array, item];
-const budget = 1000000;
-const maxUsers = 1000000n;
-const permission = 0o1234567;
-const mask = 0xabcdef;
-const flags = 0b1010000111000011;
-const ratio = 100000.25;
-const large = 1e100000;
+const budget = 1_000_000;
+const maxUsers = 1_000_000n;
+const permission = 0o1_234_567;
+const mask = 0xab_cd_ef;
+const flags = 0b10100001_11000011;
+const ratio = 100_000.25;
+const large = 1e100_000;
Decimal and octal numerals are grouped by triplets; hex and binary by byte.
-const emoji = "\uD83D\uDE00";
-const wave = `Hello ${name} \uD83D\uDC4B`;
-const key = "\ud83d\ude00";
+const emoji = "\u{1F600}";
+const wave = `Hello ${name} \u{1F44B}`;
+const key = "\u{1f600}";
Not transformed:
- Tagged templates, where
String.raw exposes the raw text
- JSX attribute values such as
<div title="\uD83D\uDE00" />, which keep the backslashes
- JSX text children such as
<div>\uD83D\uDE00</div>, which render as written
- A surrogate pair in the part of a template literal that ends in a letter, digit,
_ or $ right before ${…}, such as in `a${x}\uD83D\uDE00b${y}`, where the merge would insert a space and change the value
- Lone surrogates, reversed pairs, and code points already written as
\u{…}
-const copy = [1, 2, 3].slice(0);
-const clone = Array.from(items).slice();
+const copy = [...[1, 2, 3]];
+const clone = [...Array.from(items)];
-const sorted = [...[3, 1, 2]].sort((a, b) => a - b);
-const reversed = Array.from(items).slice().reverse();
+const sorted = [3, 1, 2].toSorted((a, b) => a - b);
+const reversed = Array.from(items).toReversed();
-const copy = [...Array.of(1, 2)];
-copy.splice(1, 2);
+const copy = Array.of(1, 2).toSpliced(1, 2);
The following are not transformed:
- Receivers that are not statically verified arrays
- Mutating calls without a copy
- Expression-form
splice() on a copy, which returns the removed elements
splice() calls whose result is used
splice() calls whose arguments come from the copy
- Copy-to-variable rewrites where the declaration is not the single declarator directly above the mutating call, as in
const copy = [...items], total = 0
-const first = [1, 2, 3].filter(n => n > 1)[0];
+const first = [1, 2, 3].find(n => n > 1);
Transformations are limited to when the receiver can be verified as an array (array literals, new Array(), or known array method chains) and filter() is called with one argument.
arr[arr.length - n] → Array.at()
-const last = arr[arr.length - 1];
-const item = arr[arr.length - n];
+const last = arr.at(-1);
+const item = arr.at(-n);