Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
coffee-react-transform
Advanced tools
Provides support for an equivalent of JSX syntax in Coffeescript (called CJSX) so you can write your Facebook React components with the full awesomeness of Coffeescript.
car-component.coffee
# @cjsx React.DOM
Car = React.createClass
render: ->
<Vehicle doors={4} locked={isLocked()} data-colour="red" on>
<Parts.FrontSeat />
<Parts.BackSeat />
<p className="kickin">Which seat can I take? {@props?.seat or 'none'}</p>
</Vehicle>
transform
cjsx-transform car-component.coffee
output
Car = React.createClass
render: ->
Vehicle({"doors": (4), "locked": (isLocked()), "data-colour": "red", "on": true},
Parts.FrontSeat(null),
Parts.BackSeat(null),
React.DOM.p({className: "kickin"}, "Which seat can I take? ", (@props?.seat or 'none'))
)
The try coffee-react tool is available to test out some CJSX code and see the CoffeeScript it transforms into.
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
executable, for compiling CJSX.require
CJSX files on the server (also possible with coffee-react/register).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...')
From npm:
npm install -g coffee-react-transform
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:
http://wzrd.in/standalone/coffee-react-transform
<script src="http://wzrd.in/standalone/coffee-react-transform"></script>
<script>
coffeeReactTransform('-> <a />');
// returns "-> React.DOM.a(null)"
</script>
A recent addition to JSX (and CJSX) is 'spread attributes' which allow merging an object of props into a component, eg:
extraProps = color: 'red', speed: 'fast'
<div color="blue" {... extraProps} />
which is transformed to:
extraProps = color: 'red', speed: 'fast'
React.DOM.div(Object.assign({"color": "blue"}, extraProps)
If you use this syntax in your code, be sure to include a shim for Object.assign
for browsers/environments which don't yet support it (basically all of them).
es6-shim and object.assign are two possible choices.
cake test
or cake watch:test
The custom file extension recently changed from .csx
to .cjsx
to avoid conflicting with an existing C# related file extension, so be sure to update your files accordingly (including changing the pragma to @cjsx
). You can also just use .coffee
as the file extension. Backwards compatibility will be maintained until the next major version.
FAQs
React JSX support for Coffeescript
The npm package coffee-react-transform receives a total of 0 weekly downloads. As such, coffee-react-transform popularity was classified as not popular.
We found that coffee-react-transform demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.