<s> from __future__ import print_function <EOL> import sys <EOL> import os <EOL> import getopt <EOL> import re <EOL> import string <EOL> import errno <EOL> from jsbeautifier . __version__ import __version__ <EOL> class BeautifierOptions : <EOL> def __init__ ( self ) : <EOL> self . indent_size = <NUM_LIT:4> <EOL> self . indent_char = '<STR_LIT:U+0020>' <EOL> self . indent_with_tabs = False <EOL> self . preserve_newlines = True <EOL> self . max_preserve_newlines = <NUM_LIT:10> <EOL> self . space_in_paren = False <EOL> self . e4x = False <EOL> self . jslint_happy = False <EOL> self . brace_style = '<STR_LIT>' <EOL> self . keep_array_indentation = False <EOL> self . keep_function_indentation = False <EOL> self . eval_code = True <EOL> self . unescape_strings = True <EOL> self . wrap_line_length = <NUM_LIT:0> <EOL> self . break_chained_methods = False <EOL> def __repr__ ( self ) : <EOL> return """<STR_LIT>""" % ( self . indent_size , <EOL> self . indent_char , <EOL> self . preserve_newlines , <EOL> self . max_preserve_newlines , <EOL> self . space_in_paren , <EOL> self . jslint_happy , <EOL> self . indent_with_tabs , <EOL> self . brace_style , <EOL> self . keep_array_indentation , <EOL> self . eval_code , <EOL> self . wrap_line_length , <EOL> self . unescape_strings , <EOL> ) <EOL> class BeautifierFlags : <EOL> def __init__ ( self , mode ) : <EOL> self . mode = mode <EOL> self . parent = None <EOL> self . last_text = '<STR_LIT>' <EOL> self . last_word = '<STR_LIT>' <EOL> self . var_line = False <EOL> self . var_line_tainted = False <EOL> self . var_line_reindented = False <EOL> self . in_html_comment = False <EOL> self . multiline_frame = False <EOL> self . if_block = False <EOL> self . do_block = False <EOL> self . do_while = False <EOL> self . in_case = False <EOL> self . in_case_statement = False <EOL> self . case_body = False <EOL> self . indentation_level = <NUM_LIT:0> <EOL> self . line_indent_level = <NUM_LIT:0> <EOL> self . start_line_index = <NUM_LIT:0> <EOL> self . ternary_depth = <NUM_LIT:0> <EOL> self . had_comment = False <EOL> def apply_base ( self , flags_base , added_newline ) : <EOL> next_indent_level = flags_base . indentation_level ; <EOL> if flags_base . var_line and flags_base . var_line_reindented : <EOL> next_indent_level += <NUM_LIT:1> <EOL> if not added_newline and flags_base . line_indent_level > next_indent_level : <EOL> next_indent_level = flags_base . line_indent_level ; <EOL> self . parent = flags_base ; <EOL> self . last_text = flags_base . last_text <EOL> self . last_word = flags_base . last_word <EOL> self . indentation_level = next_indent_level <EOL> class OutputLine : <EOL> def __init__ ( self ) : <EOL> self . text = [ ] <EOL> def default_options ( ) : <EOL> return BeautifierOptions ( ) <EOL> def beautify ( string , opts = default_options ( ) ) : <EOL> b = Beautifier ( ) <EOL> return b . beautify ( string , opts ) <EOL> def beautify_file ( file_name , opts = default_options ( ) ) : <EOL> if file_name == '<STR_LIT:->' : <EOL> stream = sys . stdin <EOL> else : <EOL> stream = open ( file_name ) <EOL> return beautify ( '<STR_LIT>' . join ( stream . readlines ( ) ) , opts ) ; <EOL> def usage ( stream = sys . stdout ) : <EOL> print ( "<STR_LIT>" + __version__ + """<STR_LIT>""" , file = stream ) <EOL> if stream == sys . stderr : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> class MODE : <EOL> BlockStatement , Statement , ObjectLiteral , ArrayLiteral , ForInitializer , Conditional , Expression = range ( <NUM_LIT:7> ) <EOL> class Beautifier : <EOL> def __init__ ( self , opts = default_options ( ) ) : <EOL> self . opts = opts <EOL> self . blank_state ( ) <EOL> def blank_state ( self ) : <EOL> self . flags = None <EOL> self . previous_flags = None <EOL> self . flag_store = [ ] <EOL> self . input_wanted_newline = False <EOL> if self . opts . indent_with_tabs : <EOL> self . opts . indent_char = "<STR_LIT:\t>" <EOL> self . opts . indent_size = <NUM_LIT:1> <EOL> self . indent_string = self . opts . indent_char * self . opts . indent_size <EOL> self . preindent_string = '<STR_LIT>' <EOL> self . last_type = '<STR_LIT>' <EOL> self . last_last_text = '<STR_LIT>' <EOL> self . input = None <EOL> self . output_lines = [ OutputLine ( ) ] <EOL> self . output_wrapped = False <EOL> self . output_space_before_token = False <EOL> self . whitespace_before_token = [ ] <EOL> self . whitespace = [ "<STR_LIT:\n>" , "<STR_LIT:\r>" , "<STR_LIT:\t>" , "<STR_LIT:U+0020>" ] <EOL> self . wordchar = '<STR_LIT>' <EOL> self . digits = '<STR_LIT>' <EOL> self . punct = '<STR_LIT>' <EOL> self . punct += '<STR_LIT>' <EOL> self . punct = self . punct . split ( '<STR_LIT:U+0020>' ) <EOL> self . line_starters = '<STR_LIT>' . split ( '<STR_LIT:U+002C>' ) <EOL> self . set_mode ( MODE . BlockStatement ) <EOL> self . parser_pos = <NUM_LIT:0> <EOL> def beautify ( self , s , opts = None ) : <EOL> if opts != None : <EOL> self . opts = opts <EOL> if self . opts . brace_style not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise ( Exception ( '<STR_LIT>' ) ) <EOL> self . blank_state ( ) <EOL> while s and s [ <NUM_LIT:0> ] in [ '<STR_LIT:U+0020>' , '<STR_LIT:\t>' ] : <EOL> self . preindent_string += s [ <NUM_LIT:0> ] <EOL> s = s [ <NUM_LIT:1> : ] <EOL> self . input = self . unpack ( s , self . opts . eval_code ) <EOL> self . parser_pos = <NUM_LIT:0> <EOL> handlers = { <EOL> '<STR_LIT>' : self . handle_start_expr , <EOL> '<STR_LIT>' : self . handle_end_expr , <EOL> '<STR_LIT>' : self . handle_start_block , <EOL> '<STR_LIT>' : self . handle_end_block , <EOL> '<STR_LIT>' : self . handle_word , <EOL> '<STR_LIT>' : self . handle_semicolon , <EOL> '<STR_LIT>' : self . handle_string , <EOL> '<STR_LIT>' : self . handle_equals , <EOL> '<STR_LIT>' : self . handle_operator , <EOL> '<STR_LIT>' : self . handle_comma , <EOL> '<STR_LIT>' : self . handle_block_comment , <EOL> '<STR_LIT>' : self . handle_inline_comment , <EOL> '<STR_LIT>' : self . handle_comment , <EOL> '<STR_LIT>' : self . handle_dot , <EOL> '<STR_LIT>' : self . handle_unknown , <EOL> } <EOL> while True : <EOL> self . token_text , token_type = self . get_next_token ( ) <EOL> if token_type == '<STR_LIT>' : <EOL> break <EOL> keep_whitespace = self . opts . keep_array_indentation and self . is_array ( self . flags . mode ) <EOL> self . input_wanted_newline = self . n_newlines > <NUM_LIT:0> <EOL> if keep_whitespace : <EOL> for i in range ( self . n_newlines ) : <EOL> self . append_newline ( i > <NUM_LIT:0> ) <EOL> else : <EOL> if self . opts . max_preserve_newlines != <NUM_LIT:0> and self . n_newlines > self . opts . max_preserve_newlines : <EOL> self . n_newlines = self . opts . max_preserve_newlines <EOL> if self . opts . preserve_newlines and self . n_newlines > <NUM_LIT:1> : <EOL> for i in range ( self . n_newlines ) : <EOL> self . append_newline ( i != <NUM_LIT:0> ) <EOL> handlers [ token_type ] ( self . token_text ) <EOL> if token_type != '<STR_LIT>' and token_type != '<STR_LIT>' and token_type != '<STR_LIT>' and token_type != '<STR_LIT>' : <EOL> self . last_last_text = self . flags . last_text <EOL> self . last_type = token_type <EOL> self . flags . last_text = self . token_text <EOL> self . flags . had_comment = token_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> sweet_code = '<STR_LIT>' . join ( self . output_lines [ <NUM_LIT:0> ] . text ) <EOL> if len ( self . output_lines ) > <NUM_LIT:1> : <EOL> for line_index in range ( <NUM_LIT:1> , len ( self . output_lines ) ) : <EOL> sweet_code += '<STR_LIT:\n>' + '<STR_LIT>' . join ( self . output_lines [ line_index ] . text ) ; <EOL> sweet_code = re . sub ( '<STR_LIT>' , '<STR_LIT>' , sweet_code ) <EOL> return sweet_code <EOL> def unpack ( self , source , evalcode = False ) : <EOL> import jsbeautifier . unpackers as unpackers <EOL> try : <EOL> return unpackers . run ( source , evalcode ) <EOL> except unpackers . UnpackingError as error : <EOL> print ( '<STR_LIT>' , error ) <EOL> return '<STR_LIT>' <EOL> def trim_output ( self , eat_newlines = False ) : <EOL> self . trim_output_line ( self . output_lines [ - <NUM_LIT:1> ] ) <EOL> while eat_newlines and len ( self . output_lines ) > <NUM_LIT:1> and len ( self . output_lines [ - <NUM_LIT:1> ] . text ) == <NUM_LIT:0> : <EOL> self . output_lines . pop ( ) <EOL> self . trim_output_line ( self . output_lines [ - <NUM_LIT:1> ] ) <EOL> def trim_output_line ( self , line ) : <EOL> while len ( line . text ) and ( <EOL> line . text [ - <NUM_LIT:1> ] == '<STR_LIT:U+0020>' or line . text [ - <NUM_LIT:1> ] == self . indent_string or line . text [ - <NUM_LIT:1> ] == self . preindent_string ) : <EOL> line . text . pop ( ) <EOL> def is_special_word ( self , s ) : <EOL> return s in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def is_array ( self , mode ) : <EOL> return mode == MODE . ArrayLiteral <EOL> def is_expression ( self , mode ) : <EOL> return mode in [ MODE . Expression , MODE . ForInitializer , MODE . Conditional ] <EOL> def just_added_newline ( self ) : <EOL> line = self . output_lines [ - <NUM_LIT:1> ] <EOL> return len ( line . text ) == <NUM_LIT:0> <EOL> def just_added_blankline ( self ) : <EOL> if self . just_added_newline ( ) : <EOL> if len ( self . output_lines ) == <NUM_LIT:1> : <EOL> return True <EOL> line = self . output_lines [ - <NUM_LIT:2> ] <EOL> return len ( line . text ) == <NUM_LIT:0> <EOL> return False <EOL> def allow_wrap_or_preserved_newline ( self , token_text , force_linewrap = False ) : <EOL> if self . opts . wrap_line_length > <NUM_LIT:0> and not force_linewrap : <EOL> line = self . output_lines [ - <NUM_LIT:1> ] <EOL> if len ( line . text ) > <NUM_LIT:0> : <EOL> proposed_line_length = len ( '<STR_LIT>' . join ( line . text ) ) + len ( token_text ) <EOL> if self . output_space_before_token : <EOL> proposed_line_length += <NUM_LIT:1> <EOL> if proposed_line_length >= self . opts . wrap_line_length : <EOL> force_linewrap = True <EOL> if ( ( self . opts . preserve_newlines and self . input_wanted_newline ) or force_linewrap ) and not self . just_added_newline ( ) : <EOL> self . append_newline ( preserve_statement_flags = True ) <EOL> if not ( self . is_array ( self . flags . mode ) or self . is_expression ( self . flags . mode ) ) : <EOL> self . output_wrapped = True <EOL> def append_newline ( self , force_newline = False , preserve_statement_flags = False ) : <EOL> self . output_wrapped = False <EOL> self . output_space_before_token = False <EOL> if not preserve_statement_flags : <EOL> if self . flags . last_text != '<STR_LIT:;>' : <EOL> while self . flags . mode == MODE . Statement and not self . flags . if_block and not self . flags . do_block : <EOL> self . restore_mode ( ) ; <EOL> if len ( self . output_lines ) == <NUM_LIT:1> and self . just_added_newline ( ) : <EOL> return <EOL> if force_newline or not self . just_added_newline ( ) : <EOL> self . flags . multiline_frame = True <EOL> self . output_lines . append ( OutputLine ( ) ) <EOL> def append_token_line_indentation ( self ) : <EOL> if self . just_added_newline ( ) : <EOL> line = self . output_lines [ - <NUM_LIT:1> ] <EOL> if self . opts . keep_array_indentation and self . is_array ( self . flags . mode ) and self . input_wanted_newline : <EOL> line . text . append ( '<STR_LIT>' ) ; <EOL> for item in self . whitespace_before_token : <EOL> line . text . append ( item ) <EOL> else : <EOL> if self . preindent_string != '<STR_LIT>' : <EOL> line . text . append ( self . preindent_string ) <EOL> level = self . flags . indentation_level ; <EOL> if self . flags . var_line and self . flags . var_line_reindented : <EOL> level += <NUM_LIT:1> <EOL> if self . output_wrapped : <EOL> level += <NUM_LIT:1> <EOL> self . append_indent_string ( level ) <EOL> def append_indent_string ( self , level ) : <EOL> if len ( self . output_lines ) > <NUM_LIT:1> : <EOL> line = self . output_lines [ - <NUM_LIT:1> ] <EOL> self . flags . line_indent_level = level <EOL> for i in range ( level ) : <EOL> line . text . append ( self . indent_string ) <EOL> def append_token_space_before ( self ) : <EOL> line = self . output_lines [ - <NUM_LIT:1> ] <EOL> if self . output_space_before_token and len ( line . text ) and line . text [ - <NUM_LIT:1> ] not in [ '<STR_LIT:U+0020>' , self . indent_string ] : <EOL> line . text . append ( '<STR_LIT:U+0020>' ) <EOL> def append_token ( self , s ) : <EOL> self . append_token_line_indentation ( ) <EOL> self . output_wrapped = False <EOL> self . append_token_space_before ( ) <EOL> self . output_space_before_token = False <EOL> self . output_lines [ - <NUM_LIT:1> ] . text . append ( s ) <EOL> def indent ( self ) : <EOL> self . flags . indentation_level += <NUM_LIT:1> <EOL> def deindent ( self ) : <EOL> allow_deindent = self . flags . indentation_level > <NUM_LIT:0> and ( ( self . flags . parent == None ) or self . flags . indentation_level > self . flags . parent . indentation_level ) <EOL> if allow_deindent : <EOL> self . flags . indentation_level -= <NUM_LIT:1> <EOL> def remove_redundant_indentation ( self , frame ) : <EOL> if frame . multiline_frame : <EOL> return <EOL> index = frame . start_line_index <EOL> splice_index = <NUM_LIT:0> <EOL> while index < len ( self . output_lines ) : <EOL> line = self . output_lines [ index ] <EOL> index += <NUM_LIT:1> <EOL> if len ( line . text ) == <NUM_LIT:0> : <EOL> continue <EOL> if self . preindent_string != '<STR_LIT>' and line . text [ <NUM_LIT:0> ] == self . preindent_string : <EOL> splice_index = <NUM_LIT:1> <EOL> else : <EOL> splice_index = <NUM_LIT:0> <EOL> if line . text [ splice_index ] == self . indent_string : <EOL> del line . text [ splice_index ] <EOL> def set_mode ( self , mode ) : <EOL> if self . flags : <EOL> self . flag_store . append ( self . flags ) <EOL> self . previous_flags = self . flags <EOL> else : <EOL> self . previous_flags = BeautifierFlags ( mode ) <EOL> self . flags = BeautifierFlags ( mode ) <EOL> self . flags . apply_base ( self . previous_flags , self . just_added_newline ( ) ) ; <EOL> self . flags . start_line_index = len ( self . output_lines ) <EOL> def restore_mode ( self ) : <EOL> if len ( self . flag_store ) > <NUM_LIT:0> : <EOL> self . previous_flags = self . flags <EOL> self . flags = self . flag_store . pop ( ) <EOL> def start_of_object_property ( self ) : <EOL> return self . flags . mode == MODE . ObjectLiteral and self . flags . last_text == '<STR_LIT::>' and self . flags . ternary_depth == <NUM_LIT:0> <EOL> def start_of_statement ( self ) : <EOL> if ( self . flags . last_text == '<STR_LIT>' or ( self . flags . last_text == '<STR_LIT>' and self . token_text != '<STR_LIT>' ) or ( self . last_type == '<STR_LIT>' and ( self . previous_flags . mode == MODE . ForInitializer or self . previous_flags . mode == MODE . Conditional ) ) ) : <EOL> self . allow_wrap_or_preserved_newline ( self . token_text , self . token_text in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ; <EOL> self . set_mode ( MODE . Statement ) ; <EOL> if self . just_added_newline ( ) : <EOL> self . indent ( ) <EOL> self . output_wrapped = False <EOL> return True <EOL> else : <EOL> return False <EOL> def is_next ( self , find ) : <EOL> local_pos = self . parser_pos <EOL> if local_pos >= len ( self . input ) : <EOL> return False <EOL> c = self . input [ local_pos ] <EOL> while ( c in self . whitespace ) and c != find : <EOL> local_pos += <NUM_LIT:1> <EOL> if local_pos >= len ( self . input ) : <EOL> return False <EOL> c = self . input [ local_pos ] <EOL> return c == find <EOL> def get_next_token ( self ) : <EOL> self . n_newlines = <NUM_LIT:0> <EOL> if self . parser_pos >= len ( self . input ) : <EOL> return '<STR_LIT>' , '<STR_LIT>' <EOL> self . input_wanted_newline = False <EOL> self . whitespace_before_token = [ ] <EOL> c = self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> while c in self . whitespace : <EOL> if c == '<STR_LIT:\n>' : <EOL> self . n_newlines += <NUM_LIT:1> <EOL> self . whitespace_before_token = [ ] <EOL> elif c == self . indent_string : <EOL> self . whitespace_before_token . append ( self . indent_string ) <EOL> elif c != '<STR_LIT:\r>' : <EOL> self . whitespace_before_token . append ( '<STR_LIT:U+0020>' ) <EOL> if self . parser_pos >= len ( self . input ) : <EOL> return '<STR_LIT>' , '<STR_LIT>' <EOL> c = self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if c in self . wordchar : <EOL> if self . parser_pos < len ( self . input ) : <EOL> while self . input [ self . parser_pos ] in self . wordchar : <EOL> c = c + self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos == len ( self . input ) : <EOL> break <EOL> if self . parser_pos != len ( self . input ) and self . input [ self . parser_pos ] in '<STR_LIT>' and re . match ( '<STR_LIT>' , c ) : <EOL> sign = self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> t = self . get_next_token ( ) <EOL> c += sign + t [ <NUM_LIT:0> ] <EOL> return c , '<STR_LIT>' <EOL> if c == '<STR_LIT>' : <EOL> return c , '<STR_LIT>' <EOL> return c , '<STR_LIT>' <EOL> if c in '<STR_LIT>' : <EOL> return c , '<STR_LIT>' <EOL> if c in '<STR_LIT>' : <EOL> return c , '<STR_LIT>' <EOL> if c == '<STR_LIT:{>' : <EOL> return c , '<STR_LIT>' <EOL> if c == '<STR_LIT:}>' : <EOL> return c , '<STR_LIT>' <EOL> if c == '<STR_LIT:;>' : <EOL> return c , '<STR_LIT>' <EOL> if c == '<STR_LIT:/>' : <EOL> comment = '<STR_LIT>' <EOL> inline_comment = True <EOL> if self . input [ self . parser_pos ] == '<STR_LIT:*>' : <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos < len ( self . input ) : <EOL> while not ( self . input [ self . parser_pos ] == '<STR_LIT:*>' and self . parser_pos + <NUM_LIT:1> < len ( self . input ) and self . input [ self . parser_pos + <NUM_LIT:1> ] == '<STR_LIT:/>' ) and self . parser_pos < len ( self . input ) : <EOL> c = self . input [ self . parser_pos ] <EOL> comment += c <EOL> if c in '<STR_LIT:\r\n>' : <EOL> inline_comment = False <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos >= len ( self . input ) : <EOL> break <EOL> self . parser_pos += <NUM_LIT:2> <EOL> if inline_comment and self . n_newlines == <NUM_LIT:0> : <EOL> return '<STR_LIT>' + comment + '<STR_LIT>' , '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' + comment + '<STR_LIT>' , '<STR_LIT>' <EOL> if self . input [ self . parser_pos ] == '<STR_LIT:/>' : <EOL> comment = c <EOL> while self . input [ self . parser_pos ] not in '<STR_LIT:\r\n>' : <EOL> comment += self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos >= len ( self . input ) : <EOL> break <EOL> return comment , '<STR_LIT>' <EOL> if c == "<STR_LIT:'>" or c == '<STR_LIT:">' or ( ( c == '<STR_LIT:/>' ) or ( self . opts . e4x and c == "<STR_LIT:<>" and re . match ( '<STR_LIT>' , self . input [ self . parser_pos - <NUM_LIT:1> : ] ) ) ) and ( ( self . last_type == '<STR_LIT>' and self . is_special_word ( self . flags . last_text ) ) or ( self . last_type == '<STR_LIT>' and self . previous_flags . mode in [ MODE . Conditional , MODE . ForInitializer ] ) or ( self . last_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) : <EOL> sep = c <EOL> esc = False <EOL> esc1 = <NUM_LIT:0> <EOL> esc2 = <NUM_LIT:0> <EOL> resulting_string = c <EOL> in_char_class = False <EOL> if self . parser_pos < len ( self . input ) : <EOL> if sep == '<STR_LIT:/>' : <EOL> in_char_class = False <EOL> while esc or in_char_class or self . input [ self . parser_pos ] != sep : <EOL> resulting_string += self . input [ self . parser_pos ] <EOL> if not esc : <EOL> esc = self . input [ self . parser_pos ] == '<STR_LIT:\\>' <EOL> if self . input [ self . parser_pos ] == '<STR_LIT:[>' : <EOL> in_char_class = True <EOL> elif self . input [ self . parser_pos ] == '<STR_LIT:]>' : <EOL> in_char_class = False <EOL> else : <EOL> esc = False <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos >= len ( self . input ) : <EOL> return resulting_string , '<STR_LIT>' <EOL> elif self . opts . e4x and sep == '<STR_LIT:<>' : <EOL> xmlRegExp = re . compile ( '<STR_LIT>' ) <EOL> xmlStr = self . input [ self . parser_pos - <NUM_LIT:1> : ] <EOL> match = xmlRegExp . match ( xmlStr ) <EOL> if match : <EOL> rootTag = match . group ( <NUM_LIT:2> ) <EOL> depth = <NUM_LIT:0> <EOL> while ( match ) : <EOL> isEndTag = match . group ( <NUM_LIT:1> ) <EOL> tagName = match . group ( <NUM_LIT:2> ) <EOL> isSingletonTag = ( match . groups ( ) [ - <NUM_LIT:1> ] != "<STR_LIT>" ) or ( match . group ( <NUM_LIT:2> ) [ <NUM_LIT:0> : <NUM_LIT:8> ] == "<STR_LIT>" ) <EOL> if tagName == rootTag and not isSingletonTag : <EOL> if isEndTag : <EOL> depth -= <NUM_LIT:1> <EOL> else : <EOL> depth += <NUM_LIT:1> <EOL> if depth <= <NUM_LIT:0> : <EOL> break <EOL> match = xmlRegExp . search ( xmlStr , match . end ( ) ) <EOL> if match : <EOL> xmlLength = match . end ( ) <EOL> else : <EOL> xmlLength = len ( xmlStr ) <EOL> self . parser_pos += xmlLength - <NUM_LIT:1> <EOL> return xmlStr [ : xmlLength ] , '<STR_LIT>' <EOL> else : <EOL> while esc or self . input [ self . parser_pos ] != sep : <EOL> resulting_string += self . input [ self . parser_pos ] <EOL> if esc1 and esc1 >= esc2 : <EOL> try : <EOL> esc1 = int ( resulting_string [ - esc2 : ] , <NUM_LIT:16> ) <EOL> except Exception : <EOL> esc1 = False <EOL> if esc1 and esc1 >= <NUM_LIT> and esc1 <= <NUM_LIT> : <EOL> esc1 = chr ( esc1 ) <EOL> resulting_string = resulting_string [ : - <NUM_LIT:2> - esc2 ] <EOL> if esc1 == sep or esc1 == '<STR_LIT:\\>' : <EOL> resulting_string += '<STR_LIT:\\>' <EOL> resulting_string += esc1 <EOL> esc1 = <NUM_LIT:0> <EOL> if esc1 : <EOL> esc1 += <NUM_LIT:1> <EOL> elif not esc : <EOL> esc = self . input [ self . parser_pos ] == '<STR_LIT:\\>' <EOL> else : <EOL> esc = False <EOL> if self . opts . unescape_strings : <EOL> if self . input [ self . parser_pos ] == '<STR_LIT:x>' : <EOL> esc1 += <NUM_LIT:1> <EOL> esc2 = <NUM_LIT:2> <EOL> elif self . input [ self . parser_pos ] == '<STR_LIT:u>' : <EOL> esc1 += <NUM_LIT:1> <EOL> esc2 = <NUM_LIT:4> <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos >= len ( self . input ) : <EOL> return resulting_string , '<STR_LIT>' <EOL> self . parser_pos += <NUM_LIT:1> <EOL> resulting_string += sep <EOL> if sep == '<STR_LIT:/>' : <EOL> while self . parser_pos < len ( self . input ) and self . input [ self . parser_pos ] in self . wordchar : <EOL> resulting_string += self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> return resulting_string , '<STR_LIT>' <EOL> if c == '<STR_LIT:#>' : <EOL> if len ( self . output_lines ) == <NUM_LIT:1> and len ( self . output_lines [ <NUM_LIT:0> ] . text ) == <NUM_LIT:0> and len ( self . input ) > self . parser_pos and self . input [ self . parser_pos ] == '<STR_LIT:!>' : <EOL> resulting_string = c <EOL> while self . parser_pos < len ( self . input ) and c != '<STR_LIT:\n>' : <EOL> c = self . input [ self . parser_pos ] <EOL> resulting_string += c <EOL> self . parser_pos += <NUM_LIT:1> <EOL> return resulting_string . strip ( ) + '<STR_LIT:\n>' , '<STR_LIT>' <EOL> sharp = '<STR_LIT:#>' <EOL> if self . parser_pos < len ( self . input ) and self . input [ self . parser_pos ] in self . digits : <EOL> while True : <EOL> c = self . input [ self . parser_pos ] <EOL> sharp += c <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos >= len ( self . input ) or c == '<STR_LIT:#>' or c == '<STR_LIT:=>' : <EOL> break <EOL> if c == '<STR_LIT:#>' or self . parser_pos >= len ( self . input ) : <EOL> pass <EOL> elif self . input [ self . parser_pos ] == '<STR_LIT:[>' and self . input [ self . parser_pos + <NUM_LIT:1> ] == '<STR_LIT:]>' : <EOL> sharp += '<STR_LIT>' <EOL> self . parser_pos += <NUM_LIT:2> <EOL> elif self . input [ self . parser_pos ] == '<STR_LIT:{>' and self . input [ self . parser_pos + <NUM_LIT:1> ] == '<STR_LIT:}>' : <EOL> sharp += '<STR_LIT:{}>' <EOL> self . parser_pos += <NUM_LIT:2> <EOL> return sharp , '<STR_LIT>' <EOL> if c == '<STR_LIT:<>' and self . input [ self . parser_pos - <NUM_LIT:1> : self . parser_pos + <NUM_LIT:3> ] == '<STR_LIT>' : <EOL> self . parser_pos += <NUM_LIT:3> <EOL> c = '<STR_LIT>' <EOL> while self . parser_pos < len ( self . input ) and self . input [ self . parser_pos ] != '<STR_LIT:\n>' : <EOL> c += self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> self . flags . in_html_comment = True <EOL> return c , '<STR_LIT>' <EOL> if c == '<STR_LIT:->' and self . flags . in_html_comment and self . input [ self . parser_pos - <NUM_LIT:1> : self . parser_pos + <NUM_LIT:2> ] == '<STR_LIT>' : <EOL> self . flags . in_html_comment = False <EOL> self . parser_pos += <NUM_LIT:2> <EOL> return '<STR_LIT>' , '<STR_LIT>' <EOL> if c == '<STR_LIT:.>' : <EOL> return c , '<STR_LIT>' <EOL> if c in self . punct : <EOL> while self . parser_pos < len ( self . input ) and c + self . input [ self . parser_pos ] in self . punct : <EOL> c += self . input [ self . parser_pos ] <EOL> self . parser_pos += <NUM_LIT:1> <EOL> if self . parser_pos >= len ( self . input ) : <EOL> break <EOL> if c == '<STR_LIT:U+002C>' : <EOL> return c , '<STR_LIT>' <EOL> if c == '<STR_LIT:=>' : <EOL> return c , '<STR_LIT>' <EOL> return c , '<STR_LIT>' <EOL> return c , '<STR_LIT>' <EOL> def handle_start_expr ( self , token_text ) : <EOL> if self . start_of_statement ( ) : <EOL> pass <EOL> next_mode = MODE . Expression <EOL> if token_text == '<STR_LIT:[>' : <EOL> if self . last_type == '<STR_LIT>' or self . flags . last_text == '<STR_LIT:)>' : <EOL> if self . flags . last_text in self . line_starters : <EOL> self . output_space_before_token = True <EOL> self . set_mode ( next_mode ) <EOL> self . append_token ( token_text ) <EOL> self . indent ( ) <EOL> if self . opts . space_in_paren : <EOL> self . output_space_before_token = True <EOL> return <EOL> next_mode = MODE . ArrayLiteral <EOL> if self . is_array ( self . flags . mode ) : <EOL> if self . flags . last_text == '<STR_LIT:[>' or ( <EOL> self . flags . last_text == '<STR_LIT:U+002C>' and ( self . last_last_text == '<STR_LIT:]>' or self . last_last_text == '<STR_LIT:}>' ) ) : <EOL> if not self . opts . keep_array_indentation : <EOL> self . append_newline ( ) <EOL> else : <EOL> if self . flags . last_text == '<STR_LIT>' : <EOL> next_mode = MODE . ForInitializer <EOL> elif self . flags . last_text in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> next_mode = MODE . Conditional <EOL> else : <EOL> next_mode = MODE . Expression <EOL> if self . flags . last_text == '<STR_LIT:;>' or self . last_type == '<STR_LIT>' : <EOL> self . append_newline ( ) <EOL> elif self . last_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] or self . flags . last_text == '<STR_LIT:.>' : <EOL> self . allow_wrap_or_preserved_newline ( token_text , self . input_wanted_newline ) ; <EOL> self . output_wrapped = False ; <EOL> elif self . last_type not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . output_space_before_token = True <EOL> elif self . flags . last_word == '<STR_LIT>' or self . flags . last_word == '<STR_LIT>' : <EOL> if self . opts . jslint_happy : <EOL> self . output_space_before_token = True <EOL> elif self . flags . last_text in self . line_starters or self . flags . last_text == '<STR_LIT>' : <EOL> self . output_space_before_token = True <EOL> if self . last_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if not self . start_of_object_property ( ) : <EOL> self . allow_wrap_or_preserved_newline ( token_text ) <EOL> self . set_mode ( next_mode ) <EOL> self . append_token ( token_text ) <EOL> if self . opts . space_in_paren : <EOL> self . output_space_before_token = True <EOL> self . indent ( ) <EOL> def handle_end_expr ( self , token_text ) : <EOL> while self . flags . mode == MODE . Statement : <EOL> self . restore_mode ( ) <EOL> if self . token_text == '<STR_LIT:]>' and self . is_array ( self . flags . mode ) and self . flags . multiline_frame and not self . opts . keep_array_indentation : <EOL> self . append_newline ( ) <EOL> if self . flags . multiline_frame : <EOL> self . allow_wrap_or_preserved_newline ( token_text ) <EOL> if self . opts . space_in_paren : <EOL> if self . last_type == '<STR_LIT>' : <EOL> self . output_space_before_token = False <EOL> self . trim_output ( ) <EOL> else : <EOL> self . output_space_before_token = True <EOL> if self . token_text == '<STR_LIT:]>' and self . opts . keep_array_indentation : <EOL> self . append_token ( token_text ) <EOL> self . restore_mode ( ) <EOL> else : <EOL> self . restore_mode ( ) <EOL> self . append_token ( token_text ) <EOL> self . remove_redundant_indentation ( self . previous_flags ) ; <EOL> if self . flags . do_while and self . previous_flags . mode == MODE . Conditional : <EOL> self . previous_flags . mode = MODE . Expression <EOL> self . flags . do_block = False <EOL> self . flags . do_while = False <EOL> def handle_start_block ( self , token_text ) : <EOL> self . set_mode ( MODE . BlockStatement ) <EOL> empty_braces = self . is_next ( '<STR_LIT:}>' ) <EOL> empty_anonymous_function = empty_braces and self . flags . last_word == '<STR_LIT>' and self . last_type == '<STR_LIT>' <EOL> if self . opts . brace_style == '<STR_LIT>' : <EOL> if self . last_type != '<STR_LIT>' and ( empty_anonymous_function or <EOL> self . last_type == '<STR_LIT>' or <EOL> ( self . is_special_word ( self . flags . last_text ) and self . flags . last_text != '<STR_LIT>' ) ) : <EOL> self . output_space_before_token = True <EOL> else : <EOL> self . append_newline ( ) <EOL> else : <EOL> if self . last_type not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if self . last_type == '<STR_LIT>' : <EOL> self . append_newline ( ) <EOL> else : <EOL> self . output_space_before_token = True <EOL> else : <EOL> if self . is_array ( self . previous_flags . mode ) and self . flags . last_text == '<STR_LIT:U+002C>' : <EOL> if self . last_last_text == '<STR_LIT:}>' : <EOL> self . output_space_before_token = True <EOL> else : <EOL> self . append_newline ( ) <EOL> self . append_token ( token_text ) <EOL> self . indent ( ) <EOL> def handle_end_block ( self , token_text ) : <EOL> while self . flags . mode == MODE . Statement : <EOL> self . restore_mode ( ) <EOL> empty_braces = self . last_type == '<STR_LIT>' ; <EOL> if self . opts . brace_style == '<STR_LIT>' : <EOL> if not empty_braces : <EOL> self . append_newline ( ) <EOL> else : <EOL> if not empty_braces : <EOL> if self . is_array ( self . flags . mode ) and self . opts . keep_array_indentation : <EOL> self . opts . keep_array_indentation = False <EOL> self . append_newline ( ) <EOL> self . opts . keep_array_indentation = True <EOL> else : <EOL> self . append_newline ( ) <EOL> self . restore_mode ( ) <EOL> self . append_token ( token_text ) <EOL> def handle_word ( self , token_text ) : <EOL> if self . start_of_statement ( ) : <EOL> pass <EOL> elif self . input_wanted_newline and not self . is_expression ( self . flags . mode ) and ( self . last_type != '<STR_LIT>' or ( self . flags . last_text == '<STR_LIT>' or self . flags . last_text == '<STR_LIT>' ) ) and self . last_type != '<STR_LIT>' and ( self . opts . preserve_newlines or self . flags . last_text != '<STR_LIT>' ) : <EOL> self . append_newline ( ) <EOL> if self . flags . do_block and not self . flags . do_while : <EOL> if token_text == '<STR_LIT>' : <EOL> self . output_space_before_token = True <EOL> self . append_token ( token_text ) <EOL> self . output_space_before_token = True <EOL> self . flags . do_while = True <EOL> return <EOL> else : <EOL> self . append_newline ( ) <EOL> self . flags . do_block = False <EOL> if self . flags . if_block : <EOL> if token_text != '<STR_LIT>' : <EOL> while self . flags . mode == MODE . Statement : <EOL> self . restore_mode ( ) <EOL> self . flags . if_block = False ; <EOL> if token_text == '<STR_LIT>' or ( token_text == '<STR_LIT:default>' and self . flags . in_case_statement ) : <EOL> self . append_newline ( ) <EOL> if self . flags . case_body or self . opts . jslint_happy : <EOL> self . flags . case_body = False <EOL> self . deindent ( ) <EOL> self . append_token ( token_text ) <EOL> self . flags . in_case = True <EOL> self . flags . in_case_statement = True <EOL> return <EOL> if token_text == '<STR_LIT>' : <EOL> if self . flags . var_line and self . flags . last_text != '<STR_LIT:=>' : <EOL> self . flags . var_line_reindented = not self . opts . keep_function_indentation <EOL> if self . flags . last_text in [ '<STR_LIT:}>' , '<STR_LIT:;>' ] or ( self . just_added_newline ( ) and not self . flags . last_text in [ '<STR_LIT:{>' , '<STR_LIT::>' , '<STR_LIT:=>' , '<STR_LIT:U+002C>' ] ) : <EOL> if not self . just_added_blankline ( ) and not self . flags . had_comment : <EOL> self . append_newline ( ) <EOL> self . append_newline ( True ) <EOL> if self . last_type == '<STR_LIT>' : <EOL> if self . flags . last_text in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . output_space_before_token = True <EOL> else : <EOL> self . append_newline ( ) <EOL> elif self . last_type == '<STR_LIT>' or self . flags . last_text == '<STR_LIT:=>' : <EOL> self . output_space_before_token = True <EOL> elif self . is_expression ( self . flags . mode ) : <EOL> pass <EOL> else : <EOL> self . append_newline ( ) <EOL> if self . last_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if not self . start_of_object_property ( ) : <EOL> self . allow_wrap_or_preserved_newline ( token_text ) <EOL> if token_text == '<STR_LIT>' : <EOL> self . append_token ( token_text ) <EOL> self . flags . last_word = token_text <EOL> return <EOL> prefix = '<STR_LIT>' <EOL> if self . last_type == '<STR_LIT>' : <EOL> if token_text not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> prefix = '<STR_LIT>' <EOL> else : <EOL> if self . opts . brace_style in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> prefix = '<STR_LIT>' <EOL> else : <EOL> prefix = '<STR_LIT>' <EOL> self . output_space_before_token = True <EOL> elif self . last_type == '<STR_LIT>' and self . flags . mode == MODE . BlockStatement : <EOL> prefix = '<STR_LIT>' <EOL> elif self . last_type == '<STR_LIT>' and self . is_expression ( self . flags . mode ) : <EOL> prefix = '<STR_LIT>' <EOL> elif self . last_type == '<STR_LIT>' : <EOL> prefix = '<STR_LIT>' <EOL> elif self . last_type == '<STR_LIT>' : <EOL> prefix = '<STR_LIT>' <EOL> elif self . last_type == '<STR_LIT>' : <EOL> prefix = '<STR_LIT>' <EOL> elif self . last_type == '<STR_LIT>' : <EOL> self . output_space_before_token = True <EOL> prefix = '<STR_LIT>' <EOL> if token_text in self . line_starters : <EOL> if self . flags . last_text == '<STR_LIT>' : <EOL> prefix = '<STR_LIT>' <EOL> else : <EOL> prefix = '<STR_LIT>' <EOL> if token_text in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if self . last_type != '<STR_LIT>' or self . opts . brace_style == '<STR_LIT>' or self . opts . brace_style == '<STR_LIT>' : <EOL> self . append_newline ( ) <EOL> else : <EOL> self . trim_output ( True ) <EOL> line = self . output_lines [ - <NUM_LIT:1> ] <EOL> if line . text [ - <NUM_LIT:1> ] != '<STR_LIT:}>' : <EOL> self . append_newline ( ) <EOL> self . output_space_before_token = True <EOL> elif prefix == '<STR_LIT>' : <EOL> if self . is_special_word ( self . flags . last_text ) : <EOL> self . output_space_before_token = True <EOL> elif self . last_type != '<STR_LIT>' : <EOL> if ( self . last_type != '<STR_LIT>' or token_text != '<STR_LIT>' ) and self . flags . last_text != '<STR_LIT::>' : <EOL> if token_text == '<STR_LIT>' and self . flags . last_word == '<STR_LIT>' and self . flags . last_text != '<STR_LIT:{>' : <EOL> self . output_space_before_token = True <EOL> else : <EOL> self . flags . var_line = False <EOL> self . flags . var_line_reindented = False <EOL> self . append_newline ( ) <EOL> elif token_text in self . line_starters and self . flags . last_text != '<STR_LIT:)>' : <EOL> self . flags . var_line = False <EOL> self . flags . var_line_reindented = False <EOL> self . append_newline ( ) <EOL> elif self . is_array ( self . flags . mode ) and self . flags . last_text == '<STR_LIT:U+002C>' and self . last_last_text == '<STR_LIT:}>' : <EOL> self . append_newline ( ) <EOL> elif prefix == '<STR_LIT>' : <EOL> self . output_space_before_token = True <EOL> self . append_token ( token_text ) <EOL> self . flags . last_word = token_text <EOL> if token_text == '<STR_LIT>' : <EOL> self . flags . var_line = True <EOL> self . flags . var_line_reindented = False <EOL> self . flags . var_line_tainted = False <EOL> if token_text == '<STR_LIT>' : <EOL> self . flags . do_block = True <EOL> if token_text == '<STR_LIT>' : <EOL> self . flags . if_block = True <EOL> def handle_semicolon ( self , token_text ) : <EOL> if self . start_of_statement ( ) : <EOL> self . output_space_before_token = False <EOL> while self . flags . mode == MODE . Statement and not self . flags . if_block and not self . flags . do_block : <EOL> self . restore_mode ( ) <EOL> self . append_token ( token_text ) <EOL> self . flags . var_line = False <EOL> self . flags . var_line_reindented = False <EOL> if self . flags . mode == MODE . ObjectLiteral : <EOL> self . flags . mode = MODE . BlockStatement <EOL> def handle_string ( self , token_text ) : <EOL> if self . start_of_statement ( ) : <EOL> self . output_space_before_token = True <EOL> elif self . last_type == '<STR_LIT>' : <EOL> self . output_space_before_token = True <EOL> elif self . last_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if not self . start_of_object_property ( ) : <EOL> self . allow_wrap_or_preserved_newline ( token_text ) <EOL> else : <EOL> self . append_newline ( ) <EOL> self . append_token ( token_text ) <EOL> def handle_equals ( self , token_text ) : <EOL> if self . flags . var_line : <EOL> self . flags . var_line_tainted = True <EOL> self . output_space_before_token = True <EOL> self . append_token ( token_text ) <EOL> self . output_space_before_token = True <EOL> def handle_comma ( self , token_text ) : <EOL> if self . flags . var_line : <EOL> if self . is_expression ( self . flags . mode ) or self . last_type == '<STR_LIT>' : <EOL> self . flags . var_line_tainted = False <EOL> if self . flags . var_line : <EOL> self . flags . var_line_reindented = True <EOL> self . append_token ( token_text ) <EOL> if self . flags . var_line_tainted : <EOL> self . flags . var_line_tainted = False <EOL> self . append_newline ( ) <EOL> else : <EOL> self . output_space_before_token = True <EOL> return <EOL> if self . last_type == '<STR_LIT>' and self . flags . mode != MODE . Expression : <EOL> self . append_token ( token_text ) <EOL> if self . flags . mode == MODE . ObjectLiteral and self . flags . last_text == '<STR_LIT:}>' : <EOL> self . append_newline ( ) <EOL> else : <EOL> self . output_space_before_token = True <EOL> else : <EOL> if self . flags . mode == MODE . ObjectLiteral : <EOL> self . append_token ( token_text ) <EOL> self . append_newline ( ) <EOL> else : <EOL> self . append_token ( token_text ) <EOL> self . output_space_before_token = True <EOL> def handle_operator ( self , token_text ) : <EOL> space_before = True <EOL> space_after = True <EOL> if self . is_special_word ( self . flags . last_text ) : <EOL> self . output_space_before_token = True <EOL> self . append_token ( token_text ) <EOL> return <EOL> if token_text == '<STR_LIT:*>' and self . last_type == '<STR_LIT>' and not self . last_last_text . isdigit ( ) : <EOL> self . append_token ( token_text ) <EOL> return <EOL> if token_text == '<STR_LIT::>' and self . flags . in_case : <EOL> self . flags . case_body = True <EOL> self . indent ( ) <EOL> self . append_token ( token_text ) <EOL> self . append_newline ( ) <EOL> self . flags . in_case = False <EOL> return <EOL> if token_text == '<STR_LIT>' : <EOL> self . append_token ( token_text ) <EOL> return <EOL> if self . input_wanted_newline and ( token_text == '<STR_LIT>' or token_text == '<STR_LIT>' ) : <EOL> self . append_newline ( ) <EOL> if token_text in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:!>' ] or ( token_text in [ '<STR_LIT:+>' , '<STR_LIT:->' ] and ( self . last_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] or self . flags . last_text in self . line_starters or self . flags . last_text == '<STR_LIT:U+002C>' ) ) : <EOL> space_before = False <EOL> space_after = False <EOL> if self . flags . last_text == '<STR_LIT:;>' and self . is_expression ( self . flags . mode ) : <EOL> space_before = True <EOL> if self . last_type == '<STR_LIT>' and self . flags . last_text in self . line_starters : <EOL> space_before = True <EOL> if self . flags . mode == MODE . BlockStatement and self . flags . last_text in [ '<STR_LIT:{>' , '<STR_LIT:;>' ] : <EOL> self . append_newline ( ) <EOL> elif token_text == '<STR_LIT::>' : <EOL> if self . flags . ternary_depth == <NUM_LIT:0> : <EOL> if self . flags . mode == MODE . BlockStatement : <EOL> self . flags . mode = MODE . ObjectLiteral <EOL> space_before = False <EOL> else : <EOL> self . flags . ternary_depth -= <NUM_LIT:1> <EOL> elif token_text == '<STR_LIT:?>' : <EOL> self . flags . ternary_depth += <NUM_LIT:1> <EOL> if space_before : <EOL> self . output_space_before_token = True <EOL> self . append_token ( token_text ) <EOL> if space_after : <EOL> self . output_space_before_token = True <EOL> def handle_block_comment ( self , token_text ) : <EOL> lines = token_text . replace ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT>' ) <EOL> javadoc = False <EOL> self . append_newline ( preserve_statement_flags = True ) <EOL> if len ( lines ) > <NUM_LIT:1> : <EOL> if not any ( l for l in lines [ <NUM_LIT:1> : ] if ( l . strip ( ) == '<STR_LIT>' or ( l . lstrip ( ) ) [ <NUM_LIT:0> ] != '<STR_LIT:*>' ) ) : <EOL> javadoc = True <EOL> self . append_token ( lines [ <NUM_LIT:0> ] ) <EOL> for line in lines [ <NUM_LIT:1> : ] : <EOL> self . append_newline ( preserve_statement_flags = True ) <EOL> if javadoc : <EOL> self . append_token ( '<STR_LIT:U+0020>' + line . strip ( ) ) <EOL> else : <EOL> self . output_lines [ - <NUM_LIT:1> ] . text . append ( line ) <EOL> self . append_newline ( preserve_statement_flags = True ) <EOL> def handle_inline_comment ( self , token_text ) : <EOL> self . output_space_before_token = True <EOL> self . append_token ( token_text ) <EOL> self . output_space_before_token = True <EOL> def handle_comment ( self , token_text ) : <EOL> if self . input_wanted_newline : <EOL> self . append_newline ( preserve_statement_flags = True ) <EOL> if not self . input_wanted_newline : <EOL> self . trim_output ( True ) <EOL> self . output_space_before_token = True <EOL> self . append_token ( token_text ) <EOL> self . append_newline ( preserve_statement_flags = True ) <EOL> def handle_dot ( self , token_text ) : <EOL> if self . is_special_word ( self . flags . last_text ) : <EOL> self . output_space_before_token = True <EOL> else : <EOL> self . allow_wrap_or_preserved_newline ( token_text , <EOL> self . flags . last_text == '<STR_LIT:)>' and self . opts . break_chained_methods ) <EOL> self . append_token ( token_text ) <EOL> def handle_unknown ( self , token_text ) : <EOL> self . append_token ( token_text ) <EOL> if token_text [ len ( token_text ) - <NUM_LIT:1> ] == '<STR_LIT:\n>' : <EOL> self . append_newline ( ) <EOL> def mkdir_p ( path ) : <EOL> try : <EOL> os . makedirs ( path ) <EOL> except OSError as exc : <EOL> if exc . errno == errno . EEXIST and os . path . isdir ( path ) : <EOL> pass <EOL> else : raise <EOL> def main ( ) : <EOL> argv = sys . argv [ <NUM_LIT:1> : ] <EOL> try : <EOL> opts , args = getopt . getopt ( argv , "<STR_LIT>" , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> except getopt . GetoptError as ex : <EOL> print ( ex , file = sys . stderr ) <EOL> return usage ( sys . stderr ) <EOL> js_options = default_options ( ) <EOL> file = None <EOL> outfile = '<STR_LIT>' <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> file = args [ <NUM_LIT:0> ] <EOL> for opt , arg in opts : <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . keep_array_indentation = True <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . keep_function_indentation = True <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> outfile = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . indent_size = int ( arg ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT:-c>' ) : <EOL> js_options . indent_char = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . indent_with_tabs = True <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . preserve_newlines = False <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . space_in_paren = True <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . jslint_happy = True <EOL> elif opt in ( '<STR_LIT>' ) : <EOL> js_options . eval_code = True <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . brace_style = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . unescape_strings = True <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . e4x = True <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> js_options . wrap_line_length = int ( arg ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> file = '<STR_LIT:->' <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return print ( __version__ ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return usage ( ) <EOL> if not file : <EOL> print ( "<STR_LIT>" , file = sys . stderr ) <EOL> return usage ( sys . stderr ) <EOL> else : <EOL> try : <EOL> if outfile == '<STR_LIT>' : <EOL> print ( beautify_file ( file , js_options ) ) <EOL> else : <EOL> mkdir_p ( os . path . dirname ( outfile ) ) <EOL> with open ( outfile , '<STR_LIT:w>' ) as f : <EOL> f . write ( beautify_file ( file , js_options ) + '<STR_LIT:\n>' ) <EOL> except Exception as ex : <EOL> print ( ex , file = sys . stderr ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> </s>
