acornjs / acorn-jsx

Alternative, faster React.js JSX parser
MIT License
648 stars 74 forks source link

Location tracking is off #14

Closed sebmck closed 9 years ago

sebmck commented 9 years ago

Excuse the convoluted example but take for example the following:

test.js

var React = require('react');

var Thing = React.createClass({
    render() {
        return (
            <div>
                <div>
                    <h1>foo</h1>
                    <p>foo</p>
                    <p>foo</p>
                    <p>foo</p>
                    <p>foo</p>
                    <p>foo</p>
                    <button onClick={this._handleClick}>click me</button>
                </div>
            </div>
        );
    },
    _handleClick(event) {
        var target = event.target;
        console.log(target);
    }
});

React.render(<Thing />, document.getElementById('main'));

If you get for example <button onClick={this._handleClick}>click me</button> on line 14:

> require("acorn-jsx").parse(require("fs").readFileSync("test.js", "utf8"), { ecmaVersion: 6, locations: true }).body[1].declarations[0].init.arguments[0].properties[0].value.body.body[0].argument.children[1].children[13].loc;
{ start: { line: 20, column: 20 },
  end: { line: 20, column: 73 } }

As you can see the line number is completely off.

RReverser commented 9 years ago

Please see https://github.com/RReverser/acorn-jsx/issues/13#issuecomment-70367070 - situation is the same (also fixed, will be released in few days).

sebmck commented 9 years ago

@RReverser Great, thank you so much!