This tool is no longer maintained. If you need to transition your codebase from it, a codemod is available to do so: cjsx-codemod
This project started as a way for me to explore how JSX could fit into Coffeescript syntax, as a quickly hacked together prototype. While I never really promoted it, it quickly took on a life of its own, and before long people were asking for it to support all kinds of different use cases. On top of that I had no experience writing parsers, so the result is something with insurmountable limitations.
As I eventually stopped using Coffeescript I ended up neglecting this project, but as people were using it I didn't want to kill it. I really should have, however, because it meant that people were using a crappy, ill-conceived, unmaintained tool. Now, long overdue, I'm putting it out to pasture.
Original readme follows:
Provides support for an equivalent of JSX syntax in Coffeescript (called CJSX) so you can write your React components with the full awesomeness of Coffeescript. Try it out.
Car = ReactcreateClass: -><Vehicle doors=4 locked=isLocked data-colour="red" on><PartsFrontSeat /><PartsBackSeat /><p className="seat">Which seat can I take? @props?seat or 'none'</p># also, this is an inline comment}</Vehicle>
Car = ReactcreateClass: ->ReactcreateElementVehicle"doors": 4"locked": isLocked"data-colour": "red""on": trueReactcreateElementPartsFrontSeatnullReactcreateElementPartsBackSeatnullReactcreateElement"p""className": "seat""Which seat can I take? "@props?seat or 'none'
coffee-react-transform simply handles preprocessing Coffeescript with JSX-style markup into valid Coffeescript. Instead of using it directly, you may want to make use of one of these more high-level tools:
- coffee-react: a drop-in replacement for the
coffeeexecutable, for compiling CJSX.
requireCJSX files on the server (also possible with coffee-react/register).
- coffee-reactify: bundle CJSX files via browserify, see also cjsxify.
- cjsx-loader: loader module for Webpack.
- react-coffee-quickstart: equivalent to react-quickstart.
- coffee-react-quickstart: Quickstart for building React single page apps using Coffeescript, Gulp, Webpack, and React-Router
- sprockets preprocessor: use CJSX with Rails/Sprockets
- ruby coffee-react gem for general ruby integration
- vim plugin for syntax highlighting
- sublime text package for syntax highlighting
- mimosa plugin for the mimosa build tool
- karma preprocessor for karma test runner
- broccoli plugin for the broccoli build tool
cjsx-transform [input file]
Outputs Coffeescript code to stdout. Redirect it to a file or straight to the Coffeescript compiler, eg.
cjsx-transform examples/car.coffee | coffee -cs > car.js
transform = require 'coffee-react-transform'transformed = transform'...some CJSX code...'
npm install -g coffee-react-transform
- 4.x - React >=0.14.x
- 3.x - React >=0.13.x <=0.14.x
- 2.1.x - React 0.12.1
- 2.x - React 0.12
- 1.x - React 0.11.2
- 0.x - React 0.11 and below
JSX/CJSX 'spread attributes' allow merging in an object of props when creating an element, eg:
extraProps = color: 'red'speed: 'fast'<div color="blue" ...extraProps />
which is transformed to:
extraProps = color: 'red'speed: 'fast'ReactcreateElement"div"Objectassign"color": "blue"extraProps
If you want to use coffee-react-transform in the browser or under ExecJS or some other environment that doesn't support CommonJS modules, you can use this build provided by BrowserifyCDN, which will work as an AMD module or just a plain old script tag:
npm test or
cake test or