Const keyword now results in static property
parent
030bdef821
commit
2d91a221aa
|
@ -470,7 +470,7 @@ function buildMembers(
|
||||||
|
|
||||||
property: function( name, value, keywords )
|
property: function( name, value, keywords )
|
||||||
{
|
{
|
||||||
var dest = ( keywords[ 'static' ] ) ? sprops : prop_init;
|
var dest = ( keywordStatic( keywords ) ) ? sprops : prop_init;
|
||||||
|
|
||||||
// build a new property, passing in the other members to compare
|
// build a new property, passing in the other members to compare
|
||||||
// against for preventing nonsensical overrides
|
// against for preventing nonsensical overrides
|
||||||
|
@ -481,7 +481,7 @@ function buildMembers(
|
||||||
|
|
||||||
getter: function( name, value, keywords )
|
getter: function( name, value, keywords )
|
||||||
{
|
{
|
||||||
var dest = ( keywords[ 'static' ] ) ? smethods : members;
|
var dest = ( keywordStatic( keywords ) ) ? smethods : members;
|
||||||
|
|
||||||
member_builder.buildGetter(
|
member_builder.buildGetter(
|
||||||
dest, null, name, value, keywords
|
dest, null, name, value, keywords
|
||||||
|
@ -490,7 +490,7 @@ function buildMembers(
|
||||||
|
|
||||||
setter: function( name, value, keywords )
|
setter: function( name, value, keywords )
|
||||||
{
|
{
|
||||||
var dest = ( keywords[ 'static' ] ) ? smethods : members;
|
var dest = ( keywordStatic( keywords ) ) ? smethods : members;
|
||||||
|
|
||||||
member_builder.buildSetter(
|
member_builder.buildSetter(
|
||||||
dest, null, name, value, keywords
|
dest, null, name, value, keywords
|
||||||
|
@ -499,7 +499,7 @@ function buildMembers(
|
||||||
|
|
||||||
method: function( name, func, is_abstract, keywords )
|
method: function( name, func, is_abstract, keywords )
|
||||||
{
|
{
|
||||||
var dest = ( keywords[ 'static' ] ) ? smethods : members;
|
var dest = ( keywordStatic( keywords ) ) ? smethods : members;
|
||||||
|
|
||||||
// constructor check
|
// constructor check
|
||||||
if ( public_methods[ name ] === true )
|
if ( public_methods[ name ] === true )
|
||||||
|
@ -536,6 +536,24 @@ function buildMembers(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the given keywords should result in a static member
|
||||||
|
*
|
||||||
|
* A member will be considered static if the static or const keywords are given.
|
||||||
|
*
|
||||||
|
* @param {Object} keywords keywords to scan
|
||||||
|
*
|
||||||
|
* @return {bool} true if to be static, otherwise false
|
||||||
|
*/
|
||||||
|
function keywordStatic( keywords )
|
||||||
|
{
|
||||||
|
return ( keywords[ 'static' ] || keywords[ 'const' ] )
|
||||||
|
? true
|
||||||
|
: false
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches __initProps() method to the class prototype
|
* Attaches __initProps() method to the class prototype
|
||||||
*
|
*
|
||||||
|
|
|
@ -84,3 +84,22 @@ var common = require( './common' ),
|
||||||
assert.fail( "Should not be able to use static keyword with const" );
|
assert.fail( "Should not be able to use static keyword with const" );
|
||||||
} )();
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The const keyword should result in a static property. The rationale for this
|
||||||
|
* is that, if a value is constant, then instances do not make sense.
|
||||||
|
*/
|
||||||
|
( function testConstKeywordDeclaresPropertiesAsStatic()
|
||||||
|
{
|
||||||
|
var val = 'baz',
|
||||||
|
Foo = builder.build(
|
||||||
|
{
|
||||||
|
'const foo': val,
|
||||||
|
} )
|
||||||
|
;
|
||||||
|
|
||||||
|
assert.equal( val, Foo.$('foo'),
|
||||||
|
"Const keyword should declare properties as static"
|
||||||
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue