coffee-react icon indicating copy to clipboard operation
coffee-react copied to clipboard

Custom element is not supported.

Open qdrk opened this issue 10 years ago • 7 comments

sample.coffee

class Button
  render: =>
    super <paper-button className="rui-button rui-form-control" onClick={@buttonClicked}>{text}</paper-button>

is translated to sample.js

// Generated by CoffeeScript 1.8.0
var Button,
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

Button = (function() {
  function Button() {
    this.render = __bind(this.render, this);
  }

  Button.prototype.render = function() {
    return Button.__super__.render.call(this, React.createElement(paper - button, {
      "className": "rui-button rui-form-control",
      "onClick": this.buttonClicked
    }, text));
  };

  return Button;

})();

Note that the React.createElement doesn't give the right output.

qdrk avatar Mar 16 '15 23:03 qdrk

Would I be right in assuming that the desired output is

React.createElement("paper-button", ...)

?

jsdf avatar Mar 17 '15 00:03 jsdf

Just bumped into this - looks like the issue is that adding non-alpha characters as the element name in JSX will cause the generated output to be encapsulated in quotes. For example:

example.cjsx

namespace = {}

namespace.SubView = React.createClass
  render: ->
    <div>Just a subview...</div>

FailureCaseView = React.createClass
  render: ->
    <namespace.SubView />

SuccessCaseView = React.createClass
  render: ->
    React.createElement(namespace.SubView, null)

and the output example.js (look at FailureCaseView vs SuccessCaseView):

// Generated by CoffeeScript 1.9.1
(function() {
  var FailureCaseView, SuccessCaseView, namespace;

  namespace = {};

  namespace.SubView = React.createClass({
    render: function() {
      return React.createElement("div", null, "Just a subview...");
    }
  });

  FailureCaseView = React.createClass({
    render: function() {
      return React.createElement("namespace.SubView", null);
    }
  });

  SuccessCaseView = React.createClass({
    render: function() {
      return React.createElement(namespace.SubView, null);
    }
  });

}).call(this);

In the output JS, FailureCaseView's render should read the same as SuccessCaseView.

briann avatar Apr 15 '15 22:04 briann

Ah nevermind - my hypothesis in the last comment wasn't right. It's the fact that the first character in my namespace is a lowercase character. According to the React documentation the convention is lowercase = HTML tag (and therefore the quotes) and uppercase is another React component. Since the convention is this way, it's probably not an issue.

briann avatar Apr 15 '15 22:04 briann

The official JSX transformer doesn't seem to require the first character to be lower case when a namespace is used. We should probably support that functionality also, to keep in line with JSX. However, the convention is certainly to use an upper case first letter.

jsdf avatar Apr 15 '15 23:04 jsdf

It would be great if this could be mentioned somewhere in the documentation. I spent awhile trying to figure out why my element wasn't being compiled "correctly."

cganas avatar Apr 28 '15 01:04 cganas

@cganas Sure thing. In the near future however, I'll change the implementation to only require the uppercase first letter for non-namespaced tags.

jsdf avatar Apr 28 '15 05:04 jsdf

I don't think this works right now. I took the example from the website with the <Vehicle> tag, and it didn't work. It compiled, but Chrome's throwing an error saying Vehicle isn't defined because it's not a string.

Sawtaytoes avatar Dec 12 '15 14:12 Sawtaytoes