A JSX transformer with extra hints around interpolations and outer templates.

Overview

@ungap/babel-plugin-transform-hinted-jsx

This plugin is a follow up of this post and it can be used together with @babel/plugin-transform-react-jsx.

A huge thanks to Nicolò Ribaudo for helping out.

babel.config.json

{
  "plugins": [
    ["@babel/plugin-transform-react-jsx", {"useSpread": true}],
    ["@ungap/babel-plugin-transform-hinted-jsx"]
  ]
}

npm install

npm i --save-dev @babel/cli
npm i --save-dev @babel/core
npm i --save-dev @babel/plugin-transform-react-jsx
npm i --save-dev @ungap/plugin-transform-hinted-jsx

What is it / How to use it

This produces a slightly different JSX transform.

const div = (
  <div>
    <p className="static" runtime={'prop'}/>
    {<p />}
  </div>
);

// becomes
const div = React.createElement``(
  'div',
  null,
  React.createElement(
    'p',
    {
      className: 'static',
      runtime: React.interpolation('prop')
    }
  ),
  React.interpolation(
    React.createElement``(
      'p',
      null
    )
  )
);

How to hint interpolations

/** @jsx your.createElement */
/** @jsxFrag your.Fragment */
/** @jsxInterpolation your.interpolation */
You might also like...

Completely free TS/JS one-file source code snippets with tests, which can be copied to avoid extra dependencies (contributions welcome).

TinySource Completely free TS/JS one-file source code snippets with tests, which can be copied to avoid extra dependencies (contributions welcome). Sn

Jan 3, 2023

Pure JS Auto Complete plugin with extra features.

Pure JS Auto Complete plugin with extra features.

Cndk.AutoComplete.js Cndk.AutoComplete.js is a pure JavaScript plugin. It performs auto-complete operations within an INPUT. Installation Include the

Jan 25, 2022

Like JSX, but native and fast

Like JSX, but native and fast

esx High throughput React Server Side Rendering For a simplified example of esx in action, check out esx-demo. esx is designed to be a high speed SSR

Jan 2, 2023

Web Components engine based on JSX & TypeScript

Web Components engine based on JSX & TypeScript

WebCell Web Components engine based on JSX & TypeScript Usage Demo & GitHub template: https://web-cell.dev/scaffold/ Project bootstrap Command npm ini

Nov 17, 2022

High performance JSX web views for S.js applications

High performance JSX web views for S.js applications

Surplus const name = S.data("world"), view = h1Hello {name()}!/h1; document.body.appendChild(view); Surplus is a compiler and runtime to all

Dec 30, 2022

Create a html response with JSX.

Htm Create a text/html response with JSX, powered by Preact and UnoCSS. Usage To use Htm, create a server.tsx file like this: /** @jsx h */ import {

Dec 9, 2022

Converts JSX to HTML strings at compile time.

unplugin-jsx-string Converts JSX to HTML strings at compile time. Installation npm i unplugin-jsx-string Vite // vite.config.ts import JsxString from

Sep 3, 2022

Add the `className` to all JSX elements in your project

Babel Plugin Transform JSX Classes This babel plugin adds the className in each JSX element. Before After function FancyComponent () { return (

Jul 15, 2022

Unofficial Library for using Discord.JS with JSX Syntax.

@chooks22/discord.jsx WARNING! This project is in very early stage of development. And while I do have plans to finish it to completion, consider this

Nov 14, 2022
Comments
  • Top createElement / h caller

    Top createElement / h caller

    This is really cool! JSX should have this feature!

    Was wondering is there 1 more piece of information lost with using JSX compared to tagged templates, the ability to know the top createElement | h caller (root node) ?

    Or is this less of an issue by using a wrapper function?

    Related issue https://github.com/developit/htm/issues/143

    opened by luwes 3
  • Simplifying the plugin + using tokens instead of templates

    Simplifying the plugin + using tokens instead of templates

    This MR does the following:

    • it uses a __token props instead of creating template tags, dropping the need to double invoke outer most templates when unique template references are needed (the token can be used as WeakMap key)
    • it doesn't need copy/paste code from the original jsx transform plugin, so it doesn't duplicate code or need extra maintenance anymore
    • it avoids duplicated interpolations for both props and outer most containers
    opened by WebReflection 2
  • Fix transformation of `JSXExpressionContainer`

    Fix transformation of `JSXExpressionContainer`

    This PR can be reviewed commit-by-commit, to more easily understand what's going on.

    1. Transform JSX elements in bottom-up order When transforming an element, its contents are converted to the arguments of the call expression and thus JSXExpressionContainer nodes are unwrapped. If we transform the AST while traversing it in top-down order (where the top is Program), the JSXExpressionContainer visitor will not find the JSXExpressionContainer nodes because they have been removed at the step before. Instead, we can transform the AST while traversing it in the opposite order: first we transform JSXExpressionContainers, and then their outer JSXElements/JSXFragments. This is similar to how it's done in the JSX transform: https://github.com/babel/babel/blob/0b0f083c777bf59b197467b973d6418325c5ddd7/packages/babel-plugin-transform-react-jsx/src/create-plugin.ts#L284

    2. Transform in Program visitor to avoid relying on plugins order Since now this plugin transforms JSX elements in the same visitor as the main JSX plugin, users would be responsible of making sure that this plugin is listed before the JSX one in their config, so that it visits those nodes first. We can avoid this configuration burden by running our transform when visiting Program, so that it always happens before that the main JSX plugins traverses the JSX nodes.

    3. Avoid double interoplation wrap Transforming during the bottom-up traversal has a problem: since Babel requeues replaced nodes (so that they can be re-transformed by other plugins), we traverse JSXExpressionContainers twice:

      • First traversal, we go down to the leaves and visit the JSXExpressionContainer nodes
      • While going up, Babel transforms top-level fragments/elements, and they are requeued
      • Since they have been requeued, Babel re-traverses them, visiting again the JSXExpressionContainer nodes

      We can avoid wrapping then twice in React.interpolation by keeping track of what we already wrapped.

    opened by nicolo-ribaudo 1
Owner
ungap
Modern Web Development One Jump At The Time
ungap
coc-pyright-tools is a coc-extension that adds its own functionality to coc-pyright for coc.nvim. Currently the "Inlay Hints", "CodeLens" and "Test Framework commands" feature is available.

coc-pyright-tools !!WARNING!! Inlay hints feature of coc-pyright-tools, have been ported to coc-pyright itself. https://github.com/fannheyward/coc-pyr

yaegassy 5 Aug 23, 2022
✏️ Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped

Sugar High Introduction Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped Usage npm install --save sugar-high import { h

Jiachi Liu 67 Dec 8, 2022
Font-end app to test the transformer model translation from Cape Verdian Creole to English

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Roberto Carlos 5 Sep 28, 2022
TypeScript Transformer for injection-js

TypeScript Transformer for injection-js TypeScript Transformer for injection-js, inspired by angular-cli. Why need this No more emitDecoratorMetadata

Yadong Xie 13 Dec 4, 2022
Markdown Transformer. Transform markdown files to different formats

Mdtx Inspired by generative programming and weed :). So I was learning Elm language at home usually in the evening and now I am missing all this gener

Aexol 13 Jan 2, 2023
Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra performance.

parallax-vanilla.js Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra perfo

Erik Engervall 91 Dec 16, 2022
Lavalink client with lots of extra functionality, easy to use and well optimized.

?? nSysLava Lavalink client with lots of extra functionality, easy to use and well optimized! พัฒนาโดยคนไทย ?? Many utility functions - มีฟังก์ชันอรรถ

nicenathapong 3 Apr 12, 2022
Extra modifications and enhancements for Discord Bot Maker. Mods you won't find on the DBM Network!

DBM Extended is a open source project meant to enhance and extend Discord Bot Maker. Downloads This repository is not meant to be downloaded or cloned

DBM Extended 11 Oct 10, 2022
DevArms - a collection of developer utils that gives you extra arms to reach more in your tasks

DevArms is a collection of developer utils that gives you extra arms to reach more in your tasks. It runs completely offline, and cross-platform across Windows, Mac and Linux. Written in Rust, React. Powered by Tauri.

Qiushi Pan 82 Dec 18, 2022
Extended magic-string with extra utilities

DEPRECATED. It has been ported back to magic-string >= 0.26.0 magic-string-extra Extended Rich-Harris/magic-string with extra utilities. Install npm i

Anthony Fu 130 Sep 8, 2022