question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Work with compile-to-JS languages (like CoffeeScript)

See original GitHub issue

JSX is nice, but those using compile-to-JS language have to change the transpiler to connect to the JSX compiler. Is there any chance of adding alternative DOM syntax to JSX so it does not break every compile-to-JS language? Something gettext-style would be nice. So in addition to:

var HelloMessage = React.createClass({
  render: function() {
    return <div>{'Hello ' + this.props.name}</div>;
  }
});

it would be nice to support

var HelloMessage = React.createClass({
  render: function() {
    return _dom_("<div>{'Hello ' + this.props.name}</div>");
  }
});

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:33 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
holmsandcommented, Jun 3, 2013

Another way to support at least CoffeeScript could be to make the component constructor a little more lenient. I’ve been playing a little with this, and my favorite syntax so far is something like this:

L = React.DOM

HelloComponent = React.createClass
  render: ->
    L.div class: 'myClass',
      L.p 'Hi there, ', @props.name
      L.input type: 'button', onClick: @onClick,
        value: 'Click me'

That is:

  • Allow props to be omitted.
  • Allow more than one child.

And, since CoffeeScript is a bit weird, combine multiple “props” objects into one. (CoffeeScript turns that last line into:

L.input({
  type: 'button',
  onClick: this.onClick
}, {
  value: 'Click me'
});

).

It may not be HTML, but it is quite readable IMHO.

0reactions
anthonybrowncommented, Jun 15, 2015
Read more comments on GitHub >

github_iconTop Results From Across the Web

20 best alternatives to CoffeeScript as of 2022 - Slant.Co
Compiles to multiple platforms and languages · Bad support in some popular IDEs · Powerfully expressive but easy to learn · You need...
Read more >
10 Languages That Compile to JavaScript - SitePoint
This article includes a list of ten interesting languages that can compile to JavaScript to be executed in the browser or on a...
Read more >
Languages that compile to JS (from CoffeeScript wiki) · GitHub
LiteScript Literate, highly-readable, type annotated, imperative language that compiles to JavaScript. ColaScript similar to Dart, CoffeeScript, Python and PHP ...
Read more >
What are some simple but powerful compile-to-JS languages I ...
I'm working on Firefly, which will compile to JS once bootstrapping is complete (almost there). It's a curly brace language like JavaScript, ...
Read more >
altJS compile-to-JavaScript language list - GitHub Pages
Sibilant An expandable JavaScript-like language inspired by Lisp. ... LiveScript Coco but much more compatible with CoffeeScript, more functional, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found