rapydscript-ng 0.8.3 → 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 +6 -0
- package/bin/build.ts +29 -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 +2543 -2432
- package/release/signatures.json +26 -26
- package/src/ast.pyj +170 -58
- 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 +34 -13
- package/src/output/literals.pyj +7 -2
- package/src/output/loops.pyj +50 -16
- 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 +300 -55
- 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/tools/compiler.mjs +0 -6
- package/tools/fmt.mjs +41 -2
- package/tools/lint-worker.mjs +7 -1
- package/tools/lint.mjs +12 -5
- package/tools/lsp.mjs +11 -1
package/src/output/stream.pyj
CHANGED
|
@@ -5,11 +5,24 @@ from __python__ import hash_literals
|
|
|
5
5
|
from tokenizer import is_identifier_char
|
|
6
6
|
from utils import make_predicate, defaults, repeat_string
|
|
7
7
|
|
|
8
|
-
DANGEROUS =
|
|
8
|
+
DANGEROUS = RegExp(
|
|
9
|
+
'[\\u0000\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5' +
|
|
10
|
+
'\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f' +
|
|
11
|
+
'\\ufeff\\ufff0-\\uffff]', 'g'
|
|
12
|
+
)
|
|
13
|
+
|
|
9
14
|
|
|
10
15
|
# Pre-computed ASCII lookup for identifier characters used in the space-emission
|
|
11
|
-
# hot path. Avoids the full unicode-aware is_identifier_char() for the
|
|
12
|
-
|
|
16
|
+
# hot path. Avoids the full unicode-aware is_identifier_char() for the
|
|
17
|
+
# common case.
|
|
18
|
+
def _make_ident_chars():
|
|
19
|
+
t = v'new Uint8Array(128)'
|
|
20
|
+
s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'
|
|
21
|
+
for i in range(s.length):
|
|
22
|
+
t[s.charCodeAt(i)] = 1
|
|
23
|
+
return t
|
|
24
|
+
|
|
25
|
+
_IDENT_CHARS = _make_ident_chars()
|
|
13
26
|
|
|
14
27
|
|
|
15
28
|
def _is_ident_char(ch):
|
|
@@ -85,11 +98,13 @@ class OutputStream:
|
|
|
85
98
|
self.with_counter = 0
|
|
86
99
|
self.try_else_counter = 0
|
|
87
100
|
self._source_map_segments = v'[]' if self.options.source_map else None
|
|
88
|
-
# Indentation string cache: avoids repeat_string() on every
|
|
101
|
+
# Indentation string cache: avoids repeat_string() on every
|
|
102
|
+
# indent() call
|
|
89
103
|
self._indent_cache_val = -1
|
|
90
104
|
self._indent_cache_str = ''
|
|
91
|
-
# Install no-op add_mapping on the instance when source maps are
|
|
92
|
-
# avoiding a null check and array push per node in the
|
|
105
|
+
# Install no-op add_mapping on the instance when source maps are
|
|
106
|
+
# disabled, avoiding a null check and array push per node in the
|
|
107
|
+
# hot output walk.
|
|
93
108
|
if not self.options.source_map:
|
|
94
109
|
self.add_mapping = def (node): pass
|
|
95
110
|
|
|
@@ -108,7 +123,10 @@ class OutputStream:
|
|
|
108
123
|
self.print(self.make_name(name))
|
|
109
124
|
|
|
110
125
|
def make_indent(self, back):
|
|
111
|
-
target =
|
|
126
|
+
target = (
|
|
127
|
+
self.options.indent_start + self._indentation -
|
|
128
|
+
(back or 0) * self.options.indent_level
|
|
129
|
+
)
|
|
112
130
|
if target == self._indent_cache_val:
|
|
113
131
|
return self._indent_cache_str
|
|
114
132
|
s = repeat_string(' ', target)
|
|
@@ -121,7 +139,8 @@ class OutputStream:
|
|
|
121
139
|
return self._last.charAt(self._last.length - 1)
|
|
122
140
|
|
|
123
141
|
def maybe_newline(self):
|
|
124
|
-
if self.options.max_line_len and
|
|
142
|
+
if (self.options.max_line_len and
|
|
143
|
+
self.current_col > self.options.max_line_len):
|
|
125
144
|
self.print('\n')
|
|
126
145
|
|
|
127
146
|
def print(self, str_):
|
|
@@ -145,7 +164,9 @@ class OutputStream:
|
|
|
145
164
|
self.might_need_semicolon = False
|
|
146
165
|
self.maybe_newline()
|
|
147
166
|
|
|
148
|
-
if not self.options.beautify and
|
|
167
|
+
if (not self.options.beautify and
|
|
168
|
+
self.options.preserve_line and
|
|
169
|
+
self._stack[self._stack.length - 1]):
|
|
149
170
|
target_line = self._stack[self._stack.length - 1].start.line
|
|
150
171
|
while self.current_line < target_line:
|
|
151
172
|
self._fragments.push('\n')
|
|
@@ -319,14 +340,24 @@ class OutputStream:
|
|
|
319
340
|
return self._stack[self._stack.length - 2 - (n or 0)]
|
|
320
341
|
|
|
321
342
|
def add_mapping(self, node):
|
|
322
|
-
if self._source_map_segments is not None and
|
|
323
|
-
|
|
343
|
+
if (self._source_map_segments is not None and
|
|
344
|
+
node.start and node.start.file):
|
|
345
|
+
self._source_map_segments.push([
|
|
346
|
+
self.current_line - 1 +
|
|
347
|
+
self.options.source_map_line_offset,
|
|
348
|
+
self.current_col,
|
|
349
|
+
node.start.file,
|
|
350
|
+
node.start.line - 1,
|
|
351
|
+
node.start.col
|
|
352
|
+
])
|
|
324
353
|
|
|
325
354
|
def add_cached_mappings(self, segments, line_offset):
|
|
326
355
|
if self._source_map_segments is None:
|
|
327
356
|
return
|
|
328
357
|
for seg in segments:
|
|
329
|
-
self._source_map_segments.push(
|
|
358
|
+
self._source_map_segments.push(
|
|
359
|
+
v'[seg[0] + line_offset, seg[1], seg[2], seg[3], seg[4]]'
|
|
360
|
+
)
|
|
330
361
|
|
|
331
362
|
def get_source_map_segments(self):
|
|
332
363
|
return self._source_map_segments
|
package/src/output/utils.pyj
CHANGED
|
@@ -25,14 +25,18 @@ def make_num(num):
|
|
|
25
25
|
a.push('0x' + num.toString(16).toLowerCase(), # probably pointless
|
|
26
26
|
'0' + num.toString(8))
|
|
27
27
|
else:
|
|
28
|
-
|
|
28
|
+
# probably pointless
|
|
29
|
+
a.push('-0x' + (-num).toString(16).toLowerCase(),
|
|
29
30
|
'-0' + (-num).toString(8))
|
|
30
31
|
|
|
31
32
|
if m = /^(.*?)(0+)$/.exec(num):
|
|
32
33
|
a.push(m[1] + 'e' + m[2].length)
|
|
33
34
|
|
|
34
35
|
elif m = /^0?\.(0+)(.*)$/.exec(num):
|
|
35
|
-
a.push(
|
|
36
|
+
a.push(
|
|
37
|
+
m[2] + 'e-' + (m[1].length + m[2].length),
|
|
38
|
+
str_.substr(str_.indexOf('.'))
|
|
39
|
+
)
|
|
36
40
|
|
|
37
41
|
return best_of(a)
|
|
38
42
|
|
|
@@ -65,7 +69,10 @@ def create_doctring(docstrings):
|
|
|
65
69
|
lines.push(v'["", ""]')
|
|
66
70
|
else:
|
|
67
71
|
leading_whitespace = leading_whitespace.replace(/\t/g, ' ')
|
|
68
|
-
if leading_whitespace and (
|
|
72
|
+
if leading_whitespace and (
|
|
73
|
+
not min_leading_whitespace or
|
|
74
|
+
leading_whitespace.length < min_leading_whitespace.length
|
|
75
|
+
):
|
|
69
76
|
min_leading_whitespace = leading_whitespace
|
|
70
77
|
lines.push(v'[leading_whitespace, line]')
|
|
71
78
|
for lw, l in lines:
|