Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Xholon and JSX
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook MIT License, Copyright (C) Ken Webb, Mon Aug 03 2020 11:00:36 GMT-0400 (Eastern Daylight Time)-->
Title: Xholon and JSX
InternalName: 6fcaeb5ce9791594ec4fea999b874d2b
My Notes
August 3, 2020
Be able to specify parts of a Xholon app using JSX.
- try acorn and acorn-jsx
JSX, or JavaScript XML, is an extension to the JavaScript language syntax.
Similar in appearance to HTML, JSX provides a way to structure component rendering using syntax familiar to many developers.
React components are typically written using JSX, although they do not have to be (components may also be written in pure JavaScript).
JSX is similar to another extension syntax created by Facebook for PHP called XHP.
An example of JSX code:
class App extends React.Component {
render() {
return (
Nested elements
Multiple elements on the same level need to be wrapped in a single container element such as the <div> element shown above, or returned as an array.
JSX provides a range of element attributes designed to mirror those provided by HTML. Custom attributes can also be passed to the component.[22] All attributes will be received by the component as props.
JavaScript expressions
JavaScript expressions (but not statements) can be used inside JSX with curly brackets {}:
The example above will render
Conditional statements
If–else statements cannot be used inside JSX but conditional expressions can be used instead.
The example below will render { i === 1 ? 'true' : 'false' } as the string 'true' because i is equal to 1.
class App extends React.Component {
render() {
const i = 1;
return (
<h1>{ i === 1 ? 'true' : 'false' }</h1>
The above will render:
Functions and JSX can be used in conditionals:
class App extends React.Component {
render() {
const sections = [1, 2, 3];
return (
{sections.length > 0 && => (
/* 'key' is used by react to keep track of list items and their changes */
/* Each 'key' must be unique */
<div key={"section-" + n}>Section {n}</div>
The above will render:
<div>Section 1</div>
<div>Section 2</div>
<div>Section 3</div>
Code written in JSX requires conversion with a tool such as Babel before it can be understood by web browsers.
This processing is generally performed during a software build process before the application is deployed.
DRAFT: JSX Specification
JSX is an XML-like syntax extension to ECMAScript without any defined semantics.
It's NOT intended to be implemented by engines or browsers.
It's NOT a proposal to incorporate JSX into the ECMAScript spec itself.
It's intended to be used by various preprocessors (transpilers) to transform these tokens into standard ECMAScript.
The purpose of this specification is to define a concise and familiar syntax for defining tree structures with attributes.
A generic but well defined syntax enables a community of independent parsers and syntax highlighters to conform to a single specification.
This specification does not attempt to comply with any XML or HTML specification.
JSX is designed as an ECMAScript feature and the similarity to XML is only for familiarity.
Parser Implementations
acorn-jsx: A fork of acorn.
esprima-fb: A fork of esprima.
jsx-reader: A sweet.js macro.
These are a set of transpilers that all conform to the JSX syntax but use different semantics on the output:
React JSX: Create ReactElements using JSX.
jsx-transform: Configurable implementation of JSX decoupled from React.
Babel: An ES2015 and beyond to ES of now transpiler with JSX support.
Bublé: Another ES2015 and beyond to ES of now transpiler with JSX support.
NOTE: A conforming transpiler may choose to use a subset of the JSX syntax.
Introducing JSX
JSX In Depth
good info
Marijn Haverbeke, marijnh, Independent open-source programmer person, Berlin
This repository holds three packages:
acorn: The main parser
acorn-loose: The error-tolerant parser
acorn-walk: The syntax tree walker
A tiny, fast JavaScript parser, written completely in JavaScript.
An abstract syntax tree walker for the ESTree format.
forwards to acornjs/acorn-jsx
Alternative, faster React.js JSX parser
This is plugin for Acorn - a tiny, fast JavaScript parser, written completely in JavaScript.
It was created as an experimental alternative, faster React.js JSX parser. Later, it replaced the official parser and these days is used by many prominent development tools.
Release 5.2.0
@RReverser RReverser released this on Feb 26
unzipped to ~/nodespace/acorn-jsx-5.2.0
This project is not actively maintained. Proceed at your own risk!
the original esprima
A reader to hook in JSX syntax to JavaScript, using sweet.js.
6 years old
JSX transpiler. A standard and configurable implementation of JSX decoupled from React.
out of date
Bublé is an ES2015+ compiler. It takes your ES2015/16 JavaScript code and turns it into code that can run in today's environments, including old versions of Node.js and Internet Explorer.
The ESTree Spec
Once upon a time, an unsuspecting Mozilla engineer created an API in Firefox that exposed the SpiderMonkey engine's JavaScript parser as a JavaScript API.
Said engineer documented the format it produced, and this format caught on as a lingua franca for tools that manipulate JavaScript source code.
Meanwhile JavaScript is evolving.
This site will serve as a community standard for people involved in building and using these tools to help evolve this format to keep up with the evolution of the JavaScript language.
This document specifies the core ESTree AST node types that support the ES5 grammar.
Build your dream language
Sweet brings the hygienic macros of languages like Scheme and Rust to JavaScript.
Macros allow you to sweeten the syntax of JavaScript and craft the language you always wanted.
<!-- domain objects -->
<!-- quantities -->
<Height superClass="Quantity"/>
<port name="height" connector="Height"/>
<Height>0.1 m</Height>
<Brick multiplicity="2"/>
<Blockbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var a = 123;
var b = 456;
var c = a * b;
if (console) {
//# sourceURL=Blockbehavior.js
<Heightbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var myHeight, testing;
var beh = {
postConfigure: function() {
testing = Math.floor(Math.random() * 10);
myHeight = this.cnode.parent();
act: function() {
toString: function() {
return "testing:" + testing;
//# sourceURL=Heightbehavior.js
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
$wnd.xh.Brickbehavior = function Brickbehavior() {}
$wnd.xh.Brickbehavior.prototype.postConfigure = function() {
this.brick = this.cnode.parent();
this.iam = " red brick";
$wnd.xh.Brickbehavior.prototype.act = function() {
this.brick.println("I am a" + this.iam);
//# sourceURL=Brickbehavior.js
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
console.log("I'm another brick behavior");
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="">
<rect id="PhysicalSystem/Block" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<rect id="PhysicalSystem/Block/Height" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.