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/lib/traceback.pyj
CHANGED
|
@@ -19,6 +19,7 @@ def serialize_error_for_formatting(err):
|
|
|
19
19
|
'message': err.message or '',
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
|
|
22
23
|
def unserialize_error_for_formatting(err):
|
|
23
24
|
ans = new Error()
|
|
24
25
|
ans.name = err.name
|
|
@@ -177,15 +178,18 @@ def format_exception(exc, limit):
|
|
|
177
178
|
js_lines = v"['Traceback (most recent call last):'].concat(js_lines)"
|
|
178
179
|
if rs_lines.length > 0:
|
|
179
180
|
js_lines = js_lines.concat(['', 'Mapped Traceback (RapydScript):']).concat(rs_lines)
|
|
180
|
-
return [l+'\n' for l in js_lines]
|
|
181
|
+
return [l + '\n' for l in js_lines]
|
|
181
182
|
return [exc.toString()]
|
|
182
183
|
|
|
184
|
+
|
|
183
185
|
def format_exc(limit):
|
|
184
186
|
return format_exception(ρσ_last_exception, limit).join('')
|
|
185
187
|
|
|
188
|
+
|
|
186
189
|
def print_exc(limit):
|
|
187
190
|
print(format_exc(limit))
|
|
188
191
|
|
|
192
|
+
|
|
189
193
|
def format_stack(limit):
|
|
190
194
|
stack = Error().stack
|
|
191
195
|
if not stack:
|
|
@@ -193,8 +197,9 @@ def format_stack(limit):
|
|
|
193
197
|
lines = str.splitlines(stack)[2:]
|
|
194
198
|
lines.reverse()
|
|
195
199
|
if limit:
|
|
196
|
-
lines = lines[:limit+1] if limit > 0 else lines[limit:]
|
|
200
|
+
lines = lines[:limit + 1] if limit > 0 else lines[limit:]
|
|
197
201
|
return [l + '\n' for l in lines]
|
|
198
202
|
|
|
203
|
+
|
|
199
204
|
def print_stack(limit):
|
|
200
205
|
print(format_stack(limit).join(''))
|
package/src/lib/uuid.pyj
CHANGED
|
@@ -47,11 +47,11 @@ def uuid4():
|
|
|
47
47
|
def num_to_string(numbers, alphabet, pad_to_length):
|
|
48
48
|
ans = v'[]'
|
|
49
49
|
alphabet_len = alphabet.length
|
|
50
|
-
numbers = Array.from(numbers)
|
|
50
|
+
numbers = Array.from (numbers)
|
|
51
51
|
for v'var i = 0; i < numbers.length - 1; i++':
|
|
52
52
|
x = divmod(numbers[i], alphabet_len)
|
|
53
53
|
numbers[i] = x[0]
|
|
54
|
-
numbers[i+1] += x[1]
|
|
54
|
+
numbers[i + 1] += x[1]
|
|
55
55
|
for v'var i = 0; i < numbers.length; i++':
|
|
56
56
|
number = numbers[i]
|
|
57
57
|
while number:
|
package/src/output/classes.pyj
CHANGED
|
@@ -7,6 +7,7 @@ from output.functions import decorate, function_definition, function_annotation
|
|
|
7
7
|
from output.utils import create_doctring
|
|
8
8
|
from utils import has_prop
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
def print_class(output):
|
|
11
12
|
self = this
|
|
12
13
|
if self.external:
|
|
@@ -16,12 +17,12 @@ def print_class(output):
|
|
|
16
17
|
output.indent()
|
|
17
18
|
self.name.print(output)
|
|
18
19
|
if not is_var and method and has_prop(self.static, method):
|
|
19
|
-
output.assign(
|
|
20
|
+
output.assign('.' + method)
|
|
20
21
|
else:
|
|
21
22
|
if is_var:
|
|
22
|
-
output.assign(
|
|
23
|
+
output.assign('.prototype[' + method + ']')
|
|
23
24
|
else:
|
|
24
|
-
output.assign(
|
|
25
|
+
output.assign('.prototype' + (('.' + method) if method else ''))
|
|
25
26
|
|
|
26
27
|
def define_method(stmt, is_property):
|
|
27
28
|
name = stmt.name.name
|
|
@@ -33,7 +34,7 @@ def print_class(output):
|
|
|
33
34
|
|
|
34
35
|
# decorate the method
|
|
35
36
|
if stmt.decorators and stmt.decorators.length:
|
|
36
|
-
decorate(stmt.decorators, output, def():function_definition(stmt, output, strip_first, True);)
|
|
37
|
+
decorate(stmt.decorators, output, def (): function_definition(stmt, output, strip_first, True);)
|
|
37
38
|
output.end_statement()
|
|
38
39
|
else:
|
|
39
40
|
function_definition(stmt, output, strip_first)
|
|
@@ -45,7 +46,7 @@ def print_class(output):
|
|
|
45
46
|
def define_default_method(name, body):
|
|
46
47
|
class_def(name)
|
|
47
48
|
output.spaced('function', name, '()', '')
|
|
48
|
-
output.with_block(def(): output.indent(), body();)
|
|
49
|
+
output.with_block(def (): output.indent(), body();)
|
|
49
50
|
output.end_statement()
|
|
50
51
|
|
|
51
52
|
def add_hidden_property(name, proceed):
|
|
@@ -55,23 +56,23 @@ def print_class(output):
|
|
|
55
56
|
|
|
56
57
|
# generate constructor
|
|
57
58
|
def write_constructor():
|
|
58
|
-
output.print(
|
|
59
|
+
output.print('function')
|
|
59
60
|
output.space()
|
|
60
61
|
self.name.print(output)
|
|
61
|
-
output.print(
|
|
62
|
+
output.print('()')
|
|
62
63
|
output.space()
|
|
63
64
|
|
|
64
|
-
output.with_block(def():
|
|
65
|
+
output.with_block(def ():
|
|
65
66
|
output.indent()
|
|
66
67
|
output.spaced('if', '(this.ρσ_object_id', '===', 'undefined)', 'Object.defineProperty(this,', '"ρσ_object_id",', '{"value":++ρσ_object_counter})')
|
|
67
68
|
output.end_statement()
|
|
68
69
|
if self.bound.length:
|
|
69
70
|
output.indent()
|
|
70
|
-
self.name.print(output), output.print(
|
|
71
|
+
self.name.print(output), output.print('.prototype.__bind_methods__.call(this)')
|
|
71
72
|
output.end_statement()
|
|
72
73
|
output.indent()
|
|
73
74
|
self.name.print(output)
|
|
74
|
-
output.print(
|
|
75
|
+
output.print('.prototype.__init__.apply(this'), output.comma(), output.print('arguments)')
|
|
75
76
|
output.end_statement()
|
|
76
77
|
)
|
|
77
78
|
|
|
@@ -98,8 +99,8 @@ def print_class(output):
|
|
|
98
99
|
# inheritance
|
|
99
100
|
if self.parent:
|
|
100
101
|
output.indent()
|
|
101
|
-
output.print(
|
|
102
|
-
output.with_parens(def():
|
|
102
|
+
output.print('ρσ_extends')
|
|
103
|
+
output.with_parens(def ():
|
|
103
104
|
self.name.print(output)
|
|
104
105
|
output.comma()
|
|
105
106
|
self.parent.print(output)
|
|
@@ -109,9 +110,9 @@ def print_class(output):
|
|
|
109
110
|
# method binding
|
|
110
111
|
if self.bound.length:
|
|
111
112
|
seen_methods = Object.create(None)
|
|
112
|
-
add_hidden_property('__bind_methods__', def():
|
|
113
|
+
add_hidden_property('__bind_methods__', def ():
|
|
113
114
|
output.spaced('function', '()', '')
|
|
114
|
-
output.with_block(def():
|
|
115
|
+
output.with_block(def ():
|
|
115
116
|
if self.bases.length:
|
|
116
117
|
for v'var i = self.bases.length - 1; i >= 0; i--':
|
|
117
118
|
base = self.bases[i]
|
|
@@ -133,12 +134,12 @@ def print_class(output):
|
|
|
133
134
|
if property_names.length:
|
|
134
135
|
output.indent()
|
|
135
136
|
output.print('Object.defineProperties')
|
|
136
|
-
output.with_parens(def():
|
|
137
|
-
self.name.print(output), output.print('.prototype'), output.comma(), output.space(), output.with_block(def():
|
|
137
|
+
output.with_parens(def ():
|
|
138
|
+
self.name.print(output), output.print('.prototype'), output.comma(), output.space(), output.with_block(def ():
|
|
138
139
|
for name in property_names:
|
|
139
140
|
prop = self.dynamic_properties[name]
|
|
140
141
|
output.indent(), output.print(JSON.stringify(name) + ':'), output.space()
|
|
141
|
-
output.with_block(def():
|
|
142
|
+
output.with_block(def ():
|
|
142
143
|
output.indent(), output.print('"enumerable":'), output.space(), output.print('true'), output.comma(), output.newline()
|
|
143
144
|
if prop.getter:
|
|
144
145
|
output.indent(), output.print('"get":'), output.space()
|
|
@@ -157,16 +158,16 @@ def print_class(output):
|
|
|
157
158
|
# actual methods
|
|
158
159
|
if not self.init:
|
|
159
160
|
# Create a default __init__ method
|
|
160
|
-
define_default_method('__init__', def():
|
|
161
|
+
define_default_method('__init__', def ():
|
|
161
162
|
if self.parent:
|
|
162
163
|
self.parent.print(output)
|
|
163
164
|
output.spaced('.prototype.__init__', '&&')
|
|
164
165
|
output.space(), self.parent.print(output)
|
|
165
|
-
output.print(
|
|
166
|
-
output.with_parens(def():
|
|
167
|
-
output.print(
|
|
166
|
+
output.print('.prototype.__init__.apply')
|
|
167
|
+
output.with_parens(def ():
|
|
168
|
+
output.print('this')
|
|
168
169
|
output.comma()
|
|
169
|
-
output.print(
|
|
170
|
+
output.print('arguments')
|
|
170
171
|
)
|
|
171
172
|
output.end_statement()
|
|
172
173
|
)
|
|
@@ -195,7 +196,7 @@ def print_class(output):
|
|
|
195
196
|
console.error('Nested classes aren\'t supported yet') # noqa:undef
|
|
196
197
|
|
|
197
198
|
if not defined_methods['__repr__']:
|
|
198
|
-
define_default_method('__repr__', def():
|
|
199
|
+
define_default_method('__repr__', def ():
|
|
199
200
|
if self.parent:
|
|
200
201
|
output.print('if('), self.parent.print(output), output.spaced('.prototype.__repr__)', 'return', self.parent)
|
|
201
202
|
output.print('.prototype.__repr__.call(this)'), output.end_statement()
|
|
@@ -205,7 +206,7 @@ def print_class(output):
|
|
|
205
206
|
)
|
|
206
207
|
|
|
207
208
|
if not defined_methods['__str__']:
|
|
208
|
-
define_default_method('__str__', def():
|
|
209
|
+
define_default_method('__str__', def ():
|
|
209
210
|
if self.parent:
|
|
210
211
|
output.print('if('), self.parent.print(output), output.spaced('.prototype.__str__)', 'return', self.parent)
|
|
211
212
|
output.print('.prototype.__str__.call(this)'), output.end_statement()
|
|
@@ -214,7 +215,7 @@ def print_class(output):
|
|
|
214
215
|
)
|
|
215
216
|
|
|
216
217
|
# Multiple inheritance
|
|
217
|
-
add_hidden_property('__bases__', def():
|
|
218
|
+
add_hidden_property('__bases__', def ():
|
|
218
219
|
output.print('[')
|
|
219
220
|
for v'var i = 0; i < self.bases.length; i++':
|
|
220
221
|
self.bases[i].print(output)
|
|
@@ -225,7 +226,7 @@ def print_class(output):
|
|
|
225
226
|
|
|
226
227
|
if self.bases.length > 1:
|
|
227
228
|
output.indent()
|
|
228
|
-
output.print(
|
|
229
|
+
output.print('ρσ_mixin(')
|
|
229
230
|
self.name.print(output)
|
|
230
231
|
for v'var i = 1; i < self.bases.length; i++':
|
|
231
232
|
output.comma()
|
|
@@ -234,7 +235,7 @@ def print_class(output):
|
|
|
234
235
|
|
|
235
236
|
# Docstring
|
|
236
237
|
if self.docstrings and self.docstrings.length and output.options.keep_docstrings:
|
|
237
|
-
add_hidden_property('__doc__', def():
|
|
238
|
+
add_hidden_property('__doc__', def ():
|
|
238
239
|
output.print(JSON.stringify(create_doctring(self.docstrings)))
|
|
239
240
|
)
|
|
240
241
|
|
package/src/output/codegen.pyj
CHANGED
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
3
|
from __python__ import hash_literals
|
|
4
4
|
|
|
5
|
-
# globals:console
|
|
6
|
-
|
|
7
|
-
from utils import noop
|
|
8
|
-
from parse import PRECEDENCE
|
|
9
5
|
from ast import (
|
|
10
6
|
AST_Array, AST_Assign, AST_BaseCall, AST_Binary, AST_BlockStatement, AST_Break,
|
|
11
7
|
AST_Class, AST_Conditional, AST_Constant, AST_Continue,
|
|
@@ -20,20 +16,23 @@ from ast import (
|
|
|
20
16
|
AST_UnaryPrefix, AST_Undefined, AST_Var, AST_VarDef, AST_Assert,
|
|
21
17
|
AST_Verbatim, AST_While, AST_With, AST_Yield, AST_Await, TreeWalker, AST_Existential
|
|
22
18
|
)
|
|
23
|
-
from output.exceptions import print_try
|
|
24
19
|
from output.classes import print_class
|
|
20
|
+
from output.comments import print_comments
|
|
21
|
+
from output.exceptions import print_try
|
|
22
|
+
from output.functions import print_function, print_function_call
|
|
25
23
|
from output.literals import print_array, print_obj_literal, print_object, print_set, print_regexp
|
|
26
24
|
from output.loops import print_do_loop, print_while_loop, print_for_loop_body, print_for_in, print_list_comprehension
|
|
27
25
|
from output.modules import print_top_level, print_imports
|
|
28
|
-
from output.comments import print_comments
|
|
29
26
|
from output.operators import (
|
|
30
27
|
print_getattr, print_getitem, print_rich_getitem, print_splice_assignment,
|
|
31
28
|
print_unary_prefix, print_binary_op, print_assign,
|
|
32
29
|
print_conditional, print_seq, print_existential
|
|
33
30
|
)
|
|
34
|
-
from output.functions import print_function, print_function_call
|
|
35
31
|
from output.statements import print_bracketed, first_in_statement, force_statement, print_with, print_assert
|
|
36
32
|
from output.utils import make_block, make_num
|
|
33
|
+
from parse import PRECEDENCE
|
|
34
|
+
from utils import noop
|
|
35
|
+
|
|
37
36
|
|
|
38
37
|
# -----[ code generators ]-----
|
|
39
38
|
def generate_code():
|
|
@@ -41,12 +40,12 @@ def generate_code():
|
|
|
41
40
|
def DEFPRINT(nodetype, generator):
|
|
42
41
|
nodetype.prototype._codegen = generator
|
|
43
42
|
|
|
44
|
-
AST_Node.prototype.print = def(stream, force_parens):
|
|
43
|
+
AST_Node.prototype.print = def (stream, force_parens):
|
|
45
44
|
self = this
|
|
46
45
|
generator = self._codegen
|
|
47
46
|
stream.push_node(self)
|
|
48
47
|
if force_parens or self.needs_parens(stream):
|
|
49
|
-
stream.with_parens(def():
|
|
48
|
+
stream.with_parens(def ():
|
|
50
49
|
self.add_comments(stream)
|
|
51
50
|
stream.add_mapping(self)
|
|
52
51
|
generator(self, stream)
|
|
@@ -59,7 +58,7 @@ def generate_code():
|
|
|
59
58
|
stream.pop_node()
|
|
60
59
|
|
|
61
60
|
# -----[ comments ]-----
|
|
62
|
-
AST_Node.prototype.add_comments = def(output):
|
|
61
|
+
AST_Node.prototype.add_comments = def (output):
|
|
63
62
|
if not is_node_type(this, AST_Toplevel):
|
|
64
63
|
print_comments(this, output)
|
|
65
64
|
|
|
@@ -67,51 +66,48 @@ def generate_code():
|
|
|
67
66
|
def PARENS(nodetype, func):
|
|
68
67
|
nodetype.prototype.needs_parens = func
|
|
69
68
|
|
|
70
|
-
PARENS(AST_Node, def():
|
|
69
|
+
PARENS(AST_Node, def ():
|
|
71
70
|
return False
|
|
72
71
|
)
|
|
73
72
|
# a function expression needs parens around it when it's provably
|
|
74
73
|
# the first token to appear in a statement.
|
|
75
|
-
PARENS(AST_Function, def(output):
|
|
74
|
+
PARENS(AST_Function, def (output):
|
|
76
75
|
return first_in_statement(output)
|
|
77
76
|
)
|
|
78
77
|
# same goes for an object literal, because otherwise it would be
|
|
79
78
|
# interpreted as a block of code.
|
|
80
|
-
PARENS(AST_Object, def(output):
|
|
79
|
+
PARENS(AST_Object, def (output):
|
|
81
80
|
return first_in_statement(output)
|
|
82
81
|
)
|
|
83
|
-
PARENS(AST_Unary, def(output):
|
|
82
|
+
PARENS(AST_Unary, def (output):
|
|
84
83
|
p = output.parent()
|
|
85
84
|
return is_node_type(p, AST_PropAccess) and p.expression is this
|
|
86
85
|
)
|
|
87
|
-
PARENS(AST_Seq, def(output):
|
|
86
|
+
PARENS(AST_Seq, def (output):
|
|
88
87
|
p = output.parent()
|
|
89
88
|
return is_node_type(p, AST_Unary) or is_node_type(p, AST_VarDef) or is_node_type(p, AST_Dot) or is_node_type(p, AST_ObjectProperty) or is_node_type(p, AST_Conditional)
|
|
90
89
|
)
|
|
91
|
-
PARENS(AST_Binary, def(output):
|
|
90
|
+
PARENS(AST_Binary, def (output):
|
|
92
91
|
p = output.parent()
|
|
93
92
|
# (foo && bar)()
|
|
94
93
|
if is_node_type(p, AST_BaseCall) and p.expression is this:
|
|
95
94
|
return True
|
|
96
|
-
|
|
97
95
|
# typeof (foo && bar)
|
|
98
96
|
if is_node_type(p, AST_Unary):
|
|
99
97
|
return True
|
|
100
|
-
|
|
101
98
|
# (foo && bar)["prop"], (foo && bar).prop
|
|
102
99
|
if is_node_type(p, AST_PropAccess) and p.expression is this:
|
|
103
100
|
return True
|
|
104
|
-
|
|
105
101
|
# this deals with precedence: 3 * (2 + 1)
|
|
106
102
|
if is_node_type(p, AST_Binary):
|
|
107
103
|
po = p.operator
|
|
108
104
|
pp = PRECEDENCE[po]
|
|
109
105
|
so = this.operator
|
|
110
106
|
sp = PRECEDENCE[so]
|
|
111
|
-
if pp > sp or pp is sp and this is p.right and not (so is po and (so is
|
|
107
|
+
if pp > sp or pp is sp and this is p.right and not (so is po and (so is '*' or so is '&&' or so is '||')):
|
|
112
108
|
return True
|
|
113
109
|
)
|
|
114
|
-
PARENS(AST_PropAccess, def(output):
|
|
110
|
+
PARENS(AST_PropAccess, def (output):
|
|
115
111
|
p = output.parent()
|
|
116
112
|
if is_node_type(p, AST_New) and p.expression is this:
|
|
117
113
|
# i.e. new (foo.bar().baz)
|
|
@@ -121,7 +117,7 @@ def generate_code():
|
|
|
121
117
|
# interpreted as passing the arguments to the upper New
|
|
122
118
|
# expression.
|
|
123
119
|
try:
|
|
124
|
-
this.walk(new TreeWalker(def(node):
|
|
120
|
+
this.walk(new TreeWalker(def (node):
|
|
125
121
|
if is_node_type(node, AST_BaseCall):
|
|
126
122
|
raise p
|
|
127
123
|
))
|
|
@@ -130,26 +126,27 @@ def generate_code():
|
|
|
130
126
|
raise ex
|
|
131
127
|
return True
|
|
132
128
|
)
|
|
133
|
-
PARENS(AST_BaseCall, def(output):
|
|
129
|
+
PARENS(AST_BaseCall, def (output):
|
|
134
130
|
p = output.parent()
|
|
135
131
|
return is_node_type(p, AST_New) and p.expression is this
|
|
136
132
|
)
|
|
137
|
-
PARENS(AST_New, def(output):
|
|
133
|
+
PARENS(AST_New, def (output):
|
|
138
134
|
p = output.parent()
|
|
139
135
|
if this.args.args.length is 0 and (is_node_type(p, AST_PropAccess) or is_node_type(p, AST_BaseCall) and p.expression is this):
|
|
140
136
|
# (new foo)(bar)
|
|
141
137
|
return True
|
|
142
138
|
)
|
|
143
|
-
PARENS(AST_Number, def(output):
|
|
139
|
+
PARENS(AST_Number, def (output):
|
|
144
140
|
p = output.parent()
|
|
145
141
|
if this.value < 0 and is_node_type(p, AST_PropAccess) and p.expression is this:
|
|
146
142
|
return True
|
|
147
143
|
)
|
|
148
|
-
PARENS(AST_NaN, def(output):
|
|
144
|
+
PARENS(AST_NaN, def (output):
|
|
149
145
|
p = output.parent()
|
|
150
146
|
if is_node_type(p, AST_PropAccess) and p.expression is this:
|
|
151
147
|
return True
|
|
152
148
|
)
|
|
149
|
+
|
|
153
150
|
def assign_and_conditional_paren_rules(output):
|
|
154
151
|
p = output.parent()
|
|
155
152
|
# !(a = false) → true
|
|
@@ -176,18 +173,18 @@ def generate_code():
|
|
|
176
173
|
PARENS(AST_Conditional, assign_and_conditional_paren_rules)
|
|
177
174
|
|
|
178
175
|
# -----[ PRINTERS ]-----
|
|
179
|
-
DEFPRINT(AST_Directive, def(self, output):
|
|
176
|
+
DEFPRINT(AST_Directive, def (self, output):
|
|
180
177
|
output.print_string(self.value)
|
|
181
178
|
output.semicolon()
|
|
182
179
|
)
|
|
183
|
-
DEFPRINT(AST_Debugger, def(self, output):
|
|
184
|
-
output.print(
|
|
180
|
+
DEFPRINT(AST_Debugger, def (self, output):
|
|
181
|
+
output.print('debugger')
|
|
185
182
|
output.semicolon()
|
|
186
183
|
)
|
|
187
|
-
AST_StatementWithBody.prototype._do_print_body = def(output):
|
|
184
|
+
AST_StatementWithBody.prototype._do_print_body = def (output):
|
|
188
185
|
force_statement(this.body, output)
|
|
189
186
|
|
|
190
|
-
DEFPRINT(AST_Statement, def(self, output):
|
|
187
|
+
DEFPRINT(AST_Statement, def (self, output):
|
|
191
188
|
self.body.print(output)
|
|
192
189
|
output.semicolon()
|
|
193
190
|
)
|
|
@@ -195,16 +192,16 @@ def generate_code():
|
|
|
195
192
|
|
|
196
193
|
DEFPRINT(AST_Imports, print_imports)
|
|
197
194
|
|
|
198
|
-
DEFPRINT(AST_SimpleStatement, def(self, output):
|
|
195
|
+
DEFPRINT(AST_SimpleStatement, def (self, output):
|
|
199
196
|
if not (is_node_type(self.body, AST_EmptyStatement)):
|
|
200
197
|
self.body.print(output)
|
|
201
198
|
output.semicolon()
|
|
202
199
|
)
|
|
203
|
-
DEFPRINT(AST_BlockStatement, def(self, output):
|
|
200
|
+
DEFPRINT(AST_BlockStatement, def (self, output):
|
|
204
201
|
print_bracketed(self, output)
|
|
205
202
|
)
|
|
206
203
|
|
|
207
|
-
DEFPRINT(AST_EmptyStatement, def(self, output):
|
|
204
|
+
DEFPRINT(AST_EmptyStatement, def (self, output):
|
|
208
205
|
pass
|
|
209
206
|
)
|
|
210
207
|
|
|
@@ -216,19 +213,19 @@ def generate_code():
|
|
|
216
213
|
|
|
217
214
|
DEFPRINT(AST_ForIn, print_for_in)
|
|
218
215
|
|
|
219
|
-
AST_ForJS.prototype._do_print_body = def(output):
|
|
216
|
+
AST_ForJS.prototype._do_print_body = def (output):
|
|
220
217
|
self = this
|
|
221
|
-
output.with_block(def():
|
|
218
|
+
output.with_block(def ():
|
|
222
219
|
for stmt in self.body.body:
|
|
223
220
|
output.indent()
|
|
224
221
|
stmt.print(output)
|
|
225
222
|
output.newline()
|
|
226
223
|
)
|
|
227
224
|
|
|
228
|
-
DEFPRINT(AST_ForJS, def(self, output):
|
|
229
|
-
output.print(
|
|
225
|
+
DEFPRINT(AST_ForJS, def (self, output):
|
|
226
|
+
output.print('for')
|
|
230
227
|
output.space()
|
|
231
|
-
output.with_parens(def():
|
|
228
|
+
output.with_parens(def ():
|
|
232
229
|
self.condition.print(output)
|
|
233
230
|
)
|
|
234
231
|
output.space()
|
|
@@ -243,15 +240,15 @@ def generate_code():
|
|
|
243
240
|
|
|
244
241
|
AST_Lambda.prototype._do_print = print_function
|
|
245
242
|
|
|
246
|
-
DEFPRINT(AST_Lambda, def(self, output):
|
|
243
|
+
DEFPRINT(AST_Lambda, def (self, output):
|
|
247
244
|
self._do_print(output)
|
|
248
245
|
)
|
|
249
246
|
AST_Class.prototype._do_print = print_class
|
|
250
|
-
DEFPRINT(AST_Class, def(self, output):
|
|
247
|
+
DEFPRINT(AST_Class, def (self, output):
|
|
251
248
|
self._do_print(output)
|
|
252
249
|
)
|
|
253
250
|
# -----[ exits ]-----
|
|
254
|
-
AST_Exit.prototype._do_print = def(output, kind):
|
|
251
|
+
AST_Exit.prototype._do_print = def (output, kind):
|
|
255
252
|
self = this
|
|
256
253
|
output.print(kind)
|
|
257
254
|
if self.value:
|
|
@@ -260,23 +257,23 @@ def generate_code():
|
|
|
260
257
|
|
|
261
258
|
output.semicolon()
|
|
262
259
|
|
|
263
|
-
DEFPRINT(AST_Yield, def(self, output):
|
|
264
|
-
self._do_print(output,
|
|
260
|
+
DEFPRINT(AST_Yield, def (self, output):
|
|
261
|
+
self._do_print(output, 'yield' + ('*' if self.is_yield_from else ''))
|
|
265
262
|
)
|
|
266
|
-
DEFPRINT(AST_Await, def(self, output):
|
|
267
|
-
output.print(
|
|
263
|
+
DEFPRINT(AST_Await, def (self, output):
|
|
264
|
+
output.print('await')
|
|
268
265
|
output.space()
|
|
269
266
|
self.value.print(output)
|
|
270
267
|
)
|
|
271
|
-
DEFPRINT(AST_Return, def(self, output):
|
|
272
|
-
self._do_print(output,
|
|
268
|
+
DEFPRINT(AST_Return, def (self, output):
|
|
269
|
+
self._do_print(output, 'return')
|
|
273
270
|
)
|
|
274
|
-
DEFPRINT(AST_Throw, def(self, output):
|
|
275
|
-
self._do_print(output,
|
|
271
|
+
DEFPRINT(AST_Throw, def (self, output):
|
|
272
|
+
self._do_print(output, 'throw')
|
|
276
273
|
)
|
|
277
274
|
|
|
278
275
|
# -----[ loop control ]-----
|
|
279
|
-
AST_LoopControl.prototype._do_print = def(output, kind):
|
|
276
|
+
AST_LoopControl.prototype._do_print = def (output, kind):
|
|
280
277
|
output.print(kind)
|
|
281
278
|
if this.label:
|
|
282
279
|
output.space()
|
|
@@ -284,11 +281,11 @@ def generate_code():
|
|
|
284
281
|
|
|
285
282
|
output.semicolon()
|
|
286
283
|
|
|
287
|
-
DEFPRINT(AST_Break, def(self, output):
|
|
288
|
-
self._do_print(output,
|
|
284
|
+
DEFPRINT(AST_Break, def (self, output):
|
|
285
|
+
self._do_print(output, 'break')
|
|
289
286
|
)
|
|
290
|
-
DEFPRINT(AST_Continue, def(self, output):
|
|
291
|
-
self._do_print(output,
|
|
287
|
+
DEFPRINT(AST_Continue, def (self, output):
|
|
288
|
+
self._do_print(output, 'continue')
|
|
292
289
|
)
|
|
293
290
|
|
|
294
291
|
# -----[ if ]-----
|
|
@@ -330,27 +327,26 @@ def generate_code():
|
|
|
330
327
|
|
|
331
328
|
force_statement(self.body, output)
|
|
332
329
|
|
|
333
|
-
DEFPRINT(AST_If, def(self, output):
|
|
334
|
-
output.print(
|
|
330
|
+
DEFPRINT(AST_If, def (self, output):
|
|
331
|
+
output.print('if')
|
|
335
332
|
output.space()
|
|
336
|
-
output.with_parens(def(): self.condition.print(output);)
|
|
333
|
+
output.with_parens(def (): self.condition.print(output);)
|
|
337
334
|
output.space()
|
|
338
335
|
if self.alternative:
|
|
339
336
|
make_then(self, output)
|
|
340
337
|
output.space()
|
|
341
|
-
output.print(
|
|
338
|
+
output.print('else')
|
|
342
339
|
output.space()
|
|
343
340
|
force_statement(self.alternative, output)
|
|
344
341
|
else:
|
|
345
342
|
self._do_print_body(output)
|
|
346
|
-
|
|
347
343
|
)
|
|
348
344
|
|
|
349
345
|
# -----[ exceptions ]-----
|
|
350
346
|
DEFPRINT(AST_Try, print_try)
|
|
351
347
|
|
|
352
348
|
# -----[ var/const ]-----
|
|
353
|
-
AST_Definitions.prototype._do_print = def(output, kind):
|
|
349
|
+
AST_Definitions.prototype._do_print = def (output, kind):
|
|
354
350
|
output.print(kind)
|
|
355
351
|
output.space()
|
|
356
352
|
for i, def_ in enumerate(this.definitions):
|
|
@@ -363,9 +359,10 @@ def generate_code():
|
|
|
363
359
|
if not avoid_semicolon:
|
|
364
360
|
output.semicolon()
|
|
365
361
|
|
|
366
|
-
DEFPRINT(AST_Var, def(self, output):
|
|
367
|
-
self._do_print(output,
|
|
362
|
+
DEFPRINT(AST_Var, def (self, output):
|
|
363
|
+
self._do_print(output, 'var')
|
|
368
364
|
)
|
|
365
|
+
|
|
369
366
|
def parenthesize_for_noin(node, output, noin):
|
|
370
367
|
if not noin:
|
|
371
368
|
node.print(output)
|
|
@@ -373,8 +370,8 @@ def generate_code():
|
|
|
373
370
|
try:
|
|
374
371
|
# need to take some precautions here:
|
|
375
372
|
# https://github.com/mishoo/RapydScript2/issues/60
|
|
376
|
-
node.walk(new TreeWalker(def(node):
|
|
377
|
-
if is_node_type(node, AST_Binary) and node.operator is
|
|
373
|
+
node.walk(new TreeWalker(def (node):
|
|
374
|
+
if is_node_type(node, AST_Binary) and node.operator is 'in':
|
|
378
375
|
raise output
|
|
379
376
|
))
|
|
380
377
|
node.print(output)
|
|
@@ -383,10 +380,10 @@ def generate_code():
|
|
|
383
380
|
raise ex
|
|
384
381
|
node.print(output, True)
|
|
385
382
|
|
|
386
|
-
DEFPRINT(AST_VarDef, def(self, output):
|
|
383
|
+
DEFPRINT(AST_VarDef, def (self, output):
|
|
387
384
|
self.name.print(output)
|
|
388
385
|
if self.value:
|
|
389
|
-
output.assign(
|
|
386
|
+
output.assign('')
|
|
390
387
|
# output.space()
|
|
391
388
|
# output.print("=")
|
|
392
389
|
# output.space()
|
|
@@ -400,7 +397,7 @@ def generate_code():
|
|
|
400
397
|
|
|
401
398
|
AST_Seq.prototype._do_print = print_seq
|
|
402
399
|
|
|
403
|
-
DEFPRINT(AST_Seq, def(self, output):
|
|
400
|
+
DEFPRINT(AST_Seq, def (self, output):
|
|
404
401
|
self._do_print(output)
|
|
405
402
|
)
|
|
406
403
|
DEFPRINT(AST_Dot, print_getattr)
|
|
@@ -428,44 +425,44 @@ def generate_code():
|
|
|
428
425
|
|
|
429
426
|
DEFPRINT(AST_Object, print_object)
|
|
430
427
|
|
|
431
|
-
DEFPRINT(AST_ObjectKeyVal, def(self, output):
|
|
428
|
+
DEFPRINT(AST_ObjectKeyVal, def (self, output):
|
|
432
429
|
self.key.print(output)
|
|
433
430
|
output.colon()
|
|
434
431
|
self.value.print(output)
|
|
435
432
|
)
|
|
436
433
|
DEFPRINT(AST_Set, print_set)
|
|
437
434
|
|
|
438
|
-
AST_Symbol.prototype.definition = def():
|
|
435
|
+
AST_Symbol.prototype.definition = def ():
|
|
439
436
|
return this.thedef
|
|
440
437
|
|
|
441
|
-
DEFPRINT(AST_Symbol, def(self, output):
|
|
438
|
+
DEFPRINT(AST_Symbol, def (self, output):
|
|
442
439
|
def_ = self.definition()
|
|
443
440
|
output.print_name((def_.mangled_name or def_.name) if def_ else self.name)
|
|
444
441
|
)
|
|
445
|
-
DEFPRINT(AST_Undefined, def(self, output):
|
|
446
|
-
output.print(
|
|
442
|
+
DEFPRINT(AST_Undefined, def (self, output):
|
|
443
|
+
output.print('void 0')
|
|
447
444
|
)
|
|
448
445
|
DEFPRINT(AST_Hole, noop)
|
|
449
446
|
|
|
450
|
-
DEFPRINT(AST_Infinity, def(self, output):
|
|
451
|
-
output.print(
|
|
447
|
+
DEFPRINT(AST_Infinity, def (self, output):
|
|
448
|
+
output.print('1/0')
|
|
452
449
|
)
|
|
453
|
-
DEFPRINT(AST_NaN, def(self, output):
|
|
454
|
-
output.print(
|
|
450
|
+
DEFPRINT(AST_NaN, def (self, output):
|
|
451
|
+
output.print('0/0')
|
|
455
452
|
)
|
|
456
|
-
DEFPRINT(AST_This, def(self, output):
|
|
457
|
-
output.print(
|
|
453
|
+
DEFPRINT(AST_This, def (self, output):
|
|
454
|
+
output.print('this')
|
|
458
455
|
)
|
|
459
|
-
DEFPRINT(AST_Constant, def(self, output):
|
|
456
|
+
DEFPRINT(AST_Constant, def (self, output):
|
|
460
457
|
output.print(self.value)
|
|
461
458
|
)
|
|
462
|
-
DEFPRINT(AST_String, def(self, output):
|
|
459
|
+
DEFPRINT(AST_String, def (self, output):
|
|
463
460
|
output.print_string(self.value)
|
|
464
461
|
)
|
|
465
|
-
DEFPRINT(AST_Verbatim, def(self, output):
|
|
462
|
+
DEFPRINT(AST_Verbatim, def (self, output):
|
|
466
463
|
output.print(self.value)
|
|
467
464
|
)
|
|
468
|
-
DEFPRINT(AST_Number, def(self, output):
|
|
465
|
+
DEFPRINT(AST_Number, def (self, output):
|
|
469
466
|
output.print(make_num(self.value))
|
|
470
467
|
)
|
|
471
468
|
DEFPRINT(AST_RegExp, print_regexp)
|