vitaly-t / decomment

:hammer: Removes comments from JSON, JavaScript, CSS, HTML, etc.
75 stars 21 forks source link

HTMLWithJS Support Added #12

Closed gauravmuk closed 7 years ago

gauravmuk commented 7 years ago

This was done to support cases when html might have javascript code as well, appended script tag.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.2%) to 99.772% when pulling f3609a0746717443e66ebca44b2c784e4cbeac72 on wingify:isHTMLWithJS into be66cae2e9ef02cc93756dcfe3aa32f7ccc1fdcc on vitaly-t:master.

vitaly-t commented 7 years ago

When HTML contains JavaScript, the JavaScript part cannot be properly processed, because for that it needs to be loaded into the JavaScript parser, which in this case is impossible, that's why it wasn't supported from the beginning.

Your change will break the parser output when it encounters certain regular expressions inside JavaScript that's inside HTML.

Therefore, you cannot process an HTML as both HTML and JavaScript at the same time.

gauravmuk commented 7 years ago

What should be done in such cases when the html file has some js?

vitaly-t commented 7 years ago

What should be done in such cases when the html file has some js?

In the context of this library - nothing. You would need to pull each JavaScript block from the HTML, load it into the JavaScript parser, process it separately, then re-inject back into the HTML. And this task alone would be more complex than the entire library now, so not worth doing.

gauravmuk commented 7 years ago

Thanks for the suggestion. I should close the PR then since this already created problems?

vitaly-t commented 7 years ago

Yep.