Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Syntax error for overwriting constructor type in flow class #508

Closed
philipp-spiess opened this issue May 3, 2017 · 3 comments · Fixed by #510
Closed

Syntax error for overwriting constructor type in flow class #508

philipp-spiess opened this issue May 3, 2017 · 3 comments · Fixed by #510

Comments

@philipp-spiess
Copy link

In a recent version change, parsing flow files introduced an error when a flow class overwrites the constructor type.

Input Code

class Foo {
  constructor: () => this;
}

Babylon/Babel Configuration

{
  "plugins": [
     "transform-class-properties",
      "transform-object-rest-spread"
   ],
   "presets": ["latest", "react"]
}

Expected Behavior

The file parses correctly. Flow parser accepts the syntax properly

Current Behavior

error  Parsing error: Classes may not have a non-static field named 'constructor'

Your Environment

software version
Babylon 6.17.0 (worked in 6.16.1)
node v6.9.1
npm 3.10.8
Operating System macOS
@hzoo
Copy link
Member

hzoo commented May 3, 2017

Hey @philipp-spiess! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@bakkot
Copy link
Contributor

bakkot commented May 3, 2017

Ah, that was me at #351, sorry.

What does this syntax do? Why does flow accept it? Do they accept it on purpose? (Also, why doesn't flow have formal documentation of their syntax?)

@philipp-spiess
Copy link
Author

We used it to fix a missing type for a constructor from a class that we extend (Immutable.Record to be more specific). It's kinda hacky since it uses the class fields API and defines constructor as a property.

Here's a working example in flow that uses this technique.

Also, why doesn't flow have formal documentation of their syntax?

I can't help you there :)

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

Successfully merging a pull request may close this issue.

4 participants