Registry / web-framework / electrum-compiler

electrum-compiler

JSON →
library1.9.0jsnpmunverified

Run-time compiler for Electrum-enabled React components, based on babel-standalone. Version 1.9.0 is the latest stable release; the package has had a low release cadence with infrequent updates. It provides a Compiler class capable of transforming JavaScript to ES5 and building React components from source code at runtime. Key differentiators include integration with the Electrum framework, support for registering external symbols, and a built-in eval for ES6/JSX. Note that it compiles synchronously in the browser and depends on Electrum v4.3.0 as a peer dependency.

web-frameworkhttp-networking
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Compiler is a named export, not default.

import { Compiler } from 'electrum-compiler'

CommonJS destructuring required for named export.

const { Compiler } = require('electrum-compiler')

No function named compile; use Compiler class.

import { Compiler } from 'electrum-compiler'

Demonstrates transforming ES6 to ES5, building an Electrum-enabled React component with registered symbols, and evaluating expressions.

import { Compiler } from 'electrum-compiler'; const compiler = new Compiler(); // Transform ES6 to ES5 const es5Source = compiler.transform('const greet = x => `Hello ${x}.`;'); console.log(es5Source); // Build a React component with Electrum support const componentSource = ` class extends React.Component { render() { return <Button>{text}</Button>; } }`; compiler.register('Button', Button); // Assume Button is a React component compiler.register('text', 'Hello'); const output = compiler.build('MyComponent', componentSource); if (output.error) { console.error(output.error); } else { console.log('Component:', output.component); } // Evaluate an expression const result = compiler.eval('2 + 3'); console.log(result); // 5
Debug
Known footguns
gotchaError positions in build() are offset by one line due to prepended code.
gotchaThe compiler relies on a bundled babel-standalone; large bundle size may impact browser performance.
gotchaThe register() method stores items in a global-like catalog; multiple components may conflict if keys overlap.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
10 hits · last 30 days
gptbot
3
ahrefsbot
3
claudebot
3
bingbot
1
Resources