Permalink
Browse files

Merge branch 'release/0.5.5'

  • Loading branch information...
2 parents 5a24819 + fb57f05 commit 639397afae6eb231a082b0e491e526a150a69f03 @rspivak committed Oct 6, 2011
Showing with 77 additions and 7 deletions.
  1. +4 −0 CHANGES
  2. +5 −0 CREDIT
  3. +1 −1 setup.py
  4. +2 −0 src/slimit/ast.py
  5. +3 −0 src/slimit/scope.py
  6. +47 −0 src/slimit/tests/test_mangler.py
  7. +15 −6 src/slimit/visitors/scopevisitor.py
View
@@ -1,6 +1,10 @@
Change History
==============
+0.5.5 (2011-10-05)
+------------------
+- Bugfix: https://github.com/rspivak/slimit/issues/7
+
0.5.4 (2011-10-01)
------------------
- Bugfix: https://github.com/rspivak/slimit/issues/6
View
5 CREDIT
@@ -1,3 +1,8 @@
+Patches
+-------
+
+- Waldemar Kornewald
+
Bug reports
-----------
View
@@ -17,7 +17,7 @@ def read(*rel_names):
setup(
name='slimit',
- version='0.5.4',
+ version='0.5.5',
url='http://slimit.org',
license='MIT',
description='SlimIt - JavaScript minifier',
View
@@ -311,6 +311,8 @@ def children(self):
class Catch(Node):
def __init__(self, identifier, elements):
self.identifier = identifier
+ # CATCH identifiers are subject to name mangling. we need to mark them.
+ self.identifier._mangle_candidate = True
self.elements = elements
def children(self):
View
@@ -74,6 +74,9 @@ def __init__(self, enclosing_scope=None):
self.enclosing_scope.add_child(self)
self.base54 = powerset(ID_CHARS)
+ def __contains__(self, sym):
+ return sym.name in self.symbols
+
def add_child(self, scope):
self.children.append(scope)
@@ -88,6 +88,53 @@ class ManglerTestCase(unittest.TestCase):
};
"""),
+ # https://github.com/rspivak/slimit/issues/7
+ ("""
+ function a() {
+ var $exc1 = null;
+ try {
+ lala();
+ } catch($exc) {
+ if ($exc.__name__ == 'hi') {
+ return 'bam';
+ }
+ }
+ return 'bum';
+ }
+ """,
+ """
+ function a() {
+ var a = null;
+ try {
+ lala();
+ } catch (b) {
+ if (b.__name__ == 'hi') {
+ return 'bam';
+ }
+ }
+ return 'bum';
+ }
+ """),
+
+ # Handle the case when function arguments are redefined;
+ # in the example below statement arg = 9; doesn't create
+ # a global variable -it changes the value of arguments[0].
+ # The same is with statement var arg = 0;
+ # http://spin.atomicobject.com/2011/04/10/javascript-don-t-reassign-your-function-arguments/
+ ("""
+ function a(arg) {
+ arg = 9;
+ var arg = 0;
+ return arg;
+ }
+ """,
+ """
+ function a(a) {
+ a = 9;
+ var a = 0;
+ return a;
+ }
+ """),
]
@@ -54,7 +54,8 @@ def __init__(self, sym_table):
def visit_VarDecl(self, node):
ident = node.identifier
symbol = VarSymbol(name=ident.value)
- self.current_scope.define(symbol)
+ if symbol not in self.current_scope:
+ self.current_scope.define(symbol)
ident.scope = self.current_scope
self.visit(node.initializer)
@@ -80,20 +81,28 @@ def visit_FuncDecl(self, node):
self.current_scope.define(VarSymbol(ident.value))
ident.scope = self.current_scope
- # push local scope
- self.current_scope = LocalScope(self.current_scope)
-
for element in node.elements:
self.visit(element)
- # pop the local scope
- self.current_scope = self.current_scope.get_enclosing_scope()
# pop the function scope
self.current_scope = self.current_scope.get_enclosing_scope()
# alias
visit_FuncExpr = visit_FuncDecl
+ def visit_Catch(self, node):
+ # The catch identifier actually lives in a new scope, but additional
+ # variables defined in the catch statement belong to the outer scope.
+ # For the sake of simplicity we just reuse any existing variables
+ # from the outer scope if they exist.
+ ident = node.identifier
+ existing_symbol = self.current_scope.symbols.get(ident.value)
+ if existing_symbol is None:
+ self.current_scope.define(VarSymbol(ident.value))
+ ident.scope = self.current_scope
+
+ for element in node.elements:
+ self.visit(element)
class RefVisitor(Visitor):
"""Fill 'ref' attribute in scopes."""

0 comments on commit 639397a

Please sign in to comment.