1
0
Fork 0

Began adding prop_parser module and moved existing property keyword parser function into it

closure/master
Mike Gerwitz 2010-12-27 20:56:36 -05:00
parent 9666a5f80f
commit f705f38640
3 changed files with 66 additions and 41 deletions

62
lib/prop_parser.js 100644
View File

@ -0,0 +1,62 @@
/**
* Property keyword parser module
*
* Copyright (C) 2010 Mike Gerwitz
*
* This file is part of ease.js.
*
* ease.js is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Gerwitz
* @package core
*/
/**
* Parses property keywords
*
* @param {string} prop property string, which may contain keywords
*
* @return {{name: string, keywords: Object.<string, boolean>}}
*/
exports.parse = function ( prop )
{
var name = prop,
keywords = [],
keyword_obj = {};
prop = ''+( prop );
if ( prop.length > 8 )
{
if ( prop[ 8 ] === ' ' )
{
// the keywords are all words, except for the last, which is the
// property name
keywords = prop.split( ' ' );
name = keywords.pop();
var i = keywords.length;
while ( i-- )
{
keyword_obj[ keywords[ i ] ] = true;
}
}
}
return {
name: name,
keywords: keyword_obj,
};
}

View File

@ -22,6 +22,8 @@
* @package core * @package core
*/ */
var propParse = require( './prop_parser' ).parse;
/** /**
* Whether getters/setters are supported * Whether getters/setters are supported
@ -154,7 +156,7 @@ exports.propParse = function( data, options )
callback_method = options.method || fvoid, callback_method = options.method || fvoid,
callback_getter = options.getter || fvoid, callback_getter = options.getter || fvoid,
callback_setter = options.setter || fvoid, callback_setter = options.setter || fvoid,
keyword_parser = options.keywordParser || propKeywordStringParser, keyword_parser = options.keywordParser || propParse,
hasOwn = Object.prototype.hasOwnProperty, hasOwn = Object.prototype.hasOwnProperty,
@ -472,45 +474,6 @@ exports.arrayShrink = function( items )
} }
/**
* Parses property keywords
*
* @param {string} prop property string, which may contain keywords
*
* @return {{name: string, keywords: Object.<string, boolean>}}
*/
function propKeywordStringParser( prop )
{
var name = prop,
keywords = [],
keyword_obj = {};
prop = ''+( prop );
if ( prop.length > 8 )
{
if ( prop[ 8 ] === ' ' )
{
// the keywords are all words, except for the last, which is the
// property name
keywords = prop.split( ' ' );
name = keywords.pop();
var i = keywords.length;
while ( i-- )
{
keyword_obj[ keywords[ i ] ] = true;
}
}
}
return {
name: name,
keywords: keyword_obj,
};
}
/** /**
* Appropriately returns defineSecureProp implementation to avoid check on each * Appropriately returns defineSecureProp implementation to avoid check on each
* invocation * invocation

View File

@ -26,7 +26,7 @@ TPL_VAR='/**{CONTENT}**/'
RMTRAIL="$PATH_TOOLS/rmtrail" RMTRAIL="$PATH_TOOLS/rmtrail"
# order matters # order matters
CAT_MODULES="util class interface" CAT_MODULES="prop_parser util class interface"
## ##
# Output template header # Output template header