1
0
Fork 0

Static keyword cannot be used with const for properties

closure/master
Mike Gerwitz 2011-05-19 18:30:55 -04:00
parent f3c1d0f9af
commit 030bdef821
2 changed files with 36 additions and 0 deletions

View File

@ -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; getMemberVisibility( members, keywords )[ name ] = value;
}; };

View File

@ -56,3 +56,31 @@ var common = require( './common' ),
assert.fail( "Should not be able to declare constant methods" ); 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" );
} )();