rapydscript-ng 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/bin/build.ts +29 -0
- package/local-agent.md +4 -0
- package/package.json +1 -1
- package/release/baselib-plain-pretty.js +85 -61
- package/release/baselib-plain-ugly.js +3 -3
- package/release/compiler.js +9661 -9540
- package/release/signatures.json +26 -26
- package/src/ast.pyj +169 -64
- package/src/baselib-builtins.pyj +35 -14
- package/src/baselib-containers.pyj +70 -40
- package/src/baselib-internal.pyj +20 -8
- package/src/baselib-itertools.pyj +6 -2
- package/src/baselib-str.pyj +74 -28
- package/src/errors.pyj +4 -1
- package/src/lib/aes.pyj +664 -35
- package/src/lib/elementmaker.pyj +105 -13
- package/src/lib/encodings.pyj +31 -7
- package/src/lib/gettext.pyj +6 -3
- package/src/lib/math.pyj +38 -22
- package/src/lib/pythonize.pyj +5 -3
- package/src/lib/random.pyj +13 -5
- package/src/lib/re.pyj +81 -18
- package/src/lib/traceback.pyj +42 -10
- package/src/lib/uuid.pyj +2 -1
- package/src/output/classes.pyj +70 -26
- package/src/output/codegen.pyj +92 -20
- package/src/output/comments.pyj +11 -4
- package/src/output/exceptions.pyj +17 -4
- package/src/output/functions.pyj +145 -26
- package/src/output/literals.pyj +7 -2
- package/src/output/loops.pyj +79 -23
- package/src/output/modules.pyj +41 -12
- package/src/output/operators.pyj +154 -31
- package/src/output/statements.pyj +38 -10
- package/src/output/stream.pyj +43 -12
- package/src/output/utils.pyj +10 -3
- package/src/parse.pyj +740 -259
- package/src/string_interpolation.pyj +4 -1
- package/src/tokenizer.pyj +314 -57
- package/src/unicode_aliases.pyj +4 -2
- package/src/utils.pyj +19 -5
- package/test/functions.pyj +8 -0
- package/test/generic.pyj +9 -0
- package/test/lsp.pyj +16 -0
- package/test/str.pyj +10 -0
- package/tools/cli.mjs +4 -3
- package/tools/compile.mjs +9 -3
- package/tools/compiler.mjs +0 -6
- package/tools/fmt.mjs +41 -2
- package/tools/lint-worker.mjs +107 -0
- package/tools/lint.mjs +134 -8
- package/tools/lsp.mjs +11 -1
- package/tree-sitter/grammar.js +27 -6
- package/tree-sitter/queries/highlights.scm +10 -0
- package/tree-sitter/src/grammar.json +130 -5
- package/tree-sitter/src/node-types.json +73 -0
- package/tree-sitter/src/parser.c +119589 -114993
- package/tree-sitter/src/scanner.c +275 -17
- package/tree-sitter/test/corpus/strings.txt +41 -5
package/src/lib/traceback.pyj
CHANGED
|
@@ -78,10 +78,17 @@ def _decode_source_map(smap):
|
|
|
78
78
|
prev_src_line = src_line
|
|
79
79
|
src_col = prev_src_col + fields[3]
|
|
80
80
|
prev_src_col = src_col
|
|
81
|
-
src_file =
|
|
81
|
+
src_file = (
|
|
82
|
+
sources[src_idx]
|
|
83
|
+
if src_idx >= 0 and src_idx < sources.length
|
|
84
|
+
else ''
|
|
85
|
+
)
|
|
82
86
|
if source_root and src_file:
|
|
83
87
|
src_file = source_root + src_file
|
|
84
|
-
line_entries.push({
|
|
88
|
+
line_entries.push({
|
|
89
|
+
'gen_col': gen_col, 'src_file': src_file,
|
|
90
|
+
'src_line': src_line, 'src_col': src_col
|
|
91
|
+
})
|
|
85
92
|
elif fields.length >= 1:
|
|
86
93
|
prev_col += fields[0]
|
|
87
94
|
decoded.push(line_entries)
|
|
@@ -106,21 +113,37 @@ def _parse_stack_frame(line):
|
|
|
106
113
|
# Chrome/Node: " at functionName (file:line:col)"
|
|
107
114
|
m = /^\s*at\s+(.*?)\s+\((.+):(\d+):(\d+)\)/.exec(line)
|
|
108
115
|
if m:
|
|
109
|
-
return {
|
|
116
|
+
return {
|
|
117
|
+
'func': m[1] or None,
|
|
118
|
+
'file': m[2],
|
|
119
|
+
'line': parseInt(m[3], 10) - 1,
|
|
120
|
+
'col': parseInt(m[4], 10) - 1,
|
|
121
|
+
}
|
|
110
122
|
# Chrome/Node: " at file:line:col"
|
|
111
123
|
m = /^\s*at (.+):(\d+):(\d+)$/.exec(line)
|
|
112
124
|
if m:
|
|
113
|
-
return {
|
|
125
|
+
return {
|
|
126
|
+
'func': None,
|
|
127
|
+
'file': m[1],
|
|
128
|
+
'line': parseInt(m[2], 10) - 1,
|
|
129
|
+
'col': parseInt(m[3], 10) - 1,
|
|
130
|
+
}
|
|
114
131
|
# Firefox: "functionName@file:line:col"
|
|
115
132
|
m = /^(.*?)@(.+):(\d+):(\d+)$/.exec(line)
|
|
116
133
|
if m:
|
|
117
|
-
return {
|
|
134
|
+
return {
|
|
135
|
+
'func': m[1] or None,
|
|
136
|
+
'file': m[2],
|
|
137
|
+
'line': parseInt(m[3], 10) - 1,
|
|
138
|
+
'col': parseInt(m[4], 10) - 1,
|
|
139
|
+
}
|
|
118
140
|
return None
|
|
119
141
|
|
|
120
142
|
|
|
121
143
|
def _get_decoded_map():
|
|
122
144
|
if _traceback_state['decoded'] is None and _traceback_state['source_map']:
|
|
123
|
-
_traceback_state['decoded'] = _decode_source_map(
|
|
145
|
+
_traceback_state['decoded'] = _decode_source_map(
|
|
146
|
+
_traceback_state['source_map'])
|
|
124
147
|
return _traceback_state['decoded']
|
|
125
148
|
|
|
126
149
|
|
|
@@ -131,7 +154,8 @@ def _get_internal_traceback(err):
|
|
|
131
154
|
for i, line in enumerate(lines):
|
|
132
155
|
if i > 0:
|
|
133
156
|
line = line.trim()
|
|
134
|
-
if line.startsWith('at new ' + err.name) or
|
|
157
|
+
if (line.startsWith('at new ' + err.name) or
|
|
158
|
+
line.startsWith(err.name + '@')):
|
|
135
159
|
# this is the constructor for a RapydScript Exception
|
|
136
160
|
start_line_idx = i + 1
|
|
137
161
|
break
|
|
@@ -140,7 +164,10 @@ def _get_internal_traceback(err):
|
|
|
140
164
|
for i, xline in enumerate(lines):
|
|
141
165
|
if i > 0:
|
|
142
166
|
line = xline.trim()
|
|
143
|
-
if
|
|
167
|
+
if (
|
|
168
|
+
v"line.startsWith('at ') || line.includes('@')" or
|
|
169
|
+
v"/:\d+:\d+$/.test(line)"
|
|
170
|
+
):
|
|
144
171
|
start_line_idx = i
|
|
145
172
|
break
|
|
146
173
|
frame_lines = lines[start_line_idx:]
|
|
@@ -153,7 +180,11 @@ def _get_internal_traceback(err):
|
|
|
153
180
|
if frame:
|
|
154
181
|
mapping = _find_mapping(decoded, frame.line, frame.col)
|
|
155
182
|
if mapping:
|
|
156
|
-
loc =
|
|
183
|
+
loc = (
|
|
184
|
+
' File "' + mapping.src_file + '", line ' +
|
|
185
|
+
(mapping.src_line + 1) + ', col ' +
|
|
186
|
+
(mapping.src_col + 1)
|
|
187
|
+
)
|
|
157
188
|
if frame.func:
|
|
158
189
|
loc += ', in ' + frame.func
|
|
159
190
|
mapped_lines.push(loc)
|
|
@@ -177,7 +208,8 @@ def format_exception(exc, limit):
|
|
|
177
208
|
js_lines.push(e)
|
|
178
209
|
js_lines = v"['Traceback (most recent call last):'].concat(js_lines)"
|
|
179
210
|
if rs_lines.length > 0:
|
|
180
|
-
js_lines = js_lines.concat(
|
|
211
|
+
js_lines = js_lines.concat(
|
|
212
|
+
['', 'Mapped Traceback (RapydScript):']).concat(rs_lines)
|
|
181
213
|
return [l + '\n' for l in js_lines]
|
|
182
214
|
return [exc.toString()]
|
|
183
215
|
|
package/src/lib/uuid.pyj
CHANGED
package/src/output/classes.pyj
CHANGED
|
@@ -34,13 +34,16 @@ def print_class(output):
|
|
|
34
34
|
|
|
35
35
|
# decorate the method
|
|
36
36
|
if stmt.decorators and stmt.decorators.length:
|
|
37
|
-
decorate(
|
|
37
|
+
decorate(
|
|
38
|
+
stmt.decorators, output,
|
|
39
|
+
def (): function_definition(stmt, output, strip_first, True);)
|
|
38
40
|
output.end_statement()
|
|
39
41
|
else:
|
|
40
42
|
function_definition(stmt, output, strip_first)
|
|
41
43
|
if not is_property:
|
|
42
44
|
output.end_statement()
|
|
43
|
-
fname = self.name.name +
|
|
45
|
+
fname = (self.name.name +
|
|
46
|
+
('.' if is_static else '.prototype.') + name)
|
|
44
47
|
function_annotation(stmt, output, strip_first, fname)
|
|
45
48
|
|
|
46
49
|
def define_default_method(name, body):
|
|
@@ -51,8 +54,12 @@ def print_class(output):
|
|
|
51
54
|
|
|
52
55
|
def add_hidden_property(name, proceed):
|
|
53
56
|
output.indent(), output.print('Object.defineProperty(')
|
|
54
|
-
self.name.print(output), output.print('.prototype')
|
|
55
|
-
output.
|
|
57
|
+
self.name.print(output), output.print('.prototype')
|
|
58
|
+
output.comma(), output.print(JSON.stringify(name)), output.comma()
|
|
59
|
+
output.spaced(
|
|
60
|
+
'{value:',
|
|
61
|
+
''
|
|
62
|
+
), proceed(), output.print('})'), output.end_statement()
|
|
56
63
|
|
|
57
64
|
# generate constructor
|
|
58
65
|
def write_constructor():
|
|
@@ -64,15 +71,22 @@ def print_class(output):
|
|
|
64
71
|
|
|
65
72
|
output.with_block(def ():
|
|
66
73
|
output.indent()
|
|
67
|
-
output.spaced(
|
|
74
|
+
output.spaced(
|
|
75
|
+
'if', '(this.ρσ_object_id',
|
|
76
|
+
'===', 'undefined)',
|
|
77
|
+
'Object.defineProperty(this,',
|
|
78
|
+
'"ρσ_object_id",',
|
|
79
|
+
'{"value":++ρσ_object_counter})')
|
|
68
80
|
output.end_statement()
|
|
69
81
|
if self.bound.length:
|
|
70
82
|
output.indent()
|
|
71
|
-
self.name.print(output)
|
|
83
|
+
self.name.print(output)
|
|
84
|
+
output.print('.prototype.__bind_methods__.call(this)')
|
|
72
85
|
output.end_statement()
|
|
73
86
|
output.indent()
|
|
74
87
|
self.name.print(output)
|
|
75
|
-
output.print('.prototype.__init__.apply(this')
|
|
88
|
+
output.print('.prototype.__init__.apply(this')
|
|
89
|
+
output.comma(), output.print('arguments)')
|
|
76
90
|
output.end_statement()
|
|
77
91
|
)
|
|
78
92
|
|
|
@@ -116,15 +130,18 @@ def print_class(output):
|
|
|
116
130
|
if self.bases.length:
|
|
117
131
|
for v'var i = self.bases.length - 1; i >= 0; i--':
|
|
118
132
|
base = self.bases[i]
|
|
119
|
-
output.indent(), base.print(output)
|
|
120
|
-
|
|
133
|
+
output.indent(), base.print(output)
|
|
134
|
+
output.spaced('.prototype.__bind_methods__', '&&', '')
|
|
135
|
+
base.print(output)
|
|
136
|
+
output.print('.prototype.__bind_methods__.call(this)')
|
|
121
137
|
output.end_statement()
|
|
122
138
|
for bname in self.bound:
|
|
123
139
|
if seen_methods[bname] or self.dynamic_properties[bname]:
|
|
124
140
|
continue
|
|
125
141
|
seen_methods[bname] = True
|
|
126
142
|
output.indent(), output.assign('this.' + bname)
|
|
127
|
-
self.name.print(output)
|
|
143
|
+
self.name.print(output)
|
|
144
|
+
output.print('.prototype.' + bname + '.bind(this)')
|
|
128
145
|
output.end_statement()
|
|
129
146
|
)
|
|
130
147
|
)
|
|
@@ -135,20 +152,32 @@ def print_class(output):
|
|
|
135
152
|
output.indent()
|
|
136
153
|
output.print('Object.defineProperties')
|
|
137
154
|
output.with_parens(def ():
|
|
138
|
-
self.name.print(output), output.print('.prototype')
|
|
155
|
+
self.name.print(output), output.print('.prototype')
|
|
156
|
+
output.comma(), output.space()
|
|
157
|
+
output.with_block(def ():
|
|
139
158
|
for name in property_names:
|
|
140
159
|
prop = self.dynamic_properties[name]
|
|
141
|
-
output.indent()
|
|
160
|
+
output.indent()
|
|
161
|
+
output.print(JSON.stringify(name) + ':'), output.space()
|
|
142
162
|
output.with_block(def ():
|
|
143
|
-
output.indent()
|
|
163
|
+
output.indent()
|
|
164
|
+
output.print('"enumerable":'), output.space()
|
|
165
|
+
output.print('true'), output.comma(), output.newline()
|
|
144
166
|
if prop.getter:
|
|
145
|
-
output.indent()
|
|
146
|
-
|
|
167
|
+
output.indent()
|
|
168
|
+
output.print('"get":'), output.space()
|
|
169
|
+
define_method(prop.getter, True)
|
|
170
|
+
output.comma(), output.newline()
|
|
147
171
|
output.indent(), output.print('"set":'), output.space()
|
|
148
172
|
if prop.setter:
|
|
149
173
|
define_method(prop.setter, True), output.newline()
|
|
150
174
|
else:
|
|
151
|
-
output.spaced(
|
|
175
|
+
output.spaced(
|
|
176
|
+
'function', '()', '{',
|
|
177
|
+
'''throw new AttributeError''' +
|
|
178
|
+
'''("can't set attribute")''',
|
|
179
|
+
'}')
|
|
180
|
+
output.newline()
|
|
152
181
|
)
|
|
153
182
|
output.comma(), output.newline()
|
|
154
183
|
)
|
|
@@ -182,10 +211,17 @@ def print_class(output):
|
|
|
182
211
|
defined_methods[stmt.name.name] = True
|
|
183
212
|
sname = stmt.name.name
|
|
184
213
|
if sname is '__init__':
|
|
185
|
-
# Copy argument handling data so that kwarg interpolation
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
214
|
+
# Copy argument handling data so that kwarg interpolation
|
|
215
|
+
# works when calling the constructor
|
|
216
|
+
for attr in [
|
|
217
|
+
'.__argnames__',
|
|
218
|
+
'.__handles_kwarg_interpolation__',
|
|
219
|
+
]:
|
|
220
|
+
output.indent()
|
|
221
|
+
self.name.print(output), output.assign(attr)
|
|
222
|
+
self.name.print(output)
|
|
223
|
+
output.print('.prototype.__init__' + attr)
|
|
224
|
+
output.end_statement()
|
|
189
225
|
if sname is '__iter__':
|
|
190
226
|
class_def('ρσ_iterator_symbol', True)
|
|
191
227
|
self.name.print(output)
|
|
@@ -198,9 +234,14 @@ def print_class(output):
|
|
|
198
234
|
if not defined_methods['__repr__']:
|
|
199
235
|
define_default_method('__repr__', def ():
|
|
200
236
|
if self.parent:
|
|
201
|
-
output.print('if('), self.parent.print(output)
|
|
202
|
-
output.
|
|
203
|
-
|
|
237
|
+
output.print('if('), self.parent.print(output)
|
|
238
|
+
output.spaced('.prototype.__repr__)', 'return', self.parent)
|
|
239
|
+
output.print('.prototype.__repr__.call(this)')
|
|
240
|
+
output.end_statement()
|
|
241
|
+
output.indent()
|
|
242
|
+
output.spaced(
|
|
243
|
+
'return', '"<"', '+', '__name__', '+',
|
|
244
|
+
'"."', '+', 'this.constructor.name', '')
|
|
204
245
|
output.spaced('+', '" #"', '+', 'this.ρσ_object_id', '+', '">"')
|
|
205
246
|
output.end_statement()
|
|
206
247
|
)
|
|
@@ -208,8 +249,10 @@ def print_class(output):
|
|
|
208
249
|
if not defined_methods['__str__']:
|
|
209
250
|
define_default_method('__str__', def ():
|
|
210
251
|
if self.parent:
|
|
211
|
-
output.print('if('), self.parent.print(output)
|
|
212
|
-
output.
|
|
252
|
+
output.print('if('), self.parent.print(output)
|
|
253
|
+
output.spaced('.prototype.__str__)', 'return', self.parent)
|
|
254
|
+
output.print('.prototype.__str__.call(this)')
|
|
255
|
+
output.end_statement()
|
|
213
256
|
output.spaced('return', 'this.__repr__()')
|
|
214
257
|
output.end_statement()
|
|
215
258
|
)
|
|
@@ -234,7 +277,8 @@ def print_class(output):
|
|
|
234
277
|
output.print(')'), output.end_statement()
|
|
235
278
|
|
|
236
279
|
# Docstring
|
|
237
|
-
if self.docstrings and self.docstrings.length
|
|
280
|
+
if (self.docstrings and self.docstrings.length
|
|
281
|
+
and output.options.keep_docstrings):
|
|
238
282
|
add_hidden_property('__doc__', def ():
|
|
239
283
|
output.print(JSON.stringify(create_doctring(self.docstrings)))
|
|
240
284
|
)
|
package/src/output/codegen.pyj
CHANGED
|
@@ -3,32 +3,94 @@
|
|
|
3
3
|
from __python__ import hash_literals
|
|
4
4
|
|
|
5
5
|
from ast import (
|
|
6
|
-
AST_Array,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
AST_Array,
|
|
7
|
+
AST_Assign,
|
|
8
|
+
AST_BaseCall,
|
|
9
|
+
AST_Binary,
|
|
10
|
+
AST_BlockStatement,
|
|
11
|
+
AST_Break,
|
|
12
|
+
AST_Class,
|
|
13
|
+
AST_Conditional,
|
|
14
|
+
AST_Constant,
|
|
15
|
+
AST_Continue,
|
|
16
|
+
AST_Debugger,
|
|
17
|
+
AST_Definitions,
|
|
18
|
+
AST_Directive,
|
|
19
|
+
AST_Do,
|
|
20
|
+
AST_Dot,
|
|
21
|
+
is_node_type,
|
|
22
|
+
AST_EmptyStatement,
|
|
23
|
+
AST_Exit,
|
|
24
|
+
AST_ExpressiveObject,
|
|
25
|
+
AST_ForIn,
|
|
26
|
+
AST_ForJS,
|
|
27
|
+
AST_Function,
|
|
28
|
+
AST_Hole,
|
|
29
|
+
AST_If,
|
|
30
|
+
AST_Imports,
|
|
31
|
+
AST_Infinity,
|
|
32
|
+
AST_Lambda,
|
|
33
|
+
AST_ListComprehension,
|
|
34
|
+
AST_LoopControl,
|
|
35
|
+
AST_NaN,
|
|
36
|
+
AST_New,
|
|
37
|
+
AST_Node,
|
|
38
|
+
AST_Number,
|
|
39
|
+
AST_Object,
|
|
40
|
+
AST_ObjectKeyVal,
|
|
41
|
+
AST_ObjectProperty,
|
|
42
|
+
AST_PropAccess,
|
|
43
|
+
AST_RegExp,
|
|
44
|
+
AST_Return,
|
|
45
|
+
AST_Set,
|
|
46
|
+
AST_Seq,
|
|
47
|
+
AST_SimpleStatement,
|
|
48
|
+
AST_Splice,
|
|
49
|
+
AST_Statement,
|
|
50
|
+
AST_StatementWithBody,
|
|
51
|
+
AST_String,
|
|
52
|
+
AST_Sub,
|
|
53
|
+
AST_ItemAccess,
|
|
54
|
+
AST_Symbol,
|
|
55
|
+
AST_This,
|
|
56
|
+
AST_Throw,
|
|
57
|
+
AST_Toplevel,
|
|
58
|
+
AST_Try,
|
|
59
|
+
AST_Unary,
|
|
60
|
+
AST_UnaryPrefix,
|
|
61
|
+
AST_Undefined,
|
|
62
|
+
AST_Var,
|
|
63
|
+
AST_VarDef,
|
|
64
|
+
AST_Assert,
|
|
65
|
+
AST_Verbatim,
|
|
66
|
+
AST_While,
|
|
67
|
+
AST_With,
|
|
68
|
+
AST_Yield,
|
|
69
|
+
AST_Await,
|
|
70
|
+
TreeWalker,
|
|
71
|
+
AST_Existential
|
|
18
72
|
)
|
|
19
73
|
from output.classes import print_class
|
|
20
74
|
from output.comments import print_comments
|
|
21
75
|
from output.exceptions import print_try
|
|
22
76
|
from output.functions import print_function, print_function_call
|
|
23
|
-
from output.literals import
|
|
24
|
-
|
|
77
|
+
from output.literals import (
|
|
78
|
+
print_array, print_obj_literal, print_object, print_set, print_regexp
|
|
79
|
+
)
|
|
80
|
+
from output.loops import (
|
|
81
|
+
print_do_loop, print_while_loop, print_for_loop_body, print_for_in,
|
|
82
|
+
print_list_comprehension
|
|
83
|
+
)
|
|
25
84
|
from output.modules import print_top_level, print_imports
|
|
26
85
|
from output.operators import (
|
|
27
86
|
print_getattr, print_getitem, print_rich_getitem, print_splice_assignment,
|
|
28
87
|
print_unary_prefix, print_binary_op, print_assign,
|
|
29
88
|
print_conditional, print_seq, print_existential
|
|
30
89
|
)
|
|
31
|
-
from output.statements import
|
|
90
|
+
from output.statements import (
|
|
91
|
+
print_bracketed, first_in_statement, force_statement,
|
|
92
|
+
print_with, print_assert
|
|
93
|
+
)
|
|
32
94
|
from output.utils import make_block, make_num
|
|
33
95
|
from parse import PRECEDENCE
|
|
34
96
|
from utils import noop
|
|
@@ -85,7 +147,11 @@ def generate_code():
|
|
|
85
147
|
)
|
|
86
148
|
PARENS(AST_Seq, def (output):
|
|
87
149
|
p = output.parent()
|
|
88
|
-
return
|
|
150
|
+
return (
|
|
151
|
+
is_node_type(p, AST_Unary) or is_node_type(p, AST_VarDef) or
|
|
152
|
+
is_node_type(p, AST_Dot) or is_node_type(p, AST_ObjectProperty) or
|
|
153
|
+
is_node_type(p, AST_Conditional)
|
|
154
|
+
)
|
|
89
155
|
)
|
|
90
156
|
PARENS(AST_Binary, def (output):
|
|
91
157
|
p = output.parent()
|
|
@@ -104,7 +170,9 @@ def generate_code():
|
|
|
104
170
|
pp = PRECEDENCE[po]
|
|
105
171
|
so = this.operator
|
|
106
172
|
sp = PRECEDENCE[so]
|
|
107
|
-
if pp > sp or pp is sp and this is p.right and
|
|
173
|
+
if (pp > sp or pp is sp and this is p.right and
|
|
174
|
+
not (so is po and (so is '*' or so is '&&' or
|
|
175
|
+
so is '||'))):
|
|
108
176
|
return True
|
|
109
177
|
)
|
|
110
178
|
PARENS(AST_PropAccess, def (output):
|
|
@@ -132,13 +200,16 @@ def generate_code():
|
|
|
132
200
|
)
|
|
133
201
|
PARENS(AST_New, def (output):
|
|
134
202
|
p = output.parent()
|
|
135
|
-
if this.args.args.length is 0 and
|
|
203
|
+
if (this.args.args.length is 0 and
|
|
204
|
+
(is_node_type(p, AST_PropAccess) or
|
|
205
|
+
is_node_type(p, AST_BaseCall) and p.expression is this)):
|
|
136
206
|
# (new foo)(bar)
|
|
137
207
|
return True
|
|
138
208
|
)
|
|
139
209
|
PARENS(AST_Number, def (output):
|
|
140
210
|
p = output.parent()
|
|
141
|
-
if this.value < 0 and
|
|
211
|
+
if (this.value < 0 and
|
|
212
|
+
is_node_type(p, AST_PropAccess) and p.expression is this):
|
|
142
213
|
return True
|
|
143
214
|
)
|
|
144
215
|
PARENS(AST_NaN, def (output):
|
|
@@ -437,7 +508,8 @@ def generate_code():
|
|
|
437
508
|
|
|
438
509
|
DEFPRINT(AST_Symbol, def (self, output):
|
|
439
510
|
def_ = self.definition()
|
|
440
|
-
output.print_name(
|
|
511
|
+
output.print_name(
|
|
512
|
+
(def_.mangled_name or def_.name) if def_ else self.name)
|
|
441
513
|
)
|
|
442
514
|
DEFPRINT(AST_Undefined, def (self, output):
|
|
443
515
|
output.print('void 0')
|
package/src/output/comments.pyj
CHANGED
|
@@ -26,11 +26,18 @@ def print_comments(self, output):
|
|
|
26
26
|
if start and not start._comments_dumped:
|
|
27
27
|
start._comments_dumped = True
|
|
28
28
|
comments = start.comments_before
|
|
29
|
-
# XXX: ugly fix for
|
|
30
|
-
#
|
|
29
|
+
# XXX: ugly fix for
|
|
30
|
+
# https://github.com/mishoo/RapydScript2/issues/112
|
|
31
|
+
# if this node is `return` or `throw`, we cannot
|
|
32
|
+
# allow comments before
|
|
31
33
|
# the returned or thrown value.
|
|
32
|
-
if is_node_type(
|
|
33
|
-
|
|
34
|
+
if is_node_type(
|
|
35
|
+
self,
|
|
36
|
+
AST_Exit
|
|
37
|
+
) and self.value and self.value.start.comments_before and (
|
|
38
|
+
self.value.start.comments_before.length > 0):
|
|
39
|
+
comments = (comments or v'[]').concat(
|
|
40
|
+
self.value.start.comments_before)
|
|
34
41
|
self.value.start.comments_before = v'[]'
|
|
35
42
|
|
|
36
43
|
if c.test:
|
|
@@ -9,13 +9,25 @@ def print_try(self, output):
|
|
|
9
9
|
else_var_name = None
|
|
10
10
|
|
|
11
11
|
def update_output_var(output):
|
|
12
|
-
output.indent()
|
|
12
|
+
output.indent()
|
|
13
|
+
output.assign(else_var_name)
|
|
14
|
+
output.print('true'), output.end_statement()
|
|
13
15
|
if self.belse:
|
|
14
16
|
else_var_name = output.new_try_else_counter()
|
|
15
|
-
output.assign('var ' + else_var_name)
|
|
17
|
+
output.assign('var ' + else_var_name)
|
|
18
|
+
output.print('false')
|
|
19
|
+
output.end_statement()
|
|
20
|
+
output.indent()
|
|
16
21
|
output.print('try')
|
|
17
22
|
output.space()
|
|
18
|
-
print_bracketed(
|
|
23
|
+
print_bracketed(
|
|
24
|
+
self,
|
|
25
|
+
output,
|
|
26
|
+
False,
|
|
27
|
+
None,
|
|
28
|
+
None,
|
|
29
|
+
update_output_var if else_var_name else None
|
|
30
|
+
)
|
|
19
31
|
if self.bcatch:
|
|
20
32
|
output.space()
|
|
21
33
|
print_catch(self.bcatch, output)
|
|
@@ -37,7 +49,8 @@ def print_catch(self, output):
|
|
|
37
49
|
output.space()
|
|
38
50
|
output.with_block(def ():
|
|
39
51
|
output.indent()
|
|
40
|
-
output.spaced('ρσ_last_exception', '=', 'ρσ_Exception')
|
|
52
|
+
output.spaced('ρσ_last_exception', '=', 'ρσ_Exception')
|
|
53
|
+
output.end_statement()
|
|
41
54
|
output.indent()
|
|
42
55
|
no_default = True
|
|
43
56
|
for i, exception in enumerate(self.body):
|