diff --git a/lib/scope.js b/lib/scope.js index 2388fb52..369d04e1 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -165,9 +165,17 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ // later. (node.scope = defun.parent_scope).def_function(node); } - else if (node instanceof AST_Var) { + else if (node instanceof AST_Var) { last_var_had_const_pragma = node.has_const_pragma(); } + else if (node instanceof AST_SymbolClass) { + defun.def_variable(node); + } + else if (node instanceof AST_SymbolDefClass) { + // This deals with the name of the class being available + // inside the class. + (node.scope = defun.parent_scope).def_function(node); + } else if (node instanceof AST_SymbolVar || node instanceof AST_SymbolConst) { var def = defun.def_variable(node); @@ -193,6 +201,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ // pass 2: find back references and eval var func = null; + var cls = null; var globals = self.globals = new Dictionary(); var tw = new TreeWalker(function(node, descend){ if (node instanceof AST_Lambda) { @@ -202,8 +211,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){ func = prev_func; return true; } - if (node instanceof AST_LoopControl && node.label) { - node.label.thedef.references.push(node); + if (node instanceof AST_Class) { + var prev_cls = cls; + cls = node; + descend(); + cls = prev_cls; return true; } if (node instanceof AST_SymbolRef) { diff --git a/test/compress/harmony.js b/test/compress/harmony.js index e1b3078a..c959b5d1 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -214,6 +214,25 @@ class_statics: { expect_exact: "x=class{static staticMethod(){}static get foo(){}static set bar(){}static(){}get(){}set(){}};" } +class_name_can_be_mangled: { + mangle = { }; + input: { + function x() { + class Foo { + } + var class1 = Foo + var class2 = class Bar {} + } + } + expect: { + function x() { + class a { } + var b = a + var c = class a {} + } + } +} + number_literals: { input: { 0b1001;