Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Extend estraverse rules to support JSX #830

Closed
wants to merge 1 commit into from

Conversation

yannickcr
Copy link
Contributor

The addition of estraverse (#817) makes impossible for us to use a custom esprima version like esprima-fb to parse JSX, since it will produce some unknown node types.

var HelloMessage = React.createClass({
    render: function(path) {
        return <div>Hello {this.props.name}</div>;
    }
});
React.render(<HelloMessage name="John" />, mountNode);
$ jscs test.jsx --esprima=esprima-fb
Error: Unknown node type XJSElement.
    at Controller.traverse (D:\Development\node-jscs\node_modules\estraverse\estraverse.js:513:31)
    at Object.traverse (D:\Development\node-jscs\node_modules\estraverse\estraverse.js:705:27)
    at Object.iterate (D:\Development\node-jscs\lib\tree-iterator.js:9:20)
    at Object.JsFile.iterate (D:\Development\node-jscs\lib\js-file.js:275:29)
    at Object.JsFile (D:\Development\node-jscs\lib\js-file.js:28:10)
    at StringChecker.checkString (D:\Development\node-jscs\lib\string-checker.js:96:20)
    at null.<anonymous> (D:\Development\node-jscs\lib\checker.js:40:25)
    at Array.0 (D:\Development\node-jscs\node_modules\vow-fs\node_modules\vow\lib\vow.js:555:39)
    at Object.callFns [as _onImmediate] (D:\Development\node-jscs\node_modules\vow-fs\node_modules\vow\lib\vow.js:1148:35)
    at processImmediate [as _immediateCallback] (timers.js:345:15)

This patch will extend estraverse traversing to XJS nodes, making JSX support possible.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 4d8c8ef on yannickcr:estraverse-jsx into 65f27dd on jscs-dev:master.

@mikesherov
Copy link
Contributor

Thanks for contributing! Please add a unit test supporting this change and we can definitely land it.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 2d82c36 on yannickcr:estraverse-jsx into 65f27dd on jscs-dev:master.

@yannickcr
Copy link
Contributor Author

Hi,

As requested I added a test to check if tree-iterator does not fail when encounting some XJS nodes. But since I do not want to add esprima-fb as a dependency just for this test I added a pre-generated JSX AST in test/data/tree-iterator/jsx-ast.js. Hope this is good for you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants