nativejsx icon indicating copy to clipboard operation
nativejsx copied to clipboard

Comments are removed from code, even for files with no JSX

Open odzb opened this issue 8 years ago • 3 comments

If nativejsx encounters a source code file where there is no JSX (which is the majority of files in my 200 KLOC project), it still passes the file through its parser and code generator, which results in comments being removed and string quote style being changed.

What I'd like to see, ideally:

  1. Comments to be retained everywhere. It's the minifier's job to remove them at a later stage in non-debug builds. As far as I understand, these instructions need to be followed to achieve this: https://github.com/ternjs/acorn#note-on-using-with-escodegen

  2. Files to be kept completely intact if there is no JSX in them.

Thanks for all your hard work.

odzb avatar Mar 17 '17 10:03 odzb

  1. This is actually non-trivial. I'm running several mutations to the AST which throws off ranges. While some comments are left intact, others cause an immediate failure. I'm not sure I have the time to figure out the range math involved.
  2. I'm now relying on internal transformed state to decide whether or not to send the AST back. If it's not transformed, I'm handing back the contents of the original file/string untouched.

treycordova avatar Mar 27 '17 00:03 treycordova

Number 2 is nice, thanks a lot.

odzb avatar Mar 27 '17 10:03 odzb

Dunno if this is the same issue but I can't comment on the JSX file:

{/* Comment 1 : Comment 2 */}

Gives me an:

TypeError: base[type] is not a function

Can I comment on my JSX file using Nativejsx? If so, how can I do that? Thanks!

ThiagoMiranda avatar Oct 01 '17 14:10 ThiagoMiranda