4 ms·
> Things happen as they are parsed. If comments aren't completely ignored by the parser, then there has to be some case where a comment inside a function has a
by alkonaut 11y ago
> Things happen as they are parsed.
If comments aren't completely ignored by the parser, then there has to be some case where a comment inside a function has an observable effect?
- ycitm 11y agoYup, see @pauljz's comment above - https://news.ycombinator.com/item?id=10375297 https://news.ycombinator.com/item?id=10375297
- alkonaut 11y agoI still don't understand that. Function.prototype.toString() wouldn't break because the parser stripped the comments, it would just output the source without comments? Does any code anywhere depend on the comments being preserved?
- spullara 11y agoPeople literally toString functions and parse them to implement features. Those features depend on there being comment text in the function that they parse. Pretty much a terrible hack but it is true that you can't remove the comments without breaking current code.
- alkonaut 11y agoWow. That's just something that should be an obvious fix in a future ES. Not only does it hurt the optimizer, it also seems to imply that the content of comments sometimes has semantic meaning in the code, such as people having invented directives etc. Surely this must be undocumented features of the language spec?