From 559bb7e0f66b420d6c0bd5b5f1689cc5866a7129 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 20 Dec 2010 09:18:13 -0500 Subject: [PATCH] Combine tool now removes trailing commas from array and object definitions (for older browsers such as IE6) --- tools/combine | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/combine b/tools/combine index c11872f..3e2882d 100755 --- a/tools/combine +++ b/tools/combine @@ -60,6 +60,38 @@ tpl_footer() }" } +## +# Removes trailing commas from array and object declarations (certain browsers, +# such as earlier versions of IE, do not parse trailing commas correctly) +# +# This is a very simple (dumb) system. It does not check to ensure we're not +# replacing text inside a string, nor is it 100% certain we're in an array or +# object declaration. However, until such an implementation is needed, I'd like +# to keep it as simple (and fast) as possible. The below implementation is +# suitable for our needs. +## +rmtrail() +{ + cat - \ + | sed -n ' + # copy first line to hold buffer + 1h + + # if not the first line, append to hold buffer + 1!H + + # if last line, process + $ { + # pull from hold and perform replacement + g + s/,\(\s*[]}]\)/\1/g + + # print result + p + } + ' +} + # ensure we can locate our template (should be in the /tools dir) if [ ! -f "$TPL_PATH" ]; then echo "Error: combine.tpl not found ($TPL_PATH)" @@ -84,7 +116,8 @@ for module in $CAT_MODULES; do echo "( function( exports )" echo "{" - cat $filename + # add the module, removing trailing commas + cat $filename | rmtrail echo "} )( exports['$module'] = {} );" done