diff --git a/packages/babylon/src/parser/expression.js b/packages/babylon/src/parser/expression.js index 6a4fcd0811..f4a39379c8 100644 --- a/packages/babylon/src/parser/expression.js +++ b/packages/babylon/src/parser/expression.js @@ -648,7 +648,10 @@ export default class ExpressionParser extends LValParser { !this.state.inClassProperty && !this.options.allowSuperOutsideMethod ) { - this.raise(this.state.start, "'super' outside of function or class"); + this.raise( + this.state.start, + "super is only allowed in object methods and classes", + ); } node = this.startNode(); diff --git a/packages/babylon/test/fixtures/es2015/class-methods/direct-super-in-object-method/actual.js b/packages/babylon/test/fixtures/es2015/class-methods/direct-super-in-object-method/actual.js new file mode 100644 index 0000000000..4f4affc38e --- /dev/null +++ b/packages/babylon/test/fixtures/es2015/class-methods/direct-super-in-object-method/actual.js @@ -0,0 +1,7 @@ +Object.create({}, { + foo: { + get: function(){ + return super.foo; + } + } +}); diff --git a/packages/babylon/test/fixtures/es2015/class-methods/direct-super-in-object-method/options.json b/packages/babylon/test/fixtures/es2015/class-methods/direct-super-in-object-method/options.json new file mode 100644 index 0000000000..660e644cf6 --- /dev/null +++ b/packages/babylon/test/fixtures/es2015/class-methods/direct-super-in-object-method/options.json @@ -0,0 +1,3 @@ +{ + "throws": "super is only allowed in object methods and classes (4:13)" +} diff --git a/packages/babylon/test/fixtures/es2015/uncategorised/344/options.json b/packages/babylon/test/fixtures/es2015/uncategorised/344/options.json index ad647a87fc..ad3fdc7d73 100644 --- a/packages/babylon/test/fixtures/es2015/uncategorised/344/options.json +++ b/packages/babylon/test/fixtures/es2015/uncategorised/344/options.json @@ -1,3 +1,3 @@ { - "throws": "'super' outside of function or class (1:0)" -} \ No newline at end of file + "throws": "super is only allowed in object methods and classes (1:0)" +} diff --git a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_not_inside_function/options.json b/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_not_inside_function/options.json index 1518a5e3fe..cf468e4854 100644 --- a/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_not_inside_function/options.json +++ b/packages/babylon/test/fixtures/esprima/es2015-super-property/invalid_super_not_inside_function/options.json @@ -1,3 +1,3 @@ { - "throws": "'super' outside of function or class (1:8)" -} \ No newline at end of file + "throws": "super is only allowed in object methods and classes (1:8)" +}