def cleanup(node): """ """ if not hasattr(node, "variables"): ScopeScanner.scan(node) # Re cleanup until nothing to remove is found iteration = 0 cleaned = False Console.info("Removing unused variables...") Console.indent() while True: iteration += 1 modified = __cleanup(node) if modified > 0: Console.info("Removed %s unused variables", modified) ScopeScanner.scan(node) cleaned = True else: break Console.outdent() return cleaned
def cleanup(node): """""" if not hasattr(node, "variables"): ScopeScanner.scan(node) # Re cleanup until nothing to remove is found iteration = 0 cleaned = False Console.debug("Removing unused variables...") Console.indent() while True: iteration += 1 modified = __cleanup(node) if modified > 0: Console.debug("Removed %s unused variables", modified) ScopeScanner.scan(node) cleaned = True else: break Console.outdent() return cleaned
def permutateTree(tree, permutation=None): """ Returns an optimized tree with permutations applied """ if permutation: # Work on a copy tree = copy.deepcopy(tree) Resolver.process(tree, permutation) ScopeScanner.scan(tree) return tree else: return tree
def reduceTree(tree, profile=None): """Applies all relevant modifications to the tree to allow compression to CSS.""" Console.info("Reducing tree: %s...", tree.fileId) Console.indent() # PHASE 2 # Trivial cleanups ScopeScanner.scan(tree) Unused.cleanup(tree) # PHASE 3 # Resolve all mixins Mixins.processMixins(tree) Mixins.processSelectors(tree) ScopeScanner.scan(tree) Unused.cleanup(tree) # PHASE 4 # Assign selectors to mixins (support for extend) Mixins.processExtends(tree) # PHASE 5 # Post mixin cleanups ScopeScanner.scan(tree) Unused.cleanup(tree) # PHASE 6 # Execute variable resolution and method calls Executer.process(tree, profile) # PHASE 7 # Flattening selectors Flatter.process(tree) # PHASE 8 # Post scan to remove (hopefully) all variable/mixin access ScopeScanner.scan(tree) Console.outdent() return tree
def getCompressed( self, session, permutation=None, translation=None, optimization=None, formatting=None, context="compressed" ): tree = self.getMergedTree(permutation, session) # PHASE 1 # Resolving conditionals self.__resolveConditionals(tree) # PHASE 2 # Trivial cleanups ScopeScanner.scan(tree) Unused.cleanup(tree) # PHASE 3 # Resolve all mixins Mixins.processExtends(tree) Mixins.processMixins(tree) Mixins.processSelectors(tree) # PHASE 4 # Post mixin cleanups ScopeScanner.scan(tree) Unused.cleanup(tree) # PHASE 5 # Compute variables Variables.compute(tree) # PHASE 6 # Flattening selectors Flatter.process(tree) # PHASE 7 # Post scan to remove (hopefully) all variable/mixin access ScopeScanner.scan(tree) # DONE return Compressor(formatting).compress(tree)
def processTree(tree): """ Applies all relevant modifications to the tree to allow compression to CSS """ # PHASE 2 # Trivial cleanups ScopeScanner.scan(tree) Unused.cleanup(tree) # PHASE 3 # Resolve all mixins Mixins.processMixins(tree) Mixins.processSelectors(tree) # PHASE 4 # Assign selectors to mixins (support for extend) Mixins.processExtends(tree) # PHASE 5 # Post mixin cleanups ScopeScanner.scan(tree) Unused.cleanup(tree) # PHASE 6 # Compute variables Variables.compute(tree) # PHASE 7 # Flattening selectors Flatter.process(tree) # PHASE 8 # Post scan to remove (hopefully) all variable/mixin access ScopeScanner.scan(tree) return tree