Registry / web-framework / generic-jsx-transpiler

generic-jsx-transpiler

JSON →
library0.9.9jsnpmunverified

A library for transpiling JSX for use without React (v0.9.9). It allows creating custom JSX transpilers by providing a serializer function that converts parsed JSX components into any output format. Has no dependencies. Includes a companion webpack loader (generic-jsx-loader). Suitable for projects that want JSX syntax without React, such as with Hyperscript or custom DOM libraries. Release cadence is low; maintained sporadically.

npm install generic-jsx-transpiler
INSTALL
IMPORT
SIG · GENERIC-JSX-TRANSP
G
generic-jsx-transpiler
web-frameworkjavascriptv0.9.9
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.

Parser
✓ const { Parser } = require('generic-jsx-transpiler');
✗ import { Parser } from 'generic-jsx-transpiler';
Library uses CommonJS; named export 'Parser'. ESM imports may fail if bundler does not support CJS interop.
default
✓ const transpiler = require('generic-jsx-transpiler'); const Parser = transpiler.Parser;
✗ import genericJsx from 'generic-jsx-transpiler';
No default export; only named exports via CJS.
Serializer
✓ const { Serializer } = require('generic-jsx-transpiler');
Serializer class also exported for advanced usage; see documentation.

Shows how to create a custom serializer that converts JSX to hyperscript calls using generic-jsx-transpiler.

const { Parser } = require('generic-jsx-transpiler'); const fs = require('fs'); // A serializer that converts JSX to Hyperscript calls function serialize(parsedComp) { const { tag, attrs, children } = parsedComp; const props = attrs ? Object.keys(attrs).map(k => `${k}: ${JSON.stringify(attrs[k])}`).join(', ') : ''; const kids = children && children.length ? children.map(c => typeof c === 'string' ? `'${c}'` : serialize(c)).join(', ') : ''; return `h('${tag}', {${props}}${kids ? ', ' + kids : ''})`; } const serializer = { serialize }; const parser = new Parser({ serializer }); const source = fs.readFileSync('example.jsx', 'utf8'); const transpiled = parser.parse({ source, async: false }); console.log(transpiled);
Debug
Known issues
gotchaThe parser input 'source' property overrides 'inputPath' if both provided.
fix
Pass only one of 'source' or 'inputPath'. When 'source' is set, 'inputPath' is ignored.
affects: >=0.1.0
gotchaSetting async: true returns a Promise; async: false returns string. Default is false.
fix
Set 'async' property in options to true if you need Promise-based parsing. Otherwise, code expects synchronous result.
affects: >=0.1.0
breakingVersion 0.2.0 changed serializer from a function to an object with a 'serialize' method.
fix
Wrap your serializer function in { serialize: myFunction } object.
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: parser.parse is not a function
Using outdated API where parse was not called; or import issue.
fix
Ensure you have created a Parser instance: const parser = new Parser({ serializer }); then call parser.parse({ source: '...' });
Cannot find module 'generic-jsx-transpiler'
Package not installed or missing from node_modules.
fix
Run 'npm install generic-jsx-transpiler --save-dev' in your project directory.
Serialize is not a function
Serializer object missing 'serialize' property; or passed incorrectly.
fix
Provide an object with a 'serialize' function: const serializer = { serialize: (parsedComp) => { /* ... */ } };
Upgrade
Version history
0.9.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
generic-jsx-transpiler — npm install generic-jsx-transpiler · libregistry