diff --git a/src/parser/statement.js b/src/parser/statement.js index cde86295ab..da148c18f2 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -763,8 +763,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 { diff --git a/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/actual.js b/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/actual.js new file mode 100644 index 0000000000..f82f8d51d7 --- /dev/null +++ b/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/actual.js @@ -0,0 +1,3 @@ +class Foo { + bar: string = 'bizz'; +} diff --git a/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/options.json b/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/options.json new file mode 100644 index 0000000000..e185feb80a --- /dev/null +++ b/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["flow"], + "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:14)" +} diff --git a/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/actual.js b/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/actual.js new file mode 100644 index 0000000000..fa80e3af68 --- /dev/null +++ b/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/actual.js @@ -0,0 +1,3 @@ +class Foo { + bar = 'bizz'; +} diff --git a/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/options.json b/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/options.json new file mode 100644 index 0000000000..af38bd1530 --- /dev/null +++ b/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/options.json @@ -0,0 +1,3 @@ +{ + "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" +} diff --git a/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/actual.js b/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/actual.js new file mode 100644 index 0000000000..a36cdd975c --- /dev/null +++ b/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/actual.js @@ -0,0 +1,3 @@ +class Foo { + bar; +} diff --git a/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/options.json b/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/options.json new file mode 100644 index 0000000000..af38bd1530 --- /dev/null +++ b/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/options.json @@ -0,0 +1,3 @@ +{ + "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" +}