WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 9c601ad

Browse files
Arielwyy王雅仪
andauthored
fix: CatchClause body should be ScopedStatement (#24)
* feat: add numOfGoMod to count go.mod files in multi-module repositories * fix: resolve index out of range when goModPath is empty * fix: WhileStatement body should be ScopedStatement * fix: CatchClause body should be ScopedStatement --------- Co-authored-by: 王雅仪 <[email protected]>
1 parent 01dc663 commit 9c601ad

File tree

2 files changed

+45
-47
lines changed

2 files changed

+45
-47
lines changed

parser-Python/uast/asttype.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -407,59 +407,48 @@ class DynamicType(BaseNode):
407407
Conditional = Union[IfStatement , SwitchStatement , ConditionalExpression]
408408

409409
Node = Union[ArrayType
410-
, AssignmentExpression
411-
, BinaryExpression
410+
, AssignmentExpression
411+
, BinaryExpression
412412
, BreakStatement
413-
, CallExpression
413+
, CallExpression
414414
, CaseClause
415-
# , CastExpression
416-
# , CatchClause
417-
# , ChanType
418-
, ClassDefinition
419-
, CompileUnit
415+
, CatchClause
416+
, ClassDefinition
417+
, CompileUnit
420418
, ConditionalExpression
421419
, ContinueStatement
422420
, DereferenceExpression
423-
, DynamicType
424-
, ExportStatement
425-
# , ExpressionStatement
426-
, ForStatement
427-
# , FuncType
428-
, FunctionDefinition
429-
, Identifier
430-
, IfStatement
421+
, DynamicType
422+
, ExportStatement
423+
, ExpressionStatement
424+
, ForStatement
425+
, FunctionDefinition
426+
, Identifier
427+
, IfStatement
431428
, ImportExpression
432-
# , LabeledStatement
433-
, Literal
434-
# , MapType
435-
, MemberAccess
429+
, Literal
430+
, MemberAccess
436431
, NewExpression
437-
, Noop
438-
, ObjectExpression
439-
, ObjectProperty
440-
# , PackageDeclaration
441-
# , PointerType
442-
, PrimitiveType
443-
, RangeStatement
432+
, Noop
433+
, ObjectExpression
434+
, ObjectProperty
435+
, PrimitiveType
436+
, RangeStatement
444437
, ReferenceExpression
445438
, ReturnStatement
446-
, ScopedStatement
447-
# , ScopedType
439+
, ScopedStatement
448440
, Sequence
449441
, SliceExpression
450-
, SpreadElement
451-
# , SuperExpression
442+
, SpreadElement
443+
, SuperExpression
452444
, SwitchStatement
453-
# , ThisExpression test?: Expression | null
454-
# body: Instruction
455-
# , ThrowStatement
445+
, ThisExpression
446+
, ThrowStatement
456447
, TryStatement
457-
, TupleExpression
458-
# , TupleType
448+
, TupleExpression
459449
, UnaryExpression
460-
, VariableDeclaration
461-
# , VoidType
462-
, WhileStatement
450+
, VariableDeclaration
451+
, WhileStatement
463452
, YieldExpression
464453
]
465454

parser-Python/uast/visitor.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,13 +1086,22 @@ def visit_UnaryOp(self, node):
10861086
self.packPos(node.operand, self.visit(node.operand))))
10871087

10881088
def visit_ExceptHandler(self, node):
1089-
body = []
1090-
for stmt in node.body:
1091-
unode = self.packPos(stmt, self.visit(stmt))
1092-
if isinstance(unode, list):
1093-
body.extend(unode)
1094-
else:
1095-
body.append(unode)
1089+
bodys = []
1090+
if node.body:
1091+
col_offsets = [body.col_offset for body in node.body]
1092+
end_col_offsets = [body.end_col_offset for body in node.body]
1093+
min_col = min(col_offsets)
1094+
max_col = max(end_col_offsets)
1095+
body_loc = UNode.SourceLocation(
1096+
UNode.Position(node.body[0].lineno, min_col),
1097+
UNode.Position(node.body[-1].end_lineno, max_col),
1098+
self.sourcefile
1099+
)
1100+
# 处理 body
1101+
for body in node.body:
1102+
bodys.append(self.packPos(body, self.visit(body)))
1103+
else:
1104+
body_loc = UNode.SourceLocation()
10961105
type = None
10971106
if node.type is not None and node.name is not None:
10981107
type = self.packPos(node.type, self.visit(node.type))
@@ -1105,7 +1114,7 @@ def visit_ExceptHandler(self, node):
11051114
UNode.DynamicType(UNode.SourceLocation(),
11061115
UNode.Meta()))))
11071116
return self.packPos(node, UNode.CatchClause(UNode.SourceLocation(), UNode.Meta(), parameter,
1108-
body))
1117+
UNode.ScopedStatement(body_loc, UNode.Meta(), bodys)))
11091118

11101119
def visit_FormattedValue(self, node):
11111120
return self.packPos(node.value, self.visit(node.value))

0 commit comments

Comments
 (0)