Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/slimit/visitors/minvisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
def _is_identifier(value):
return _HAS_ID_MATCH(value) and value not in Lexer.keywords_dict

specials = re.compile(r'[`\\~!@#%\^&*(){}\[\]\-+=/|<>,.:;?]+')

class ECMAMinifier(object):

Expand Down Expand Up @@ -394,14 +395,15 @@ def visit_DotAccessor(self, node):
def visit_BracketAccessor(self, node):
if isinstance(node.expr, ast.String):
value = node.expr.value
# remove single or double quotes around the value, but not both
if value.startswith("'"):
value = value.strip("'")
elif value.startswith('"'):
value = value.strip('"')
if _is_identifier(value):
s = '%s.%s' % (self.visit(node.node), value)
return s
if not specials.search(value):
# remove single or double quotes around the value, but not both
if value.startswith("'"):
value = value.strip("'")
elif value.startswith('"'):
value = value.strip('"')
if _is_identifier(value):
s = '%s.%s' % (self.visit(node.node), value)
return s

s = '%s[%s]' % (self.visit(node.node), self.visit(node.expr))
return s
Expand Down