rapydscript-ng 0.8.2 → 0.8.4

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 (60) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/bin/build.ts +29 -0
  3. package/local-agent.md +4 -0
  4. package/package.json +1 -1
  5. package/release/baselib-plain-pretty.js +85 -61
  6. package/release/baselib-plain-ugly.js +3 -3
  7. package/release/compiler.js +9661 -9540
  8. package/release/signatures.json +26 -26
  9. package/src/ast.pyj +169 -64
  10. package/src/baselib-builtins.pyj +35 -14
  11. package/src/baselib-containers.pyj +70 -40
  12. package/src/baselib-internal.pyj +20 -8
  13. package/src/baselib-itertools.pyj +6 -2
  14. package/src/baselib-str.pyj +74 -28
  15. package/src/errors.pyj +4 -1
  16. package/src/lib/aes.pyj +664 -35
  17. package/src/lib/elementmaker.pyj +105 -13
  18. package/src/lib/encodings.pyj +31 -7
  19. package/src/lib/gettext.pyj +6 -3
  20. package/src/lib/math.pyj +38 -22
  21. package/src/lib/pythonize.pyj +5 -3
  22. package/src/lib/random.pyj +13 -5
  23. package/src/lib/re.pyj +81 -18
  24. package/src/lib/traceback.pyj +42 -10
  25. package/src/lib/uuid.pyj +2 -1
  26. package/src/output/classes.pyj +70 -26
  27. package/src/output/codegen.pyj +92 -20
  28. package/src/output/comments.pyj +11 -4
  29. package/src/output/exceptions.pyj +17 -4
  30. package/src/output/functions.pyj +145 -26
  31. package/src/output/literals.pyj +7 -2
  32. package/src/output/loops.pyj +79 -23
  33. package/src/output/modules.pyj +41 -12
  34. package/src/output/operators.pyj +154 -31
  35. package/src/output/statements.pyj +38 -10
  36. package/src/output/stream.pyj +43 -12
  37. package/src/output/utils.pyj +10 -3
  38. package/src/parse.pyj +740 -259
  39. package/src/string_interpolation.pyj +4 -1
  40. package/src/tokenizer.pyj +314 -57
  41. package/src/unicode_aliases.pyj +4 -2
  42. package/src/utils.pyj +19 -5
  43. package/test/functions.pyj +8 -0
  44. package/test/generic.pyj +9 -0
  45. package/test/lsp.pyj +16 -0
  46. package/test/str.pyj +10 -0
  47. package/tools/cli.mjs +4 -3
  48. package/tools/compile.mjs +9 -3
  49. package/tools/compiler.mjs +0 -6
  50. package/tools/fmt.mjs +41 -2
  51. package/tools/lint-worker.mjs +107 -0
  52. package/tools/lint.mjs +134 -8
  53. package/tools/lsp.mjs +11 -1
  54. package/tree-sitter/grammar.js +27 -6
  55. package/tree-sitter/queries/highlights.scm +10 -0
  56. package/tree-sitter/src/grammar.json +130 -5
  57. package/tree-sitter/src/node-types.json +73 -0
  58. package/tree-sitter/src/parser.c +119589 -114993
  59. package/tree-sitter/src/scanner.c +275 -17
  60. package/tree-sitter/test/corpus/strings.txt +41 -5
@@ -2,10 +2,11 @@
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 AST_ClassCall, AST_New, has_calls, AST_Dot, AST_SymbolRef, is_node_type
5
+ from ast import (
6
+ AST_ClassCall, AST_New, has_calls, AST_Dot, AST_SymbolRef, is_node_type
7
+ )
6
8
  from output.operators import print_getattr
7
9
  from output.statements import print_bracketed
8
- from output.stream import OutputStream
9
10
  from output.utils import create_doctring
10
11
 
11
12
  anonfunc = 'ρσ_anonfunc'
@@ -38,8 +39,12 @@ def decorate(decorators, output, func):
38
39
 
39
40
  def function_args(argnames, output, strip_first):
40
41
  output.with_parens(def ():
41
- if argnames and argnames.args.length and (argnames.is_simple_func is True or argnames.is_simple_func is undefined):
42
- for i, arg in enumerate((argnames.args.slice(1) if strip_first else argnames.args)):
42
+ if (argnames and argnames.args.length
43
+ and (argnames.is_simple_func is True
44
+ or argnames.is_simple_func is undefined)):
45
+ for i, arg in enumerate(
46
+ argnames.args.slice(1) if strip_first else argnames.args
47
+ ):
43
48
  if i:
44
49
  output.comma()
45
50
  arg.print(output)
@@ -51,7 +56,8 @@ def function_preamble(node, output, offset):
51
56
  a = node.argnames
52
57
  if not a or a.is_simple_func:
53
58
  return
54
- # If this function has optional parameters/*args/**kwargs declare it differently
59
+ # If this function has optional parameters/*args/**kwargs
60
+ # declare it differently
55
61
  fname = node.name.name if node.name else anonfunc
56
62
  kw = 'arguments[arguments.length-1]'
57
63
  # Define all formal parameters
@@ -63,14 +69,59 @@ def function_preamble(node, output, offset):
63
69
  output.space()
64
70
  output.assign(arg)
65
71
  if Object.prototype.hasOwnProperty.call(a.defaults, arg.name):
66
- output.spaced('(arguments[' + i + ']', '===', 'undefined', '||',
67
- '(', i, '===', 'arguments.length-1', '&&', kw, '!==', 'null', '&&', 'typeof', kw, '===', '"object"', '&&',
68
- kw, '[ρσ_kwargs_symbol]', '===', 'true))', '?', '')
72
+ output.spaced(
73
+ '(arguments[' + i + ']',
74
+ '===',
75
+ 'undefined',
76
+ '||',
77
+ '(',
78
+ i,
79
+ '===',
80
+ 'arguments.length-1',
81
+ '&&',
82
+ kw,
83
+ '!==',
84
+ 'null',
85
+ '&&',
86
+ 'typeof',
87
+ kw,
88
+ '===',
89
+ '"object"',
90
+ '&&',
91
+ kw,
92
+ '[ρσ_kwargs_symbol]',
93
+ '===',
94
+ 'true))',
95
+ '?',
96
+ ''
97
+ )
69
98
  output.print(fname + '.__defaults__.'), arg.print(output)
70
99
  output.space(), output.print(':'), output.space()
71
100
  else:
72
- output.spaced('(', i, '===', 'arguments.length-1', '&&', kw, '!==', 'null', '&&', 'typeof', kw, '===', '"object"', '&&',
73
- kw, '[ρσ_kwargs_symbol]', '===', 'true)', '?', 'undefined', ':', '')
101
+ output.spaced(
102
+ '(',
103
+ i,
104
+ '===',
105
+ 'arguments.length-1',
106
+ '&&',
107
+ kw,
108
+ '!==',
109
+ 'null',
110
+ '&&',
111
+ 'typeof',
112
+ kw,
113
+ '===',
114
+ '"object"',
115
+ '&&',
116
+ kw,
117
+ '[ρσ_kwargs_symbol]',
118
+ '===',
119
+ 'true)',
120
+ '?',
121
+ 'undefined',
122
+ ':',
123
+ ''
124
+ )
74
125
  output.print('arguments[' + i + ']')
75
126
  output.end_statement()
76
127
  if a.kwargs or a.has_defaults:
@@ -81,13 +132,35 @@ def function_preamble(node, output, offset):
81
132
  output.end_statement()
82
133
  # Ensure kwargs is the options object
83
134
  output.indent()
84
- output.spaced('if', '(' + kw, '===', 'null', '||', 'typeof', kw, '!==', '"object"', '||', kw, '[ρσ_kwargs_symbol]', '!==', 'true)', kw, '=', '{}')
135
+ output.spaced(
136
+ 'if',
137
+ '(' + kw,
138
+ '===',
139
+ 'null',
140
+ '||',
141
+ 'typeof',
142
+ kw,
143
+ '!==',
144
+ '"object"',
145
+ '||',
146
+ kw,
147
+ '[ρσ_kwargs_symbol]',
148
+ '!==',
149
+ 'true)',
150
+ kw,
151
+ '=',
152
+ '{}'
153
+ )
85
154
  output.end_statement()
86
155
  # Read values from the kwargs object for any formal parameters
87
156
  if a.has_defaults:
88
157
  for dname in Object.keys(a.defaults):
89
158
  output.indent()
90
- output.spaced('if', '(Object.prototype.hasOwnProperty.call(' + kw + ',', '"' + dname + '"))')
159
+ output.spaced(
160
+ 'if',
161
+ '(Object.prototype.hasOwnProperty.call(' + kw + ',',
162
+ '"' + dname + '"))'
163
+ )
91
164
  output.with_block(def ():
92
165
  output.indent()
93
166
  output.spaced(dname, '=', kw + '.' + dname)
@@ -100,14 +173,37 @@ def function_preamble(node, output, offset):
100
173
  output.newline()
101
174
 
102
175
  if a.starargs is not undefined:
103
- # Define the *args parameter, putting in whatever is left after assigning the formal parameters and the options object
176
+ # Define the *args parameter, putting in whatever is left
177
+ # after assigning the formal parameters and the options object
104
178
  nargs = a.args.length - offset
105
179
  output.indent()
106
- output.spaced('var', a.starargs.name, '=', 'Array.prototype.slice.call(arguments,', nargs + ')')
180
+ output.spaced(
181
+ 'var',
182
+ a.starargs.name,
183
+ '=',
184
+ 'Array.prototype.slice.call(arguments,',
185
+ nargs + ')'
186
+ )
107
187
  output.end_statement()
108
188
  # Remove the options object, if present
109
189
  output.indent()
110
- output.spaced('if', '(' + kw, '!==', 'null', '&&', 'typeof', kw, '===', '"object"', '&&', kw, '[ρσ_kwargs_symbol]', '===', 'true)', a.starargs.name)
190
+ output.spaced(
191
+ 'if',
192
+ '(' + kw,
193
+ '!==',
194
+ 'null',
195
+ '&&',
196
+ 'typeof',
197
+ kw,
198
+ '===',
199
+ '"object"',
200
+ '&&',
201
+ kw,
202
+ '[ρσ_kwargs_symbol]',
203
+ '===',
204
+ 'true)',
205
+ a.starargs.name
206
+ )
111
207
  output.print('.pop()')
112
208
  output.end_statement()
113
209
 
@@ -135,7 +231,8 @@ def function_annotation(self, output, strip_first, name):
135
231
  arg.print(output)
136
232
  output.print(':'), output.space()
137
233
  arg.annotation.print(output)
138
- if i < self.argnames.args.length - 1 or self.return_annotation:
234
+ if (i < self.argnames.args.length - 1
235
+ or self.return_annotation):
139
236
  output.comma()
140
237
  if self.return_annotation:
141
238
  output.print('return:'), output.space()
@@ -172,7 +269,8 @@ def function_annotation(self, output, strip_first, name):
172
269
  output.print(']')
173
270
 
174
271
  # Create __doc__
175
- if output.options.keep_docstrings and self.docstrings and self.docstrings.length:
272
+ if (output.options.keep_docstrings and self.docstrings
273
+ and self.docstrings.length):
176
274
  props.__doc__ = def ():
177
275
  output.print(JSON.stringify(create_doctring(self.docstrings)))
178
276
 
@@ -183,12 +281,19 @@ def function_annotation(self, output, strip_first, name):
183
281
  output.indent()
184
282
  # Only define the properties if they were not already defined, which
185
283
  # can happen if the function definition is inside a loop, for example.
186
- output.spaced('if', '(!' + fname + '.' + names[0] + ')', 'Object.defineProperties(' + fname)
284
+ output.spaced(
285
+ 'if',
286
+ '(!' + fname + '.' + names[0] + ')',
287
+ 'Object.defineProperties(' + fname
288
+ )
187
289
  output.comma()
188
290
  output.with_block(def ():
189
291
  for v'var i = 0; i < names.length; i++':
190
292
  name = names[i]
191
- output.indent(), output.spaced(name, ':', '{value:', ''), props[name](), output.print('}')
293
+ output.indent()
294
+ output.spaced(name, ':', '{value:', '')
295
+ props[name]()
296
+ output.print('}')
192
297
  if i < names.length - 1:
193
298
  output.print(',')
194
299
  output.newline()
@@ -218,9 +323,12 @@ def function_definition(self, output, strip_first, as_expression):
218
323
  print_bracketed(self, output, True, function_preamble)
219
324
  output.newline()
220
325
  output.indent()
221
- output.spaced('var', 'result', '=', 'js_generator.apply(this,', 'arguments)')
326
+ output.spaced(
327
+ 'var', 'result', '=',
328
+ 'js_generator.apply(this,', 'arguments)')
222
329
  output.end_statement()
223
- # Python's generator objects use a separate method to send data to the generator
330
+ # Python's generator objects use a separate method to
331
+ # send data to the generator
224
332
  output.indent()
225
333
  output.spaced('result.send', '=', 'result.next')
226
334
  output.end_statement()
@@ -235,7 +343,10 @@ def function_definition(self, output, strip_first, as_expression):
235
343
  if as_expression:
236
344
  output.end_statement()
237
345
  function_annotation(self, output, strip_first, anonfunc)
238
- output.indent(), output.spaced('return', anonfunc), output.end_statement()
346
+ output.indent(), output.spaced(
347
+ 'return',
348
+ anonfunc
349
+ ), output.end_statement()
239
350
  output.set_indentation(orig_indent)
240
351
  output.indent(), output.print('})()')
241
352
 
@@ -246,7 +357,9 @@ def print_function(output):
246
357
  output.print('var')
247
358
  output.space()
248
359
  output.assign(self.name.name)
249
- decorate(self.decorators, output, def (): function_definition(self, output, False, True);)
360
+ decorate(
361
+ self.decorators, output,
362
+ def (): function_definition(self, output, False, True);)
250
363
  output.end_statement()
251
364
  else:
252
365
  function_definition(self, output, False)
@@ -324,7 +437,9 @@ def print_function_call(self, output):
324
437
 
325
438
  def print_new(apply):
326
439
  output.print('ρσ_interpolate_kwargs_constructor.call(')
327
- output.print('Object.create('), self.expression.print(output), output.print('.prototype)')
440
+ output.print('Object.create(')
441
+ self.expression.print(output)
442
+ output.print('.prototype)')
328
443
  output.comma()
329
444
  output.print('true' if apply else 'false')
330
445
  output.comma()
@@ -366,7 +481,8 @@ def print_function_call(self, output):
366
481
  is_new = is_node_type(self, AST_New)
367
482
  is_repeatable = True
368
483
 
369
- if is_new and not self.args.args.length and not has_kwargs and not self.args.starargs:
484
+ if (is_new and not self.args.args.length
485
+ and not has_kwargs and not self.args.starargs):
370
486
  output.print('new'), output.space()
371
487
  print_function_name()
372
488
  return # new A is the same as new A() in javascript
@@ -386,7 +502,10 @@ def print_function_call(self, output):
386
502
 
387
503
  is_repeatable = is_new or not has_calls(self.expression)
388
504
  if not is_repeatable:
389
- output.assign('(ρσ_expr_temp'), print_this(self.expression, output), output.comma()
505
+ output.assign('(ρσ_expr_temp'), print_this(
506
+ self.expression,
507
+ output
508
+ ), output.comma()
390
509
 
391
510
  if has_kwargs:
392
511
  if is_new:
@@ -28,7 +28,9 @@ def print_obj_literal(self, output):
28
28
  if self.is_pydict:
29
29
  output.spaced.apply(output, 'var ρσ_d = ρσ_dict()'.split(' '))
30
30
  else:
31
- output.spaced('var', 'ρσ_d', '=', ('Object.create(null)' if self.is_jshash else '{}'))
31
+ output.spaced(
32
+ 'var', 'ρσ_d', '=',
33
+ ('Object.create(null)' if self.is_jshash else '{}'))
32
34
  output.end_statement()
33
35
  for i, prop in enumerate(self.properties):
34
36
  output.indent()
@@ -95,5 +97,8 @@ def print_regexp(self, output):
95
97
  str_ = output.to_ascii(str_)
96
98
  output.print(str_)
97
99
  p = output.parent()
98
- if is_node_type(p, AST_Binary) and /^in/.test(p.operator) and p.left is self:
100
+ if is_node_type(
101
+ p,
102
+ AST_Binary
103
+ ) and /^in/.test(p.operator) and p.left is self:
99
104
  output.print(' ')
@@ -2,8 +2,10 @@
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 AST_BaseCall, AST_SymbolRef, AST_Array, AST_Unary, AST_Number, has_calls, AST_Seq, AST_ListComprehension, is_node_type
6
- from output.stream import OutputStream
5
+ from ast import (
6
+ AST_BaseCall, AST_SymbolRef, AST_Array, AST_Unary, AST_Number,
7
+ has_calls, AST_Seq, AST_ListComprehension, is_node_type
8
+ )
7
9
 
8
10
 
9
11
  def unpack_tuple(elems, output, in_statement):
@@ -42,24 +44,28 @@ def is_simple_for_in(self):
42
44
  # return true if this loop can be simplified into a basic for (i in j) loop
43
45
  if is_node_type(self.object, AST_BaseCall)
44
46
  and is_node_type(self.object.expression, AST_SymbolRef)
45
- and self.object.expression.name is 'dir' and self.object.args.args.length is 1:
47
+ and self.object.expression.name is 'dir'
48
+ and self.object.args.args.length is 1:
46
49
  return True
47
50
  return False
48
51
 
49
52
 
50
53
  def is_simple_for(self):
51
- # returns true if this loop can be simplified into a basic for(i=n;i<h;i++) loop
54
+ # returns true if this loop can be simplified into a
55
+ # basic for(i=n;i<h;i++) loop
52
56
  if (is_node_type(self.object, AST_BaseCall) and
53
57
  is_node_type(self.object.expression, AST_SymbolRef) and
54
58
  self.object.expression.name is 'range' and
55
59
  not (is_node_type(self.init, AST_Array))):
56
60
  a = self.object.args.args
57
61
  l = a.length
58
- if l < 3 or (
59
- is_node_type(a[2].value, AST_Number) or (
60
- is_node_type(a[2].value, AST_Unary) and a[2].value.operator is '-' and is_node_type(a[2].value.expression, AST_Number)
61
- )):
62
- if (l is 1 and not has_calls(a[0].value)) or (l > 1 and not has_calls(a[1].value)):
62
+ if (l < 3 or (
63
+ is_node_type(a[2].value, AST_Number) or (
64
+ is_node_type(a[2].value, AST_Unary) and
65
+ a[2].value.operator is '-' and
66
+ is_node_type(a[2].value.expression, AST_Number)))):
67
+ if ((l is 1 and not has_calls(a[0].value)) or
68
+ (l > 1 and not has_calls(a[1].value))):
63
69
  return True
64
70
  return False
65
71
 
@@ -99,8 +105,24 @@ def print_for_loop_body(output):
99
105
 
100
106
  def init_es6_itervar(output, itervar):
101
107
  output.indent()
102
- output.spaced(itervar, '=', '((typeof', itervar + '[Symbol.iterator]', '===', '"function")', '?',
103
- '(' + itervar, 'instanceof', 'Map', '?', itervar + '.keys()', ':', itervar + ')', ':', 'Object.keys(' + itervar + '))')
108
+ output.spaced(
109
+ itervar,
110
+ '=',
111
+ '((typeof',
112
+ itervar + '[Symbol.iterator]',
113
+ '===',
114
+ '"function")',
115
+ '?',
116
+ '(' + itervar,
117
+ 'instanceof',
118
+ 'Map',
119
+ '?',
120
+ itervar + '.keys()',
121
+ ':',
122
+ itervar + ')',
123
+ ':',
124
+ 'Object.keys(' + itervar + '))'
125
+ )
104
126
  output.end_statement()
105
127
 
106
128
 
@@ -138,13 +160,18 @@ def print_for_in(self, output):
138
160
  output.space()
139
161
  output.print(idx)
140
162
  output.space()
141
- output.print('>') if is_node_type(increment, AST_Unary) else output.print('<')
163
+ if is_node_type(increment, AST_Unary):
164
+ output.print('>')
165
+ else:
166
+ output.print('<')
142
167
  output.space()
143
168
  end.print(output)
144
169
  output.semicolon()
145
170
  output.space()
146
171
  output.print(idx)
147
- if increment and (not (is_node_type(increment, AST_Unary)) or increment.expression.value is not '1'):
172
+ if (increment and (
173
+ not (is_node_type(increment, AST_Unary)) or
174
+ increment.expression.value is not '1')):
148
175
  if is_node_type(increment, AST_Unary):
149
176
  output.print('-=')
150
177
  increment.expression.print(output)
@@ -176,7 +203,13 @@ def print_for_in(self, output):
176
203
  output.end_statement()
177
204
  init_es6_itervar(output, itervar)
178
205
  output.indent()
179
- output.spaced('for', '(var', 'ρσ_Index' + output.index_counter, 'of', itervar + ')')
206
+ output.spaced(
207
+ 'for',
208
+ '(var',
209
+ 'ρσ_Index' + output.index_counter,
210
+ 'of',
211
+ itervar + ')'
212
+ )
180
213
 
181
214
  output.space()
182
215
  self._do_print_body(output)
@@ -184,7 +217,13 @@ def print_for_in(self, output):
184
217
 
185
218
  def print_list_comprehension(self, output):
186
219
  tname = self.constructor.name.slice(4)
187
- result_obj = {'ListComprehension': '[]', 'DictComprehension': ('Object.create(null)' if self.is_jshash else '{}'), 'SetComprehension': 'ρσ_set()'}[tname]
220
+ result_obj = {
221
+ 'ListComprehension': '[]',
222
+ 'DictComprehension': (
223
+ 'Object.create(null)' if self.is_jshash else '{}'
224
+ ),
225
+ 'SetComprehension': 'ρσ_set()',
226
+ }[tname]
188
227
  is_generator = tname is 'GeneratorComprehension'
189
228
  if tname is 'DictComprehension':
190
229
  if self.is_pydict:
@@ -197,7 +236,9 @@ def print_list_comprehension(self, output):
197
236
  output.space(), output.print(','), output.space()
198
237
  output.with_parens(def ():
199
238
  if self.value_statement.constructor is AST_Seq:
200
- output.with_square(def (): self.value_statement.print(output);)
239
+ output.with_square(def ():
240
+ self.value_statement.print(output)
241
+ )
201
242
  else:
202
243
  self.value_statement.print(output)
203
244
  )
@@ -213,13 +254,18 @@ def print_list_comprehension(self, output):
213
254
  output.space(), output.print('='), output.space()
214
255
  output.with_parens(def ():
215
256
  if self.value_statement.constructor is AST_Seq:
216
- output.with_square(def (): self.value_statement.print(output);)
257
+ output.with_square(def ():
258
+ self.value_statement.print(output)
259
+ )
217
260
  else:
218
261
  self.value_statement.print(output)
219
262
  )
220
263
  output.end_statement()
221
264
  else:
222
- push_func = 'ρσ_Result.' + ('push' if self.constructor is AST_ListComprehension else 'add')
265
+ push_func = 'ρσ_Result.' + (
266
+ 'push' if self.constructor is AST_ListComprehension
267
+ else 'add'
268
+ )
223
269
  if is_generator:
224
270
  push_func = 'yield '
225
271
  add_to_result = def (output):
@@ -241,7 +287,9 @@ def print_list_comprehension(self, output):
241
287
  body_out = output
242
288
  if is_generator:
243
289
  body_out.indent()
244
- body_out.print('function* js_generator()'), body_out.space(), body_out.print('{')
290
+ body_out.print('function* js_generator()')
291
+ body_out.space()
292
+ body_out.print('{')
245
293
  body_out.newline()
246
294
  previous_indentation = output.indentation()
247
295
  output.set_indentation(output.next_indent())
@@ -289,7 +337,9 @@ def print_list_comprehension(self, output):
289
337
  body_out.indent()
290
338
  body_out.print('if')
291
339
  body_out.space()
292
- body_out.with_parens(def (): self.condition.print(body_out);)
340
+ body_out.with_parens(def ():
341
+ self.condition.print(body_out)
342
+ )
293
343
  body_out.space()
294
344
  body_out.with_block(def ():
295
345
  add_to_result(body_out)
@@ -301,7 +351,10 @@ def print_list_comprehension(self, output):
301
351
  body_out.newline()
302
352
  if self.constructor is AST_ListComprehension:
303
353
  body_out.indent()
304
- body_out.spaced('ρσ_Result', '=', 'ρσ_list_constructor(ρσ_Result)')
354
+ body_out.spaced(
355
+ 'ρσ_Result', '=',
356
+ 'ρσ_list_constructor(ρσ_Result)'
357
+ )
305
358
  body_out.end_statement()
306
359
  if not is_generator:
307
360
  body_out.indent()
@@ -309,11 +362,14 @@ def print_list_comprehension(self, output):
309
362
  body_out.end_statement()
310
363
  if is_generator:
311
364
  output.set_indentation(previous_indentation)
312
- body_out.newline(), body_out.indent(), body_out.print('}') # end js_generator
365
+ body_out.newline()
366
+ body_out.indent()
367
+ body_out.print('}') # end js_generator
313
368
  output.newline(), output.indent()
314
369
  output.spaced('var', 'result', '=', 'js_generator.call(this)')
315
370
  output.end_statement()
316
- # Python's generator objects use a separate method to send data to the generator
371
+ # Python's generator objects use a separate method to
372
+ # send data to the generator
317
373
  output.indent()
318
374
  output.spaced('result.send', '=', 'result.next')
319
375
  output.end_statement()
@@ -42,7 +42,8 @@ def write_imports(module, output):
42
42
  output.print('ρσ_modules.' + module_id)
43
43
  else:
44
44
  output.print('ρσ_modules["' + module_id + '"]')
45
- output.space(), output.print('='), output.space(), output.print('{}')
45
+ output.space(), output.print('=')
46
+ output.space(), output.print('{}')
46
47
  output.end_statement()
47
48
 
48
49
  # Output module code
@@ -63,7 +64,8 @@ def write_main_name(output):
63
64
 
64
65
  def const_decl(js_version):
65
66
  # return 'const' if js_version > 5 else 'var'
66
- # Workaround for bug in Chrome eval(). eval() barfs if it sees const before a function.
67
+ # Workaround for bug in Chrome eval(). eval() barfs if it sees const
68
+ # before a function.
67
69
  # See https://github.com/kovidgoyal/rapydscript-ng/issues/29
68
70
  return 'var'
69
71
 
@@ -74,7 +76,8 @@ def declare_exports(module_id, exports, output, docstrings):
74
76
  exports.push({'name': '__doc__', 'refname': 'ρσ_module_doc__'})
75
77
  output.newline(), output.indent()
76
78
  v = const_decl(output.options.js_version)
77
- output.assign(v + ' ρσ_module_doc__'), output.print(JSON.stringify(create_doctring(docstrings)))
79
+ output.assign(v + ' ρσ_module_doc__')
80
+ output.print(JSON.stringify(create_doctring(docstrings)))
78
81
  output.end_statement()
79
82
  output.newline()
80
83
  for symbol in exports:
@@ -84,7 +87,8 @@ def declare_exports(module_id, exports, output, docstrings):
84
87
  output.print('ρσ_modules.' + module_id + '.' + symbol.name)
85
88
  else:
86
89
  output.print('ρσ_modules["' + module_id + '"].' + symbol.name)
87
- output.space(), output.print('='), output.space(), output.print(symbol.refname or symbol.name)
90
+ output.space(), output.print('=')
91
+ output.space(), output.print(symbol.refname or symbol.name)
88
92
  seen[symbol.name] = True
89
93
  output.end_statement()
90
94
 
@@ -98,17 +102,36 @@ def prologue(module, output):
98
102
  output.print(v), output.space()
99
103
  output.spaced.apply(
100
104
  output,
101
- (('ρσ_iterator_symbol = (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") ? Symbol.iterator : "iterator-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' ')))
105
+ ((
106
+ 'ρσ_iterator_symbol = (typeof Symbol === "function"' +
107
+ ' && typeof Symbol.iterator === "symbol") ?' +
108
+ ' Symbol.iterator : "iterator-Symbol-' +
109
+ '5d0927e5554349048cf0e3762a228256"'
110
+ ).split(' '))
102
111
  )
103
112
  output.end_statement()
104
113
  output.indent(), output.print(v), output.space()
105
114
  output.spaced.apply(
106
115
  output,
107
- (('ρσ_kwargs_symbol = (typeof Symbol === "function") ? Symbol("kwargs-object") : "kwargs-object-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' ')))
116
+ ((
117
+ 'ρσ_kwargs_symbol = (typeof Symbol === "function") ?' +
118
+ ' Symbol("kwargs-object") : "kwargs-object-Symbol-' +
119
+ '5d0927e5554349048cf0e3762a228256"'
120
+ ).split(' '))
108
121
  )
109
122
  output.end_statement()
110
- output.indent(), output.spaced('var', 'ρσ_cond_temp,', 'ρσ_expr_temp,', 'ρσ_last_exception'), output.end_statement()
111
- output.indent(), output.spaced('var', 'ρσ_object_counter', '=', '0'), output.end_statement()
123
+ output.indent(), output.spaced(
124
+ 'var',
125
+ 'ρσ_cond_temp,',
126
+ 'ρσ_expr_temp,',
127
+ 'ρσ_last_exception'
128
+ ), output.end_statement()
129
+ output.indent(), output.spaced(
130
+ 'var',
131
+ 'ρσ_object_counter',
132
+ '=',
133
+ '0'
134
+ ), output.end_statement()
112
135
  # Needed for Chrome < 51 and Edge as of August 2016
113
136
  output.indent(), output.spaced(
114
137
  'if(',
@@ -132,7 +155,10 @@ def prologue(module, output):
132
155
  output.end_statement()
133
156
  # output the baselib
134
157
  if not output.options.baselib_plain:
135
- raise ValueError('The baselib is missing! Remember to set the baselib_plain field on the options for OutputStream')
158
+ raise ValueError(
159
+ 'The baselib is missing! Remember to set the' +
160
+ ' baselib_plain field on the options for OutputStream'
161
+ )
136
162
  output.print(output.options.baselib_plain)
137
163
  output.end_statement()
138
164
 
@@ -142,17 +168,20 @@ def print_top_level(self, output):
142
168
  is_main = self.module_id is '__main__'
143
169
 
144
170
  def write_docstrings():
145
- if is_main and output.options.keep_docstrings and self.docstrings and self.docstrings.length:
171
+ if (is_main and output.options.keep_docstrings
172
+ and self.docstrings and self.docstrings.length):
146
173
  output.newline(), output.indent()
147
174
  v = const_decl(output.options.js_version)
148
- output.assign(v + ' ρσ_module_doc__'), output.print(JSON.stringify(create_doctring(self.docstrings)))
175
+ output.assign(v + ' ρσ_module_doc__')
176
+ output.print(JSON.stringify(create_doctring(self.docstrings)))
149
177
  output.end_statement()
150
178
 
151
179
  if output.options.private_scope and is_main:
152
180
  output.with_parens(def ():
153
181
  output.print('function()')
154
182
  output.with_block(def ():
155
- # strict mode is more verbose about errors, and less forgiving about them
183
+ # strict mode is more verbose about errors, and less
184
+ # forgiving about them
156
185
  # kind of like Python
157
186
  output.indent()
158
187
  output.print('"use strict"')