Combine tool now removes trailing commas from array and object definitions (for older browsers such as IE6)
parent
5e999b8167
commit
559bb7e0f6
|
@ -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)
|
# ensure we can locate our template (should be in the /tools dir)
|
||||||
if [ ! -f "$TPL_PATH" ]; then
|
if [ ! -f "$TPL_PATH" ]; then
|
||||||
echo "Error: combine.tpl not found ($TPL_PATH)"
|
echo "Error: combine.tpl not found ($TPL_PATH)"
|
||||||
|
@ -84,7 +116,8 @@ for module in $CAT_MODULES; do
|
||||||
echo "( function( exports )"
|
echo "( function( exports )"
|
||||||
echo "{"
|
echo "{"
|
||||||
|
|
||||||
cat $filename
|
# add the module, removing trailing commas
|
||||||
|
cat $filename | rmtrail
|
||||||
|
|
||||||
echo "} )( exports['$module'] = {} );"
|
echo "} )( exports['$module'] = {} );"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue