rapydscript-ng 0.8.0 → 0.8.2
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 +14 -0
- package/README.md +8 -0
- package/bin/build.ts +117 -0
- package/build_wheels.py +133 -0
- package/editor-plugins/README.md +80 -0
- package/editor-plugins/nvim.lua +321 -0
- package/package.json +1 -1
- package/publish.py +27 -17
- package/release/compiler.js +8125 -8093
- package/release/signatures.json +27 -27
- package/release/stdlib_modules.json +1 -0
- package/src/ast.pyj +379 -279
- package/src/baselib-builtins.pyj +47 -26
- package/src/baselib-containers.pyj +105 -92
- package/src/baselib-errors.pyj +8 -1
- package/src/baselib-internal.pyj +35 -20
- package/src/baselib-itertools.pyj +13 -7
- package/src/baselib-str.pyj +55 -80
- 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 +490 -17
- package/src/lib/traceback.pyj +7 -2
- package/src/lib/uuid.pyj +2 -2
- package/src/output/classes.pyj +28 -27
- package/src/output/codegen.pyj +80 -83
- package/src/output/comments.pyj +8 -8
- package/src/output/exceptions.pyj +20 -21
- package/src/output/functions.pyj +37 -26
- package/src/output/literals.pyj +14 -10
- package/src/output/loops.pyj +63 -59
- package/src/output/modules.pyj +52 -23
- package/src/output/operators.pyj +40 -29
- package/src/output/statements.pyj +20 -14
- package/src/output/stream.pyj +33 -34
- package/src/output/utils.pyj +12 -8
- package/src/parse.pyj +234 -233
- package/src/string_interpolation.pyj +5 -3
- package/src/tokenizer.pyj +176 -148
- package/src/utils.pyj +31 -14
- package/test/fmt.pyj +94 -4
- package/test/generic.pyj +9 -0
- package/test/lsp.pyj +35 -0
- package/test/str.pyj +8 -0
- package/tools/cli.mjs +25 -4
- package/tools/compile.mjs +7 -3
- package/tools/compiler.mjs +34 -2
- package/tools/fmt.mjs +269 -22
- package/tools/ini.mjs +112 -1
- package/tools/lsp.mjs +56 -6
- package/tools/repl.mjs +5 -2
- package/tools/self.mjs +15 -0
- package/tools/test.mjs +100 -0
- package/tools/web_repl_export.mjs +4 -0
- package/tree-sitter/package.json +1 -1
- package/tree-sitter/tree-sitter.json +1 -1
- package/editor-plugins/nvim/rapydscript/README.md +0 -184
- package/editor-plugins/nvim/rapydscript/bin/rapydscript.so +0 -0
- package/editor-plugins/nvim/rapydscript/ftdetect/rapydscript.lua +0 -10
- package/editor-plugins/nvim/rapydscript/lua/rapydscript/health.lua +0 -88
- package/editor-plugins/nvim/rapydscript/lua/rapydscript/init.lua +0 -279
- /package/tree-sitter/queries/{rapydscript/highlights.scm → highlights.scm} +0 -0
- /package/tree-sitter/queries/{rapydscript/indents.scm → indents.scm} +0 -0
- /package/tree-sitter/queries/{rapydscript/injections.scm → injections.scm} +0 -0
- /package/tree-sitter/queries/{rapydscript/locals.scm → locals.scm} +0 -0
package/src/output/loops.pyj
CHANGED
|
@@ -5,48 +5,53 @@ from __python__ import hash_literals
|
|
|
5
5
|
from ast import AST_BaseCall, AST_SymbolRef, AST_Array, AST_Unary, AST_Number, has_calls, AST_Seq, AST_ListComprehension, is_node_type
|
|
6
6
|
from output.stream import OutputStream
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
def unpack_tuple(elems, output, in_statement):
|
|
9
10
|
for i, elem in enumerate(elems):
|
|
10
11
|
output.indent()
|
|
11
12
|
output.assign(elem)
|
|
12
|
-
output.print(
|
|
13
|
-
output.with_square(def():
|
|
13
|
+
output.print('ρσ_unpack')
|
|
14
|
+
output.with_square(def ():
|
|
14
15
|
output.print(i)
|
|
15
16
|
)
|
|
16
17
|
if not in_statement or i < elems.length - 1:
|
|
17
18
|
output.semicolon()
|
|
18
19
|
output.newline()
|
|
19
20
|
|
|
21
|
+
|
|
20
22
|
def print_do_loop(self, output):
|
|
21
|
-
output.print(
|
|
23
|
+
output.print('do')
|
|
22
24
|
output.space()
|
|
23
25
|
self._do_print_body(output)
|
|
24
26
|
output.space()
|
|
25
|
-
output.print(
|
|
27
|
+
output.print('while')
|
|
26
28
|
output.space()
|
|
27
|
-
output.with_parens(def(): self.condition.print(output);)
|
|
29
|
+
output.with_parens(def (): self.condition.print(output);)
|
|
28
30
|
output.semicolon()
|
|
29
31
|
|
|
32
|
+
|
|
30
33
|
def print_while_loop(self, output):
|
|
31
|
-
output.print(
|
|
34
|
+
output.print('while')
|
|
32
35
|
output.space()
|
|
33
|
-
output.with_parens(def(): self.condition.print(output);)
|
|
36
|
+
output.with_parens(def (): self.condition.print(output);)
|
|
34
37
|
output.space()
|
|
35
38
|
self._do_print_body(output)
|
|
36
39
|
|
|
40
|
+
|
|
37
41
|
def is_simple_for_in(self):
|
|
38
42
|
# return true if this loop can be simplified into a basic for (i in j) loop
|
|
39
43
|
if is_node_type(self.object, AST_BaseCall)
|
|
40
44
|
and is_node_type(self.object.expression, AST_SymbolRef)
|
|
41
|
-
and self.object.expression.name is
|
|
45
|
+
and self.object.expression.name is 'dir' and self.object.args.args.length is 1:
|
|
42
46
|
return True
|
|
43
47
|
return False
|
|
44
48
|
|
|
49
|
+
|
|
45
50
|
def is_simple_for(self):
|
|
46
51
|
# returns true if this loop can be simplified into a basic for(i=n;i<h;i++) loop
|
|
47
52
|
if (is_node_type(self.object, AST_BaseCall) and
|
|
48
53
|
is_node_type(self.object.expression, AST_SymbolRef) and
|
|
49
|
-
self.object.expression.name is
|
|
54
|
+
self.object.expression.name is 'range' and
|
|
50
55
|
not (is_node_type(self.init, AST_Array))):
|
|
51
56
|
a = self.object.args.args
|
|
52
57
|
l = a.length
|
|
@@ -58,16 +63,17 @@ def is_simple_for(self):
|
|
|
58
63
|
return True
|
|
59
64
|
return False
|
|
60
65
|
|
|
66
|
+
|
|
61
67
|
def print_for_loop_body(output):
|
|
62
68
|
self = this
|
|
63
|
-
output.with_block(def():
|
|
69
|
+
output.with_block(def ():
|
|
64
70
|
if not (self.simple_for_index or is_simple_for_in(self)):
|
|
65
71
|
# if we're using multiple iterators, unpack them
|
|
66
72
|
output.indent()
|
|
67
|
-
itervar =
|
|
73
|
+
itervar = 'ρσ_Index' + output.index_counter
|
|
68
74
|
if is_node_type(self.init, AST_Array):
|
|
69
75
|
flat = self.init.flatten()
|
|
70
|
-
output.assign(
|
|
76
|
+
output.assign('ρσ_unpack')
|
|
71
77
|
if flat.length > self.init.elements.length:
|
|
72
78
|
output.print('ρσ_flatten(' + itervar + ')')
|
|
73
79
|
else:
|
|
@@ -78,30 +84,30 @@ def print_for_loop_body(output):
|
|
|
78
84
|
output.assign(self.init)
|
|
79
85
|
output.print(itervar)
|
|
80
86
|
output.end_statement()
|
|
81
|
-
|
|
82
87
|
output.index_counter += 1
|
|
83
88
|
if self.simple_for_index:
|
|
84
89
|
output.indent()
|
|
85
90
|
output.assign(self.init)
|
|
86
91
|
output.print(self.simple_for_index)
|
|
87
92
|
output.end_statement()
|
|
88
|
-
|
|
89
93
|
for stmt in self.body.body:
|
|
90
94
|
output.indent()
|
|
91
95
|
stmt.print(output)
|
|
92
96
|
output.newline()
|
|
93
97
|
)
|
|
94
98
|
|
|
99
|
+
|
|
95
100
|
def init_es6_itervar(output, itervar):
|
|
96
101
|
output.indent()
|
|
97
102
|
output.spaced(itervar, '=', '((typeof', itervar + '[Symbol.iterator]', '===', '"function")', '?',
|
|
98
|
-
'('+itervar, 'instanceof', 'Map', '?', itervar + '.keys()', ':', itervar+')', ':', 'Object.keys(' + itervar + '))')
|
|
103
|
+
'(' + itervar, 'instanceof', 'Map', '?', itervar + '.keys()', ':', itervar + ')', ':', 'Object.keys(' + itervar + '))')
|
|
99
104
|
output.end_statement()
|
|
100
105
|
|
|
106
|
+
|
|
101
107
|
def print_for_in(self, output):
|
|
102
108
|
def write_object():
|
|
103
109
|
if self.object.constructor is AST_Seq:
|
|
104
|
-
(new AST_Array({'elements':self.object.to_array()})).print(output)
|
|
110
|
+
(new AST_Array({'elements': self.object.to_array()})).print(output)
|
|
105
111
|
else:
|
|
106
112
|
self.object.print(output)
|
|
107
113
|
|
|
@@ -123,39 +129,39 @@ def print_for_in(self, output):
|
|
|
123
129
|
|
|
124
130
|
self.simple_for_index = idx = 'ρσ_Index' + output.index_counter
|
|
125
131
|
output.index_counter += 1
|
|
126
|
-
output.print(
|
|
132
|
+
output.print('for')
|
|
127
133
|
output.space()
|
|
128
|
-
output.with_parens(def():
|
|
134
|
+
output.with_parens(def ():
|
|
129
135
|
output.spaced('var', idx, '='), output.space()
|
|
130
136
|
start.print(output) if start.print else output.print(start)
|
|
131
137
|
output.semicolon()
|
|
132
138
|
output.space()
|
|
133
139
|
output.print(idx)
|
|
134
140
|
output.space()
|
|
135
|
-
output.print(
|
|
141
|
+
output.print('>') if is_node_type(increment, AST_Unary) else output.print('<')
|
|
136
142
|
output.space()
|
|
137
143
|
end.print(output)
|
|
138
144
|
output.semicolon()
|
|
139
145
|
output.space()
|
|
140
146
|
output.print(idx)
|
|
141
|
-
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'):
|
|
142
148
|
if is_node_type(increment, AST_Unary):
|
|
143
|
-
output.print(
|
|
149
|
+
output.print('-=')
|
|
144
150
|
increment.expression.print(output)
|
|
145
151
|
else:
|
|
146
|
-
output.print(
|
|
152
|
+
output.print('+=')
|
|
147
153
|
increment.print(output)
|
|
148
154
|
else:
|
|
149
155
|
if is_node_type(increment, AST_Unary):
|
|
150
|
-
output.print(
|
|
156
|
+
output.print('--')
|
|
151
157
|
else:
|
|
152
|
-
output.print(
|
|
158
|
+
output.print('++')
|
|
153
159
|
)
|
|
154
160
|
elif is_simple_for_in(self):
|
|
155
161
|
# optimize dir() into a simple for in loop
|
|
156
|
-
output.print(
|
|
162
|
+
output.print('for')
|
|
157
163
|
output.space()
|
|
158
|
-
output.with_parens(def():
|
|
164
|
+
output.with_parens(def ():
|
|
159
165
|
self.init.print(output)
|
|
160
166
|
output.space()
|
|
161
167
|
output.print('in')
|
|
@@ -164,8 +170,8 @@ def print_for_in(self, output):
|
|
|
164
170
|
)
|
|
165
171
|
else:
|
|
166
172
|
# regular loop
|
|
167
|
-
itervar =
|
|
168
|
-
output.assign(
|
|
173
|
+
itervar = 'ρσ_Iter' + output.index_counter
|
|
174
|
+
output.assign('var ' + itervar)
|
|
169
175
|
write_object()
|
|
170
176
|
output.end_statement()
|
|
171
177
|
init_es6_itervar(output, itervar)
|
|
@@ -175,62 +181,63 @@ def print_for_in(self, output):
|
|
|
175
181
|
output.space()
|
|
176
182
|
self._do_print_body(output)
|
|
177
183
|
|
|
184
|
+
|
|
178
185
|
def print_list_comprehension(self, output):
|
|
179
186
|
tname = self.constructor.name.slice(4)
|
|
180
|
-
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]
|
|
181
188
|
is_generator = tname is 'GeneratorComprehension'
|
|
182
189
|
if tname is 'DictComprehension':
|
|
183
190
|
if self.is_pydict:
|
|
184
191
|
result_obj = 'ρσ_dict()'
|
|
185
|
-
add_to_result = def(output):
|
|
192
|
+
add_to_result = def (output):
|
|
186
193
|
output.indent()
|
|
187
194
|
output.print('ρσ_Result.set')
|
|
188
|
-
output.with_parens(def():
|
|
195
|
+
output.with_parens(def ():
|
|
189
196
|
self.statement.print(output)
|
|
190
197
|
output.space(), output.print(','), output.space()
|
|
191
|
-
output.with_parens(def():
|
|
198
|
+
output.with_parens(def ():
|
|
192
199
|
if self.value_statement.constructor is AST_Seq:
|
|
193
|
-
output.with_square(def():self.value_statement.print(output);)
|
|
200
|
+
output.with_square(def (): self.value_statement.print(output);)
|
|
194
201
|
else:
|
|
195
202
|
self.value_statement.print(output)
|
|
196
203
|
)
|
|
197
204
|
)
|
|
198
205
|
output.end_statement()
|
|
199
206
|
else:
|
|
200
|
-
add_to_result = def(output):
|
|
207
|
+
add_to_result = def (output):
|
|
201
208
|
output.indent()
|
|
202
209
|
output.print('ρσ_Result')
|
|
203
|
-
output.with_square(def():
|
|
210
|
+
output.with_square(def ():
|
|
204
211
|
self.statement.print(output)
|
|
205
212
|
)
|
|
206
213
|
output.space(), output.print('='), output.space()
|
|
207
|
-
output.with_parens(def():
|
|
214
|
+
output.with_parens(def ():
|
|
208
215
|
if self.value_statement.constructor is AST_Seq:
|
|
209
|
-
output.with_square(def():self.value_statement.print(output);)
|
|
216
|
+
output.with_square(def (): self.value_statement.print(output);)
|
|
210
217
|
else:
|
|
211
218
|
self.value_statement.print(output)
|
|
212
219
|
)
|
|
213
220
|
output.end_statement()
|
|
214
221
|
else:
|
|
215
|
-
push_func =
|
|
222
|
+
push_func = 'ρσ_Result.' + ('push' if self.constructor is AST_ListComprehension else 'add')
|
|
216
223
|
if is_generator:
|
|
217
224
|
push_func = 'yield '
|
|
218
|
-
add_to_result = def(output):
|
|
225
|
+
add_to_result = def (output):
|
|
219
226
|
output.indent()
|
|
220
227
|
output.print(push_func)
|
|
221
|
-
output.with_parens(def():
|
|
228
|
+
output.with_parens(def ():
|
|
222
229
|
if self.statement.constructor is AST_Seq:
|
|
223
|
-
output.with_square(def():self.statement.print(output);)
|
|
230
|
+
output.with_square(def (): self.statement.print(output);)
|
|
224
231
|
else:
|
|
225
232
|
self.statement.print(output)
|
|
226
233
|
)
|
|
227
234
|
output.end_statement()
|
|
228
235
|
|
|
229
|
-
output.with_parens(def():
|
|
230
|
-
output.print(
|
|
231
|
-
output.print(
|
|
236
|
+
output.with_parens(def ():
|
|
237
|
+
output.print('function')
|
|
238
|
+
output.print('()')
|
|
232
239
|
output.space()
|
|
233
|
-
output.with_block(def():
|
|
240
|
+
output.with_block(def ():
|
|
234
241
|
body_out = output
|
|
235
242
|
if is_generator:
|
|
236
243
|
body_out.indent()
|
|
@@ -239,12 +246,11 @@ def print_list_comprehension(self, output):
|
|
|
239
246
|
previous_indentation = output.indentation()
|
|
240
247
|
output.set_indentation(output.next_indent())
|
|
241
248
|
body_out.indent()
|
|
242
|
-
body_out.assign(
|
|
249
|
+
body_out.assign('var ρσ_Iter')
|
|
243
250
|
self.object.print(body_out)
|
|
244
|
-
|
|
245
251
|
if result_obj:
|
|
246
252
|
body_out.comma()
|
|
247
|
-
body_out.assign(
|
|
253
|
+
body_out.assign('ρσ_Result')
|
|
248
254
|
body_out.print(result_obj)
|
|
249
255
|
# make sure to locally scope loop variables
|
|
250
256
|
if is_node_type(self.init, AST_Array):
|
|
@@ -255,21 +261,20 @@ def print_list_comprehension(self, output):
|
|
|
255
261
|
body_out.comma()
|
|
256
262
|
self.init.print(body_out)
|
|
257
263
|
body_out.end_statement()
|
|
258
|
-
|
|
259
264
|
init_es6_itervar(body_out, 'ρσ_Iter')
|
|
260
265
|
body_out.indent()
|
|
261
|
-
body_out.print(
|
|
266
|
+
body_out.print('for')
|
|
262
267
|
body_out.space()
|
|
263
|
-
body_out.with_parens(def():
|
|
268
|
+
body_out.with_parens(def ():
|
|
264
269
|
body_out.spaced('var', 'ρσ_Index', 'of', 'ρσ_Iter')
|
|
265
270
|
)
|
|
266
271
|
body_out.space()
|
|
267
|
-
body_out.with_block(def():
|
|
272
|
+
body_out.with_block(def ():
|
|
268
273
|
body_out.indent()
|
|
269
274
|
itervar = 'ρσ_Index'
|
|
270
275
|
if is_node_type(self.init, AST_Array):
|
|
271
276
|
flat = self.init.flatten()
|
|
272
|
-
body_out.assign(
|
|
277
|
+
body_out.assign('ρσ_unpack')
|
|
273
278
|
if flat.length > self.init.elements.length:
|
|
274
279
|
body_out.print('ρσ_flatten(' + itervar + ')')
|
|
275
280
|
else:
|
|
@@ -280,14 +285,13 @@ def print_list_comprehension(self, output):
|
|
|
280
285
|
body_out.assign(self.init)
|
|
281
286
|
body_out.print(itervar)
|
|
282
287
|
body_out.end_statement()
|
|
283
|
-
|
|
284
288
|
if self.condition:
|
|
285
289
|
body_out.indent()
|
|
286
|
-
body_out.print(
|
|
290
|
+
body_out.print('if')
|
|
287
291
|
body_out.space()
|
|
288
|
-
body_out.with_parens(def(): self.condition.print(body_out);)
|
|
292
|
+
body_out.with_parens(def (): self.condition.print(body_out);)
|
|
289
293
|
body_out.space()
|
|
290
|
-
body_out.with_block(def():
|
|
294
|
+
body_out.with_block(def ():
|
|
291
295
|
add_to_result(body_out)
|
|
292
296
|
)
|
|
293
297
|
body_out.newline()
|
|
@@ -301,7 +305,7 @@ def print_list_comprehension(self, output):
|
|
|
301
305
|
body_out.end_statement()
|
|
302
306
|
if not is_generator:
|
|
303
307
|
body_out.indent()
|
|
304
|
-
body_out.print(
|
|
308
|
+
body_out.print('return ρσ_Result')
|
|
305
309
|
body_out.end_statement()
|
|
306
310
|
if is_generator:
|
|
307
311
|
output.set_indentation(previous_indentation)
|
|
@@ -318,4 +322,4 @@ def print_list_comprehension(self, output):
|
|
|
318
322
|
output.end_statement()
|
|
319
323
|
)
|
|
320
324
|
)
|
|
321
|
-
output.print(
|
|
325
|
+
output.print('()')
|
package/src/output/modules.pyj
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
3
|
from __python__ import hash_literals
|
|
4
4
|
|
|
5
|
-
from output.statements import declare_vars, display_body
|
|
6
|
-
from output.utils import create_doctring
|
|
7
5
|
from output.comments import print_comments, output_comments
|
|
8
6
|
from output.functions import set_module_name
|
|
7
|
+
from output.statements import declare_vars, display_body
|
|
8
|
+
from output.utils import create_doctring
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def write_imports(module, output):
|
|
12
12
|
imports = []
|
|
13
13
|
for import_id in Object.keys(module.imports):
|
|
14
14
|
imports.push(module.imports[import_id])
|
|
15
|
-
imports.sort(def(a, b):
|
|
15
|
+
imports.sort(def (a, b):
|
|
16
16
|
a, b = a.import_order, b.import_order
|
|
17
17
|
return -1 if a < b else (1 if a > b else 0)
|
|
18
18
|
)
|
|
@@ -50,6 +50,7 @@ def write_imports(module, output):
|
|
|
50
50
|
if module_.module_id is not '__main__':
|
|
51
51
|
print_module(module_, output)
|
|
52
52
|
|
|
53
|
+
|
|
53
54
|
def write_main_name(output):
|
|
54
55
|
if output.options.write_name:
|
|
55
56
|
output.newline()
|
|
@@ -59,16 +60,18 @@ def write_main_name(output):
|
|
|
59
60
|
output.newline()
|
|
60
61
|
output.newline()
|
|
61
62
|
|
|
63
|
+
|
|
62
64
|
def const_decl(js_version):
|
|
63
65
|
# return 'const' if js_version > 5 else 'var'
|
|
64
66
|
# Workaround for bug in Chrome eval(). eval() barfs if it sees const before a function.
|
|
65
67
|
# See https://github.com/kovidgoyal/rapydscript-ng/issues/29
|
|
66
68
|
return 'var'
|
|
67
69
|
|
|
70
|
+
|
|
68
71
|
def declare_exports(module_id, exports, output, docstrings):
|
|
69
72
|
seen = {}
|
|
70
73
|
if output.options.keep_docstrings and docstrings and docstrings.length:
|
|
71
|
-
exports.push({'name':'__doc__', 'refname': 'ρσ_module_doc__'})
|
|
74
|
+
exports.push({'name': '__doc__', 'refname': 'ρσ_module_doc__'})
|
|
72
75
|
output.newline(), output.indent()
|
|
73
76
|
v = const_decl(output.options.js_version)
|
|
74
77
|
output.assign(v + ' ρσ_module_doc__'), output.print(JSON.stringify(create_doctring(docstrings)))
|
|
@@ -85,6 +88,7 @@ def declare_exports(module_id, exports, output, docstrings):
|
|
|
85
88
|
seen[symbol.name] = True
|
|
86
89
|
output.end_statement()
|
|
87
90
|
|
|
91
|
+
|
|
88
92
|
def prologue(module, output):
|
|
89
93
|
# any code that should appear before the main body
|
|
90
94
|
if output.options.omit_baselib:
|
|
@@ -92,16 +96,39 @@ def prologue(module, output):
|
|
|
92
96
|
output.indent()
|
|
93
97
|
v = const_decl(output.options.js_version)
|
|
94
98
|
output.print(v), output.space()
|
|
95
|
-
output.spaced.apply(
|
|
99
|
+
output.spaced.apply(
|
|
100
|
+
output,
|
|
101
|
+
(('ρσ_iterator_symbol = (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") ? Symbol.iterator : "iterator-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' ')))
|
|
102
|
+
)
|
|
96
103
|
output.end_statement()
|
|
97
104
|
output.indent(), output.print(v), output.space()
|
|
98
|
-
output.spaced.apply(
|
|
105
|
+
output.spaced.apply(
|
|
106
|
+
output,
|
|
107
|
+
(('ρσ_kwargs_symbol = (typeof Symbol === "function") ? Symbol("kwargs-object") : "kwargs-object-Symbol-5d0927e5554349048cf0e3762a228256"'.split(' ')))
|
|
108
|
+
)
|
|
99
109
|
output.end_statement()
|
|
100
110
|
output.indent(), output.spaced('var', 'ρσ_cond_temp,', 'ρσ_expr_temp,', 'ρσ_last_exception'), output.end_statement()
|
|
101
111
|
output.indent(), output.spaced('var', 'ρσ_object_counter', '=', '0'), output.end_statement()
|
|
102
112
|
# Needed for Chrome < 51 and Edge as of August 2016
|
|
103
|
-
output.indent(), output.spaced(
|
|
104
|
-
'
|
|
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
|
+
)
|
|
105
132
|
output.end_statement()
|
|
106
133
|
# output the baselib
|
|
107
134
|
if not output.options.baselib_plain:
|
|
@@ -122,22 +149,21 @@ def print_top_level(self, output):
|
|
|
122
149
|
output.end_statement()
|
|
123
150
|
|
|
124
151
|
if output.options.private_scope and is_main:
|
|
125
|
-
output.with_parens(def():
|
|
126
|
-
output.print(
|
|
127
|
-
output.with_block(def():
|
|
152
|
+
output.with_parens(def ():
|
|
153
|
+
output.print('function()')
|
|
154
|
+
output.with_block(def ():
|
|
128
155
|
# strict mode is more verbose about errors, and less forgiving about them
|
|
129
156
|
# kind of like Python
|
|
130
157
|
output.indent()
|
|
131
158
|
output.print('"use strict"')
|
|
132
159
|
output.end_statement()
|
|
133
|
-
|
|
134
160
|
prologue(self, output)
|
|
135
161
|
write_imports(self, output)
|
|
136
162
|
output.newline()
|
|
137
163
|
output.indent()
|
|
138
|
-
output.with_parens(def():
|
|
139
|
-
output.print(
|
|
140
|
-
output.with_block(def():
|
|
164
|
+
output.with_parens(def ():
|
|
165
|
+
output.print('function()')
|
|
166
|
+
output.with_block(def ():
|
|
141
167
|
write_main_name(output)
|
|
142
168
|
output.newline()
|
|
143
169
|
declare_vars(self.localvars, output)
|
|
@@ -150,12 +176,12 @@ def print_top_level(self, output):
|
|
|
150
176
|
output.newline()
|
|
151
177
|
)
|
|
152
178
|
)
|
|
153
|
-
output.print(
|
|
179
|
+
output.print('();')
|
|
154
180
|
output.newline()
|
|
155
181
|
)
|
|
156
182
|
)
|
|
157
|
-
output.print(
|
|
158
|
-
output.print(
|
|
183
|
+
output.print('();')
|
|
184
|
+
output.print('')
|
|
159
185
|
else:
|
|
160
186
|
if is_main:
|
|
161
187
|
prologue(self, output)
|
|
@@ -168,6 +194,7 @@ def print_top_level(self, output):
|
|
|
168
194
|
output_comments(self.comments_after, output)
|
|
169
195
|
set_module_name()
|
|
170
196
|
|
|
197
|
+
|
|
171
198
|
def print_module(self, output):
|
|
172
199
|
set_module_name(self.module_id)
|
|
173
200
|
|
|
@@ -178,9 +205,9 @@ def print_module(self, output):
|
|
|
178
205
|
|
|
179
206
|
output.newline()
|
|
180
207
|
output.indent()
|
|
181
|
-
output.with_parens(def():
|
|
182
|
-
output.print(
|
|
183
|
-
output.with_block(def():
|
|
208
|
+
output.with_parens(def ():
|
|
209
|
+
output.print('function()')
|
|
210
|
+
output.with_block(def ():
|
|
184
211
|
# dump the logic of this module
|
|
185
212
|
print_comments(self, output)
|
|
186
213
|
if output.options.write_name:
|
|
@@ -193,13 +220,15 @@ def print_module(self, output):
|
|
|
193
220
|
output_module(output)
|
|
194
221
|
)
|
|
195
222
|
)
|
|
196
|
-
output.print(
|
|
223
|
+
output.print('()')
|
|
197
224
|
output.semicolon()
|
|
198
225
|
output.newline()
|
|
199
226
|
set_module_name()
|
|
200
227
|
|
|
228
|
+
|
|
201
229
|
def print_imports(container, output):
|
|
202
230
|
is_first_aname = True
|
|
231
|
+
|
|
203
232
|
def add_aname(aname, key, from_import):
|
|
204
233
|
nonlocal is_first_aname
|
|
205
234
|
if is_first_aname:
|
|
@@ -232,7 +261,7 @@ def print_imports(container, output):
|
|
|
232
261
|
if i is 0:
|
|
233
262
|
add_aname(part, part, False)
|
|
234
263
|
else:
|
|
235
|
-
q = parts[:i+1].join('.')
|
|
264
|
+
q = parts[:i + 1].join('.')
|
|
236
265
|
output.indent()
|
|
237
266
|
output.spaced(q, '=', 'ρσ_modules["' + q + '"]')
|
|
238
267
|
output.end_statement()
|