       while (match = HEREDOC_INDENT.exec doc)
         attempt = match[1]
         indent = attempt if indent is null or 0 < attempt.length < indent.length
-    doc = doc.replace /\n#{ indent }/g, '\n' if indent
+    doc = doc.replace /// \n #{indent} ///g, '\n' if indent
     return doc if herecomment
     {quote} = options
     doc = doc.replace /^\n/, ''
     doc = doc.replace /\\([\s\S])/g, (m, c) -> if c in ['\n', quote] then c else m
-    doc = doc.replace /#{quote}/g, '\\$&'
+    doc = doc.replace /// #{quote} ///g, '\\$&'
     doc = @escapeLines doc, yes if quote is "'"
     doc
 

  # interpolations within strings, ad infinitum.
  balancedString: (str, delimited, options) ->
    options or= {}
    slash = delimited[0][0] is '/'
    levels = []
    i = 0
    slen = str.length

JSTOKEN    = /^`[^\\`]*(?:\\.[^\\`]*)*`/

# Regex-matching-regexes.
REGEX = /// ^
  / (?!\s)  # disallow leading whitespace
  (?: [^ [ / \n \\ ]+  # every other things
    | \\.              # anything escaped
    | \[ ( [^\\\]]+ | \\. )* ]  # character class
  )+
  / [imgy]{0,4} (?![A-Za-z])
///
HEREGEX      = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?![A-Za-z])/
HEREGEX_OMIT = /\s+(?:#.*)?/g

