Flow: es6/7 class parsing failure - property declarations without semicolons - [bounty][test repo available]

Created on 8 Jun 2016  Â·  8Comments  Â·  Source: facebook/flow

version: 0.26.0

bountrsource

Bug description

This shows an ES2015/ES6/ES7 parsing bug - it will fail if there isn't a semicolon or static method after property declarations and before the first member method.

I first found in the test case that a constructor without a static method above it causes linting to fail on the first method with ^^^^^^^^^^^ Unexpected identifier. After suggestion, I tried adding a semicolon which proves the parsing error.

flowconfig

Same results with and without the following:

esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable

Test cases

https://github.com/rosskevin/react-flow-classes

Works (static method above)

// @flow
import React from 'react'

type DefaultProps = { x: 1 }
type Props = { x: number }
type State = { y: number }

class Foo extends React.Component {
  props:Props
  state:State
  static defaultProps:DefaultProps

  static bar ():void {}

  constructor (props) {
    super(props)
  }

  render () {
    return <div>Hello World</div>
  }
}

Fails (no static method above)

// @flow
import React from 'react'

type DefaultProps = { x: 1 }
type Props = { x: number }
type State = { y: number }

class Foo extends React.Component {
  props:Props
  state:State
  static defaultProps:DefaultProps

  // fails without this static method above constructor
  //static bar ():void {}

  constructor (props) {
    super(props)
  }

  render () {
    return <div>Hello World</div>
  }
}

Works (a single semicolon)

// @flow
import React from 'react'

type DefaultProps = { x: 1 }
type Props = { x: number }
type State = { y: number }

class Foo extends React.Component {
  props:Props
  state:State
  static defaultProps:DefaultProps;

  // fails without this static method or semicolon above first constructor/member method
  //static bar ():void {}

  constructor (props) {
    super(props)
  }

  render () {
    return <div>Hello World</div>
  }
}

I proved the same in the sample repo with parameterized classes. May be related to #1171
cc @STRML

Expectation

All current failing classes in the test repo should succeed. I should not need to use any semicolons, and I don't need static methods above my constructor or member method.

ES2015+ bug parsing

Most helpful comment

fix incoming

All 8 comments

I think there may still be some odd parsing rules with semicolons, try
that?
On Jun 8, 2016 5:46 PM, "Kevin Ross" [email protected] wrote:

version: 0.26.0

I'm at a loss, where I can get one thing to work, I cannot get a
combination of Props and State to work. I found in the test case that a
constructor _without_ a static method above it causes linting to fail on
the first method with ^^^^^^^^^^^ Unexpected identifier

https://github.com/rosskevin/react-flow-classes
Works

// @flowimport React from 'react'

type DefaultProps = { x: 1 }
type Props = { x: number }
type State = { y: number }
class Foo extends React.Component {
props:Props
state:State
static defaultProps:DefaultProps

static bar ():void {}

constructor (props) {
super(props)
}

render () {
return

Hello World

}
}

Fails

// @flowimport React from 'react'

type DefaultProps = { x: 1 }
type Props = { x: number }
type State = { y: number }
class Foo extends React.Component {
props:Props
state:State
static defaultProps:DefaultProps

// fails without this static method above constructor
//static bar ():void {}

constructor (props) {
super(props)
}

render () {
return

Hello World

}
}

I proved the same with parameterized classes. May be related to #1171
https://github.com/facebook/flow/issues/1171
cc @STRML https://github.com/STRML

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/facebook/flow/issues/1908, or mute the thread
https://github.com/notifications/unsubscribe/ABJFP6RZmGKyKVdvEVKn3Sfay63tIXI1ks5qJ0ZRgaJpZM4IxXs8
.

fix incoming

@rosskevin thanks for offering the bounty, but I can't accept it :) it's generous and a cool idea, so maybe move it to your next favorite bug instead!

Thanks for the quick fix! Will definitely move it to the next one.

@mroch - please reopen, my sample cases still fail with 0.27.0.

src/es6/Fails.js:16
 16:   constructor (props) {
       ^^^^^^^^^^^ Unexpected identifier

src/es6/FooFails.js:14
 14:   constructor (props) {
       ^^^^^^^^^^^ Unexpected identifier

src/es6/ParameterizedFails.js:16
 16:   constructor (props) {
       ^^^^^^^^^^^ Unexpected identifier

@rosskevin this didn't make it into the 0.27 branch. should be fixed in master, though.

ah, thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mjj2000 picture mjj2000  Â·  3Comments

pelotom picture pelotom  Â·  3Comments

ghost picture ghost  Â·  3Comments

glenjamin picture glenjamin  Â·  3Comments

ctrlplusb picture ctrlplusb  Â·  3Comments