parameters: (self, text)
return_statement: return "\n".join(new_lines) + "\n"
docstring: The main entry point.  Takes a text and returns a compressed version.
  
      The compressed version hopefully does the same thing.  Line breaks are
      preserved.
  
      Args:
        text: The text of the code snippet as a multiline string.
  
      Returns:
        The compressed text of the code snippet as a multiline string.
docstring_summary: The main entry point.  Takes a text and returns a compressed version.
docstring_tokens: The main entry point . Takes a text and returns a compressed version .
function: def JSMinify(self, text):
      """The main entry point.  Takes a text and returns a compressed version.
  
      The compressed version hopefully does the same thing.  Line breaks are
      preserved.
  
      Args:
        text: The text of the code snippet as a multiline string.
  
      Returns:
        The compressed text of the code snippet as a multiline string.
      """
      new_lines = []
      for line in re.split(r"\n", text):
        line = line.replace("\t", " ")
        if self.in_comment:
          m = re.search(r"\*/", line)
          if m:
            line = line[m.end():]
            self.in_comment = False
          else:
            new_lines.append("")
            continue
  
        if not self.in_comment:
          line = re.sub(r"/\*.*?\*/", " ", line)
          line = re.sub(r"//.*", "", line)
          m = re.search(r"/\*", line)
          if m:
            line = line[:m.start()]
            self.in_comment = True
  
        # Strip leading and trailing spaces.
        line = re.sub(r"^ +", "", line)
        line = re.sub(r" +$", "", line)
        # A regexp that matches a literal string surrounded by "double quotes".
        # This regexp can handle embedded backslash-escaped characters including
        # embedded backslash-escaped double quotes.
        double_quoted_string = r'"(?:[^"\\]|\\.)*"'
        # A regexp that matches a literal string surrounded by 'double quotes'.
        single_quoted_string = r"'(?:[^'\\]|\\.)*'"
        # A regexp that matches a regexp literal surrounded by /slashes/.
        # Don't allow a regexp to have a ) before the first ( since that's a
        # syntax error and it's probably just two unrelated slashes.
        # Also don't allow it to come after anything that can only be the
        # end of a primary expression.
        slash_quoted_regexp = r"(?<![\w$'\")\]])/(?:(?=\()|(?:[^()/\\]|\\.)+)(?:\([^/\\]|\\.)*/"
        # Replace multiple spaces with a single space.
        line = re.sub("|".join([double_quoted_string,
                                single_quoted_string,
                                slash_quoted_regexp,
                                "( )+"]),
                      self.RemoveSpaces,
                      line)
        # Strip single spaces unless they have an identifier character both before
        # and after the space.  % and $ are counted as identifier characters.
        line = re.sub("|".join([double_quoted_string,
                                single_quoted_string,
                                slash_quoted_regexp,
                                r"(?<![a-zA-Z_0-9$%]) | (?![a-zA-Z_0-9$%])()"]),
                      self.RemoveSpaces,
                      line)
        # Collect keywords and identifiers that are already in use.
        if self.nesting == 0:
          re.sub(r"([a-zA-Z0-9_$%]+)", self.LookAtIdentifier, line)
        function_declaration_regexp = (
            r"\bfunction"              # Function definition keyword...
            r"( [\w$%]+)?"             # ...optional function name...
            r"\([\w$%,]+\)\{")         # ...argument declarations.
        # Unfortunately the keyword-value syntax { key:value } makes the key look
        # like a variable where in fact it is a literal string.  We use the
        # presence or absence of a question mark to try to distinguish between
        # this case and the ternary operator: "condition ? iftrue : iffalse".
        if re.search(r"\?", line):
          block_trailing_colon = r""
        else:
          block_trailing_colon = r"(?![:\w$%])"
        # Variable use.  Cannot follow a period precede a colon.
        variable_use_regexp = r"(?<![.\w$%])[\w$%]+" + block_trailing_colon
        line = re.sub("|".join([double_quoted_string,
                                single_quoted_string,
                                slash_quoted_regexp,
                                r"\{",                  # Curly braces.
                                r"\}",
                                r"\bvar [\w$%,]+",      # var declarations.
                                function_declaration_regexp,
                                variable_use_regexp]),
                      self.Declaration,
                      line)
        new_lines.append(line)
  
      return "\n".join(new_lines) + "\n"
function_tokens: def JSMinify ( self , text ) : new_lines = [ ] for line in re . split ( r"\n" , text ) : line = line . replace ( "\t" , " " ) if self . in_comment : m = re . search ( r"\*/" , line ) if m : line = line [ m . end ( ) : ] self . in_comment = False else : new_lines . append ( "" ) continue if not self . in_comment : line = re . sub ( r"/\*.*?\*/" , " " , line ) line = re . sub ( r"//.*" , "" , line ) m = re . search ( r"/\*" , line ) if m : line = line [ : m . start ( ) ] self . in_comment = True # Strip leading and trailing spaces. line = re . sub ( r"^ +" , "" , line ) line = re . sub ( r" +$" , "" , line ) # A regexp that matches a literal string surrounded by "double quotes". # This regexp can handle embedded backslash-escaped characters including # embedded backslash-escaped double quotes. double_quoted_string = r'"(?:[^"\\]|\\.)*"' # A regexp that matches a literal string surrounded by 'double quotes'. single_quoted_string = r"'(?:[^'\\]|\\.)*'" # A regexp that matches a regexp literal surrounded by /slashes/. # Don't allow a regexp to have a ) before the first ( since that's a # syntax error and it's probably just two unrelated slashes. # Also don't allow it to come after anything that can only be the # end of a primary expression. slash_quoted_regexp = r"(?<![\w$'\")\]])/(?:(?=\()|(?:[^()/\\]|\\.)+)(?:\([^/\\]|\\.)*/" # Replace multiple spaces with a single space. line = re . sub ( "|" . join ( [ double_quoted_string , single_quoted_string , slash_quoted_regexp , "( )+" ] ) , self . RemoveSpaces , line ) # Strip single spaces unless they have an identifier character both before # and after the space.  % and $ are counted as identifier characters. line = re . sub ( "|" . join ( [ double_quoted_string , single_quoted_string , slash_quoted_regexp , r"(?<![a-zA-Z_0-9$%]) | (?![a-zA-Z_0-9$%])()" ] ) , self . RemoveSpaces , line ) # Collect keywords and identifiers that are already in use. if self . nesting == 0 : re . sub ( r"([a-zA-Z0-9_$%]+)" , self . LookAtIdentifier , line ) function_declaration_regexp = ( r"\bfunction" # Function definition keyword... r"( [\w$%]+)?" # ...optional function name... r"\([\w$%,]+\)\{" ) # ...argument declarations. # Unfortunately the keyword-value syntax { key:value } makes the key look # like a variable where in fact it is a literal string.  We use the # presence or absence of a question mark to try to distinguish between # this case and the ternary operator: "condition ? iftrue : iffalse". if re . search ( r"\?" , line ) : block_trailing_colon = r"" else : block_trailing_colon = r"(?![:\w$%])" # Variable use.  Cannot follow a period precede a colon. variable_use_regexp = r"(?<![.\w$%])[\w$%]+" + block_trailing_colon line = re . sub ( "|" . join ( [ double_quoted_string , single_quoted_string , slash_quoted_regexp , r"\{" , # Curly braces. r"\}" , r"\bvar [\w$%,]+" , # var declarations. function_declaration_regexp , variable_use_regexp ] ) , self . Declaration , line ) new_lines . append ( line ) return "\n" . join ( new_lines ) + "\n"