Skip to content

Commit

Permalink
Preserve opening brace position other than whitespace / indentation i…
Browse files Browse the repository at this point in the history
…n Python version
  • Loading branch information
c32hedge committed Oct 6, 2014
1 parent 4524383 commit 0fa529f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions python/jsbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ def beautify(self, s, opts = None ):
if opts != None:
self.opts = copy.copy(opts)

if self.opts.brace_style not in ['expand', 'collapse', 'end-expand']:
raise(Exception('opts.brace_style must be "expand", "collapse" or "end-expand".'))
if self.opts.brace_style not in ['expand', 'collapse', 'end-expand', 'none']:
raise(Exception('opts.brace_style must be "expand", "collapse", "end-expand", or "none".'))

s = self.blank_state(s)

Expand Down Expand Up @@ -680,7 +680,8 @@ def handle_start_block(self, current_token):
empty_anonymous_function = empty_braces and self.flags.last_word == 'function' and \
self.last_type == 'TK_END_EXPR'

if self.opts.brace_style == 'expand':
if self.opts.brace_style == 'expand' or \
(self.opts.brace_style == 'none' and current_token.wanted_newline):
if self.last_type != 'TK_OPERATOR' and \
(empty_anonymous_function or
self.last_type == 'TK_EQUALS' or
Expand Down Expand Up @@ -824,7 +825,8 @@ def handle_word(self, current_token):
if not (current_token.type == 'TK_RESERVED' and current_token.text in ['else', 'catch', 'finally']):
prefix = 'NEWLINE'
else:
if self.opts.brace_style in ['expand', 'end-expand']:
if self.opts.brace_style in ['expand', 'end-expand'] or \
(self.opts.brace_style == 'none' and current_token.wanted_newline):
prefix = 'NEWLINE'
else:
prefix = 'SPACE'
Expand Down Expand Up @@ -854,7 +856,8 @@ def handle_word(self, current_token):
if current_token.type == 'TK_RESERVED' and current_token.text in ['else', 'catch', 'finally']:
if self.last_type != 'TK_END_BLOCK' \
or self.opts.brace_style == 'expand' \
or self.opts.brace_style == 'end-expand':
or self.opts.brace_style == 'end-expand' \
or (self.opts.brace_style == 'none' and current_token.wanted_newline):
self.print_newline()
else:
self.output.trim(True)
Expand Down

0 comments on commit 0fa529f

Please sign in to comment.