diff --git a/lib/MemberBuilderValidator.js b/lib/MemberBuilderValidator.js index c889952..fe33c5a 100644 --- a/lib/MemberBuilderValidator.js +++ b/lib/MemberBuilderValidator.js @@ -291,6 +291,14 @@ exports.prototype.validateGetterSetter = function( ); } + // for const getters/setters, omit the setter + if ( keywords[ 'const' ] ) + { + throw TypeError( + "Cannot declare const getter/setter '" + name + "'" + ); + } + if ( prev || prev_gs ) { // perform this check first, as it will make more sense than those that diff --git a/test/MemberBuilderValidator/GetterSetterTest.js b/test/MemberBuilderValidator/GetterSetterTest.js index c5ff29c..4e37046 100644 --- a/test/MemberBuilderValidator/GetterSetterTest.js +++ b/test/MemberBuilderValidator/GetterSetterTest.js @@ -154,4 +154,15 @@ require( 'common' ).testCase( { this.quickKeywordTest( [ 'abstract' ], 'abstract' ); }, + + + /** + * As getters/setters are essentially methods, they are treated very + * similarity. They cannot be declared as const. Rather, that should be + * handled by omitting a setter. + */ + 'Cannot declare const getters/setters': function() + { + this.quickKeywordTest( [ 'const' ], 'const' ); + }, } );