Skip to content

Commit 8d2c5ea

Browse files
author
hartsantler
committed
fixed list.sort(), numeric elements now sort properly as they should in numeric order
1 parent fdefd75 commit 8d2c5ea

4 files changed

Lines changed: 105 additions & 38 deletions

File tree

pythonjs/python_to_pythonjs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,9 @@ def visit_Call(self, node):
20102010
elif anode.attr == 'split' and not args:
20112011
return '__split_method(%s)' %self.visit(anode.value)
20122012

2013+
elif anode.attr == 'sort' and not args:
2014+
return '__sort_method(%s)' %self.visit(anode.value)
2015+
20132016
elif anode.attr == 'replace' and len(node.args)==2:
20142017
return '__replace_method(%s, %s)' %(self.visit(anode.value), ','.join(args) )
20152018

@@ -2192,7 +2195,7 @@ def visit_Call(self, node):
21922195
#######################################
21932196

21942197
## special method calls ##
2195-
if isinstance(node.func, ast.Attribute) and node.func.attr in ('get', 'keys', 'values', 'pop', 'items', 'split', 'replace') and not self._with_lua:
2198+
if isinstance(node.func, ast.Attribute) and node.func.attr in ('get', 'keys', 'values', 'pop', 'items', 'split', 'replace', 'sort') and not self._with_lua:
21962199
anode = node.func
21972200
if anode.attr == 'get' and len(node.args) > 0 and len(node.args) <= 2:
21982201
return '__jsdict_get(%s, %s)' %(self.visit(anode.value), args )
@@ -2212,6 +2215,9 @@ def visit_Call(self, node):
22122215
else:
22132216
return '__jsdict_pop(%s)' %self.visit(anode.value)
22142217

2218+
elif anode.attr == 'sort' and not args:
2219+
return '__sort_method(%s)' %self.visit(anode.value)
2220+
22152221
elif anode.attr == 'split' and len(node.args) <= 1:
22162222
if not args:
22172223
return '__split_method(%s)' %self.visit(anode.value)

0 commit comments

Comments
 (0)