denoify icon indicating copy to clipboard operation
denoify copied to clipboard

denoify creates imports from comments

Open hermann-p opened this issue 1 year ago • 3 comments

Denoifying a TypeScript file with a comment containing the word "Buffer" led to an output file importing the Buffer package, subsequently breaking our backend build.

See this commit for context.

Observed behaviour:

The word "Buffer" in a comment makes denoify create an import statement for Buffer.

Desired behaviour:

Denoify will not treat comments as code.

hermann-p avatar Mar 13 '23 14:03 hermann-p

Hi @hermann-p,
Damn, I know this day would come.
Denoifiy is using Regexp, instead of an actuall parser. Part because it's started as a toy project to convert my own libraries and grown from here and part because I didn't want to be worried about a new keyword breaking it. (We still can't use satisfies in many context).

I don't know, I could introduce yet another hack so that it wont happen.
Or maybe I should properly parse at least comments.

I ran across grubber the other day. Looks interesting.

What do you thing @Gin-Quin? Could Denoify be a good usecase for grubber?

garronej avatar Mar 13 '23 14:03 garronej

Yep, it's exactly the kind of tasks Grubber has been designed for. Think of Grubber as something in-between a full parser and a basic search and replace system.

This is especially suited for top-level static declarations, like ESM imports. You'll have 100% safety with a very simple usage.

Gin-Quin avatar Mar 13 '23 15:03 Gin-Quin

Ok thanks for the insight @Gin-Quin,
Grubber did seems like a well executed good offer.
I'll see if I can make it work

garronej avatar Mar 13 '23 15:03 garronej