rapydscript-ng 0.7.24 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +80 -26
  3. package/bin/build.ts +117 -0
  4. package/bin/package.json +1 -0
  5. package/bin/rapydscript +65 -62
  6. package/build_wheels.py +133 -0
  7. package/editor-plugins/README.md +80 -0
  8. package/editor-plugins/nvim.lua +321 -0
  9. package/local-agent.md +28 -0
  10. package/package.json +4 -5
  11. package/publish.py +27 -17
  12. package/release/baselib-plain-pretty.js +448 -326
  13. package/release/baselib-plain-ugly.js +3 -3
  14. package/release/compiler.js +9027 -8139
  15. package/release/signatures.json +27 -27
  16. package/release/stdlib_modules.json +1 -0
  17. package/src/ast.pyj +428 -280
  18. package/src/baselib-builtins.pyj +49 -28
  19. package/src/baselib-containers.pyj +241 -226
  20. package/src/baselib-errors.pyj +8 -1
  21. package/src/baselib-internal.pyj +38 -23
  22. package/src/baselib-itertools.pyj +13 -7
  23. package/src/baselib-str.pyj +59 -84
  24. package/src/compiler.pyj +4 -4
  25. package/src/errors.pyj +3 -4
  26. package/src/lib/aes.pyj +46 -32
  27. package/src/lib/elementmaker.pyj +11 -9
  28. package/src/lib/encodings.pyj +15 -5
  29. package/src/lib/gettext.pyj +9 -4
  30. package/src/lib/math.pyj +106 -45
  31. package/src/lib/operator.pyj +10 -10
  32. package/src/lib/pythonize.pyj +2 -1
  33. package/src/lib/random.pyj +28 -21
  34. package/src/lib/re.pyj +492 -19
  35. package/src/lib/traceback.pyj +171 -29
  36. package/src/lib/uuid.pyj +2 -2
  37. package/src/output/classes.pyj +28 -27
  38. package/src/output/codegen.pyj +87 -83
  39. package/src/output/comments.pyj +8 -8
  40. package/src/output/exceptions.pyj +20 -21
  41. package/src/output/functions.pyj +66 -64
  42. package/src/output/literals.pyj +24 -23
  43. package/src/output/loops.pyj +84 -142
  44. package/src/output/modules.pyj +55 -68
  45. package/src/output/operators.pyj +40 -29
  46. package/src/output/statements.pyj +21 -15
  47. package/src/output/stream.pyj +82 -56
  48. package/src/output/utils.pyj +12 -8
  49. package/src/parse.pyj +971 -620
  50. package/src/string_interpolation.pyj +5 -3
  51. package/src/tokenizer.pyj +188 -148
  52. package/src/utils.pyj +32 -15
  53. package/test/_treeshake_mod.pyj +30 -0
  54. package/test/_treeshake_side_effect.pyj +9 -0
  55. package/test/ast_serialization.pyj +392 -0
  56. package/test/async.pyj +95 -0
  57. package/test/baselib.pyj +1 -2
  58. package/test/embedded_compiler.pyj +57 -0
  59. package/test/fmt.pyj +291 -0
  60. package/test/generic.pyj +16 -3
  61. package/test/imports.pyj +8 -6
  62. package/test/internationalization.pyj +38 -37
  63. package/test/lint.pyj +120 -117
  64. package/test/lsp.pyj +257 -0
  65. package/test/repl.pyj +70 -65
  66. package/test/sourcemaps.pyj +315 -0
  67. package/test/starargs.pyj +46 -39
  68. package/test/str.pyj +8 -0
  69. package/test/traceback.pyj +263 -0
  70. package/test/treeshaking.pyj +181 -0
  71. package/test/web_repl_export.pyj +88 -0
  72. package/tools/ast_serialize.mjs +557 -0
  73. package/tools/cli.mjs +531 -0
  74. package/tools/compile.mjs +205 -0
  75. package/tools/compiler.mjs +159 -0
  76. package/tools/{completer.js → completer.mjs} +6 -6
  77. package/tools/{embedded_compiler.js → embedded_compiler.mjs} +17 -13
  78. package/tools/export.js +109 -56
  79. package/tools/fmt.mjs +975 -0
  80. package/tools/{gettext.js → gettext.mjs} +46 -53
  81. package/tools/ini.mjs +175 -0
  82. package/tools/{lint.js → lint.mjs} +78 -55
  83. package/tools/lsp.mjs +964 -0
  84. package/tools/lsp_protocol.mjs +259 -0
  85. package/tools/lsp_symbols.mjs +418 -0
  86. package/tools/{msgfmt.js → msgfmt.mjs} +18 -18
  87. package/tools/{repl.js → repl.mjs} +56 -42
  88. package/tools/{self.js → self.mjs} +71 -46
  89. package/tools/sourcemap.mjs +123 -0
  90. package/tools/test.mjs +252 -0
  91. package/tools/treeshake.mjs +400 -0
  92. package/tools/{utils.js → utils.mjs} +26 -23
  93. package/tools/{web_repl.js → web_repl.mjs} +15 -13
  94. package/tools/web_repl_export.mjs +97 -0
  95. package/tree-sitter/README.md +101 -0
  96. package/tree-sitter/grammar.js +992 -0
  97. package/tree-sitter/package.json +43 -0
  98. package/tree-sitter/queries/highlights.scm +232 -0
  99. package/tree-sitter/queries/indents.scm +64 -0
  100. package/tree-sitter/queries/injections.scm +14 -0
  101. package/tree-sitter/queries/locals.scm +108 -0
  102. package/tree-sitter/src/grammar.json +4976 -0
  103. package/tree-sitter/src/node-types.json +2901 -0
  104. package/tree-sitter/src/parser.c +196465 -0
  105. package/tree-sitter/src/scanner.c +294 -0
  106. package/tree-sitter/src/tree_sitter/alloc.h +54 -0
  107. package/tree-sitter/src/tree_sitter/array.h +330 -0
  108. package/tree-sitter/src/tree_sitter/parser.h +286 -0
  109. package/tree-sitter/test/corpus/chaining.txt +99 -0
  110. package/tree-sitter/test/corpus/classes.txt +147 -0
  111. package/tree-sitter/test/corpus/comprehensions.txt +155 -0
  112. package/tree-sitter/test/corpus/containers.txt +242 -0
  113. package/tree-sitter/test/corpus/control_flow.txt +361 -0
  114. package/tree-sitter/test/corpus/decorators.txt +64 -0
  115. package/tree-sitter/test/corpus/existential.txt +102 -0
  116. package/tree-sitter/test/corpus/functions.txt +293 -0
  117. package/tree-sitter/test/corpus/imports.txt +117 -0
  118. package/tree-sitter/test/corpus/literals.txt +135 -0
  119. package/tree-sitter/test/corpus/operators.txt +296 -0
  120. package/tree-sitter/test/corpus/statements.txt +189 -0
  121. package/tree-sitter/test/corpus/strings.txt +90 -0
  122. package/tree-sitter/test/corpus/subscripts.txt +227 -0
  123. package/tree-sitter/tree-sitter.json +36 -0
  124. package/web-repl/env.js +35 -23
  125. package/web-repl/main.js +8 -8
  126. package/bin/export +0 -75
  127. package/bin/web-repl-export +0 -102
  128. package/tools/cli.js +0 -523
  129. package/tools/compile.js +0 -184
  130. package/tools/compiler.js +0 -84
  131. package/tools/ini.js +0 -65
  132. package/tools/test.js +0 -110
@@ -1,22 +1,18 @@
1
1
  # vim:fileencoding=utf-8
2
2
  # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
- # globals: writefile
4
3
  from __python__ import hash_literals
5
4
 
6
- from output.statements import declare_vars, display_body
7
- from output.stream import OutputStream
8
- from output.utils import create_doctring
9
5
  from output.comments import print_comments, output_comments
10
6
  from output.functions import set_module_name
11
- from parse import get_compiler_version
12
- from utils import cache_file_name
7
+ from output.statements import declare_vars, display_body
8
+ from output.utils import create_doctring
13
9
 
14
10
 
15
11
  def write_imports(module, output):
16
12
  imports = []
17
13
  for import_id in Object.keys(module.imports):
18
14
  imports.push(module.imports[import_id])
19
- imports.sort(def(a, b):
15
+ imports.sort(def (a, b):
20
16
  a, b = a.import_order, b.import_order
21
17
  return -1 if a < b else (1 if a > b else 0)
22
18
  )
@@ -54,6 +50,7 @@ def write_imports(module, output):
54
50
  if module_.module_id is not '__main__':
55
51
  print_module(module_, output)
56
52
 
53
+
57
54
  def write_main_name(output):
58
55
  if output.options.write_name:
59
56
  output.newline()
@@ -63,16 +60,18 @@ def write_main_name(output):
63
60
  output.newline()
64
61
  output.newline()
65
62
 
63
+
66
64
  def const_decl(js_version):
67
65
  # return 'const' if js_version > 5 else 'var'
68
66
  # Workaround for bug in Chrome eval(). eval() barfs if it sees const before a function.
69
67
  # See https://github.com/kovidgoyal/rapydscript-ng/issues/29
70
68
  return 'var'
71
69
 
70
+
72
71
  def declare_exports(module_id, exports, output, docstrings):
73
72
  seen = {}
74
73
  if output.options.keep_docstrings and docstrings and docstrings.length:
75
- exports.push({'name':'__doc__', 'refname': 'ρσ_module_doc__'})
74
+ exports.push({'name': '__doc__', 'refname': 'ρσ_module_doc__'})
76
75
  output.newline(), output.indent()
77
76
  v = const_decl(output.options.js_version)
78
77
  output.assign(v + ' ρσ_module_doc__'), output.print(JSON.stringify(create_doctring(docstrings)))
@@ -89,6 +88,7 @@ def declare_exports(module_id, exports, output, docstrings):
89
88
  seen[symbol.name] = True
90
89
  output.end_statement()
91
90
 
91
+
92
92
  def prologue(module, output):
93
93
  # any code that should appear before the main body
94
94
  if output.options.omit_baselib:
@@ -96,21 +96,40 @@ def prologue(module, output):
96
96
  output.indent()
97
97
  v = const_decl(output.options.js_version)
98
98
  output.print(v), output.space()
99
- output.spaced.apply(output, (('ρσ_iterator_symbol = (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") ? Symbol.iterator : "iterator-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' '))))
99
+ output.spaced.apply(
100
+ output,
101
+ (('ρσ_iterator_symbol = (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") ? Symbol.iterator : "iterator-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' ')))
102
+ )
100
103
  output.end_statement()
101
104
  output.indent(), output.print(v), output.space()
102
- output.spaced.apply(output, (('ρσ_kwargs_symbol = (typeof Symbol === "function") ? Symbol("kwargs-object") : "kwargs-object-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' '))))
105
+ output.spaced.apply(
106
+ output,
107
+ (('ρσ_kwargs_symbol = (typeof Symbol === "function") ? Symbol("kwargs-object") : "kwargs-object-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' ')))
108
+ )
103
109
  output.end_statement()
104
110
  output.indent(), output.spaced('var', 'ρσ_cond_temp,', 'ρσ_expr_temp,', 'ρσ_last_exception'), output.end_statement()
105
111
  output.indent(), output.spaced('var', 'ρσ_object_counter', '=', '0'), output.end_statement()
106
- if output.options.js_version > 5:
107
- # Needed for Chrome < 51 and Edge as of August 2016
108
- output.indent(), output.spaced('if(', 'typeof', 'HTMLCollection', '!==', '"undefined"', '&&', 'typeof', 'Symbol', '===', '"function")',
109
- 'NodeList.prototype[Symbol.iterator]', '=', 'HTMLCollection.prototype[Symbol.iterator]', '=', 'NamedNodeMap.prototype[Symbol.iterator]', '=', 'Array.prototype[Symbol.iterator]')
110
- output.end_statement()
111
- needs_yield = output.options.js_version < 6 and module.baselib['yield']
112
- if needs_yield:
113
- output.dump_yield()
112
+ # Needed for Chrome < 51 and Edge as of August 2016
113
+ output.indent(), output.spaced(
114
+ 'if(',
115
+ 'typeof',
116
+ 'HTMLCollection',
117
+ '!==',
118
+ '"undefined"',
119
+ '&&',
120
+ 'typeof',
121
+ 'Symbol',
122
+ '===',
123
+ '"function")',
124
+ 'NodeList.prototype[Symbol.iterator]',
125
+ '=',
126
+ 'HTMLCollection.prototype[Symbol.iterator]',
127
+ '=',
128
+ 'NamedNodeMap.prototype[Symbol.iterator]',
129
+ '=',
130
+ 'Array.prototype[Symbol.iterator]'
131
+ )
132
+ output.end_statement()
114
133
  # output the baselib
115
134
  if not output.options.baselib_plain:
116
135
  raise ValueError('The baselib is missing! Remember to set the baselib_plain field on the options for OutputStream')
@@ -130,22 +149,21 @@ def print_top_level(self, output):
130
149
  output.end_statement()
131
150
 
132
151
  if output.options.private_scope and is_main:
133
- output.with_parens(def():
134
- output.print("function()")
135
- output.with_block(def():
152
+ output.with_parens(def ():
153
+ output.print('function()')
154
+ output.with_block(def ():
136
155
  # strict mode is more verbose about errors, and less forgiving about them
137
156
  # kind of like Python
138
157
  output.indent()
139
158
  output.print('"use strict"')
140
159
  output.end_statement()
141
-
142
160
  prologue(self, output)
143
161
  write_imports(self, output)
144
162
  output.newline()
145
163
  output.indent()
146
- output.with_parens(def():
147
- output.print("function()")
148
- output.with_block(def():
164
+ output.with_parens(def ():
165
+ output.print('function()')
166
+ output.with_block(def ():
149
167
  write_main_name(output)
150
168
  output.newline()
151
169
  declare_vars(self.localvars, output)
@@ -158,12 +176,12 @@ def print_top_level(self, output):
158
176
  output.newline()
159
177
  )
160
178
  )
161
- output.print("();")
179
+ output.print('();')
162
180
  output.newline()
163
181
  )
164
182
  )
165
- output.print("();")
166
- output.print("")
183
+ output.print('();')
184
+ output.print('')
167
185
  else:
168
186
  if is_main:
169
187
  prologue(self, output)
@@ -176,6 +194,7 @@ def print_top_level(self, output):
176
194
  output_comments(self.comments_after, output)
177
195
  set_module_name()
178
196
 
197
+
179
198
  def print_module(self, output):
180
199
  set_module_name(self.module_id)
181
200
 
@@ -186,9 +205,9 @@ def print_module(self, output):
186
205
 
187
206
  output.newline()
188
207
  output.indent()
189
- output.with_parens(def():
190
- output.print("function()")
191
- output.with_block(def():
208
+ output.with_parens(def ():
209
+ output.print('function()')
210
+ output.with_block(def ():
192
211
  # dump the logic of this module
193
212
  print_comments(self, output)
194
213
  if output.options.write_name:
@@ -198,50 +217,18 @@ def print_module(self, output):
198
217
  output.print('"' + self.module_id + '"')
199
218
  output.semicolon()
200
219
  output.newline()
201
- def output_key(beautify, keep_docstrings, js_version):
202
- return 'beautify:' + beautify + ' keep_docstrings:' + keep_docstrings + ' js_version:' + js_version
203
- okey = output_key(output.options.beautify, output.options.keep_docstrings, output.options.js_version)
204
- if self.is_cached and okey in self.outputs:
205
- output.print(self.outputs[okey])
206
- else:
207
- output_module(output)
208
- if self.srchash and self.filename:
209
- cached = {
210
- 'version':get_compiler_version(), 'signature':self.srchash, 'classes': {}, 'baselib':self.baselib,
211
- 'nonlocalvars':self.nonlocalvars, 'imported_module_ids':self.imported_module_ids, 'exports':[],
212
- 'outputs':{}, 'discard_asserts': v'!!output.options.discard_asserts'
213
- }
214
- for cname in Object.keys(self.classes):
215
- cobj = self.classes[cname]
216
- cached.classes[cname] = {'name':{'name':cobj.name.name}, 'static':cobj.static, 'bound':cobj.bound, 'classvars':cobj.classvars}
217
- for symdef in self.exports:
218
- cached.exports.push({'name':symdef.name})
219
- for beautify in [True, False]:
220
- for keep_docstrings in [True, False]:
221
- for js_version in [5, 6]:
222
- co = OutputStream({
223
- 'beautify':beautify, 'keep_docstrings':keep_docstrings,
224
- 'js_version':js_version, 'private_scope':False,
225
- 'write_name':False, 'discard_asserts':output.options.discard_asserts
226
- })
227
- co.with_indent(output.indentation(), def():
228
- output_module(co)
229
- )
230
- raw = co.get()
231
- cached.outputs[output_key(beautify, keep_docstrings, js_version)] = raw
232
- try:
233
- writefile(cache_file_name(self.filename, output.options.module_cache_dir), JSON.stringify(cached, None, '\t'))
234
- except Error as e:
235
- console.error('Failed to write output cache file:', self.filename + '-cached', 'with error:', e)
220
+ output_module(output)
236
221
  )
237
222
  )
238
- output.print("()")
223
+ output.print('()')
239
224
  output.semicolon()
240
225
  output.newline()
241
226
  set_module_name()
242
227
 
228
+
243
229
  def print_imports(container, output):
244
230
  is_first_aname = True
231
+
245
232
  def add_aname(aname, key, from_import):
246
233
  nonlocal is_first_aname
247
234
  if is_first_aname:
@@ -274,7 +261,7 @@ def print_imports(container, output):
274
261
  if i is 0:
275
262
  add_aname(part, part, False)
276
263
  else:
277
- q = parts[:i+1].join('.')
264
+ q = parts[:i + 1].join('.')
278
265
  output.indent()
279
266
  output.spaced(q, '=', 'ρσ_modules["' + q + '"]')
280
267
  output.end_statement()
@@ -1,6 +1,7 @@
1
1
  # vim:fileencoding=utf-8
2
2
  # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
3
  from __python__ import hash_literals
4
+
4
5
  from ast import (
5
6
  AST_Array, AST_Assign, AST_BaseCall, AST_Binary, AST_Conditional,
6
7
  AST_ItemAccess, AST_Number, AST_Object, AST_Return, AST_Seq, AST_Set,
@@ -16,11 +17,12 @@ def print_getattr(self, output, skip_expression): # AST_Dot
16
17
  expr.print(output)
17
18
  if is_node_type(expr, AST_Number) and expr.value >= 0:
18
19
  if not /[xa-f.]/i.test(output.last()):
19
- output.print(".")
20
- output.print(".")
20
+ output.print('.')
21
+ output.print('.')
21
22
  # the name after dot would be mapped about here.
22
23
  output.print_name(self.property)
23
24
 
25
+
24
26
  def print_getitem(self, output): # AST_Sub
25
27
  expr = self.expression
26
28
  prop = self.property
@@ -28,13 +30,13 @@ def print_getitem(self, output): # AST_Sub
28
30
  expr.print(output)
29
31
  output.print('['), prop.print(output), output.print(']')
30
32
  return
31
- is_negative_number = is_node_type(prop, AST_Unary) and prop.operator is "-" and is_node_type(prop.expression, AST_Number)
33
+ is_negative_number = is_node_type(prop, AST_Unary) and prop.operator is '-' and is_node_type(prop.expression, AST_Number)
32
34
  is_repeatable = is_node_type(expr, AST_SymbolRef)
33
35
  if is_repeatable:
34
36
  expr.print(output)
35
37
  else:
36
38
  output.spaced('(ρσ_expr_temp', '=', expr), output.print(')')
37
- expr = {'print': def(): output.print('ρσ_expr_temp');}
39
+ expr = {'print': def (): output.print('ρσ_expr_temp');}
38
40
 
39
41
  if is_negative_number:
40
42
  output.print('['), expr.print(output), output.print('.length'), prop.print(output), output.print(']')
@@ -45,7 +47,7 @@ def print_getitem(self, output): # AST_Sub
45
47
  if is_repeatable:
46
48
  output.spaced('[(typeof', prop, '===', '"number"', '&&', prop)
47
49
  output.spaced('', '<', '0)', '?', expr), output.spaced('.length', '+', prop, ':', prop)
48
- output.print("]")
50
+ output.print(']')
49
51
  else:
50
52
  output.print('[ρσ_bound_index('), prop.print(output), output.comma(), expr.print(output), output.print(')]')
51
53
 
@@ -68,6 +70,7 @@ def print_rich_getitem(self, output): # AST_ItemAccess
68
70
  self.assignment.print(output)
69
71
  output.print(')')
70
72
 
73
+
71
74
  def print_splice_assignment(self, output): # AST_Splice
72
75
  # splice assignment via pythonic array[start:end]
73
76
  output.print('ρσ_splice(')
@@ -78,6 +81,7 @@ def print_splice_assignment(self, output): # AST_Splice
78
81
  self.property2.print(output)
79
82
  output.print(')')
80
83
 
84
+
81
85
  def print_delete(self, output):
82
86
  if is_node_type(self, AST_Symbol):
83
87
  output.assign(self), output.print('undefined')
@@ -86,6 +90,7 @@ def print_delete(self, output):
86
90
  else:
87
91
  output.spaced('delete', self)
88
92
 
93
+
89
94
  def print_unary_prefix(self, output):
90
95
  op = self.operator
91
96
  if op is 'delete':
@@ -94,14 +99,14 @@ def print_unary_prefix(self, output):
94
99
  if /^[a-z]/i.test(op):
95
100
  output.space()
96
101
  if self.parenthesized:
97
- output.with_parens(def():
102
+ output.with_parens(def ():
98
103
  self.expression.print(output)
99
104
  )
100
105
  else:
101
106
  self.expression.print(output)
102
107
 
103
- def write_instanceof(left, right, output):
104
108
 
109
+ def write_instanceof(left, right, output):
105
110
  def do_many(vals):
106
111
  output.print('ρσ_instanceof.apply(null,'), output.space()
107
112
  output.print('['), left.print(output), output.comma()
@@ -119,6 +124,7 @@ def write_instanceof(left, right, output):
119
124
  output.print('ρσ_instanceof(')
120
125
  left.print(output), output.comma(), right.print(output), output.print(')')
121
126
 
127
+
122
128
  def write_smart_equality(self, output):
123
129
  def is_ok(x):
124
130
  return not (
@@ -141,14 +147,14 @@ def write_smart_equality(self, output):
141
147
 
142
148
 
143
149
  comparators = {
144
- "<": True,
145
- ">": True,
146
- "<=": True,
147
- ">=": True,
150
+ '<': True,
151
+ '>': True,
152
+ '<=': True,
153
+ '>=': True,
148
154
  }
149
155
 
150
156
  function_ops = {
151
- "in": "ρσ_in",
157
+ 'in': 'ρσ_in',
152
158
  'nin': '!ρσ_in',
153
159
  }
154
160
 
@@ -156,7 +162,7 @@ function_ops = {
156
162
  def print_binary_op(self, output):
157
163
  if function_ops[self.operator]:
158
164
  output.print(function_ops[self.operator])
159
- output.with_parens(def():
165
+ output.with_parens(def ():
160
166
  self.left.print(output)
161
167
  output.comma()
162
168
  self.right.print(output)
@@ -174,15 +180,15 @@ def print_binary_op(self, output):
174
180
  output.space()
175
181
  output.print(self.left.operator)
176
182
  output.space()
177
- output.with_parens(def():
183
+ output.with_parens(def ():
178
184
  nonlocal leftvar
179
- output.assign("ρσ_cond_temp")
185
+ output.assign('ρσ_cond_temp')
180
186
  self.left.right.print(output)
181
- leftvar = "ρσ_cond_temp"
187
+ leftvar = 'ρσ_cond_temp'
182
188
  )
183
189
 
184
190
  output.space()
185
- output.print("&&")
191
+ output.print('&&')
186
192
  output.space()
187
193
  output.print(leftvar)
188
194
  output.space()
@@ -191,7 +197,7 @@ def print_binary_op(self, output):
191
197
  self.right.print(output)
192
198
  elif self.operator is '//':
193
199
  output.print('Math.floor')
194
- output.with_parens(def():
200
+ output.with_parens(def ():
195
201
  self.left.print(output)
196
202
  output.space()
197
203
  output.print('/')
@@ -228,7 +234,8 @@ def print_binary_op(self, output):
228
234
  else:
229
235
  output.spaced(self.left, self.operator, self.right)
230
236
 
231
- after_map = {'.':'d', '(':'c', '[':'d', 'g':'g', 'null':'n'}
237
+ after_map = {'.': 'd', '(': 'c', '[': 'd', 'g': 'g', 'null': 'n'}
238
+
232
239
 
233
240
  def print_existential(self, output):
234
241
  key = after_map[self.after] if self.after is None or jstype(self.after) is 'string' else 'e'
@@ -253,15 +260,16 @@ def print_existential(self, output):
253
260
  output.comma(), self.after.print(output)
254
261
  output.print(')')
255
262
 
263
+
256
264
  def print_assignment(self, output):
257
265
  flattened = False
258
266
  left = self.left
259
267
  if is_node_type(left, AST_Seq):
260
- left = new AST_Array({'elements':v'[left.car, left.cdr]'})
268
+ left = new AST_Array({'elements': v'[left.car, left.cdr]'})
261
269
  if is_node_type(left, AST_Array):
262
270
  flat = left.flatten()
263
271
  flattened = flat.length > left.elements.length
264
- output.print("ρσ_unpack")
272
+ output.print('ρσ_unpack')
265
273
  else:
266
274
  left.print(output)
267
275
  output.space()
@@ -269,7 +277,7 @@ def print_assignment(self, output):
269
277
  output.space()
270
278
  if flattened:
271
279
  output.print('ρσ_flatten')
272
- output.with_parens(def():self.right.print(output);)
280
+ output.with_parens(def (): self.right.print(output);)
273
281
  else:
274
282
  self.right.print(output)
275
283
  if is_node_type(left, AST_Array):
@@ -280,11 +288,12 @@ def print_assignment(self, output):
280
288
  output.end_statement()
281
289
  unpack_tuple(flat, output, True)
282
290
 
291
+
283
292
  def print_assign(self, output):
284
293
  if self.operator is '//=':
285
294
  output.assign(self.left)
286
295
  output.print('Math.floor')
287
- output.with_parens(def():
296
+ output.with_parens(def ():
288
297
  self.left.print(output)
289
298
  output.space()
290
299
  output.print('/')
@@ -300,11 +309,11 @@ def print_assign(self, output):
300
309
  is_compound_assign = True
301
310
  break
302
311
  if is_compound_assign:
303
- temp_rhs = new AST_SymbolRef({'name':'ρσ_chain_assign_temp'})
304
- print_assignment(new AST_Assign({'left':temp_rhs, 'operator':'=', 'right':rhs}), output)
312
+ temp_rhs = new AST_SymbolRef({'name': 'ρσ_chain_assign_temp'})
313
+ print_assignment(new AST_Assign({'left': temp_rhs, 'operator': '=', 'right': rhs}), output)
305
314
  for lhs in left_hand_sides:
306
315
  output.end_statement(), output.indent()
307
- print_assignment(new AST_Assign({'left':lhs, 'right':temp_rhs, 'operator':self.operator}), output)
316
+ print_assignment(new AST_Assign({'left': lhs, 'right': temp_rhs, 'operator': self.operator}), output)
308
317
  else:
309
318
  for lhs in left_hand_sides:
310
319
  output.spaced(lhs, '=', '')
@@ -312,21 +321,23 @@ def print_assign(self, output):
312
321
  else:
313
322
  print_assignment(self, output)
314
323
 
324
+
315
325
  def print_conditional(self, output, condition, consequent, alternative):
316
326
  condition, consequent, alternative = self.condition, self.consequent, self.alternative
317
- output.with_parens(def():condition.print(output);)
327
+ output.with_parens(def (): condition.print(output);)
318
328
  output.space()
319
- output.print("?")
329
+ output.print('?')
320
330
  output.space()
321
331
  consequent.print(output)
322
332
  output.space()
323
333
  output.colon()
324
334
  alternative.print(output)
325
335
 
336
+
326
337
  def print_seq(output):
327
338
  self = this
328
339
  p = output.parent()
329
- print_seq = def():
340
+ print_seq = def ():
330
341
  self.car.print(output)
331
342
  if self.cdr:
332
343
  output.comma()
@@ -8,14 +8,15 @@ from ast import (
8
8
  AST_Conditional, AST_Binary, AST_BlockStatement, is_node_type
9
9
  )
10
10
 
11
+
11
12
  def force_statement(stat, output):
12
13
  if output.options.bracketize:
13
14
  if not stat or is_node_type(stat, AST_EmptyStatement):
14
- output.print("{}")
15
+ output.print('{}')
15
16
  elif is_node_type(stat, AST_BlockStatement):
16
17
  stat.print(output)
17
18
  else:
18
- output.with_block(def():
19
+ output.with_block(def ():
19
20
  output.indent()
20
21
  stat.print(output)
21
22
  output.newline()
@@ -26,6 +27,7 @@ def force_statement(stat, output):
26
27
  else:
27
28
  stat.print(output)
28
29
 
30
+
29
31
  # return true if the node at the top of the stack (that means the
30
32
  # innermost node in the current output) is lexically the first in
31
33
  # a statement.
@@ -54,7 +56,7 @@ def declare_vars(vars, output):
54
56
  # declare all variables as local, unless explictly set otherwise
55
57
  if vars.length:
56
58
  output.indent()
57
- output.print("var")
59
+ output.print('var')
58
60
  output.space()
59
61
  for i, arg in enumerate(vars):
60
62
  if i:
@@ -64,6 +66,7 @@ def declare_vars(vars, output):
64
66
  output.semicolon()
65
67
  output.newline()
66
68
 
69
+
67
70
  def display_body(body, is_toplevel, output):
68
71
  last = body.length - 1
69
72
  for i, stmt in enumerate(body):
@@ -80,10 +83,10 @@ def display_complex_body(node, is_toplevel, output, function_preamble):
80
83
  # this is a method, add 'var self = this'
81
84
  if is_node_type(node, AST_Method) and not node.static:
82
85
  output.indent()
83
- output.print("var")
86
+ output.print('var')
84
87
  output.space()
85
- output.assign(node.argnames[0])
86
- output.print("this")
88
+ output.assign(node.argnames.args[0])
89
+ output.print('this')
87
90
  output.semicolon()
88
91
  output.newline()
89
92
  offset += 1
@@ -95,18 +98,19 @@ def display_complex_body(node, is_toplevel, output, function_preamble):
95
98
  elif is_node_type(node, AST_Except):
96
99
  if node.argname:
97
100
  output.indent()
98
- output.print("var")
101
+ output.print('var')
99
102
  output.space()
100
103
  output.assign(node.argname)
101
- output.print("ρσ_Exception")
104
+ output.print('ρσ_Exception')
102
105
  output.semicolon()
103
106
  output.newline()
104
107
 
105
108
  display_body(node.body, is_toplevel, output)
106
109
 
110
+
107
111
  def print_bracketed(node, output, complex, function_preamble, before, after):
108
112
  if node.body.length > 0:
109
- output.with_block(def():
113
+ output.with_block(def ():
110
114
  if before:
111
115
  before(output)
112
116
  if complex:
@@ -118,14 +122,15 @@ def print_bracketed(node, output, complex, function_preamble, before, after):
118
122
  )
119
123
  else:
120
124
  if before or after:
121
- output.with_block(def():
125
+ output.with_block(def ():
122
126
  if before:
123
127
  before(output)
124
128
  if after:
125
129
  after(output)
126
130
  )
127
131
  else:
128
- output.print("{}")
132
+ output.print('{}')
133
+
129
134
 
130
135
  def print_with(self, output):
131
136
  exits = v'[]'
@@ -143,22 +148,22 @@ def print_with(self, output):
143
148
  output.print(clause_name + '.__enter__()')
144
149
  output.end_statement()
145
150
  output.indent(), output.print('try'), output.space()
146
- output.with_block(def():
151
+ output.with_block(def ():
147
152
  output.indent()
148
153
  self._do_print_body(output)
149
154
  output.newline()
150
155
  )
151
156
  output.space(), output.print('catch(e)')
152
- output.with_block(def():
157
+ output.with_block(def ():
153
158
  output.indent(), output.assign('ρσ_with_exception'), output.print('e'), output.end_statement()
154
159
  )
155
160
  output.newline(), output.indent(), output.spaced('if', '(ρσ_with_exception', '===', 'undefined)')
156
- output.with_block(def():
161
+ output.with_block(def ():
157
162
  for clause in exits:
158
163
  output.indent(), output.print(clause + '.__exit__()'), output.end_statement()
159
164
  )
160
165
  output.space(), output.print('else'), output.space()
161
- output.with_block(def():
166
+ output.with_block(def ():
162
167
  output.indent(), output.assign('ρσ_with_suppress'), output.print('false'), output.end_statement()
163
168
  for clause in exits:
164
169
  output.indent()
@@ -168,6 +173,7 @@ def print_with(self, output):
168
173
  output.indent(), output.spaced('if', '(!ρσ_with_suppress)', 'throw ρσ_with_exception'), output.end_statement()
169
174
  )
170
175
 
176
+
171
177
  def print_assert(self, output):
172
178
  if output.options.discard_asserts:
173
179
  return