Skip to content
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

Allow super in methods with dynamic names #3785

Merged
merged 1 commit into from
Feb 3, 2015
Merged

Conversation

lydell
Copy link
Collaborator

@lydell lydell commented Jan 11, 2015

As discussed in #3039 (comment).
This is the first step to implement dynamic object literal keys (see #3597).

This also fixes #1392.

In short, super is now allowed:

# in class definitions:
class A
  instanceMethod: -> super
  @staticMethod: -> super
  @staticMethod2 = -> super

# in assignment where the next to last property is 'prototype':
A::m = -> super
A['prototype'].m = -> super
a.b()[5]::m = -> super
A::[x()] = -> super
class B
  @::m = -> super

@lydell
Copy link
Collaborator Author

lydell commented Jan 11, 2015

Since

class A
  @a = -> super

is allowed, and the static method compiles to

  A.a = function() {
    return A.__super__.constructor.a.apply(this, arguments);
  };

shouldn’t

A.a = -> super

be allowed too, and compile to the same thing? This would allow:

# class style
class A extends B
  @a: -> super
  a: -> super

# classic style
A = ->
A extends B
A.a = -> super # currently an error
A::a = -> super

@@ -2296,3 +2303,10 @@ unfoldSoak = (o, parent, name) ->
parent[name] = ifn.body
ifn.body = new Value parent
ifn

# Check if `.prop` or `["prop"]` is equal to `property`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this comment is wrong.

@lydell
Copy link
Collaborator Author

lydell commented Jan 12, 2015

I’ve fixed the bad comment now.

@lydell
Copy link
Collaborator Author

lydell commented Jan 14, 2015

My proposal above might not be a good idea, because then

A['prototype'].a = -> super

and

prototype = 'prototype'
A[prototype].a = -> super

would compile to different things, which might be confusing. An error message in the latter case might be preferable.

@lydell
Copy link
Collaborator Author

lydell commented Jan 14, 2015

Fixed merge conflict.

@lydell
Copy link
Collaborator Author

lydell commented Jan 16, 2015

I’ve removed the code to allow A['prototype'].m=->super; see #3796. This effectively turns this PR into a code cleanup plus implementation of agreed-upon features:

In other words, nothing controversial. This should make it easier to merge, I think.

@jashkenas
Copy link
Owner

Rebase for a clean merge, and we'll merge?

As discussed in jashkenas#3039 (comment).
This is the first step to implement dynamic object literal keys (see jashkenas#3597).

This also fixes jashkenas#1392.

In short, `super` is now allowed:

    # in class definitions:
    class A
      instanceMethod: -> super
      @staticmethod: -> super
      @staticMethod2 = -> super

    # in assignment where the next to last access is 'prototype':
    A::m = -> super
    A.prototype.m = -> super
    a.b()[5]::m = -> super
    A::[x()] = -> super
    class B
      @::m = -> super
@lydell
Copy link
Collaborator Author

lydell commented Feb 3, 2015

Rebased.

@jashkenas
Copy link
Owner

Merged.

jashkenas added a commit that referenced this pull request Feb 3, 2015
Allow super in methods with dynamic names
@jashkenas jashkenas merged commit c0e1f23 into jashkenas:master Feb 3, 2015
@jashkenas
Copy link
Owner

Bravo on killing off that nasty METHOD_DEF, by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

calling super in methods defined on namespaced classes
2 participants