debugger icon indicating copy to clipboard operation
debugger copied to clipboard

Syntax highlighting is crazy for some JSX construct

Open julienw opened this issue 9 years ago • 16 comments

Here is the code that makes the syntax highlighting crazy:

  render() {
    this._scheduleDraw();
    return (
      <div className={this.props.className}>
        <canvas
          className={classNames(
            `${this.props.className}Canvas`,
            'threadStackGraphCanvas'
          )}
          ref={ref => (this._canvas = ref)}
          onMouseUp={this._onMouseUp}
        />
      </div>
    );
  }

See how it renders: capture d ecran de 2017-09-04 17-59-00

julienw avatar Sep 04 '17 15:09 julienw

It would be nice to see what is available w/ codemirror, maybe others have found a good solution?

jasonLaster avatar Oct 27 '17 20:10 jasonLaster

Maybe CodeMirror's latest version has fixed it? I don't see a note in the changelog about the JSX mode specifically. Also maybe worth reporting to them if it does seem broken.

wldcordeiro avatar Oct 30 '17 07:10 wldcordeiro

It was easy to actually try: screenshot-2017-10-30 codemirror

Yep, it looks like Code Mirror's newer versions actually fix this.

julienw avatar Oct 30 '17 09:10 julienw

Though some of the colors are still weird: see the angle bracket in the ref's arrow function, or onMouseUp not having the right color, or the closing div tag.

But it's not as broken as it was.

julienw avatar Oct 30 '17 09:10 julienw

I added this example in that issue: https://github.com/codemirror/CodeMirror/issues/3745#issuecomment-340389826

julienw avatar Oct 30 '17 09:10 julienw

Ah, they answered that we should be in JSX mode, and this actually works in JSX mode (while JS mode still shows the same issue as initially shown). I don't know if there's any drawbacks using this mode for all JS code, I asked there.

julienw avatar Oct 30 '17 09:10 julienw

Thanks @julienw we can be pretty smart about the mode if we parse the source text and see a JSX node

jasonLaster avatar Oct 30 '17 13:10 jasonLaster

when was the JSX mode introduced? should we try to do this w/ 28? or jump and do it?

jasonLaster avatar Oct 30 '17 13:10 jasonLaster

@jasonLaster jsx mode was introduced in v5.11.0. in Jan 2016

@julienw Are you already onto it? Otherwise I'd claim it and look if we always can always use jsx mode for javascript

nyrosmith avatar Oct 30 '17 14:10 nyrosmith

@nyrosmith I'm not, I was just trying to make things clear :)

julienw avatar Oct 30 '17 14:10 julienw

They say there shouldn't be any drawback to always use JSX, but maybe there are other implications, like performance.

julienw avatar Oct 30 '17 14:10 julienw

@julienw can you provide an URL I can test the changes?

nyrosmith avatar Oct 30 '17 14:10 nyrosmith

/claim

nyrosmith avatar Oct 30 '17 14:10 nyrosmith

Thanks for claiming the issue! :wave:

Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.

:fox_face: Debugger team!

claim avatar Oct 30 '17 14:10 claim

I don't have one easily usable online.

But here is a not-so-simple STR:

  1. clone https://github.com/devtools-html/perf.html/
  2. run yarn install && yarn start
  3. with Firefox, go to http://localhost:4242/public/1ecd7a421948995171a4bb483b7bcc8e1868cc57/calltree/
  4. Open the Debugger and open the file webpack > src > components > shared > TreeView.js

You'll see most of the file is blue because of the pattern className={`treeViewHeaderColumn treeViewFixedColumn ${col.propName}`} line 34.

julienw avatar Oct 30 '17 15:10 julienw

That's fine for me. Let's see if I can improve the highlighting

nyrosmith avatar Oct 30 '17 16:10 nyrosmith