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

Compiles to invalid JS: computed class property #5204

Closed
helixbass opened this issue Apr 26, 2019 · 2 comments · Fixed by #5206
Closed

Compiles to invalid JS: computed class property #5204

helixbass opened this issue Apr 26, 2019 · 2 comments · Fixed by #5206
Labels

Comments

@helixbass
Copy link
Collaborator

@GeoffreyBooth I came across this while working on class AST:

This:

class A
  [b]: 3

compiles to:

var A;

A = (function() {
  class A {};

  A.prototype.[b] = 3;

  return A;

}).call(this);

which doesn't parse

Does it make sense to allow computed class properties like this?

If so, it's probably just a question of omitting the . when compiling (so here generate A.prototype[b] = 3 instead)?

Fwiw, it looks like this didn't compile (as Coffeescript source) in Coffeescript 1.x. I didn't trace when it became allowed Coffeescript syntax

@helixbass
Copy link
Collaborator Author

For the static case, it's currently inconsistent as far as allowed syntax:

# this compiles
class A
  @[b] = 3

# but this doesn't
class A
  @[b]: 3

but the version that compiles (@[b] = 3) generates valid JS it appears (A[b] = 3)

@GeoffreyBooth
Copy link
Collaborator

I guess it might as well compile, since we support the same for objects since #4803. That might’ve been the PR where this broke for classes.

Can we fix this on master?

helixbass added a commit to helixbass/copheescript that referenced this issue Apr 28, 2019
GeoffreyBooth pushed a commit that referenced this issue Apr 28, 2019
* class prototype property AST

* consistent naming

* extract fix for #5204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants