Don't parse class properties without initializers when classProperties is disabled and Flow is enabled (#300)

This commit is contained in:
Andrew Levine 2017-01-23 16:56:39 -06:00 committed by Daniel Tschinder
parent 56a92ccec1
commit aec4beff0c
7 changed files with 25 additions and 1 deletions

View File

@ -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 {

View File

@ -0,0 +1,3 @@
class Foo {
bar: string = 'bizz';
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["flow"],
"throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:14)"
}

View File

@ -0,0 +1,3 @@
class Foo {
bar = 'bizz';
}

View File

@ -0,0 +1,3 @@
{
"throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)"
}

View File

@ -0,0 +1,3 @@
class Foo {
bar;
}

View File

@ -0,0 +1,3 @@
{
"throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)"
}