diff --git a/src/slimit/visitors/minvisitor.py b/src/slimit/visitors/minvisitor.py index 1c6fd15..ae822fe 100644 --- a/src/slimit/visitors/minvisitor.py +++ b/src/slimit/visitors/minvisitor.py @@ -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): @@ -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