Permalink
Browse files

Use a "called" flag instead of attribs.length, so that we can safely …

…remove attribs and add other args
  • Loading branch information...
1 parent 2c42545 commit 74e17143a405c04eb3c402bf64ec892b24eb923b @brandonbloom committed Nov 2, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/convert.coffee
View
10 lib/convert.coffee
@@ -36,6 +36,7 @@ exports.convert = (html, stream, options, callback) ->
tag: (tag) ->
code = prefix + tag.name
+ called = false
# Force attribute ordering of `id`, `class`, then others.
attribs = []
@@ -54,11 +55,12 @@ exports.convert = (html, stream, options, callback) ->
attribs = for [key, value] in attribs
" #{key}: #{stringLiteral value}"
code += attribs.join(',')
+ called ||= attribs.length > 0
# Render content
endTag = (suffix) =>
if suffix
- code += ',' if attribs.length > 0
+ code += ',' if called
code += suffix
emit code
if (children = tag.children)?
@@ -67,10 +69,10 @@ exports.convert = (html, stream, options, callback) ->
else
endTag ' ->'
nest -> visit.array children
- else if attribs.length == 0
- endTag('()')
- else
+ else if called
endTag()
+ else
+ endTag('()')
text: (text) ->
return if text.data.match /^\s*$/

0 comments on commit 74e1714

Please sign in to comment.