Registry / serialization / jsx-transform

jsx-transform

JSON →
library2.4.1jsnpmunverified

JSX transpiler that desugars JSX into plain JavaScript, decoupled from React. Current stable version is 2.4.1. Release cadence is low/infrequent. It provides configurable factory function names, spread attribute handling, and unknown tag patterns, making it suitable for use with Mercury, virtual-dom, or custom virtual DOM implementations. Key differentiators: not tied to React, supports browserify transforms, and offers fine-grained control over output.

npm install jsx-transform
INSTALL
IMPORT
SIG · JSX-TRANSFORM
J
jsx-transform
serializationjavascriptv2.4.1
harness data pending
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.

fromString
import { fromString } from 'jsx-transform'
const fromString = require('jsx-transform').fromString
ESM-style import works with bundlers; CommonJS require also works.
fromFile
import { fromFile } from 'jsx-transform'
const jsx = require('jsx-transform'); jsx.fromFile
Named export available via ESM or CommonJS property access.
browserifyTransform
import { browserifyTransform } from 'jsx-transform'
const browserifyTransform = require('jsx-transform/browserifyTransform')
Not a submodule; use named export from main package.

Shows basic usage of fromString, fromFile, and browserifyTransform with custom factory.

const jsx = require('jsx-transform'); const result = jsx.fromString('<h1>Hello World</h1>', { factory: 'mercury.h' }); console.log(result); // 'mercury.h("h1", null, ["Hello World"])' // Using fromFile const fs = require('fs'); fs.writeFileSync('test.jsx', '<div>Test</div>'); const output = jsx.fromFile('test.jsx', { factory: 'h' }); console.log(output); // 'h("div", null, ["Test"])' // Browserify transform const browserify = require('browserify'); const b = browserify(); b.transform(jsx.browserifyTransform({ factory: 'h' }));
Debug
Known issues
gotchaDefault options may not suit all virtual DOM libraries. Check factory, spreadFn, and unknownTagPattern.
fix
Explicitly pass options matching your virtual DOM library (e.g., factory: 'mercury.h', spreadFn: 'Object.assign').
affects: >=2.0.0
gotchaWhen using browserifyTransform, ensure filename ends with .jsx or pass appropriate options.
fix
Use b.transform(jsx.browserifyTransform({ ext: '.jsx' })) or rename files to .jsx.
affects: >=1.0.0
deprecatedSome options like `passUnknownTagsToFactory` and `unknownTagsAsString` may be confusing; prefer `unknownTagPattern` for custom rendering.
fix
Use unknownTagPattern for template-based rendering instead of boolean flags.
affects: <3.0.0
gotchaChildren are passed as array by default (arrayChildren: true). If library expects separate arguments, set arrayChildren: false.
fix
Pass `arrayChildren: false` to spread children as arguments.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'jsx-transform'
Package not installed or path incorrectly set.
fix
Run `npm install jsx-transform` and ensure node_modules is in require/import path.
Unexpected token '<'
Code containing JSX is being run without transformation.
fix
Use jsx-transform.fromString() or set up browserify transform to transpile .jsx files.
Factory function not defined
The factory option points to a function not in scope.
fix
Make sure the factory function (e.g., mercury.h) is available in the output context, or define it as a global.
TypeError: Cannot read properties of undefined (reading 'replace')
fromFile received a non-string path or file does not exist.
fix
Ensure the path is a valid existing file path.
Upgrade
Version history
2.4.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
jsx-transform — npm install jsx-transform · libregistry