Skip to content

Commit 42b5c7a

Browse files
author
hartsantler
committed
optimized get list item
1 parent 8319867 commit 42b5c7a

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

pythonjs/python_to_pythonjs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,11 +1513,13 @@ def visit_Subscript(self, node):
15131513
src = src.replace('"', '\\"')
15141514
err = 'line %s: %s' %(node.lineno, src.strip())
15151515

1516-
return '__get__(%s, "__getitem__", "%s")([%s], __NULL_OBJECT__)' % (
1517-
self.visit(node.value),
1518-
err,
1519-
self.visit(node.slice)
1520-
)
1516+
value = self.visit(node.value)
1517+
slice = self.visit(node.slice)
1518+
fallback = '__get__(%s, "__getitem__", "%s")([%s], __NULL_OBJECT__)' % (value, err, slice)
1519+
if not self._with_lua and isinstance(node.value, ast.Name):
1520+
return '__ternary_operator__(instanceof(%s, Array), %s[%s], %s)' %(value, value,slice, fallback)
1521+
else:
1522+
return fallback
15211523

15221524
def visit_Slice(self, node):
15231525
if self._with_dart:

0 commit comments

Comments
 (0)