version: 0.26.0
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.
Same results with and without the following:
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable
https://github.com/rosskevin/react-flow-classes
// @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>
}
}
// @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>
}
}
// @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
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.
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 identifierhttps://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:DefaultPropsstatic bar ():void {}
constructor (props) {
super(props)
}render () {
returnHello 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 () {
returnHello 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
.
Indeed a single semicolon and it works (repo updated):
https://github.com/rosskevin/react-flow-classes/commit/3c56fd9b7efe4bbcf4ca434e57af0b8c9b5218b7
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.
Most helpful comment
fix incoming