as2wasm - Apache Royale Actionscript to WebAssembly Transpiler

raw JSON →
0.1.5 verified Fri May 01 auth: no javascript

as2wasm is an Apache Royale tool that transpiles Actionscript (AS3) source code directly to WebAssembly (Wasm) modules. Version 0.1.5 is the latest stable release, part of the Apache Royale 0.9.x series. It enables running legacy Flash/Actionscript applications in modern browsers without the Flash plugin, targeting WebAssembly for near-native performance. Key differentiators: it is the only open-source AS3-to-Wasm transpiler, integrates with the Apache Royale framework for cross-platform UI compilation, and supports both ActionScript 3 and optional SWF input via a separate binary variant. Release cadence follows Apache Royale's quarterly releases.

error Error: Cannot find module 'as2wasm'
cause Package not installed or not in the node_modules path.
fix
Run npm install as2wasm (or yarn add as2wasm) in your project root.
error TypeError: as2wasm.compile is not a function
cause Using the old `compile()` function name replaced in v0.1.3.
fix
Use compileString() instead of compile().
error SyntaxError: Octal literals are not allowed in strict mode in AS3
cause ActionScript code contains legacy octal literals (e.g., 0777) not supported in strict mode.
fix
Convert octal literals to decimal or hex (e.g., 0777 -> 511 or 0x1FF).
error Compile error: 'import' declarations may only appear at top level of a module
cause Used ES module import syntax inside ActionScript code (file), but transpiler expects AS3 import.
fix
Use ActionScript import statements: import flash.display.Sprite;
error Wasm runtime error: out of memory (OOM) when allocating large string
cause WebAssembly memory insufficient for large ActionScript objects.
fix
Increase initial memory size: compileString(code, { memory: { initial: 512 } }).
breaking as2wasm v0.1.0 removed the SWF-to-Wasm pipeline; use apache-royale-0.9.x-bin-js-swf for SWF support.
fix Install the SWF variant: npm install apache-royale-0.9.x-bin-js-swf or use the royale-asjs SWF build.
deprecated The function `compile()` was renamed to `compileString()` in v0.1.3.
fix Replace calls to `compile()` with `compileString()`.
gotcha Module uses ES modules only; importing with CommonJS `require()` throws an error.
fix Use dynamic import (e.g., `import('as2wasm')`) in Node.js or configure your bundler for ESM.
gotcha WebAssembly memory limit: AS3 strings and arrays may exceed default Wasm memory (64KB).
fix Use the `memory` option: `compileString(code, { memory: { initial: 256, maximum: 512 } })`.
breaking v0.1.4 dropped support for ActionScript 2 compatibility flags; use AS3-only.
fix Remove `-as2` or `--as2` flags in compile options; code must be AS3 compliant.
npm install as2wasm
yarn add as2wasm
pnpm add as2wasm

Demonstrates compiling ActionScript files and strings to WebAssembly modules, then instantiating them.

import { compileFile, compileString, transpile } from 'as2wasm';

// Compile a .as file to Wasm
async function compileAsFile(inputFile) {
  const result = await compileFile(inputFile);
  console.log('Wasm module size:', result.byteLength);
  return result;
}

// Transpile inline ActionScript
const asCode = `
class HelloWorld {
  static function sayHello():String {
    return "Hello from AS3 in Wasm!";
  }
}
`;
const wasmModule = await compileString(asCode);
// wasmModule is a Uint8Array containing the Wasm binary

// Instantiate and use
const wasmInstance = await WebAssembly.instantiate(wasmModule);
const sayHello = wasmInstance.exports['HelloWorld.sayHello'];
console.log(sayHello()); // prints the string