diff --git a/lib/member_builder.js b/lib/member_builder.js index a8dbba1..b6d1803 100644 --- a/lib/member_builder.js +++ b/lib/member_builder.js @@ -227,6 +227,14 @@ exports.buildProp = function( members, meta, name, value, keywords, base ) ); } + if ( keywords[ 'static' ] && keywords[ 'const' ] ) + { + throw TypeError( + "Static keyword cannot be used with const for property '" + + name + "'" + ); + } + getMemberVisibility( members, keywords )[ name ] = value; }; diff --git a/test/test-class_builder-const.js b/test/test-class_builder-const.js index 95602af..87817d8 100644 --- a/test/test-class_builder-const.js +++ b/test/test-class_builder-const.js @@ -56,3 +56,31 @@ var common = require( './common' ), assert.fail( "Should not be able to declare constant methods" ); } )(); + +/** + * The const keyword implies static. Using static along with it is redundant and + * messy. Disallow it. + */ +( function testConstKeywordCannotBeUsedWithStatic() +{ + try + { + // should fail + builder.build( + { + 'static const foo': 'val', + } ); + } + catch ( e ) + { + assert.ok( + e.message.search( 'foo' ) !== -1, + "Static const method error message should contain name of property" + ); + + return; + } + + assert.fail( "Should not be able to use static keyword with const" ); +} )(); +