本文整理匯總了Python中jasy.js.parse.Node.Node.wrapped方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.wrapped方法的具體用法?Python Node.wrapped怎麽用?Python Node.wrapped使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jasy.js.parse.Node.Node
的用法示例。
在下文中一共展示了Node.wrapped方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: reworkElse
# 需要導入模塊: from jasy.js.parse.Node import Node [as 別名]
# 或者: from jasy.js.parse.Node.Node import wrapped [as 別名]
def reworkElse(node, elsePart):
"""
If an if ends with a return/throw we are able to inline the content
of the else to the same parent as the if resides into. This method
deals with all the nasty details of this operation.
"""
target = node.parent
targetIndex = target.index(node)+1
# A workaround for compact if-else blocks
# We are a elsePart of the if where we want to move our
# content to. This cannot work. So we need to wrap ourself
# into a block and move the else statements to this newly
# established block
if not target.type in ("block","script"):
newBlock = Node(None, "block")
newBlock.wrapped = True
# Replace node with newly created block and put ourself into it
node.parent.replace(node, newBlock)
newBlock.append(node)
# Update the target and the index
target = newBlock
targetIndex = 1
if not target.type in ("block", "script"):
# print("No possible target found/created")
return elsePart
if elsePart.type == "block":
for child in reversed(elsePart):
target.insert(targetIndex, child)
# Remove else block from if statement
node.remove(elsePart)
else:
target.insert(targetIndex, elsePart)
return