You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

jsx-to-h

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

jsx-to-h

A CLI command for converting JSX files into standard JS.

1.1.9
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

jsx-to-h

A CLI command for converting JSX files into standard JS.

Usage:

npx jsx-to-h <glob> [--write] [--factory='h'] [--flow]
or
node ./node_modules/jsx-to-h/src/cli.mjs <glob> [--write] [--factory='h']

Some examples of what <glob> can be:

build/**/*.js
build/**/*{.js,.jsx}
file.js

CLI Flags

  • --write - Causes the files matching the glob to be overwritten by the output, otherwise output goes to stdout.
  • --factory='h' - By default the factory function is h. Use this to change it.
  • --flow - Passes the input through flow-remove-types before transforming.

Examples

Input:

// Instances of React are transformed as well
import React from "hyperscript"

const signs = [{ value: "+" }, { value: "-" }]

const renderSign = (props) => {
  return (
    <span>{props.value}</span>
  )
}

const Component = () => (<div></div>)
const test = (
  <div style={{color: 'orange'}}>
    <Component />
    <button
      onClick={() => {
        const el = <div/>
        console?.log(el)
      }}
      {...passProps}
    />
    {signs.map(renderSign)}
  </div>
)

Output:

// Instances of h are transformed as well
import h from "hyperscript"

const signs = [{ value: "+" }, { value: "-" }]

const renderSign = (props) => {
  return h("span", null, [props.value])
}

const Component = () => h("div", null, [])
const test = h("div", { style: { color: "orange" } }, [
  Component({}),
  h(
    "button",
    {
      onClick: () => {
        const el = h("div", null, [])
        console?.log(el)
      },
      ...passProps,
    },
    []
  ),
  signs.map(renderSign),
])

Fragments are supported, too:

// input
function renderRow() {
  return (
    <>
      <span/>
      <span/>
    </>
  )
}
// output
function renderRow() {
  return (
    [
      h('span', null, []), 
      h('span', null, [])
    ]
  )
}

Keywords

cli

FAQs

Package last updated on 21 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts