本文整理汇总了Python中jasy.js.parse.Node.Node.replace方法的典型用法代码示例。如果您正苦于以下问题:Python Node.replace方法的具体用法?Python Node.replace怎么用?Python Node.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jasy.js.parse.Node.Node
的用法示例。
在下文中一共展示了Node.replace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __rebuildAsAssignment
# 需要导入模块: from jasy.js.parse.Node import Node [as 别名]
# 或者: from jasy.js.parse.Node.Node import replace [as 别名]
def __rebuildAsAssignment(node, firstVarStatement):
"""Rebuilds the items of a var statement into a assignment list and moves declarations to the given var statement"""
assignment = Node(node.tokenizer, "semicolon")
assignmentList = Node(node.tokenizer, "comma")
assignment.append(assignmentList, "expression")
# Casting to list() creates a copy during the process (keeps loop stable)
for child in list(node):
if hasattr(child, "name"):
# Cleanup initializer and move to assignment
if hasattr(child, "initializer"):
assign = __createSimpleAssignment(child.name, child.initializer)
assignmentList.append(assign)
firstVarStatement.append(child)
else:
# JS 1.7 Destructing Expression
for identifier in child.names:
firstVarStatement.append(__createDeclaration(identifier.value))
if hasattr(child, "initializer"):
assign = __createMultiAssignment(child.names, child.initializer)
assignmentList.append(assign)
node.remove(child)
# Patch parent node to contain assignment instead of declaration
if len(assignmentList) > 0:
node.parent.replace(node, assignment)
# Special process for "for-in" loops
# It is OK to be second because of assignments are not allowed at
# all in for-in loops and so the first if basically does nothing
# for these kind of statements.
elif getattr(node, "rel", None) == "iterator":
if hasattr(child, "name"):
node.parent.replace(node, __createIdentifier(child.name))
else:
# JS 1.7 Destructing Expressions
node.parent.replace(node, child.names)
# Edge case. Not yet found if this happen realistically
else:
if hasattr(node, "rel"):
logging.warn("Remove related node (%s) from parent: %s" % (node.rel, node))
node.parent.remove(node)
# Minor post-cleanup. Remove useless comma statement when only one expression is the result
if len(assignmentList) == 1:
assignment.replace(assignmentList, assignmentList[0])