-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: make js2c.py strip comments from sources #11417
Conversation
/cc @bnoordhuis @addaleax |
I'm conflicted if we should actually do this. Are comments in the core deployed source useful anywhere for debugging? |
Also I was under the impression we'd make the lint rule for ASCII code ignore the comments, rather than removing them. 😕 |
@Fishrock123 the idea was to strip comments during build, make the lint rule only enforce ASCII in the code and allow any characters in comments. What about debugging... yeah, the core sources shown in, e.g., Chrome DevTools will be without comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is okay to do… it saves 250 kB in the final executable, which is, like, not huge compared to the total output size, but still.
/cc @nodejs/python
We have at least one comment in Line 161 in 00c86cc
|
@targos right, thanks for pointing that out. What if we introduce some kind of marker (like |
'///' could be misinterpreted as a typo and isn't obvious it is intentional or why it was added. |
the “Unhandled 'error' event” thing should be sorted out first
@mscdex is your objection related to |
tools/js2c.py
Outdated
if char in ('\'', '"', '`'): | ||
if char == string_mode and not escape_mode: | ||
string_mode = None | ||
elif not string_mode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer explicit check, like elif string_mode is not None:
. Thats more pythonic and readable as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is None
:)
Thanks for your feedback, I've pushed a new commit.
@aqrln I'd definitely object to '///' or any similar variant, but I'm skeptical about generally having special markers as being a good solution. |
In order to allow using Unicode characters inside comments of built-in JavaScript libraries without forcing them to be stored as UTF-16 data in Node's binary, update the tooling to strip comments during build process. All line breaks are preserved so that line numbers in stack traces aren't broken. Refs: nodejs#11129 Refs: nodejs#11371 (comment)
9c4f699
to
6296a6c
Compare
@mscdex well, it indeed sounds like a little kludge, but I have no other ideas for now, though I'll try to come up with a better solution. I'll be grateful if you have any ideas about this. |
Two alternative ideas:
I like the latter one, but maybe only because it’s the easiest way… |
I'd say a much simpler solution is:
The file for 3. could be just this: // eslint-disable-next-line
module.exports = 'ç'; And the test: // Flags: --expose_internals
// ...
assert.strictEqual(require('internal/test/unicode'), 'ç'); |
@bnoordhuis Does that mean you’d oppose a change like this? We can do 3. anyway. |
'Oppose' is too strong a word, it just seems like over-engineering a fix for a simple problem. I might change my mind if it turns out comments are a substantial chunk of the embedded sources but I don't think they are. |
Not only we can do 3 anyway, we should have had it, IMO. #11423. |
I'm not clear why we acre so much about this anyways. What is actually wrong today? |
Not much… forbidding non-ASCII characters in comments just seems like a needless restriction, and it would be nice to keep the timers diagram as-is (the proper lines actually help with readability, imho). (Aside: If English is your first language you might find it hard to imagine how much encountering “ASCII-only” validation rules feels like being shown the middle finger in general. :/ I do see that that might not be too relevant to Node core.)
I mentioned it above, the difference is about 250 kB. That’s probably not “substantial”. 😄 |
I'm really not seeing the need for stripping comments OR having the linting rule for ASCII only. At this point I'm definitely -1 on this. |
One possible reason, that you may or may not agree with, is that when you open lib/timers.js in a terminal window that isn't set to UTF-8, it looks like absolute garbage. |
I'm fine with the idea of pulling out that large diagram in timers.js, it would likely be better suited for inclusion in a guide anyway. Even so, I'd be -1 on this. |
There has been quite a much of discussion in #11371 and this PR for such a minor issue. Let me describe my point of view. There are only two question that need to be considered for both PRs:
I am -1 on not allowing to use Unicode characters at all (and, as an example, replacing a classy diagram in What about this PR, @Fishrock123's counterargument about comments being useful for debugging is very sensible, so after some thinking about it, I'd take @addaleax's idea about keep-next-comment directive and flip it so that the proposal is to keep all comments by default but strip those preceded by a special directive. But if there's no consensus, I join the position that nothing should really be done here, except, maybe, enforcing ASCII-only characters outside comments so that the linter will catch if someone adds some kind of weird Unicode whitespace character. |
@aqrln do you want to follow up on this? Right now I do not have the feeling that this will come to a conclusion that everyone likes to live with. |
@BridgeAR at this point I don't see enough evidence that it is something that we should do too, right. Let's close this for now so it doesn't clutter the backlog, we can always revisit it later if there is a need to do so. |
In order to allow using Unicode characters inside comments of built-in JavaScript libraries without forcing them to be stored as UTF-16 data in Node's binary, update the tooling to strip comments during build process. All line breaks are preserved so that line numbers in stack traces aren't broken.
Refs: #11129
Refs: #11371 (comment)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
tools