peitalin / vim-jsx-typescript

React JSX syntax highlighting for vim and Typescript
The Unlicense
305 stars 29 forks source link

JSX elements within JS-blocks inside of JSX-blocks need to be wrapped in parentheses #1

Closed peitalin closed 5 years ago

peitalin commented 7 years ago

E.g for a code block like this:

render() {
  return (
    <div>
        { 
            this.showIfTrue &&
            <Modal/>
        }
    <div>
  )
}

The last } will not be correctly highlighted.

You'll need to wrap the <Modal/> element inside the JS-block (inside the JSX-block) in parentheses:

render() {
  return (
    <div>
        { 
            this.showIfTrue &&
            (<Modal/>)
        }
    <div>
  )
}

Alternatively, I've been wrapping the entire block in parentheses for consistency:

render() {
  return (
    <div>
        {( 
            this.showIfTrue &&
            <Modal/>
        )}
    <div>
  )
}
setthase commented 6 years ago

Any plans to fix this issue?

The workaround will not work for projects that use prettier for they code formatting.

peitalin commented 5 years ago

Should be fixed now. image

peitalin commented 5 years ago

Should also work for react fragments syntax as well now. image