예제 #1
0
def update(node, found, prefix="$", skipPrefix="", debug=False):

  # Handle all identifiers
  if node.type == "identifier":

    isFirstChild = False
    isVariableMember = False

    if node.parent.type == "variable":
      isVariableMember = True
      varParent = node.parent.parent

      if not (varParent.type == "right" and varParent.parent.type == "accessor"):
        isFirstChild = node.parent.getFirstChild(True, True) == node

    elif node.parent.type == "identifier" and node.parent.parent.type == "accessor":
      isVariableMember = True
      accessor = node.parent.parent
      isFirstChild = accessor.parent.getFirstChild(True, True) == accessor

    # inside a variable parent only respect the first member
    if not isVariableMember or isFirstChild:
      idenName = node.get("name", False)

      if idenName != None and idenName in found and not skip(idenName, skipPrefix):
        replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
        node.set("name", replName)

        if debug:
          print "  - Replaced '%s' with '%s'" % (idenName, replName)

  # Handle variable definition
  elif node.type == "definition":
    idenName = node.get("identifier", False)

    if idenName != None and idenName in found and not skip(idenName, skipPrefix):
      replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
      node.set("identifier", replName)

      if debug:
        print "  - Replaced '%s' with '%s'" % (idenName, replName)

  # Handle function definition
  elif node.type == "function":
    idenName = node.get("name", False)

    if idenName != None and idenName in found and not skip(idenName, skipPrefix):
      replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
      node.set("name", replName)

      if debug:
        print "  - Replaced '%s' with '%s'" % (idenName, replName)

  # Iterate over children
  if node.hasChildren():
    for child in node.children:
      update(child, found, prefix, skipPrefix, debug)
def patch(unique, node, known, prefix="__$", verbose=False):
    if node.type == "definition":
        name = node.get("identifier", False)
        
        if name != None and name.startswith("__") and not name in ignore:
            if not name in known:
                known[name] = "%s%s_%s" % (prefix, unique, mapper.convert(len(known)))

            if verbose:
                print "      - Replace definition: %s with %s" % (name, known[name])

            node.set("identifier", known[name])
                    
    elif node.type == "identifier":
        name = node.get("name", False)

        if name != None and name.startswith("__") and not name in ignore:
            if not name in known:
                known[name] = "%s%s_%s" % (prefix, unique, mapper.convert(len(known)))

            if verbose:
                print "      - Replace identifier: %s with %s" % (name, known[name])

            node.set("name", known[name])

    elif node.type == "keyvalue":
        name = node.get("key", False)

        if name != None and name.startswith("__") and not name in ignore:
            if not name in known:
                known[name] = "%s%s_%s" % (prefix, unique, mapper.convert(len(known)))
                
            if verbose:
                print "      - Replace key: %s with %s" % (name, known[name])

            node.set("key", known[name])

    if node.hasChildren():
        for child in node.children:
            patch(unique, child, known, prefix, verbose)

    return len(known)
예제 #3
0
def add(key, identifiers):
    if key == None or key == "":
        return

    if " " in key:
        return

    # Don't reoptimize local variables
    if key.startswith("$"):
        return

    # JS system stuff
    if key in systemNames:
        return

    # mainly keyvalue pairs where the key is a string
    if "." in key:
        return

    # ignore dimensions
    if key.endswith("%") or key.endswith("px") or key.endswith(
            "em") or key.endswith("pt"):
        return

    # ignore numbers
    if re.compile("^[0-9]+").search(key):
        return

    # base
    for item in baseNames:
        if item in key:
            return

    # qooxdoo
    if key in qooxdooNames:
        return

    for start in qooxdooStart:
        if key.startswith(start):
            return

    # Test for identifier
    if not identifiers.has_key(key):
        #print "        - Found key: %s" % key
        identifiers[key] = "$$$%s" % mapper.convert(len(identifiers))
예제 #4
0
def update(node, list, prefix):
    counter = 0

    if node.type == "identifier":
        idenName = node.get("name", False)

        if idenName != None and idenName in list:
            replName = "%s%s" % (prefix, mapper.convert(list.index(idenName)))
            node.set("name", replName)
            counter += 1

            # print "  - Replaced '%s' with '%s'" % (idenName, replName)

    if node.hasChildren():
        for child in node.children:
            counter += update(child, list, prefix)

    return counter
예제 #5
0
def update(node, list, prefix):
  counter = 0

  if node.type == "identifier":
    idenName = node.get("name", False)

    if idenName != None and idenName in list:
      replName = "%s%s" % (prefix, mapper.convert(list.index(idenName)))
      node.set("name", replName)
      counter += 1

      # print "  - Replaced '%s' with '%s'" % (idenName, replName)

  if node.hasChildren():
    for child in node.children:
      counter += update(child, list, prefix)

  return counter
예제 #6
0
def add(key, identifiers):
    if key == None or key == "":
        return
        
    if " " in key:
        return
        
    # Don't reoptimize local variables
    if key.startswith("$"):
        return
    
    # JS system stuff
    if key in systemNames:
        return
        
    # mainly keyvalue pairs where the key is a string
    if "." in key:
        return
        
    # ignore dimensions
    if key.endswith("%") or key.endswith("px") or key.endswith("em") or key.endswith("pt"):
        return
        
    # ignore numbers
    if re.compile("^[0-9]+").search(key):
        return

    # base
    for item in baseNames:
        if item in key:
            return
        
    # qooxdoo
    if key in qooxdooNames:
        return
        
    for start in qooxdooStart:
        if key.startswith(start):
            return

    # Test for identifier
    if not identifiers.has_key(key):
        #print "        - Found key: %s" % key
        identifiers[key] = "$$$%s" % mapper.convert(len(identifiers))
예제 #7
0
def update(node, found, counter, prefix="$", skipPrefix="", verbose=False):
    # Handle all identifiers
    if node.type == "identifier":
        isFirstChild = False
        isVariableMember = False

        if node.parent.type == "variable":
            isVariableMember = True
            varParent = node.parent.parent

            # catch corner case: a().b(); var b;
            if varParent.type == "operand" and varParent.parent.type == "call" and varParent.parent.parent.type == "right" and varParent.parent.parent.parent.type == "accessor":
                varParent = varParent.parent.parent

            if not (varParent.type == "right"
                    and varParent.parent.type == "accessor"):
                isFirstChild = node.parent.getFirstChild(True, True) == node

        # used in foo.bar.some[thing] where "some" is the identifier
        elif node.parent.type == "accessor":
            isVariableMember = True
            accessor = node.parent
            isFirstChild = accessor.parent.getFirstChild(True,
                                                         True) == accessor

        # inside a variable parent only respect the first member
        if not isVariableMember or isFirstChild:
            idenName = node.get("name", False)

            if idenName != None and idenName in found and not skip(
                    idenName, skipPrefix):
                replName = "%s%s" % (prefix,
                                     mapper.convert(found.index(idenName)))
                node.set("name", replName)
                counter += 1

                if verbose:
                    print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Handle variable definition
    elif node.type == "definition":
        idenName = node.get("identifier", False)

        if idenName != None and idenName in found and not skip(
                idenName, skipPrefix):
            replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
            node.set("identifier", replName)
            counter += 1

            if verbose:
                print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Handle function definition
    elif node.type == "function":
        idenName = node.get("name", False)

        if idenName != None and idenName in found and not skip(
                idenName, skipPrefix):
            replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
            node.set("name", replName)
            counter += 1

            if verbose:
                print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Iterate over children
    if node.hasChildren():
        for child in node.children:
            counter += update(child, found, 0, prefix, skipPrefix, verbose)

    return counter
예제 #8
0
def update(node, found, prefix="$", skipPrefix="", debug=False):

    # Handle all identifiers
    if node.type == "identifier":

        isFirstChild = False
        isVariableMember = False

        if node.parent.type == "variable":
            isVariableMember = True
            varParent = node.parent.parent

            if not (varParent.type == "right"
                    and varParent.parent.type == "accessor"):
                isFirstChild = node.parent.getFirstChild(True, True) == node

        elif node.parent.type == "identifier" and node.parent.parent.type == "accessor":
            isVariableMember = True
            accessor = node.parent.parent
            isFirstChild = accessor.parent.getFirstChild(True,
                                                         True) == accessor

        # inside a variable parent only respect the first member
        if not isVariableMember or isFirstChild:
            idenName = node.get("name", False)

            if idenName != None and idenName in found and not skip(
                    idenName, skipPrefix):
                replName = "%s%s" % (prefix,
                                     mapper.convert(found.index(idenName)))
                node.set("name", replName)

                if debug:
                    print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Handle variable definition
    elif node.type == "definition":
        idenName = node.get("identifier", False)

        if idenName != None and idenName in found and not skip(
                idenName, skipPrefix):
            replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
            node.set("identifier", replName)

            if debug:
                print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Handle function definition
    elif node.type == "function":
        idenName = node.get("name", False)

        if idenName != None and idenName in found and not skip(
                idenName, skipPrefix):
            replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
            node.set("name", replName)

            if debug:
                print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Iterate over children
    if node.hasChildren():
        for child in node.children:
            update(child, found, prefix, skipPrefix, debug)
def update(node, found, counter, prefix="$", skipPrefix="", verbose=False):
    # Handle all identifiers
    if node.type == "identifier":
        isFirstChild = False
        isVariableMember = False

        if node.parent.type == "variable":
            isVariableMember = True
            varParent = node.parent.parent

            # catch corner case: a().b(); var b;
            if varParent.type == "operand" and varParent.parent.type == "call" and varParent.parent.parent.type == "right" and varParent.parent.parent.parent.type == "accessor":
                varParent = varParent.parent.parent

            if not (varParent.type == "right" and varParent.parent.type == "accessor"):
                isFirstChild = node.parent.getFirstChild(True, True) == node

        # used in foo.bar.some[thing] where "some" is the identifier
        elif node.parent.type == "accessor":
            isVariableMember = True
            accessor = node.parent
            isFirstChild = accessor.parent.getFirstChild(True, True) == accessor

        # inside a variable parent only respect the first member
        if not isVariableMember or isFirstChild:
            idenName = node.get("name", False)

            if idenName != None and idenName in found and not skip(idenName, skipPrefix):
                replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
                node.set("name", replName)
                counter += 1

                if verbose:
                    print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Handle variable definition
    elif node.type == "definition":
        idenName = node.get("identifier", False)

        if idenName != None and idenName in found and not skip(idenName, skipPrefix):
            replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
            node.set("identifier", replName)
            counter += 1

            if verbose:
                print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Handle function definition
    elif node.type == "function":
        idenName = node.get("name", False)

        if idenName != None and idenName in found and not skip(idenName, skipPrefix):
            replName = "%s%s" % (prefix, mapper.convert(found.index(idenName)))
            node.set("name", replName)
            counter += 1

            if verbose:
                print "  - Replaced '%s' with '%s'" % (idenName, replName)

    # Iterate over children
    if node.hasChildren():
        for child in node.children:
            counter += update(child, found, 0, prefix, skipPrefix, verbose)

    return counter