Registry / serialization / jsx-transpiler

jsx-transpiler

JSON →
library0.1.4jsnpmunverified

Parses and compiles JSX code to JavaScript AST or code, providing a fork of jsx-recast using acorn-jsx for parsing, estraverse/estraverse-fb for traversal, and escodegen for code generation. Current version is 0.1.4. It supports attaching comments to AST in an esprima-compatible way, respects /** @jsx */ annotations, and enables source maps for JSX elements. Differentiators include native AST tools (acorn, estraverse, escodegen) and compatibility with older JavaScript toolchains. Suitable for use as a browserify transform or standalone transformer for JSX to JS.

npm install jsx-transpiler
INSTALL
IMPORT
SIG · JSX-TRANSPILER
J
jsx-transpiler
serializationjavascriptv0.1.4
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.

default
import jsx from 'jsx-transpiler'
const jsx = require('jsx-transpiler')
Package does not ship ES modules; use CommonJS for now.
parse
const { parse } = require('jsx-transpiler')
import { parse } from 'jsx-transpiler'
CommonJS-only; named exports not available as ES modules.
compile
const { compile } = require('jsx-transpiler')
import compile from 'jsx-transpiler'
Default import yields module object, not compile function.
transform
const { transform } = require('jsx-transpiler')
import { transform } from 'jsx-transpiler'
Same as parse; CommonJS-only.

Demonstrates parsing JSX to AST, transforming to JavaScript AST, and compiling to JavaScript code with source map.

const jsx = require('jsx-transpiler'); const jsxCode = '<X prop={false}><Y /></X>'; const ast = jsx.parse(jsxCode); const jsAST = jsx.transform(ast); const result = jsx.compile(jsxCode); console.log(result.code); // X({prop: false}, Y(null)); console.log(result.map); // source map object
Debug
Known issues
gotchaThis package is a fork of jsx-recast and uses older versions of acorn, estraverse, and escodegen. It may not support modern JSX features or React JSX transform.
fix
Consider using @babel/core + @babel/preset-react or esbuild/swc for modern JSX compilation.
affects: <=0.1.4
breakingPackage does not ship ES module (ESM) support. Using import statements will fail in Node.js ESM context.
fix
Use CommonJS require() or use a bundler like webpack with CommonJS compatibility.
affects: <=0.1.4
gotchaThe parse function returns a JSX-specific AST, not a standard ESTree. Using this AST directly with other tools may not work without transform.
fix
Always call transform() to convert to standard JavaScript AST before passing to escodegen or other ESTree-based tools.
affects: <=0.1.4
Errors
Common errors & fixes
Error: Cannot find module 'jsx-transpiler'
Package not installed or installed globally but required locally.
fix
Run 'npm install jsx-transpiler' in your project directory.
SyntaxError: Unexpected token '<'
JSX code passed to jsx.parse is not recognized because acorn-jsx might not be properly configured.
fix
Ensure the JavaScript code is valid JSX and that the options object is passed correctly. The package expects JSX source code as a string.
TypeError: jsx.compile is not a function
Incorrect import: using default import instead of destructuring require.
fix
Use 'const { compile } = require('jsx-transpiler')'.
Upgrade
Version history
0.1.4latest on npm
Audit
Dependencies
acornrequiredCore parser library, required for acorn-jsx extension
acorn-jsxrequiredParse JSX syntax into AST
estraverserequiredAST traversal and transformation
estraverse-fbrequiredEnable traversal and transformation of JSX AST nodes
escodegenrequiredGenerate JavaScript code and source maps from AST
Agent activity
2 hits · last 30 days
node
2
Resources
jsx-transpiler — npm install jsx-transpiler · libregistry