-
-
Notifications
You must be signed in to change notification settings - Fork 255
Don't parse class properties without initializers when classProperties plugin is disabled, and Flow is enabled #300
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -771,8 +771,13 @@ pp.parseClassBody = function (node) { | |
}; | ||
|
||
pp.parseClassProperty = function (node) { | ||
const noPluginMsg = "You can only use Class Properties when the 'classProperties' plugin is enabled."; | ||
if (!node.typeAnnotation && !this.hasPlugin("classProperties")) { | ||
this.raise(node.start, noPluginMsg); | ||
} | ||
|
||
if (this.match(tt.eq)) { | ||
if (!this.hasPlugin("classProperties")) this.unexpected(); | ||
if (!this.hasPlugin("classProperties")) this.raise(this.state.start, noPluginMsg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure it's safe to provide a better message here. We should only get to this point if we're inside the top level of a class body and we've found either a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should note I'm using class Foo {
bar: string = 'bizz';
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this was the same before, as |
||
this.next(); | ||
node.value = this.parseMaybeAssign(); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
bar: string = 'bizz'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"plugins": ["flow"], | ||
"throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:14)" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
bar = 'bizz'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
bar; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super happy about a flow-specific check leaking into the general parser, but I didn't see a straight-forward way to do this otherwise. Only other way I could see was to just have the flow extension for
parseClassProperty
invoke this with an optional second param ofhadType
, but even then, Flow-related stuff still leaks in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code will not stay forever anyway, as as soon as class-properties are final, we can remove all this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really need to do #178
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point