From 030bdef8215e294232188c5d8e26d52bfbf872e8 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 19 May 2011 18:30:55 -0400 Subject: [PATCH] Static keyword cannot be used with const for properties --- lib/member_builder.js | 8 ++++++++ test/test-class_builder-const.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) 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" ); +} )(); +