extendscript-compat
v1.2.0
Published
Build-time and runtime compatibility fixes for Adobe ExtendScript
Readme
extendscript-compat
日本語(正本) | English
A library providing build-time bug corrections and runtime compatibility for Adobe ExtendScript.
- Corrects expression precedence,
continueacrossswitchstatements, regular-expression hyphens, andinoperators inforinitializers at build time. - Rollup's
extendscriptCompat()automatically validates ES3 syntax after correction and stops the build on invalid output. - Provides JSON, selected ES5, ES6, and later polyfills, and corrections for
parseIntand three string methods when explicitly imported. - Rollup's ponyfill mode supplies supported APIs inside the bundle without installing them into the host.
- Provides explicit helpers for
UnitValuesubtraction andnullcomparison.
In this example, an expression that returns true in ordinary JavaScript returns false in After Effects ExtendScript. Adding parentheses to the generated code preserves the intended evaluation order.

var isAdmin = true;
var isOwner = false;
var isReady = false;
// Before correction: false in AE.
var enabled = isAdmin || isOwner && isReady;
// Generated code after correction: true in AE.
var enabled = isAdmin || (isOwner && isReady);See 1.2.0 changes, 1.1.0 changes, and 1.0.0 migration and validation.
Installation
Node.js 22 or later is required.
pnpm add -D extendscript-compatRollup integration
In a Rollup 4 host build, place the plugin after minification, include expansion, and the addition of compatibility code, but before conversion to JSXBin:
import { extendscriptCompat } from "extendscript-compat/rollup";
export default {
input: "src/index.js",
output: { file: "dist/script.jsx", format: "iife", sourcemap: true },
plugins: [
// Babel, Terser, include expansion, etc.
extendscriptCompat(),
// JSXBin conversion if needed
],
};A later generator or minifier that removes parentheses can undo the precedence protection. See build-time compatibility for direct APIs and correction conditions.
Runtime corrections
Import the runtime before initializing the application or its dependencies. It applies JSON, selected ES5, ES6, and later polyfills, as well as the four function corrections. Bundle the following application code with Rollup or a similar tool before running it:
import "extendscript-compat/runtime";
parseInt("a?", 16); // 10For example, parseInt("a?", 16) returns 175 in uncorrected After Effects. After importing the runtime, it stops at the invalid ? character and returns 10.

This entry adds and replaces built-in functions and also affects other scripts in the same engine. UnitValue arithmetic and comparisons are not corrected automatically; use subtractUnitValues and isNull at the affected sites. See runtime compatibility for load order and limitations.
To keep the same standard API syntax without modifying host built-ins, use extendscriptCompat({ runtime: "ponyfill" }) in Rollup. This also rewrites ES5 methods such as map, filter, reduce, and bind, and suppresses an existing /runtime import. Omitting the option restores the existing behavior. See supported forms and limitations.
Scope and documentation
Input must be code generated as ordinary JavaScript. Transpiling TypeScript to JavaScript and targeting ES3 syntax require separate build steps. Raw JSX containing E4X or unexpanded preprocessor directives is not supported.
The host-validation baseline is After Effects 26.5x89 / ExtendScript 4.5.6. JSON parsing and serialization were also checked in Illustrator 30.8.2 / ExtendScript 4.5.6 and Photoshop 27.11.0 / ExtendScript 4.5.12. Other features remain unverified in Illustrator and Photoshop.
- Public contract and compatibility policy for v1
- Build-time corrections, diagnostics, and APIs
- Runtime corrections and UnitValue helpers
- additional compatibility host validation and built-in function host validation
- npm publication procedure
Japanese is the authoritative documentation; English is displayed first on GitHub and npm. If versions differ, the Japanese version takes precedence; update the corresponding English version in the same change. Type-declaration documentation places English first, followed by the authoritative Japanese text.
MIT License.
