Dosa
raw JSON → 1.0.0 verified Fri May 01 auth: no javascript
Dosa is a JavaScript AST transpiler for instrumentation, wrapping variable accesses, function calls, binary expressions, and string literals with custom box_* functions. Version 1.0.0 is the initial stable release with no active development. It uses UglifyJS under the hood to parse and transform code, targeting debugging or runtime monitoring. Unlike Babel plugins or other instrumentation libraries, Dosa focuses on a simple, predictable transformation pattern, making it suitable for lightweight tracing but limited in customization.
Common errors
error Cannot find module 'uglify-js' ↓
cause Missing peer dependency uglify-js
fix
Run
npm install uglify-js alongside dosa. error TypeError: dosa.instrument is not a function ↓
cause Using require('dosa') which returns an object, not the instrument function directly
fix
Use
const dosa = require('dosa'); dosa.instrument(input); or ES6 import. Warnings
gotcha Instrumentation wraps all function calls and property accesses, which can break performance and runtime behavior if not expected. ↓
fix Use only in development or debugging contexts; do not use in production without profiling.
gotcha The package does not handle dynamic eval() or with() statements; they will be passed through unchanged without instrumentation. ↓
fix Avoid using eval() or with() in source code to ensure consistent instrumentation.
deprecated No longer maintained; last release 2018. Consider using @babel/plugin-transform-runtime or custom Babel plugin for more robust instrumentation. ↓
fix Migrate to a maintained alternative like babel-plugin-istanbul or a custom Babel plugin.
Install
npm install dosa yarn add dosa pnpm add dosa Imports
- dosa (default) wrong
const dosa = require('dosa')correctimport dosa from 'dosa' - instrument wrong
const instrument = require('dosa').instrumentcorrectimport { instrument } from 'dosa' - DosaOptions wrong
import { DosaOptions } from 'dosa'correctimport type { DosaOptions } from 'dosa'
Quickstart
import { instrument } from 'dosa';
const input = "var a = location.hash.split('#')[1]";
const output = instrument(input);
console.log(output);
// 'var a = box_accessor(box_call(location.hash.split(box_string("#"))), 1);'