-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[CS2] Remove unnecessary utility helper functions #4526
Conversation
Neat! On |
The place I see it being used is with frameworks. Consider Backbone, with lines like |
src/nodes.coffee
Outdated
@@ -3118,7 +3118,7 @@ UTILITIES = | |||
|
|||
# Correctly set up a prototype chain for inheritance, including a reference | |||
# to the superclass for `super()` calls, and copies of any static properties. | |||
extend: (o) -> " | |||
extend: (o) -> """ |
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.
This will make the helper function take several lines in the output JS. Is this change intended?
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.
Oh, no, I was just figuring that multiline strings should always be block-quoted as a matter of style.
I agree. I think it should be removed for CS2. The reason for its existence was CS1's "classes via JavaScript prototypes" helpers. |
@jashkenas you would be the one to confirm: does removing |
Even if it did — that shouldn't be a consideration that CoffeeScript needs to worry about. But it doesn't: http://backbonejs.org/#Model-extend |
Okay, I’m convinced.
Do these shortcuts, like |
Regardless of whether we should remove the shortcuts, does this PR look okay? |
Inspired by @connec’s comment:
indexOf
, leaving the shortcut to the native function.bind
entirely, replacing its one usage with a call to the nativebind
.class
to be supportedThe one outlier is the utility function for
extends
, which remains. Now that we compile to nativeclass
andextends
, there’s only one very narrow case where this helper still gets used:which pairs with:
We have zero tests covering this. I suppose the hundreds of
class
tests used to cover it in the 1.x codebase, but now that this only applies to straight prototypal inheritance we don’t have any tests that refer to that as opposed to classes. This is mentioned in the docs, but there’s no example, just a single half-sentence: “Theextends
operator can be used to create an inheritance chain between any pair of constructor functions”.Anyway for the purposes of this PR we can just leave it as is. Later on though we should probably decide whether or not we want to keep it (might as well, I suppose) and if we do keep it, it should get some tests of its own and probably an example in the docs.
EDIT
extends
.splice
just likeslice
.