Implementation:A9T9 RPA transpileScript
| Knowledge Sources | |
|---|---|
| Domains | Scripting_API, Code_Transpilation |
| Last Updated | 2026-10-22 00:00 GMT |
Overview
Concrete tool for transpiling ES6+ JavaScript macro source to ES5 for the JS-Interpreter sandbox, provided by the Ui.Vision Babel transpiler module.
Description
The transpileScript function (`src/modules/js_transpile.js`) uses `@babel/standalone` to compile user-authored ES6+ JavaScript macro code into ES5-compatible code that the vendored JS-Interpreter sandbox can execute. It preserves page functions via a custom Babel plugin (so functions passed into the sandbox can be identified in the original source), builds a source-map line map for error line attribution, and rejects top-level `await` (the sandbox is synchronous) with a clear error message.
The function returns `{ code, evaluateFunctions, lineMap }` where `code` is the transpiled ES5 string, `evaluateFunctions` maps preserved function keys to their source, and `lineMap` translates transpiled lines back to the user's original source line — used to report the exact failing line in the execution log.
Usage
Call `transpileScript` before passing user-authored JS macro code to the JS-Interpreter sandbox. It is the transpilation step in the JS script macro execution pipeline.
Code Reference
Source Location
- Repository: A9T9/RPA
- File: src/modules/js_transpile.js
- Lines: L22-L52 (loadBabel), L182-L253 (transpileScript)
Signature
export async function transpileScript(source: string): Promise<{
code: string, // ES5-transpiled code
evaluateFunctions: object, // Preserved page function source map
lineMap: number[] | null // Transpiled line → original line mapping
}>
Import
import { transpileScript } from '@/modules/js_transpile'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| source | string | Yes | ES6+ JavaScript macro source code |
Outputs
| Name | Type | Description |
|---|---|---|
| code | string | ES5-transpiled code ready for the JS-Interpreter sandbox |
| evaluateFunctions | object | Map of preserved function keys to original source |
| lineMap | null | Transpiled line number → original source line number |
Usage Examples
Transpile a JS Macro
import { transpileScript } from '@/modules/js_transpile'
const userCode = `
const match = uiv.getByRole('button', { name: 'Login' })
uiv.page.click(match)
`
const { code, lineMap } = await transpileScript(userCode)
// `code` is now ES5, ready for the JS-Interpreter sandbox
Error Handling with Line Attribution
try {
const result = await transpileScript(badCode)
} catch (e) {
// e.scriptLine is the original source line (if available)
console.error(`Syntax error at line ${e.scriptLine}: ${e.message}`)
}