-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Language pollution due to inherit()
#2270
Conversation
Could you provide a test case (in the test suite) to show the issue we're fixing here? Did you do any performance testing to see if this is a regression? Though I wonder if the "proper" fix for this might actually be for us to document that inherit PURPOSELY doesn't deep clone and in a case like this you'd need to deep clone contains manually. In that case though we might rename inherit so it's understood that it's shallow. |
We definitely need to freeze all the constants we're exposing from |
+1 for freezing constants from But wouldn't freezing constants just cause |
Yes, because right now there is a HIDDEN bug... preventing the constants from being accidentally modified is a good idea regardless of whether inherit should be shallow or not. Did you also look into why your tests are failing? It's possible grammars and the codebase in general expect the current shallow behavior.
Not sure, but it always has been. And I think I've seen grammars that assume so and work around it properly. |
Looks like I was breaking RegExp objects inside of Should this be moved to an issue instead? I thought this was going to be a much simpler fix. |
Well, I'm find discussing it here or in an issue, I think the problem is we're not certain what needs to happen yet... which would make an issue more appropriate, but we already have the context here... :-) I'm whipping up a quick PR for the freeze stuff... it seems |
In the future starting with an issue is probably a better idea. Often the solution you think of isn't actually the correct solution, and having a discussion on an issue first can save time and prevent false starts, etc. |
I will pull this back into an issue. I think the correct immediate fix is my PR: |
By reading through
inherit()
, it seems to me that its purpose is to clone an object and copy over all its values.The existing behavior right now is that Mercury is making a "copy" of
hljs.QUOTE_STRING_MODE
by usinginherit
. But becauseinherit()
is just making a shallow copy, whenSTRING.contains.push(STRING_FMT);
is called, Mercury is actually pushingSTRING_FMT
intohljs.QUOTE_STRING_MODE.contains
.highlight.js/src/languages/mercury.js
Lines 45 to 52 in 980ac21
At the moment,
mercury
is pollutingarmasm
.highlight.js/src/languages/armasm.js
Lines 63 to 65 in 980ac21