minimize_source: Handling indentation
In the case that string(s) are replaced, any indent or dedent tags must be re-inserted after the replacemnts.
This commit is contained in:
parent
36c5ff1d05
commit
556ee2aec6
|
@ -120,13 +120,16 @@ def strip_docstrings(tokens):
|
|||
if state == 'wait_string':
|
||||
if typ in (tokenize.NL, tokenize.COMMENT):
|
||||
yield t
|
||||
elif typ == tokenize.STRING:
|
||||
elif typ in (tokenize.DEDENT, tokenize.INDENT, tokenize.STRING):
|
||||
stack.append(t)
|
||||
elif typ == tokenize.NEWLINE:
|
||||
stack.append(t)
|
||||
start_line, end_line = stack[0][2][0], stack[-1][3][0]+1
|
||||
for i in range(start_line, end_line):
|
||||
yield tokenize.NL, '\n', (i, 0), (i,1), '\n'
|
||||
for t in stack:
|
||||
if t[0] in (tokenize.DEDENT, tokenize.INDENT):
|
||||
yield t[0], t[1], (i+1, t[2][1]), (i+1, t[3][1]), t[4]
|
||||
del stack[:]
|
||||
else:
|
||||
stack.append(t)
|
||||
|
|
|
@ -45,5 +45,5 @@ class c2(object):
|
|||
"docstring"
|
||||
def inner(): pass
|
||||
d = {'a':0}
|
||||
for x in '':
|
||||
for x in '': # FIXME Removing this leaves nothing, hence a SyntaxError
|
||||
"justastring"
|
||||
|
|
|
@ -46,4 +46,4 @@ class c2(object):
|
|||
def inner(): pass
|
||||
d = {'a':0}
|
||||
for x in '':
|
||||
"justastring"
|
||||
|
||||
|
|
Loading…
Reference in New Issue