Open jed opened 8 years ago
You can reproduce using this Tonic notebook: https://tonicdev.com/gnestor/lave-react-element/1.0.0
Hey there @gnestor, thanks for the issue! The problem appears to be that you are using JSX, which unfortunately, is not valid JavaScript.
However, in the example in Tonic, I am using React.createElement
, so what's being passed to lave is valid JS, not JSX:
var lave = require('lave')
var React = require('react')
var ReactDOM = require('react-dom')
class ReactComponent extends React.Component {
render() {
return <span>{this.props.text}</span>
}
}
var element = React.createElement(ReactComponent, {text: 'This is a React element'})
var ast = lave(element)
console.log(element, ast)
I think this "Cannot convert a Symbol value to a number" error refers to the $$typeof: Symbol.for('react.element')
property that is added to React element objects.
I would love to add support for symbols soon, but can't imagine this will work, for it would assume that React doesn't use any closures (which means that not even lave could stringify it).
@jed if you wouldn't mind explaining the problem here, I would love to help. If I understand you correctly, if an value/expression involves closures, you can't stringified it using lave? However, circular references are ok? I've tried to stringify React classes using a lot of different methods with no luck yet for ES6 class components (ES5 composite class components and stateless components work).
@gnestor: that's exactly right. lave works by crawling every property of a given object, and since closures are not properties, they cannot be crawled.
+1
I get the following error when trying: