From f705f38640e86795addec36d31c2aaf333cec98a Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 27 Dec 2010 20:56:36 -0500 Subject: [PATCH] Began adding prop_parser module and moved existing property keyword parser function into it --- lib/prop_parser.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++ lib/util.js | 43 +++----------------------------- tools/combine | 2 +- 3 files changed, 66 insertions(+), 41 deletions(-) create mode 100644 lib/prop_parser.js diff --git a/lib/prop_parser.js b/lib/prop_parser.js new file mode 100644 index 0000000..d3776be --- /dev/null +++ b/lib/prop_parser.js @@ -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 . + * + * @author Mike Gerwitz + * @package core + */ + + +/** + * Parses property keywords + * + * @param {string} prop property string, which may contain keywords + * + * @return {{name: string, keywords: Object.}} + */ +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, + }; +} diff --git a/lib/util.js b/lib/util.js index fc01f60..0fa2e51 100644 --- a/lib/util.js +++ b/lib/util.js @@ -22,6 +22,8 @@ * @package core */ +var propParse = require( './prop_parser' ).parse; + /** * Whether getters/setters are supported @@ -154,7 +156,7 @@ exports.propParse = function( data, options ) callback_method = options.method || fvoid, callback_getter = options.getter || fvoid, callback_setter = options.setter || fvoid, - keyword_parser = options.keywordParser || propKeywordStringParser, + keyword_parser = options.keywordParser || propParse, 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.}} - */ -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 * invocation diff --git a/tools/combine b/tools/combine index ebd4dad..1a0e6ff 100755 --- a/tools/combine +++ b/tools/combine @@ -26,7 +26,7 @@ TPL_VAR='/**{CONTENT}**/' RMTRAIL="$PATH_TOOLS/rmtrail" # order matters -CAT_MODULES="util class interface" +CAT_MODULES="prop_parser util class interface" ## # Output template header