From eab4dbfe4d3554f068ce8e3b515d371232acad36 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 11 Mar 2014 06:37:16 -0400 Subject: [PATCH] Throwing exception on trait static member These will be supported in future versions; this is not something that I want to rush, nor is it something I want to hold up the first GNU release; it is likely to be a much lesser-used feature. --- lib/Trait.js | 9 +++++++++ test/Trait/DefinitionTest.js | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/Trait.js b/lib/Trait.js index c2bb77b..f1f40da 100644 --- a/lib/Trait.js +++ b/lib/Trait.js @@ -152,6 +152,15 @@ function _parseMember( name, value, keywords, h ) throw Error( "Traits may not define __construct" ); } + // will be supported in future versions + if ( keywords['static'] ) + { + throw Error( + "Cannot define member `" + name + "'; static trait " + + "members are currently unsupported" + ); + } + // apply original handler h.apply( this, arguments ); } diff --git a/test/Trait/DefinitionTest.js b/test/Trait/DefinitionTest.js index 465f0a4..fba9190 100644 --- a/test/Trait/DefinitionTest.js +++ b/test/Trait/DefinitionTest.js @@ -390,4 +390,27 @@ require( 'common' ).testCase( }, } )().go(); }, + + + /** + * Support for static members will be added in future versions; this is + * not something that the author wanted to rush for the first trait + * release, as static members have their own odd quirks. + */ + 'Trait static members are prohibited': function() + { + var Sut = this.Sut; + + // property + this.assertThrows( function() + { + Sut( { 'static private foo': 'prop' } ); + } ); + + // method + this.assertThrows( function() + { + Sut( { 'static foo': function() {} } ); + } ); + }, } );