tpope / vim-commentary

commentary.vim: comment stuff out
http://www.vim.org/scripts/script.php?script_id=3695
5.9k stars 214 forks source link

Commenting a comment in a react component breaks source file #117

Closed preslavmihaylov closed 5 years ago

preslavmihaylov commented 5 years ago

Given the file:

// @flow
import * as React from 'react';

export default function Foo() {
  return (
    <div>
      {/* some comment */}
      <div>Bar</div>
    </div>
  );
}

Do steps:

  1. Visual-select the comment line and the Bar line
  2. Comment the lines using vim-commentary (gc)

Result:

// @flow
import * as React from 'react';

export default function Foo() {
  return (
    <div>
      {/* {1/* some comment */1} */}
      {/* <div>Bar</div> */}
    </div>
  );
}

The comment line is broken and I have to manually go and fix it.

I expected the commented comment to look like this:

{/* {/* some comment *\/} */}
tpope commented 5 years ago

Uncommenting undoes it. What's wrong with Commentary's syntax, and how is it supposed to know you prefer a different syntax?

preslavmihaylov commented 5 years ago

The react component doesnt render with this syntax

I will provide a screenshot later, busy atm.

tpope commented 5 years ago

I suppose non-functioning code is a valid objection. Would changing it to {/1* ... *1/} do the trick?

preslavmihaylov commented 5 years ago

Here's how the component renders without commenting anything: image

Here's how it renders after commenting the lines mentioned out: image

The suggestion you made works and the component is rendered properly this way: image

(a blank page is expected)