Registry / serialization / jsx-to-js

jsx-to-js

JSON →
library1.0.1jsnpmunverified

Transpile JSX to JS with non-standard syntax: ignores tag name capitalization (uses variable tracking), provides ES6-style parameter shorthand (defaults to variable with same name instead of true). Unmaintained since 2015; version 1.0.1 is the latest. Different from standard JSX transpilers (e.g., Babel) in semantics; useful for custom JSX runtimes that want shorthand syntax. No TypeScript definitions, no updates, likely abandonware.

npm install jsx-to-js
INSTALL
IMPORT
SIG · JSX-TO-JS
J
jsx-to-js
serializationjavascriptv1.0.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.

JSX
const JSX = require('jsx-to-js')
import JSX from 'jsx-to-js'
Package uses CommonJS; no default export for ESM. Only compatible with Node.js require.
transform (no default export)
const { transform } = require('jsx-to-js')
No standard named export; the module exports a single function that expects a JSX AST node.
JSX (as a function)
const JSX = require('jsx-to-js'); const ast = JSX(parse('<div/>'))
The exported function is used to transform a parsed JSX AST to a JavaScript AST.

Shows how to transform a JSX AST (parsed externally) into a JavaScript AST using jsx-to-js.

const parse = require('jsx-parser') // hypothetical parser const JSX = require('jsx-to-js') // Parse JSX string to AST (you need a JSX parser yourself) const jsxAst = parse('<div className="foo" onClick={handleClick}/>') // Transform to JS AST const jsAst = JSX(jsxAst) console.log(JSON.stringify(jsAst, null, 2)) // Output: JSX("div", {className: "foo", onClick: handleClick})
Debug
Known issues
breakingNon-standard JSX syntax: tag name case is ignored. Variables used for component detection instead of capitalization.
fix
Ensure all components are in scope as variables; do not rely on capitalization to distinguish HTML tags from components.
affects: *
breakingES6-style parameter shorthand: attribute without value defaults to variable with same name, not true.
fix
Use explicit attribute values (e.g., onMousedown={true}) if you need standard behavior, or rename variables to match attribute names.
affects: *
deprecatedPackage has no updates since 2015, no TypeScript types, no ESM support.
fix
Consider using Babel's @babel/plugin-transform-react-jsx or similar for standard behavior.
affects: 1.x
gotchaThe package does not parse JSX; it requires a pre-parsed JSX AST. You need a separate parser (like jsx-parser or acorn-jsx).
fix
Pass a valid JSX AST object, not a string.
affects: *
gotchaThe exported function is named 'JSX' but is not the default export; only works with CommonJS require.
fix
Use const JSX = require('jsx-to-js') instead of import.
affects: *
Errors
Common errors & fixes
TypeError: JSX is not a function
Using ES module import syntax (import JSX from 'jsx-to-js') with a CommonJS-only package.
fix
Use const JSX = require('jsx-to-js') instead.
Cannot read property 'type' of undefined
Passing a JSX string to the function instead of a parsed AST object.
fix
Preparse your JSX string with a parser like jsx-parser or acorn-jsx before passing to JSX().
Unexpected token
Using standard JSX syntax (e.g., uppercase components) expecting default behavior; jsx-to-js uses variable tracking and ignores case.
fix
Ensure all component names are defined as variables in scope; use lowercase for HTML elements if needed.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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