示例#1
0
文件: Class.py 项目: zynga/jasy
    def getCompressed(self,
                      permutation=None,
                      translation=None,
                      optimization=None,
                      formatting=None,
                      context="compressed"):
        permutation = self.filterPermutation(permutation)

        # Disable translation for caching / patching when not actually used
        if translation and not self.getTranslations():
            translation = None

        field = "compressed[%s]-%s-%s-%s-%s" % (
            self.id, permutation, translation, optimization, formatting)
        compressed = self.project.getCache().read(field, self.mtime)
        if compressed == None:
            tree = self.__getOptimizedTree(permutation, context)

            if translation or optimization:
                tree = copy.deepcopy(tree)

                if translation:
                    jasy.js.optimize.Translation.optimize(tree, translation)

                if optimization:
                    try:
                        optimization.apply(tree)
                    except jasy.js.output.Optimization.Error as error:
                        raise ClassError(
                            self, "Could not compress class! %s" % error)

            compressed = Compressor(formatting).compress(tree)
            self.project.getCache().store(field, compressed, self.mtime)

        return compressed
示例#2
0
文件: Class.py 项目: csakatoku/jasy
    def getCompressed(self,
                      permutation=None,
                      translation=None,
                      optimization=None,
                      format=None):
        permutation = self.filterPermutation(permutation)
        translation = self.filterTranslation(translation)

        field = "compressed[%s]-%s-%s-%s-%s" % (
            self.__id, permutation, translation, optimization, format)
        field = hashlib.md5(field.encode("utf-8")).hexdigest()

        compressed = self.__cache.read(field, self.__mtime)
        if compressed == None:
            tree = self.getTree(permutation)

            if translation or optimization:
                tree = copy.deepcopy(tree)

                if translation:
                    translation.patch(tree)

                if optimization:
                    try:
                        optimization.apply(tree)
                    except jasy.js.output.Optimization.Error as error:
                        raise Error(self,
                                    "Could not compress class! %s" % error)

            compressed = Compressor(format).compress(tree)
            self.__cache.store(field, compressed, self.__mtime)

        return compressed
示例#3
0
#
# Jasy - Web Tooling Framework
# Copyright 2010-2012 Zynga Inc.
#

from jasy.js.output.Compressor import Compressor

# Shared instance
compressor = Compressor()

pseudoTypes = set(["var", "undefined", "null", "true", "false", "this", "arguments"])
builtinTypes = set(["Object", "String", "Number", "Boolean", "Array", "Function", "RegExp", "Date"])

# Basic user friendly node type to human type
nodeTypeToDocType = {

    # Primitives
    "string": "String",
    "number": "Number",
    "not": "Boolean",
    "true": "Boolean",
    "false": "Boolean",

    # Literals
    "function": "Function",
    "regexp": "RegExp",
    "object_init": "Map",
    "array_init": "Array",

    # We could figure out the real class automatically - at least that's the case quite often
    "new": "Object",
示例#4
0
def optimize(node):
    logging.debug(">>> Reducing block complexity...")
    return __optimize(node, Compressor())