From 9a52aeda58e996a197806d9dcaac51918f34bcff Mon Sep 17 00:00:00 2001 From: Pursuer2 <1596067968@qq.com> Date: Tue, 28 Sep 2021 20:49:37 +0800 Subject: [PATCH] fix bug in ObjectExpression translation --- js2py/translators/translating_nodes.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/js2py/translators/translating_nodes.py b/js2py/translators/translating_nodes.py index 4e2b5760..7e3ebd1d 100644 --- a/js2py/translators/translating_nodes.py +++ b/js2py/translators/translating_nodes.py @@ -239,12 +239,17 @@ def ObjectExpression(type, properties): name = None elems = [] after = '' + + # Anonymous Object must be put into inline_stack before its properties + for p in properties: + if p['kind'] != 'init': + name = inline_stack.require('Object') + break + for p in properties: if p['kind'] == 'init': elems.append('%s:%s' % Property(**p)) - else: - if name is None: - name = inline_stack.require('Object') + else: if p['kind'] == 'set': k, setter = Property( **p