module Sprockets::Utils

def concat_javascript_sources(buf, source)

Returns buf String.

source - String source to append
buf - String buffer to append to

semicolon if necessary.
Internal: Accumulate asset source to buffer and append a trailing
def concat_javascript_sources(buf, source)
  return buf if source.bytesize <= 0
  buf << source
  # If the source contains non-ASCII characters, indexing on it becomes O(N).
  # This will lead to O(N^2) performance in string_end_with_semicolon?, so we should use 32 bit encoding to make sure indexing stays O(1)
  source = source.encode(Encoding::UTF_32LE) unless source.ascii_only?
  return buf if string_end_with_semicolon?(source)
  # If the last character in the string was whitespace,
  # such as a newline, then we want to put the semicolon
  # before the whitespace. Otherwise append a semicolon.
  if whitespace = WHITESPACE_ORDINALS[source[-1].ord]
    buf[-1] = ";#{whitespace}"
  else
    buf << ";"
  end
  buf
end