1
0
Fork 0

Combine tool now removes trailing commas from array and object definitions (for older browsers such as IE6)

closure/master
Mike Gerwitz 2010-12-20 09:18:13 -05:00
parent 5e999b8167
commit 559bb7e0f6
1 changed files with 34 additions and 1 deletions

View File

@ -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