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/functions.pyj
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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_ClassCall, AST_New, has_calls, AST_Dot, AST_SymbolRef, is_node_type
|
|
7
|
-
from output.
|
|
6
|
+
from output.operators import print_getattr
|
|
8
7
|
from output.statements import print_bracketed
|
|
8
|
+
from output.stream import OutputStream
|
|
9
9
|
from output.utils import create_doctring
|
|
10
|
-
from output.operators import print_getattr
|
|
11
10
|
|
|
12
11
|
anonfunc = 'ρσ_anonfunc'
|
|
13
12
|
module_name = 'null'
|
|
14
13
|
|
|
14
|
+
|
|
15
15
|
def set_module_name(x):
|
|
16
16
|
nonlocal module_name
|
|
17
17
|
module_name = '"' + x + '"' if x else 'null'
|
|
@@ -19,30 +19,34 @@ def set_module_name(x):
|
|
|
19
19
|
|
|
20
20
|
# Function definition {{{
|
|
21
21
|
|
|
22
|
+
|
|
22
23
|
def decorate(decorators, output, func):
|
|
23
24
|
pos = 0
|
|
25
|
+
|
|
24
26
|
def wrap():
|
|
25
27
|
nonlocal pos
|
|
26
28
|
if pos < decorators.length:
|
|
27
29
|
decorators[pos].expression.print(output)
|
|
28
30
|
pos += 1
|
|
29
|
-
output.with_parens(def():
|
|
31
|
+
output.with_parens(def ():
|
|
30
32
|
wrap()
|
|
31
33
|
)
|
|
32
34
|
else:
|
|
33
35
|
func()
|
|
34
36
|
wrap()
|
|
35
37
|
|
|
38
|
+
|
|
36
39
|
def function_args(argnames, output, strip_first):
|
|
37
|
-
output.with_parens(def():
|
|
38
|
-
if argnames and argnames.length and (argnames.is_simple_func is True or argnames.is_simple_func is undefined):
|
|
39
|
-
for i, arg in enumerate((argnames.slice(1) if strip_first else argnames)):
|
|
40
|
+
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)):
|
|
40
43
|
if i:
|
|
41
44
|
output.comma()
|
|
42
45
|
arg.print(output)
|
|
43
46
|
)
|
|
44
47
|
output.space()
|
|
45
48
|
|
|
49
|
+
|
|
46
50
|
def function_preamble(node, output, offset):
|
|
47
51
|
a = node.argnames
|
|
48
52
|
if not a or a.is_simple_func:
|
|
@@ -51,11 +55,11 @@ def function_preamble(node, output, offset):
|
|
|
51
55
|
fname = node.name.name if node.name else anonfunc
|
|
52
56
|
kw = 'arguments[arguments.length-1]'
|
|
53
57
|
# Define all formal parameters
|
|
54
|
-
for c, arg in enumerate(a):
|
|
58
|
+
for c, arg in enumerate(a.args):
|
|
55
59
|
i = c - offset
|
|
56
60
|
if i >= 0:
|
|
57
61
|
output.indent()
|
|
58
|
-
output.print(
|
|
62
|
+
output.print('var')
|
|
59
63
|
output.space()
|
|
60
64
|
output.assign(arg)
|
|
61
65
|
if Object.prototype.hasOwnProperty.call(a.defaults, arg.name):
|
|
@@ -84,7 +88,7 @@ def function_preamble(node, output, offset):
|
|
|
84
88
|
for dname in Object.keys(a.defaults):
|
|
85
89
|
output.indent()
|
|
86
90
|
output.spaced('if', '(Object.prototype.hasOwnProperty.call(' + kw + ',', '"' + dname + '"))')
|
|
87
|
-
output.with_block(def():
|
|
91
|
+
output.with_block(def ():
|
|
88
92
|
output.indent()
|
|
89
93
|
output.spaced(dname, '=', kw + '.' + dname)
|
|
90
94
|
output.end_statement()
|
|
@@ -97,7 +101,7 @@ def function_preamble(node, output, offset):
|
|
|
97
101
|
|
|
98
102
|
if a.starargs is not undefined:
|
|
99
103
|
# Define the *args parameter, putting in whatever is left after assigning the formal parameters and the options object
|
|
100
|
-
nargs = a.length - offset
|
|
104
|
+
nargs = a.args.length - offset
|
|
101
105
|
output.indent()
|
|
102
106
|
output.spaced('var', a.starargs.name, '=', 'Array.prototype.slice.call(arguments,', nargs + ')')
|
|
103
107
|
output.end_statement()
|
|
@@ -107,29 +111,31 @@ def function_preamble(node, output, offset):
|
|
|
107
111
|
output.print('.pop()')
|
|
108
112
|
output.end_statement()
|
|
109
113
|
|
|
114
|
+
|
|
110
115
|
def has_annotations(self):
|
|
111
116
|
if self.return_annotation:
|
|
112
117
|
return True
|
|
113
|
-
for arg in self.argnames:
|
|
118
|
+
for arg in self.argnames.args:
|
|
114
119
|
if arg.annotation:
|
|
115
120
|
return True
|
|
116
121
|
return False
|
|
117
122
|
|
|
123
|
+
|
|
118
124
|
def function_annotation(self, output, strip_first, name):
|
|
119
125
|
fname = name or (self.name.name if self.name else anonfunc)
|
|
120
126
|
props = Object.create(None)
|
|
121
127
|
|
|
122
128
|
# Create __annotations__
|
|
123
129
|
if has_annotations(self):
|
|
124
|
-
props.__annotations__ = def():
|
|
130
|
+
props.__annotations__ = def ():
|
|
125
131
|
output.print('{')
|
|
126
|
-
if self.argnames and self.argnames.length:
|
|
127
|
-
for i, arg in enumerate(self.argnames):
|
|
132
|
+
if self.argnames and self.argnames.args.length:
|
|
133
|
+
for i, arg in enumerate(self.argnames.args):
|
|
128
134
|
if arg.annotation:
|
|
129
135
|
arg.print(output)
|
|
130
136
|
output.print(':'), output.space()
|
|
131
137
|
arg.annotation.print(output)
|
|
132
|
-
if i < self.argnames.length - 1 or self.return_annotation:
|
|
138
|
+
if i < self.argnames.args.length - 1 or self.return_annotation:
|
|
133
139
|
output.comma()
|
|
134
140
|
if self.return_annotation:
|
|
135
141
|
output.print('return:'), output.space()
|
|
@@ -140,7 +146,7 @@ def function_annotation(self, output, strip_first, name):
|
|
|
140
146
|
defaults = self.argnames.defaults
|
|
141
147
|
dkeys = Object.keys(self.argnames.defaults)
|
|
142
148
|
if dkeys.length:
|
|
143
|
-
props.__defaults__ = def():
|
|
149
|
+
props.__defaults__ = def ():
|
|
144
150
|
output.print('{')
|
|
145
151
|
for i, k in enumerate(dkeys):
|
|
146
152
|
output.print(k + ':'), defaults[k].print(output)
|
|
@@ -150,27 +156,27 @@ def function_annotation(self, output, strip_first, name):
|
|
|
150
156
|
|
|
151
157
|
# Create __handles_kwarg_interpolation__
|
|
152
158
|
if not self.argnames.is_simple_func:
|
|
153
|
-
props.__handles_kwarg_interpolation__ = def():
|
|
159
|
+
props.__handles_kwarg_interpolation__ = def ():
|
|
154
160
|
output.print('true')
|
|
155
161
|
|
|
156
162
|
# Create __argnames__
|
|
157
|
-
if self.argnames.length > (1 if strip_first else 0):
|
|
158
|
-
props.__argnames__ = def():
|
|
163
|
+
if self.argnames.args.length > (1 if strip_first else 0):
|
|
164
|
+
props.__argnames__ = def ():
|
|
159
165
|
output.print('[')
|
|
160
|
-
for i, arg in enumerate(self.argnames):
|
|
166
|
+
for i, arg in enumerate(self.argnames.args):
|
|
161
167
|
if strip_first and i is 0:
|
|
162
168
|
continue
|
|
163
169
|
output.print(JSON.stringify(arg.name))
|
|
164
|
-
if i is not self.argnames.length - 1:
|
|
170
|
+
if i is not self.argnames.args.length - 1:
|
|
165
171
|
output.comma()
|
|
166
172
|
output.print(']')
|
|
167
173
|
|
|
168
174
|
# Create __doc__
|
|
169
175
|
if output.options.keep_docstrings and self.docstrings and self.docstrings.length:
|
|
170
|
-
props.__doc__ = def():
|
|
176
|
+
props.__doc__ = def ():
|
|
171
177
|
output.print(JSON.stringify(create_doctring(self.docstrings)))
|
|
172
178
|
|
|
173
|
-
props.__module__ = def():
|
|
179
|
+
props.__module__ = def ():
|
|
174
180
|
output.print(module_name)
|
|
175
181
|
|
|
176
182
|
names = Object.keys(props)
|
|
@@ -179,7 +185,7 @@ def function_annotation(self, output, strip_first, name):
|
|
|
179
185
|
# can happen if the function definition is inside a loop, for example.
|
|
180
186
|
output.spaced('if', '(!' + fname + '.' + names[0] + ')', 'Object.defineProperties(' + fname)
|
|
181
187
|
output.comma()
|
|
182
|
-
output.with_block(def():
|
|
188
|
+
output.with_block(def ():
|
|
183
189
|
for v'var i = 0; i < names.length; i++':
|
|
184
190
|
name = names[i]
|
|
185
191
|
output.indent(), output.spaced(name, ':', '{value:', ''), props[name](), output.print('}')
|
|
@@ -197,28 +203,19 @@ def function_definition(self, output, strip_first, as_expression):
|
|
|
197
203
|
output.set_indentation(output.next_indent())
|
|
198
204
|
output.spaced('(function()', '{'), output.newline()
|
|
199
205
|
output.indent(), output.spaced('var', anonfunc, '='), output.space()
|
|
200
|
-
|
|
206
|
+
if self.is_async:
|
|
207
|
+
output.print('async'), output.space()
|
|
208
|
+
output.print('function'), output.space()
|
|
201
209
|
if self.name:
|
|
202
210
|
self.name.print(output)
|
|
203
211
|
|
|
204
212
|
if self.is_generator:
|
|
205
213
|
output.print('()'), output.space()
|
|
206
|
-
output.with_block(def():
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
print_bracketed(self, output, True, function_preamble)
|
|
212
|
-
else:
|
|
213
|
-
temp = OutputStream({'beautify':True})
|
|
214
|
-
temp.print('function* js_generator')
|
|
215
|
-
function_args(self.argnames, temp, strip_first)
|
|
216
|
-
print_bracketed(self, temp, True, function_preamble)
|
|
217
|
-
transpiled = regenerate(temp.get(), output.options.beautify).replace(/regeneratorRuntime.(wrap|mark)/g, 'ρσ_regenerator.regeneratorRuntime.$1')
|
|
218
|
-
if output.options.beautify:
|
|
219
|
-
ci = output.make_indent(0)
|
|
220
|
-
transpiled = [ci + x for x in transpiled.split('\n')].join('\n')
|
|
221
|
-
output.print(transpiled)
|
|
214
|
+
output.with_block(def ():
|
|
215
|
+
output.indent()
|
|
216
|
+
output.print('function* js_generator')
|
|
217
|
+
function_args(self.argnames, output, strip_first)
|
|
218
|
+
print_bracketed(self, output, True, function_preamble)
|
|
222
219
|
output.newline()
|
|
223
220
|
output.indent()
|
|
224
221
|
output.spaced('var', 'result', '=', 'js_generator.apply(this,', 'arguments)')
|
|
@@ -240,15 +237,16 @@ def function_definition(self, output, strip_first, as_expression):
|
|
|
240
237
|
function_annotation(self, output, strip_first, anonfunc)
|
|
241
238
|
output.indent(), output.spaced('return', anonfunc), output.end_statement()
|
|
242
239
|
output.set_indentation(orig_indent)
|
|
243
|
-
output.indent(), output.print(
|
|
240
|
+
output.indent(), output.print('})()')
|
|
241
|
+
|
|
244
242
|
|
|
245
243
|
def print_function(output):
|
|
246
244
|
self = this
|
|
247
245
|
if self.decorators and self.decorators.length:
|
|
248
|
-
output.print(
|
|
246
|
+
output.print('var')
|
|
249
247
|
output.space()
|
|
250
248
|
output.assign(self.name.name)
|
|
251
|
-
decorate(self.decorators, output, def():function_definition(self, output, False, True);)
|
|
249
|
+
decorate(self.decorators, output, def (): function_definition(self, output, False, True);)
|
|
252
250
|
output.end_statement()
|
|
253
251
|
else:
|
|
254
252
|
function_definition(self, output, False)
|
|
@@ -259,12 +257,14 @@ def print_function(output):
|
|
|
259
257
|
|
|
260
258
|
# Function call {{{
|
|
261
259
|
|
|
260
|
+
|
|
262
261
|
def find_this(expression):
|
|
263
262
|
if is_node_type(expression, AST_Dot):
|
|
264
263
|
return expression.expression
|
|
265
264
|
if not is_node_type(expression, AST_SymbolRef):
|
|
266
265
|
return expression
|
|
267
266
|
|
|
267
|
+
|
|
268
268
|
def print_this(expression, output):
|
|
269
269
|
obj = find_this(expression)
|
|
270
270
|
if obj:
|
|
@@ -272,6 +272,7 @@ def print_this(expression, output):
|
|
|
272
272
|
else:
|
|
273
273
|
output.print('this')
|
|
274
274
|
|
|
275
|
+
|
|
275
276
|
def print_function_call(self, output):
|
|
276
277
|
is_prototype_call = False
|
|
277
278
|
|
|
@@ -281,15 +282,15 @@ def print_function_call(self, output):
|
|
|
281
282
|
# class methods are called through the prototype unless static
|
|
282
283
|
if self.static:
|
|
283
284
|
self.class.print(output)
|
|
284
|
-
output.print(
|
|
285
|
+
output.print('.')
|
|
285
286
|
output.print(self.method)
|
|
286
287
|
else:
|
|
287
288
|
is_prototype_call = True
|
|
288
289
|
self.class.print(output)
|
|
289
|
-
output.print(
|
|
290
|
+
output.print('.prototype.')
|
|
290
291
|
output.print(self.method)
|
|
291
292
|
if not no_call:
|
|
292
|
-
output.print(
|
|
293
|
+
output.print('.call')
|
|
293
294
|
else:
|
|
294
295
|
if not is_repeatable:
|
|
295
296
|
output.print('ρσ_expr_temp')
|
|
@@ -338,19 +339,20 @@ def print_function_call(self, output):
|
|
|
338
339
|
def print_positional_args():
|
|
339
340
|
# basic arguments
|
|
340
341
|
i = 0
|
|
341
|
-
|
|
342
|
-
|
|
342
|
+
pargs = self.args.args
|
|
343
|
+
while i < pargs.length:
|
|
344
|
+
expr = pargs[i]
|
|
343
345
|
is_first = i is 0
|
|
344
346
|
if not is_first:
|
|
345
347
|
output.print('.concat(')
|
|
346
348
|
if expr.is_array:
|
|
347
|
-
expr.print(output)
|
|
349
|
+
expr.value.print(output)
|
|
348
350
|
i += 1
|
|
349
351
|
else:
|
|
350
352
|
output.print('[')
|
|
351
|
-
while i <
|
|
352
|
-
|
|
353
|
-
if i + 1 <
|
|
353
|
+
while i < pargs.length and not pargs[i].is_array:
|
|
354
|
+
pargs[i].value.print(output)
|
|
355
|
+
if i + 1 < pargs.length and not pargs[i + 1].is_array:
|
|
354
356
|
output.print(',')
|
|
355
357
|
output.space()
|
|
356
358
|
i += 1
|
|
@@ -364,21 +366,21 @@ def print_function_call(self, output):
|
|
|
364
366
|
is_new = is_node_type(self, AST_New)
|
|
365
367
|
is_repeatable = True
|
|
366
368
|
|
|
367
|
-
if is_new and not self.args.length and not has_kwargs and not self.args.starargs:
|
|
369
|
+
if is_new and not self.args.args.length and not has_kwargs and not self.args.starargs:
|
|
368
370
|
output.print('new'), output.space()
|
|
369
371
|
print_function_name()
|
|
370
|
-
return
|
|
372
|
+
return # new A is the same as new A() in javascript
|
|
371
373
|
|
|
372
374
|
if not has_kwargs and not self.args.starargs:
|
|
373
375
|
# A simple function call, do nothing special
|
|
374
376
|
if is_new:
|
|
375
377
|
output.print('new'), output.space()
|
|
376
378
|
print_function_name()
|
|
377
|
-
output.with_parens(def():
|
|
378
|
-
for i, a in enumerate(self.args):
|
|
379
|
+
output.with_parens(def ():
|
|
380
|
+
for i, a in enumerate(self.args.args):
|
|
379
381
|
if i:
|
|
380
382
|
output.comma()
|
|
381
|
-
a.print(output)
|
|
383
|
+
a.value.print(output)
|
|
382
384
|
)
|
|
383
385
|
return
|
|
384
386
|
|
|
@@ -404,21 +406,21 @@ def print_function_call(self, output):
|
|
|
404
406
|
output.print('.apply(')
|
|
405
407
|
do_print_this()
|
|
406
408
|
|
|
407
|
-
if is_prototype_call and self.args.length > 1:
|
|
408
|
-
self.args.shift()
|
|
409
|
+
if is_prototype_call and self.args.args.length > 1:
|
|
410
|
+
self.args.args.shift()
|
|
409
411
|
|
|
410
412
|
print_positional_args()
|
|
411
413
|
|
|
412
414
|
if has_kwargs:
|
|
413
|
-
if self.args.length:
|
|
415
|
+
if self.args.args.length:
|
|
414
416
|
output.print('.concat(')
|
|
415
417
|
output.print('[')
|
|
416
418
|
print_kwargs()
|
|
417
419
|
output.print(']')
|
|
418
|
-
if self.args.length:
|
|
420
|
+
if self.args.args.length:
|
|
419
421
|
output.print(')')
|
|
420
422
|
|
|
421
423
|
output.print(')')
|
|
422
424
|
if not is_repeatable:
|
|
423
425
|
output.print(')')
|
|
424
|
-
# }}}
|
|
426
|
+
# }}}
|
package/src/output/literals.pyj
CHANGED
|
@@ -4,28 +4,26 @@ from __python__ import hash_literals
|
|
|
4
4
|
|
|
5
5
|
from ast import AST_Binary, is_node_type
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
def print_array(self, output):
|
|
8
|
-
output.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if len_ > 0:
|
|
20
|
-
output.space()
|
|
21
|
-
)
|
|
9
|
+
output.with_square(def ():
|
|
10
|
+
a = self.elements
|
|
11
|
+
len_ = a.length
|
|
12
|
+
if len_ > 0:
|
|
13
|
+
output.space()
|
|
14
|
+
for i, exp in enumerate(a):
|
|
15
|
+
if i:
|
|
16
|
+
output.comma()
|
|
17
|
+
exp.print(output)
|
|
18
|
+
if len_ > 0:
|
|
19
|
+
output.space()
|
|
22
20
|
)
|
|
23
21
|
|
|
24
22
|
|
|
25
23
|
def print_obj_literal(self, output):
|
|
26
|
-
output.with_parens(def():
|
|
24
|
+
output.with_parens(def ():
|
|
27
25
|
output.print('function()')
|
|
28
|
-
output.with_block(def():
|
|
26
|
+
output.with_block(def ():
|
|
29
27
|
output.indent()
|
|
30
28
|
if self.is_pydict:
|
|
31
29
|
output.spaced.apply(output, 'var ρσ_d = ρσ_dict()'.split(' '))
|
|
@@ -36,14 +34,14 @@ def print_obj_literal(self, output):
|
|
|
36
34
|
output.indent()
|
|
37
35
|
if self.is_pydict:
|
|
38
36
|
output.print('ρσ_d.set')
|
|
39
|
-
output.with_parens(def():
|
|
37
|
+
output.with_parens(def ():
|
|
40
38
|
prop.key.print(output)
|
|
41
39
|
output.print(','), output.space()
|
|
42
40
|
prop.value.print(output)
|
|
43
41
|
)
|
|
44
42
|
else:
|
|
45
43
|
output.print('ρσ_d')
|
|
46
|
-
output.with_square(def():prop.key.print(output);)
|
|
44
|
+
output.with_square(def (): prop.key.print(output);)
|
|
47
45
|
output.space(), output.print('='), output.space()
|
|
48
46
|
prop.value.print(output)
|
|
49
47
|
output.end_statement()
|
|
@@ -54,6 +52,7 @@ def print_obj_literal(self, output):
|
|
|
54
52
|
)
|
|
55
53
|
output.print('.call(this)')
|
|
56
54
|
|
|
55
|
+
|
|
57
56
|
def print_object(self, output):
|
|
58
57
|
if self.is_pydict:
|
|
59
58
|
if self.properties.length > 0:
|
|
@@ -64,22 +63,23 @@ def print_object(self, output):
|
|
|
64
63
|
if self.properties.length > 0:
|
|
65
64
|
print_obj_literal(self, output)
|
|
66
65
|
else:
|
|
67
|
-
output.print(
|
|
66
|
+
output.print('Object.create(null)' if self.is_jshash else '{}')
|
|
67
|
+
|
|
68
68
|
|
|
69
69
|
def print_set(self, output):
|
|
70
70
|
if self.items.length is 0:
|
|
71
71
|
output.print('ρσ_set()')
|
|
72
72
|
return
|
|
73
|
-
output.with_parens(def():
|
|
73
|
+
output.with_parens(def ():
|
|
74
74
|
output.print('function()')
|
|
75
|
-
output.with_block(def():
|
|
75
|
+
output.with_block(def ():
|
|
76
76
|
output.indent()
|
|
77
77
|
output.spaced.apply(output, 'var s = ρσ_set()'.split(' '))
|
|
78
78
|
output.end_statement()
|
|
79
79
|
for item in self.items:
|
|
80
80
|
output.indent()
|
|
81
81
|
output.print('s.jsset.add')
|
|
82
|
-
output.with_parens(def():item.value.print(output);)
|
|
82
|
+
output.with_parens(def (): item.value.print(output);)
|
|
83
83
|
output.end_statement()
|
|
84
84
|
output.indent()
|
|
85
85
|
output.spaced('return', 's')
|
|
@@ -88,6 +88,7 @@ def print_set(self, output):
|
|
|
88
88
|
)
|
|
89
89
|
output.print('()')
|
|
90
90
|
|
|
91
|
+
|
|
91
92
|
def print_regexp(self, output):
|
|
92
93
|
str_ = self.value.toString()
|
|
93
94
|
if output.options.ascii_only:
|
|
@@ -95,4 +96,4 @@ def print_regexp(self, output):
|
|
|
95
96
|
output.print(str_)
|
|
96
97
|
p = output.parent()
|
|
97
98
|
if is_node_type(p, AST_Binary) and /^in/.test(p.operator) and p.left is self:
|
|
98
|
-
output.print(
|
|
99
|
+
output.print(' ')
|