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.
- package/CHANGELOG.md +28 -0
- package/README.md +80 -26
- package/bin/build.ts +117 -0
- package/bin/package.json +1 -0
- package/bin/rapydscript +65 -62
- package/build_wheels.py +133 -0
- package/editor-plugins/README.md +80 -0
- package/editor-plugins/nvim.lua +321 -0
- package/local-agent.md +28 -0
- package/package.json +4 -5
- package/publish.py +27 -17
- package/release/baselib-plain-pretty.js +448 -326
- package/release/baselib-plain-ugly.js +3 -3
- package/release/compiler.js +9027 -8139
- package/release/signatures.json +27 -27
- package/release/stdlib_modules.json +1 -0
- package/src/ast.pyj +428 -280
- package/src/baselib-builtins.pyj +49 -28
- package/src/baselib-containers.pyj +241 -226
- package/src/baselib-errors.pyj +8 -1
- package/src/baselib-internal.pyj +38 -23
- package/src/baselib-itertools.pyj +13 -7
- package/src/baselib-str.pyj +59 -84
- package/src/compiler.pyj +4 -4
- package/src/errors.pyj +3 -4
- package/src/lib/aes.pyj +46 -32
- package/src/lib/elementmaker.pyj +11 -9
- package/src/lib/encodings.pyj +15 -5
- package/src/lib/gettext.pyj +9 -4
- package/src/lib/math.pyj +106 -45
- package/src/lib/operator.pyj +10 -10
- package/src/lib/pythonize.pyj +2 -1
- package/src/lib/random.pyj +28 -21
- package/src/lib/re.pyj +492 -19
- package/src/lib/traceback.pyj +171 -29
- package/src/lib/uuid.pyj +2 -2
- package/src/output/classes.pyj +28 -27
- package/src/output/codegen.pyj +87 -83
- package/src/output/comments.pyj +8 -8
- package/src/output/exceptions.pyj +20 -21
- package/src/output/functions.pyj +66 -64
- package/src/output/literals.pyj +24 -23
- package/src/output/loops.pyj +84 -142
- package/src/output/modules.pyj +55 -68
- package/src/output/operators.pyj +40 -29
- package/src/output/statements.pyj +21 -15
- package/src/output/stream.pyj +82 -56
- package/src/output/utils.pyj +12 -8
- package/src/parse.pyj +971 -620
- package/src/string_interpolation.pyj +5 -3
- package/src/tokenizer.pyj +188 -148
- package/src/utils.pyj +32 -15
- package/test/_treeshake_mod.pyj +30 -0
- package/test/_treeshake_side_effect.pyj +9 -0
- package/test/ast_serialization.pyj +392 -0
- package/test/async.pyj +95 -0
- package/test/baselib.pyj +1 -2
- package/test/embedded_compiler.pyj +57 -0
- package/test/fmt.pyj +291 -0
- package/test/generic.pyj +16 -3
- package/test/imports.pyj +8 -6
- package/test/internationalization.pyj +38 -37
- package/test/lint.pyj +120 -117
- package/test/lsp.pyj +257 -0
- package/test/repl.pyj +70 -65
- package/test/sourcemaps.pyj +315 -0
- package/test/starargs.pyj +46 -39
- package/test/str.pyj +8 -0
- package/test/traceback.pyj +263 -0
- package/test/treeshaking.pyj +181 -0
- package/test/web_repl_export.pyj +88 -0
- package/tools/ast_serialize.mjs +557 -0
- package/tools/cli.mjs +531 -0
- package/tools/compile.mjs +205 -0
- package/tools/compiler.mjs +159 -0
- package/tools/{completer.js → completer.mjs} +6 -6
- package/tools/{embedded_compiler.js → embedded_compiler.mjs} +17 -13
- package/tools/export.js +109 -56
- package/tools/fmt.mjs +975 -0
- package/tools/{gettext.js → gettext.mjs} +46 -53
- package/tools/ini.mjs +175 -0
- package/tools/{lint.js → lint.mjs} +78 -55
- package/tools/lsp.mjs +964 -0
- package/tools/lsp_protocol.mjs +259 -0
- package/tools/lsp_symbols.mjs +418 -0
- package/tools/{msgfmt.js → msgfmt.mjs} +18 -18
- package/tools/{repl.js → repl.mjs} +56 -42
- package/tools/{self.js → self.mjs} +71 -46
- package/tools/sourcemap.mjs +123 -0
- package/tools/test.mjs +252 -0
- package/tools/treeshake.mjs +400 -0
- package/tools/{utils.js → utils.mjs} +26 -23
- package/tools/{web_repl.js → web_repl.mjs} +15 -13
- package/tools/web_repl_export.mjs +97 -0
- package/tree-sitter/README.md +101 -0
- package/tree-sitter/grammar.js +992 -0
- package/tree-sitter/package.json +43 -0
- package/tree-sitter/queries/highlights.scm +232 -0
- package/tree-sitter/queries/indents.scm +64 -0
- package/tree-sitter/queries/injections.scm +14 -0
- package/tree-sitter/queries/locals.scm +108 -0
- package/tree-sitter/src/grammar.json +4976 -0
- package/tree-sitter/src/node-types.json +2901 -0
- package/tree-sitter/src/parser.c +196465 -0
- package/tree-sitter/src/scanner.c +294 -0
- package/tree-sitter/src/tree_sitter/alloc.h +54 -0
- package/tree-sitter/src/tree_sitter/array.h +330 -0
- package/tree-sitter/src/tree_sitter/parser.h +286 -0
- package/tree-sitter/test/corpus/chaining.txt +99 -0
- package/tree-sitter/test/corpus/classes.txt +147 -0
- package/tree-sitter/test/corpus/comprehensions.txt +155 -0
- package/tree-sitter/test/corpus/containers.txt +242 -0
- package/tree-sitter/test/corpus/control_flow.txt +361 -0
- package/tree-sitter/test/corpus/decorators.txt +64 -0
- package/tree-sitter/test/corpus/existential.txt +102 -0
- package/tree-sitter/test/corpus/functions.txt +293 -0
- package/tree-sitter/test/corpus/imports.txt +117 -0
- package/tree-sitter/test/corpus/literals.txt +135 -0
- package/tree-sitter/test/corpus/operators.txt +296 -0
- package/tree-sitter/test/corpus/statements.txt +189 -0
- package/tree-sitter/test/corpus/strings.txt +90 -0
- package/tree-sitter/test/corpus/subscripts.txt +227 -0
- package/tree-sitter/tree-sitter.json +36 -0
- package/web-repl/env.js +35 -23
- package/web-repl/main.js +8 -8
- package/bin/export +0 -75
- package/bin/web-repl-export +0 -102
- package/tools/cli.js +0 -523
- package/tools/compile.js +0 -184
- package/tools/compiler.js +0 -84
- package/tools/ini.js +0 -65
- package/tools/test.js +0 -110
package/src/output/loops.pyj
CHANGED
|
@@ -1,77 +1,79 @@
|
|
|
1
1
|
# vim:fileencoding=utf-8
|
|
2
2
|
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
|
-
# globals: regenerate
|
|
4
3
|
from __python__ import hash_literals
|
|
5
4
|
|
|
6
5
|
from ast import AST_BaseCall, AST_SymbolRef, AST_Array, AST_Unary, AST_Number, has_calls, AST_Seq, AST_ListComprehension, is_node_type
|
|
7
6
|
from output.stream import OutputStream
|
|
8
7
|
|
|
8
|
+
|
|
9
9
|
def unpack_tuple(elems, output, in_statement):
|
|
10
10
|
for i, elem in enumerate(elems):
|
|
11
11
|
output.indent()
|
|
12
12
|
output.assign(elem)
|
|
13
|
-
output.print(
|
|
14
|
-
output.with_square(def():
|
|
13
|
+
output.print('ρσ_unpack')
|
|
14
|
+
output.with_square(def ():
|
|
15
15
|
output.print(i)
|
|
16
16
|
)
|
|
17
17
|
if not in_statement or i < elems.length - 1:
|
|
18
18
|
output.semicolon()
|
|
19
19
|
output.newline()
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
def print_do_loop(self, output):
|
|
22
|
-
output.print(
|
|
23
|
+
output.print('do')
|
|
23
24
|
output.space()
|
|
24
25
|
self._do_print_body(output)
|
|
25
26
|
output.space()
|
|
26
|
-
output.print(
|
|
27
|
+
output.print('while')
|
|
27
28
|
output.space()
|
|
28
|
-
output.with_parens(def(): self.condition.print(output);)
|
|
29
|
+
output.with_parens(def (): self.condition.print(output);)
|
|
29
30
|
output.semicolon()
|
|
30
31
|
|
|
32
|
+
|
|
31
33
|
def print_while_loop(self, output):
|
|
32
|
-
output.print(
|
|
34
|
+
output.print('while')
|
|
33
35
|
output.space()
|
|
34
|
-
output.with_parens(def(): self.condition.print(output);)
|
|
36
|
+
output.with_parens(def (): self.condition.print(output);)
|
|
35
37
|
output.space()
|
|
36
38
|
self._do_print_body(output)
|
|
37
39
|
|
|
40
|
+
|
|
38
41
|
def is_simple_for_in(self):
|
|
39
42
|
# return true if this loop can be simplified into a basic for (i in j) loop
|
|
40
43
|
if is_node_type(self.object, AST_BaseCall)
|
|
41
44
|
and is_node_type(self.object.expression, AST_SymbolRef)
|
|
42
|
-
and self.object.expression.name is
|
|
45
|
+
and self.object.expression.name is 'dir' and self.object.args.args.length is 1:
|
|
43
46
|
return True
|
|
44
47
|
return False
|
|
45
48
|
|
|
49
|
+
|
|
46
50
|
def is_simple_for(self):
|
|
47
51
|
# returns true if this loop can be simplified into a basic for(i=n;i<h;i++) loop
|
|
48
52
|
if (is_node_type(self.object, AST_BaseCall) and
|
|
49
53
|
is_node_type(self.object.expression, AST_SymbolRef) and
|
|
50
|
-
self.object.expression.name is
|
|
54
|
+
self.object.expression.name is 'range' and
|
|
51
55
|
not (is_node_type(self.init, AST_Array))):
|
|
52
|
-
a = self.object.args
|
|
56
|
+
a = self.object.args.args
|
|
53
57
|
l = a.length
|
|
54
58
|
if l < 3 or (
|
|
55
|
-
is_node_type(a[2], AST_Number) or (
|
|
56
|
-
is_node_type(a[2], AST_Unary) and a[2].operator is '-' and is_node_type(a[2].expression, AST_Number)
|
|
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)
|
|
57
61
|
)):
|
|
58
|
-
if (l is 1 and not has_calls(a[0])) or (l > 1 and not has_calls(a[1])):
|
|
62
|
+
if (l is 1 and not has_calls(a[0].value)) or (l > 1 and not has_calls(a[1].value)):
|
|
59
63
|
return True
|
|
60
64
|
return False
|
|
61
65
|
|
|
66
|
+
|
|
62
67
|
def print_for_loop_body(output):
|
|
63
68
|
self = this
|
|
64
|
-
output.with_block(def():
|
|
69
|
+
output.with_block(def ():
|
|
65
70
|
if not (self.simple_for_index or is_simple_for_in(self)):
|
|
66
71
|
# if we're using multiple iterators, unpack them
|
|
67
72
|
output.indent()
|
|
68
|
-
|
|
69
|
-
itervar = "ρσ_Iter" + output.index_counter + "[ρσ_Index" + output.index_counter + "]"
|
|
70
|
-
else:
|
|
71
|
-
itervar = "ρσ_Index" + output.index_counter
|
|
73
|
+
itervar = 'ρσ_Index' + output.index_counter
|
|
72
74
|
if is_node_type(self.init, AST_Array):
|
|
73
75
|
flat = self.init.flatten()
|
|
74
|
-
output.assign(
|
|
76
|
+
output.assign('ρσ_unpack')
|
|
75
77
|
if flat.length > self.init.elements.length:
|
|
76
78
|
output.print('ρσ_flatten(' + itervar + ')')
|
|
77
79
|
else:
|
|
@@ -82,208 +84,173 @@ def print_for_loop_body(output):
|
|
|
82
84
|
output.assign(self.init)
|
|
83
85
|
output.print(itervar)
|
|
84
86
|
output.end_statement()
|
|
85
|
-
|
|
86
87
|
output.index_counter += 1
|
|
87
88
|
if self.simple_for_index:
|
|
88
89
|
output.indent()
|
|
89
90
|
output.assign(self.init)
|
|
90
91
|
output.print(self.simple_for_index)
|
|
91
92
|
output.end_statement()
|
|
92
|
-
|
|
93
93
|
for stmt in self.body.body:
|
|
94
94
|
output.indent()
|
|
95
95
|
stmt.print(output)
|
|
96
96
|
output.newline()
|
|
97
97
|
)
|
|
98
98
|
|
|
99
|
+
|
|
99
100
|
def init_es6_itervar(output, itervar):
|
|
100
101
|
output.indent()
|
|
101
102
|
output.spaced(itervar, '=', '((typeof', itervar + '[Symbol.iterator]', '===', '"function")', '?',
|
|
102
|
-
'('+itervar, 'instanceof', 'Map', '?', itervar + '.keys()', ':', itervar+')', ':', 'Object.keys(' + itervar + '))')
|
|
103
|
+
'(' + itervar, 'instanceof', 'Map', '?', itervar + '.keys()', ':', itervar + ')', ':', 'Object.keys(' + itervar + '))')
|
|
103
104
|
output.end_statement()
|
|
104
105
|
|
|
106
|
+
|
|
105
107
|
def print_for_in(self, output):
|
|
106
108
|
def write_object():
|
|
107
109
|
if self.object.constructor is AST_Seq:
|
|
108
|
-
(new AST_Array({'elements':self.object.to_array()})).print(output)
|
|
110
|
+
(new AST_Array({'elements': self.object.to_array()})).print(output)
|
|
109
111
|
else:
|
|
110
112
|
self.object.print(output)
|
|
111
113
|
|
|
112
114
|
if is_simple_for(self):
|
|
113
115
|
# optimize range() into a simple for loop
|
|
114
116
|
increment = None
|
|
115
|
-
args = self.object.args
|
|
117
|
+
args = self.object.args.args
|
|
116
118
|
tmp_ = args.length
|
|
117
119
|
if tmp_ is 1:
|
|
118
120
|
start = 0
|
|
119
|
-
end = args[0]
|
|
121
|
+
end = args[0].value
|
|
120
122
|
elif tmp_ is 2:
|
|
121
|
-
start = args[0]
|
|
122
|
-
end = args[1]
|
|
123
|
+
start = args[0].value
|
|
124
|
+
end = args[1].value
|
|
123
125
|
elif tmp_ is 3:
|
|
124
|
-
start = args[0]
|
|
125
|
-
end = args[1]
|
|
126
|
-
increment = args[2]
|
|
126
|
+
start = args[0].value
|
|
127
|
+
end = args[1].value
|
|
128
|
+
increment = args[2].value
|
|
127
129
|
|
|
128
130
|
self.simple_for_index = idx = 'ρσ_Index' + output.index_counter
|
|
129
131
|
output.index_counter += 1
|
|
130
|
-
output.print(
|
|
132
|
+
output.print('for')
|
|
131
133
|
output.space()
|
|
132
|
-
output.with_parens(def():
|
|
134
|
+
output.with_parens(def ():
|
|
133
135
|
output.spaced('var', idx, '='), output.space()
|
|
134
136
|
start.print(output) if start.print else output.print(start)
|
|
135
137
|
output.semicolon()
|
|
136
138
|
output.space()
|
|
137
139
|
output.print(idx)
|
|
138
140
|
output.space()
|
|
139
|
-
output.print(
|
|
141
|
+
output.print('>') if is_node_type(increment, AST_Unary) else output.print('<')
|
|
140
142
|
output.space()
|
|
141
143
|
end.print(output)
|
|
142
144
|
output.semicolon()
|
|
143
145
|
output.space()
|
|
144
146
|
output.print(idx)
|
|
145
|
-
if increment and (not (is_node_type(increment, AST_Unary)) or increment.expression.value is not
|
|
147
|
+
if increment and (not (is_node_type(increment, AST_Unary)) or increment.expression.value is not '1'):
|
|
146
148
|
if is_node_type(increment, AST_Unary):
|
|
147
|
-
output.print(
|
|
149
|
+
output.print('-=')
|
|
148
150
|
increment.expression.print(output)
|
|
149
151
|
else:
|
|
150
|
-
output.print(
|
|
152
|
+
output.print('+=')
|
|
151
153
|
increment.print(output)
|
|
152
154
|
else:
|
|
153
155
|
if is_node_type(increment, AST_Unary):
|
|
154
|
-
output.print(
|
|
156
|
+
output.print('--')
|
|
155
157
|
else:
|
|
156
|
-
output.print(
|
|
158
|
+
output.print('++')
|
|
157
159
|
)
|
|
158
160
|
elif is_simple_for_in(self):
|
|
159
161
|
# optimize dir() into a simple for in loop
|
|
160
|
-
output.print(
|
|
162
|
+
output.print('for')
|
|
161
163
|
output.space()
|
|
162
|
-
output.with_parens(def():
|
|
164
|
+
output.with_parens(def ():
|
|
163
165
|
self.init.print(output)
|
|
164
166
|
output.space()
|
|
165
167
|
output.print('in')
|
|
166
168
|
output.space()
|
|
167
|
-
self.object.args[0].print(output)
|
|
169
|
+
self.object.args.args[0].value.print(output)
|
|
168
170
|
)
|
|
169
171
|
else:
|
|
170
172
|
# regular loop
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
output.print("for")
|
|
179
|
-
output.space()
|
|
180
|
-
output.with_parens(def():
|
|
181
|
-
output.print("var")
|
|
182
|
-
output.space()
|
|
183
|
-
output.assign("ρσ_Index" + output.index_counter)
|
|
184
|
-
output.print("0")
|
|
185
|
-
output.semicolon()
|
|
186
|
-
output.space()
|
|
187
|
-
output.print("ρσ_Index" + output.index_counter)
|
|
188
|
-
output.space()
|
|
189
|
-
output.print("<")
|
|
190
|
-
output.space()
|
|
191
|
-
output.print("ρσ_Iter" + output.index_counter + ".length")
|
|
192
|
-
output.semicolon()
|
|
193
|
-
output.space()
|
|
194
|
-
output.print("ρσ_Index" + output.index_counter + "++")
|
|
195
|
-
)
|
|
196
|
-
else:
|
|
197
|
-
itervar = "ρσ_Iter" + output.index_counter
|
|
198
|
-
output.assign("var " + itervar)
|
|
199
|
-
write_object()
|
|
200
|
-
output.end_statement()
|
|
201
|
-
init_es6_itervar(output, itervar)
|
|
202
|
-
output.indent()
|
|
203
|
-
output.spaced('for', '(var', 'ρσ_Index' + output.index_counter, 'of', itervar + ')')
|
|
173
|
+
itervar = 'ρσ_Iter' + output.index_counter
|
|
174
|
+
output.assign('var ' + itervar)
|
|
175
|
+
write_object()
|
|
176
|
+
output.end_statement()
|
|
177
|
+
init_es6_itervar(output, itervar)
|
|
178
|
+
output.indent()
|
|
179
|
+
output.spaced('for', '(var', 'ρσ_Index' + output.index_counter, 'of', itervar + ')')
|
|
204
180
|
|
|
205
181
|
output.space()
|
|
206
182
|
self._do_print_body(output)
|
|
207
183
|
|
|
184
|
+
|
|
208
185
|
def print_list_comprehension(self, output):
|
|
209
186
|
tname = self.constructor.name.slice(4)
|
|
210
|
-
result_obj = {'ListComprehension':'[]', 'DictComprehension':('Object.create(null)' if self.is_jshash else '{}'), 'SetComprehension':'ρσ_set()'}[tname]
|
|
187
|
+
result_obj = {'ListComprehension': '[]', 'DictComprehension': ('Object.create(null)' if self.is_jshash else '{}'), 'SetComprehension': 'ρσ_set()'}[tname]
|
|
211
188
|
is_generator = tname is 'GeneratorComprehension'
|
|
212
|
-
es5 = output.options.js_version is 5
|
|
213
189
|
if tname is 'DictComprehension':
|
|
214
190
|
if self.is_pydict:
|
|
215
191
|
result_obj = 'ρσ_dict()'
|
|
216
|
-
add_to_result = def(output):
|
|
192
|
+
add_to_result = def (output):
|
|
217
193
|
output.indent()
|
|
218
194
|
output.print('ρσ_Result.set')
|
|
219
|
-
output.with_parens(def():
|
|
195
|
+
output.with_parens(def ():
|
|
220
196
|
self.statement.print(output)
|
|
221
197
|
output.space(), output.print(','), output.space()
|
|
222
|
-
output.with_parens(def():
|
|
198
|
+
output.with_parens(def ():
|
|
223
199
|
if self.value_statement.constructor is AST_Seq:
|
|
224
|
-
output.with_square(def():self.value_statement.print(output);)
|
|
200
|
+
output.with_square(def (): self.value_statement.print(output);)
|
|
225
201
|
else:
|
|
226
202
|
self.value_statement.print(output)
|
|
227
203
|
)
|
|
228
204
|
)
|
|
229
205
|
output.end_statement()
|
|
230
206
|
else:
|
|
231
|
-
add_to_result = def(output):
|
|
207
|
+
add_to_result = def (output):
|
|
232
208
|
output.indent()
|
|
233
209
|
output.print('ρσ_Result')
|
|
234
|
-
output.with_square(def():
|
|
210
|
+
output.with_square(def ():
|
|
235
211
|
self.statement.print(output)
|
|
236
212
|
)
|
|
237
213
|
output.space(), output.print('='), output.space()
|
|
238
|
-
output.with_parens(def():
|
|
214
|
+
output.with_parens(def ():
|
|
239
215
|
if self.value_statement.constructor is AST_Seq:
|
|
240
|
-
output.with_square(def():self.value_statement.print(output);)
|
|
216
|
+
output.with_square(def (): self.value_statement.print(output);)
|
|
241
217
|
else:
|
|
242
218
|
self.value_statement.print(output)
|
|
243
219
|
)
|
|
244
220
|
output.end_statement()
|
|
245
221
|
else:
|
|
246
|
-
push_func =
|
|
222
|
+
push_func = 'ρσ_Result.' + ('push' if self.constructor is AST_ListComprehension else 'add')
|
|
247
223
|
if is_generator:
|
|
248
224
|
push_func = 'yield '
|
|
249
|
-
add_to_result = def(output):
|
|
225
|
+
add_to_result = def (output):
|
|
250
226
|
output.indent()
|
|
251
227
|
output.print(push_func)
|
|
252
|
-
output.with_parens(def():
|
|
228
|
+
output.with_parens(def ():
|
|
253
229
|
if self.statement.constructor is AST_Seq:
|
|
254
|
-
output.with_square(def():self.statement.print(output);)
|
|
230
|
+
output.with_square(def (): self.statement.print(output);)
|
|
255
231
|
else:
|
|
256
232
|
self.statement.print(output)
|
|
257
233
|
)
|
|
258
234
|
output.end_statement()
|
|
259
235
|
|
|
260
|
-
output.with_parens(def():
|
|
261
|
-
output.print(
|
|
262
|
-
output.print(
|
|
236
|
+
output.with_parens(def ():
|
|
237
|
+
output.print('function')
|
|
238
|
+
output.print('()')
|
|
263
239
|
output.space()
|
|
264
|
-
output.with_block(def():
|
|
240
|
+
output.with_block(def ():
|
|
265
241
|
body_out = output
|
|
266
242
|
if is_generator:
|
|
267
|
-
if es5:
|
|
268
|
-
body_out = OutputStream({'beautify':True})
|
|
269
243
|
body_out.indent()
|
|
270
244
|
body_out.print('function* js_generator()'), body_out.space(), body_out.print('{')
|
|
271
245
|
body_out.newline()
|
|
272
246
|
previous_indentation = output.indentation()
|
|
273
247
|
output.set_indentation(output.next_indent())
|
|
274
248
|
body_out.indent()
|
|
275
|
-
body_out.assign(
|
|
276
|
-
|
|
277
|
-
body_out.print("ρσ_Iterable")
|
|
278
|
-
body_out.with_parens(def():
|
|
279
|
-
self.object.print(body_out)
|
|
280
|
-
)
|
|
281
|
-
else:
|
|
282
|
-
self.object.print(body_out)
|
|
283
|
-
|
|
249
|
+
body_out.assign('var ρσ_Iter')
|
|
250
|
+
self.object.print(body_out)
|
|
284
251
|
if result_obj:
|
|
285
252
|
body_out.comma()
|
|
286
|
-
body_out.assign(
|
|
253
|
+
body_out.assign('ρσ_Result')
|
|
287
254
|
body_out.print(result_obj)
|
|
288
255
|
# make sure to locally scope loop variables
|
|
289
256
|
if is_node_type(self.init, AST_Array):
|
|
@@ -294,38 +261,20 @@ def print_list_comprehension(self, output):
|
|
|
294
261
|
body_out.comma()
|
|
295
262
|
self.init.print(body_out)
|
|
296
263
|
body_out.end_statement()
|
|
297
|
-
|
|
298
|
-
if not es5:
|
|
299
|
-
init_es6_itervar(body_out, 'ρσ_Iter')
|
|
264
|
+
init_es6_itervar(body_out, 'ρσ_Iter')
|
|
300
265
|
body_out.indent()
|
|
301
|
-
body_out.print(
|
|
266
|
+
body_out.print('for')
|
|
302
267
|
body_out.space()
|
|
303
|
-
body_out.with_parens(def():
|
|
304
|
-
|
|
305
|
-
body_out.print("var")
|
|
306
|
-
body_out.space()
|
|
307
|
-
body_out.assign("ρσ_Index")
|
|
308
|
-
body_out.print("0")
|
|
309
|
-
body_out.semicolon()
|
|
310
|
-
body_out.space()
|
|
311
|
-
body_out.print("ρσ_Index")
|
|
312
|
-
body_out.space()
|
|
313
|
-
body_out.print("<")
|
|
314
|
-
body_out.space()
|
|
315
|
-
body_out.print("ρσ_Iter.length")
|
|
316
|
-
body_out.semicolon()
|
|
317
|
-
body_out.space()
|
|
318
|
-
body_out.print("ρσ_Index++")
|
|
319
|
-
else:
|
|
320
|
-
body_out.spaced('var', 'ρσ_Index', 'of', 'ρσ_Iter')
|
|
268
|
+
body_out.with_parens(def ():
|
|
269
|
+
body_out.spaced('var', 'ρσ_Index', 'of', 'ρσ_Iter')
|
|
321
270
|
)
|
|
322
271
|
body_out.space()
|
|
323
|
-
body_out.with_block(def():
|
|
272
|
+
body_out.with_block(def ():
|
|
324
273
|
body_out.indent()
|
|
325
|
-
itervar = 'ρσ
|
|
274
|
+
itervar = 'ρσ_Index'
|
|
326
275
|
if is_node_type(self.init, AST_Array):
|
|
327
276
|
flat = self.init.flatten()
|
|
328
|
-
body_out.assign(
|
|
277
|
+
body_out.assign('ρσ_unpack')
|
|
329
278
|
if flat.length > self.init.elements.length:
|
|
330
279
|
body_out.print('ρσ_flatten(' + itervar + ')')
|
|
331
280
|
else:
|
|
@@ -336,14 +285,13 @@ def print_list_comprehension(self, output):
|
|
|
336
285
|
body_out.assign(self.init)
|
|
337
286
|
body_out.print(itervar)
|
|
338
287
|
body_out.end_statement()
|
|
339
|
-
|
|
340
288
|
if self.condition:
|
|
341
289
|
body_out.indent()
|
|
342
|
-
body_out.print(
|
|
290
|
+
body_out.print('if')
|
|
343
291
|
body_out.space()
|
|
344
|
-
body_out.with_parens(def(): self.condition.print(body_out);)
|
|
292
|
+
body_out.with_parens(def (): self.condition.print(body_out);)
|
|
345
293
|
body_out.space()
|
|
346
|
-
body_out.with_block(def():
|
|
294
|
+
body_out.with_block(def ():
|
|
347
295
|
add_to_result(body_out)
|
|
348
296
|
)
|
|
349
297
|
body_out.newline()
|
|
@@ -357,17 +305,11 @@ def print_list_comprehension(self, output):
|
|
|
357
305
|
body_out.end_statement()
|
|
358
306
|
if not is_generator:
|
|
359
307
|
body_out.indent()
|
|
360
|
-
body_out.print(
|
|
308
|
+
body_out.print('return ρσ_Result')
|
|
361
309
|
body_out.end_statement()
|
|
362
310
|
if is_generator:
|
|
363
311
|
output.set_indentation(previous_indentation)
|
|
364
312
|
body_out.newline(), body_out.indent(), body_out.print('}') # end js_generator
|
|
365
|
-
if es5:
|
|
366
|
-
transpiled = regenerate(body_out.get(), output.options.beautify).replace(/regeneratorRuntime.(wrap|mark)/g, 'ρσ_regenerator.regeneratorRuntime.$1')
|
|
367
|
-
if output.options.beautify:
|
|
368
|
-
ci = output.make_indent(0)
|
|
369
|
-
transpiled = [ci + x for x in transpiled.split('\n')].join('\n')
|
|
370
|
-
output.print(transpiled)
|
|
371
313
|
output.newline(), output.indent()
|
|
372
314
|
output.spaced('var', 'result', '=', 'js_generator.call(this)')
|
|
373
315
|
output.end_statement()
|
|
@@ -380,4 +322,4 @@ def print_list_comprehension(self, output):
|
|
|
380
322
|
output.end_statement()
|
|
381
323
|
)
|
|
382
324
|
)
|
|
383
|
-
output.print(
|
|
325
|
+
output.print('()')
|