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

Commit

Permalink
Don't parse class properties without initializers when classPropertie…
Browse files Browse the repository at this point in the history
…s is disabled and Flow is enabled (#300)
  • Loading branch information
DrewML authored and danez committed Mar 1, 2017
1 parent 56a92cc commit aec4bef
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,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);
this.next();
node.value = this.parseMaybeAssign();
} else {
Expand Down
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)"
}

0 comments on commit aec4bef

Please sign in to comment.