Skip to content

Commit f080c3c

Browse files
authored
Merge pull request #1 from Herst/patch-1
Fix reduce_operators() with check whether prev_tok is not None
2 parents 087ea7b + 3a95839 commit f080c3c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pyminifier/minification.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ def foo(foo,bar,blah):
196196
last_col = 0
197197
if token_type != tokenize.OP:
198198
if start_col > last_col and token_type not in nl_types:
199-
if prev_tok[0] != tokenize.OP:
199+
if prev_tok and prev_tok[0] != tokenize.OP:
200200
out += (" " * (start_col - last_col))
201201
if token_type == tokenize.STRING:
202-
if prev_tok[0] == tokenize.STRING:
202+
if prev_tok and prev_tok[0] == tokenize.STRING:
203203
# Join the strings into one
204204
string_type = token_string[0] # '' or ""
205205
prev_string_type = prev_tok[1][0]
@@ -215,15 +215,15 @@ def foo(foo,bar,blah):
215215
new_string += token_string.strip(string_type)
216216
else:
217217
if token_string in ('}', ')', ']'):
218-
if prev_tok[1] == ',':
218+
if prev_tok and prev_tok[1] == ',':
219219
out = out.rstrip(',')
220220
if joining_strings:
221221
# NOTE: Using triple quotes so that this logic works with
222222
# mixed strings using both single quotes and double quotes.
223223
out += "'''" + new_string + "'''"
224224
joining_strings = False
225225
if token_string == '@': # Decorators need special handling
226-
if prev_tok[0] == tokenize.NEWLINE:
226+
if prev_tok and prev_tok[0] == tokenize.NEWLINE:
227227
# Ensure it gets indented properly
228228
out += (" " * (start_col - last_col))
229229
if not joining_strings:

0 commit comments

Comments
 (0)