rapydscript-ns 0.9.1 → 0.9.3
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 +22 -1
- package/PYTHON_GAPS.md +420 -0
- package/README.md +154 -30
- package/TODO.md +22 -7
- package/language-service/index.js +241 -12
- package/language-service/language-service.d.ts +1 -1
- package/memory/project_string_impl.md +43 -0
- package/package.json +6 -2
- package/release/baselib-plain-pretty.js +248 -38
- package/release/baselib-plain-ugly.js +8 -8
- package/release/compiler.js +821 -305
- package/release/signatures.json +15 -15
- package/src/ast.pyj +4 -1
- package/src/baselib-builtins.pyj +56 -2
- package/src/baselib-containers.pyj +2 -0
- package/src/baselib-errors.pyj +7 -3
- package/src/baselib-internal.pyj +51 -6
- package/src/baselib-str.pyj +5 -3
- package/src/lib/asyncio.pyj +534 -0
- package/src/lib/base64.pyj +399 -0
- package/src/lib/bisect.pyj +73 -0
- package/src/lib/collections.pyj +1 -1
- package/src/lib/csv.pyj +494 -0
- package/src/lib/heapq.pyj +98 -0
- package/src/lib/html.pyj +382 -0
- package/src/lib/http/__init__.pyj +98 -0
- package/src/lib/http/client.pyj +304 -0
- package/src/lib/http/cookies.pyj +236 -0
- package/src/lib/logging.pyj +672 -0
- package/src/lib/pythonize.pyj +1 -1
- package/src/lib/string.pyj +357 -0
- package/src/lib/textwrap.pyj +329 -0
- package/src/lib/urllib/__init__.pyj +14 -0
- package/src/lib/urllib/error.pyj +66 -0
- package/src/lib/urllib/parse.pyj +475 -0
- package/src/lib/urllib/request.pyj +86 -0
- package/src/monaco-language-service/analyzer.js +5 -2
- package/src/monaco-language-service/completions.js +26 -0
- package/src/monaco-language-service/diagnostics.js +204 -5
- package/src/monaco-language-service/index.js +2 -2
- package/src/monaco-language-service/scope.js +1 -0
- package/src/output/functions.pyj +152 -6
- package/src/output/loops.pyj +26 -2
- package/src/output/modules.pyj +1 -1
- package/src/output/operators.pyj +15 -0
- package/src/output/stream.pyj +0 -1
- package/src/parse.pyj +80 -17
- package/src/tokenizer.pyj +1 -1
- package/test/async_generators.pyj +144 -0
- package/test/asyncio.pyj +307 -0
- package/test/base64.pyj +202 -0
- package/test/bisect.pyj +178 -0
- package/test/csv.pyj +405 -0
- package/test/float_special.pyj +64 -0
- package/test/heapq.pyj +174 -0
- package/test/html.pyj +212 -0
- package/test/http.pyj +259 -0
- package/test/imports.pyj +7 -0
- package/test/logging.pyj +356 -0
- package/test/long.pyj +130 -0
- package/test/parenthesized_with.pyj +141 -0
- package/test/python_compat.pyj +3 -5
- package/test/python_modulo.pyj +76 -0
- package/test/python_modulo_off.pyj +21 -0
- package/test/str.pyj +14 -0
- package/test/string.pyj +245 -0
- package/test/textwrap.pyj +172 -0
- package/test/type_display.pyj +48 -0
- package/test/type_enforcement.pyj +164 -0
- package/test/unit/index.js +80 -6
- package/test/unit/language-service-completions.js +119 -0
- package/test/unit/language-service-scope.js +32 -0
- package/test/unit/language-service.js +128 -4
- package/test/unit/run-language-service.js +17 -3
- package/test/unit/web-repl.js +2094 -29
- package/test/urllib.pyj +193 -0
- package/tools/compile.js +1 -1
- package/tools/compiler.d.ts +367 -0
- package/tools/embedded_compiler.js +7 -7
- package/web-repl/main.js +1 -1
- package/web-repl/rapydscript.js +3 -3
- package/test/omit_function_metadata.pyj +0 -20
package/test/urllib.pyj
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# globals: assrt
|
|
2
|
+
# vim:fileencoding=utf-8
|
|
3
|
+
#
|
|
4
|
+
# urllib.pyj
|
|
5
|
+
# Tests for the urllib standard library module.
|
|
6
|
+
#
|
|
7
|
+
# Covers urllib.parse (pure-JS, no network) and urllib.error exception classes.
|
|
8
|
+
# urllib.request requires a live network (Fetch API) so it is exercised only
|
|
9
|
+
# in the web-repl bundle tests via a mocked Promise chain.
|
|
10
|
+
|
|
11
|
+
from urllib.parse import (
|
|
12
|
+
quote, unquote, quote_plus, unquote_plus,
|
|
13
|
+
urlencode, urlsplit, urlunsplit, urlparse, urlunparse,
|
|
14
|
+
urljoin, parse_qs, parse_qsl,
|
|
15
|
+
SplitResult, ParseResult
|
|
16
|
+
)
|
|
17
|
+
from urllib.error import URLError, HTTPError
|
|
18
|
+
|
|
19
|
+
ae = assrt.equal
|
|
20
|
+
ade = assrt.deepEqual
|
|
21
|
+
ok = assrt.ok
|
|
22
|
+
|
|
23
|
+
# ── 1. quote — basic percent-encoding ────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
ae(quote('hello world'), 'hello%20world')
|
|
26
|
+
ae(quote('a/b/c'), 'a/b/c') # '/' is safe by default
|
|
27
|
+
ae(quote('a/b/c', safe=''), 'a%2Fb%2Fc')
|
|
28
|
+
ae(quote('abc123-_.~'), 'abc123-_.~') # unreserved chars pass through
|
|
29
|
+
ae(quote('a+b'), 'a%2Bb')
|
|
30
|
+
ae(quote('a=1&b=2', safe=''), 'a%3D1%26b%3D2')
|
|
31
|
+
ae(quote('!*\'()'), '%21%2A%27%28%29') # sub-delimiters encoded
|
|
32
|
+
|
|
33
|
+
# ── 2. unquote ────────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
ae(unquote('hello%20world'), 'hello world')
|
|
36
|
+
ae(unquote('a%2Fb'), 'a/b')
|
|
37
|
+
ae(unquote('abc'), 'abc')
|
|
38
|
+
ae(unquote('a%2Bb'), 'a+b') # '+' is not decoded by unquote
|
|
39
|
+
|
|
40
|
+
# ── 3. quote_plus / unquote_plus ─────────────────────────────────────────────
|
|
41
|
+
|
|
42
|
+
ae(quote_plus('hello world'), 'hello+world')
|
|
43
|
+
ae(quote_plus('a+b'), 'a%2Bb')
|
|
44
|
+
ae(quote_plus('a/b', safe=''), 'a%2Fb')
|
|
45
|
+
ae(unquote_plus('hello+world'), 'hello world')
|
|
46
|
+
ae(unquote_plus('a%2Bb'), 'a+b')
|
|
47
|
+
ae(unquote_plus('hello%20world'), 'hello world')
|
|
48
|
+
|
|
49
|
+
# ── 4. urlencode — list of pairs ─────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
ae(urlencode([['a', '1'], ['b', '2']]), 'a=1&b=2')
|
|
52
|
+
ae(urlencode([['q', 'hello world']]), 'q=hello%20world')
|
|
53
|
+
ae(urlencode([['k', 'a+b']]), 'k=a%2Bb')
|
|
54
|
+
ae(urlencode([]), '')
|
|
55
|
+
|
|
56
|
+
# ── 5. urlencode — doseq ─────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
ae(urlencode([['a', ['x', 'y']]], doseq=True), 'a=x&a=y')
|
|
59
|
+
ae(urlencode([['a', ['x', 'y']], ['b', '1']], doseq=True), 'a=x&a=y&b=1')
|
|
60
|
+
|
|
61
|
+
# ── 6. urlsplit — absolute URL ────────────────────────────────────────────────
|
|
62
|
+
|
|
63
|
+
r = urlsplit('http://example.com/path?q=1#frag')
|
|
64
|
+
ae(r.scheme, 'http')
|
|
65
|
+
ae(r.netloc, 'example.com')
|
|
66
|
+
ae(r.path, '/path')
|
|
67
|
+
ae(r.query, 'q=1')
|
|
68
|
+
ae(r.fragment, 'frag')
|
|
69
|
+
ae(r.hostname, 'example.com')
|
|
70
|
+
ae(r.port, None)
|
|
71
|
+
ae(r.username, None)
|
|
72
|
+
ae(r.password, None)
|
|
73
|
+
|
|
74
|
+
# ── 7. urlsplit — authority with user:pass@host:port ─────────────────────────
|
|
75
|
+
|
|
76
|
+
r2 = urlsplit('https://user:pw@host:8080/p?x=1')
|
|
77
|
+
ae(r2.scheme, 'https')
|
|
78
|
+
ae(r2.netloc, 'user:pw@host:8080')
|
|
79
|
+
ae(r2.path, '/p')
|
|
80
|
+
ae(r2.query, 'x=1')
|
|
81
|
+
ae(r2.hostname, 'host')
|
|
82
|
+
ae(r2.port, 8080)
|
|
83
|
+
ae(r2.username, 'user')
|
|
84
|
+
ae(r2.password, 'pw')
|
|
85
|
+
|
|
86
|
+
# ── 8. urlsplit — no fragment ─────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
r3 = urlsplit('http://example.com/path?q=1', allow_fragments=False)
|
|
89
|
+
ae(r3.fragment, '')
|
|
90
|
+
ae(r3.query, 'q=1')
|
|
91
|
+
|
|
92
|
+
# ── 9. urlsplit — relative URL ────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
r4 = urlsplit('/path?q=1#frag')
|
|
95
|
+
ae(r4.scheme, '')
|
|
96
|
+
ae(r4.netloc, '')
|
|
97
|
+
ae(r4.path, '/path')
|
|
98
|
+
ae(r4.query, 'q=1')
|
|
99
|
+
ae(r4.fragment, 'frag')
|
|
100
|
+
|
|
101
|
+
# ── 10. urlparse — params split from path ─────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
r5 = urlparse('http://example.com/path;params?q=1#frag')
|
|
104
|
+
ae(r5.scheme, 'http')
|
|
105
|
+
ae(r5.path, '/path')
|
|
106
|
+
ae(r5.params, 'params')
|
|
107
|
+
ae(r5.query, 'q=1')
|
|
108
|
+
ae(r5.fragment, 'frag')
|
|
109
|
+
|
|
110
|
+
r6 = urlparse('http://example.com/path?q=1')
|
|
111
|
+
ae(r6.params, '')
|
|
112
|
+
|
|
113
|
+
# ── 11. urlunsplit / urlunparse ───────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
ae(urlunsplit(('http', 'example.com', '/path', 'q=1', 'frag')),
|
|
116
|
+
'http://example.com/path?q=1#frag')
|
|
117
|
+
ae(urlunsplit(('http', 'example.com', '/path', '', '')),
|
|
118
|
+
'http://example.com/path')
|
|
119
|
+
ae(urlunsplit(('', '', '/path', 'q=1', '')),
|
|
120
|
+
'/path?q=1')
|
|
121
|
+
ae(urlunparse(('http', 'example.com', '/path', 'par', 'q=1', 'frag')),
|
|
122
|
+
'http://example.com/path;par?q=1#frag')
|
|
123
|
+
ae(urlunparse(('http', 'example.com', '/path', '', 'q=1', '')),
|
|
124
|
+
'http://example.com/path?q=1')
|
|
125
|
+
|
|
126
|
+
# ── 12. geturl round-trip ─────────────────────────────────────────────────────
|
|
127
|
+
|
|
128
|
+
r7 = urlsplit('http://example.com/path?q=1#frag')
|
|
129
|
+
ae(r7.geturl(), 'http://example.com/path?q=1#frag')
|
|
130
|
+
|
|
131
|
+
r8 = urlparse('http://example.com/path?q=1#frag')
|
|
132
|
+
ae(r8.geturl(), 'http://example.com/path?q=1#frag')
|
|
133
|
+
|
|
134
|
+
# ── 13. urljoin ───────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
ae(urljoin('http://example.com/foo', 'bar'), 'http://example.com/bar')
|
|
137
|
+
ae(urljoin('http://example.com/foo/', 'bar'), 'http://example.com/foo/bar')
|
|
138
|
+
ae(urljoin('http://example.com/', '/other'), 'http://example.com/other')
|
|
139
|
+
ae(urljoin('http://example.com/foo', 'http://other.com/'), 'http://other.com/')
|
|
140
|
+
ae(urljoin('http://example.com/foo', '?q=1'), 'http://example.com/foo?q=1')
|
|
141
|
+
|
|
142
|
+
# ── 14. parse_qsl ─────────────────────────────────────────────────────────────
|
|
143
|
+
|
|
144
|
+
pairs = parse_qsl('a=1&b=2&a=3')
|
|
145
|
+
ade(pairs[0], ['a', '1'])
|
|
146
|
+
ade(pairs[1], ['b', '2'])
|
|
147
|
+
ade(pairs[2], ['a', '3'])
|
|
148
|
+
ae(len(pairs), 3)
|
|
149
|
+
|
|
150
|
+
pairs2 = parse_qsl('a=hello+world')
|
|
151
|
+
ae(len(pairs2), 1)
|
|
152
|
+
ae(pairs2[0][1], 'hello world')
|
|
153
|
+
|
|
154
|
+
pairs3 = parse_qsl('q=a%20b')
|
|
155
|
+
ae(pairs3[0][1], 'a b')
|
|
156
|
+
|
|
157
|
+
ae(len(parse_qsl('')), 0)
|
|
158
|
+
|
|
159
|
+
# ── 15. parse_qs ─────────────────────────────────────────────────────────────
|
|
160
|
+
|
|
161
|
+
d = parse_qs('a=1&b=2&a=3')
|
|
162
|
+
ade(d['a'], ['1', '3'])
|
|
163
|
+
ade(d['b'], ['2'])
|
|
164
|
+
|
|
165
|
+
d2 = parse_qs('q=hello+world')
|
|
166
|
+
ae(d2['q'][0], 'hello world')
|
|
167
|
+
|
|
168
|
+
ae(len(parse_qs('')), 0)
|
|
169
|
+
|
|
170
|
+
# ── 16. URLError / HTTPError ──────────────────────────────────────────────────
|
|
171
|
+
|
|
172
|
+
try:
|
|
173
|
+
raise URLError('network error')
|
|
174
|
+
ok(False)
|
|
175
|
+
except URLError as e:
|
|
176
|
+
ok('network error' in str(e.reason))
|
|
177
|
+
|
|
178
|
+
try:
|
|
179
|
+
raise HTTPError('http://example.com', 404, 'Not Found', {}, None)
|
|
180
|
+
ok(False)
|
|
181
|
+
except HTTPError as e:
|
|
182
|
+
ae(e.code, 404)
|
|
183
|
+
ae(e.msg, 'Not Found')
|
|
184
|
+
ae(e.getcode(), 404)
|
|
185
|
+
ae(e.geturl(), 'http://example.com')
|
|
186
|
+
ok(isinstance(e, URLError))
|
|
187
|
+
|
|
188
|
+
try:
|
|
189
|
+
raise HTTPError('http://example.com', 500, 'Internal Server Error', {}, None)
|
|
190
|
+
ok(False)
|
|
191
|
+
except URLError as e:
|
|
192
|
+
# HTTPError is caught by URLError handler (inheritance)
|
|
193
|
+
ae(e.code, 500)
|
package/tools/compile.js
CHANGED
|
@@ -76,7 +76,7 @@ module.exports = function(start_time, argv, base_path, src_path, lib_path) {
|
|
|
76
76
|
|
|
77
77
|
var global_scoped_flags = build_scoped_flags(argv.python_flags);
|
|
78
78
|
if (!argv.legacy_rapydscript) {
|
|
79
|
-
var python_mode_flags = ['dict_literals', 'overload_getitem', 'bound_methods', 'hash_literals', 'overload_operators', 'truthiness', 'jsx'];
|
|
79
|
+
var python_mode_flags = ['dict_literals', 'overload_getitem', 'bound_methods', 'hash_literals', 'overload_operators', 'truthiness', 'jsx', 'type_enforcement'];
|
|
80
80
|
python_mode_flags.forEach(function(f) { if (!(f in global_scoped_flags)) global_scoped_flags[f] = true; });
|
|
81
81
|
if (!argv.pythonize_strings) OUTPUT_OPTIONS.pythonize_strings = true;
|
|
82
82
|
}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// compiler.d.ts — Type declarations for the RapydScript-N compiler
|
|
2
|
+
|
|
3
|
+
// -- Token & Position ---------------------------------------------------
|
|
4
|
+
|
|
5
|
+
export interface AST_Position {
|
|
6
|
+
line: number;
|
|
7
|
+
col: number;
|
|
8
|
+
pos: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AST_Token {
|
|
12
|
+
type: string;
|
|
13
|
+
value: string;
|
|
14
|
+
line: number;
|
|
15
|
+
col: number;
|
|
16
|
+
pos: number;
|
|
17
|
+
nlb: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// -- AST Nodes ----------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
export interface AST_Node {
|
|
23
|
+
start: AST_Token;
|
|
24
|
+
end: AST_Token;
|
|
25
|
+
print(output: OutputStream): void;
|
|
26
|
+
walk(visitor: TreeWalker): boolean | undefined;
|
|
27
|
+
_walk(visitor: TreeWalker): boolean | undefined;
|
|
28
|
+
clone(): this;
|
|
29
|
+
_dump(depth?: number, omit?: string[], offset?: number, include_name?: boolean): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface TreeWalker {
|
|
33
|
+
_visit(node: AST_Node): boolean | undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AST_Toplevel extends AST_Node {
|
|
37
|
+
body: AST_Node[];
|
|
38
|
+
globals: Record<string, unknown>;
|
|
39
|
+
baselib: Record<string, boolean>;
|
|
40
|
+
imports: Record<string, AST_ImportedModule>;
|
|
41
|
+
imported_module_ids: string[];
|
|
42
|
+
nonlocalvars: string[];
|
|
43
|
+
localvars: string[];
|
|
44
|
+
shebang: string | null;
|
|
45
|
+
import_order: number;
|
|
46
|
+
module_id: string;
|
|
47
|
+
exports: unknown[];
|
|
48
|
+
classes: Record<string, unknown>;
|
|
49
|
+
scoped_flags: Record<string, boolean>;
|
|
50
|
+
filename: string;
|
|
51
|
+
srchash: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface AST_ImportedModule {
|
|
55
|
+
filename: string;
|
|
56
|
+
body: AST_Node[] | null;
|
|
57
|
+
src_code: string | null;
|
|
58
|
+
localvars: string[];
|
|
59
|
+
nonlocalvars: string[];
|
|
60
|
+
needed_names: Set<string> | null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// -- Errors -------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
export interface RapydScriptSyntaxError extends Error {
|
|
66
|
+
message: string;
|
|
67
|
+
filename: string;
|
|
68
|
+
line: number;
|
|
69
|
+
col: number;
|
|
70
|
+
pos: number;
|
|
71
|
+
is_eof: boolean;
|
|
72
|
+
toString(): string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface RapydScriptSyntaxErrorConstructor {
|
|
76
|
+
new (message: string, filename: string, line: number, col: number, pos: number, is_eof?: boolean): RapydScriptSyntaxError;
|
|
77
|
+
(message: string, filename: string, line: number, col: number, pos: number, is_eof?: boolean): RapydScriptSyntaxError;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type ImportError = RapydScriptSyntaxError;
|
|
81
|
+
export interface ImportErrorConstructor extends RapydScriptSyntaxErrorConstructor {}
|
|
82
|
+
|
|
83
|
+
export interface DefaultsError extends Error {
|
|
84
|
+
message: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface DefaultsErrorConstructor {
|
|
88
|
+
new (name: string, defs: Record<string, unknown>): DefaultsError;
|
|
89
|
+
(name: string, defs: Record<string, unknown>): DefaultsError;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// -- Parse Options ------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
export interface ParseOptions {
|
|
95
|
+
filename?: string | null;
|
|
96
|
+
module_id?: string;
|
|
97
|
+
toplevel?: AST_Toplevel | null;
|
|
98
|
+
for_linting?: boolean;
|
|
99
|
+
import_dirs?: string[];
|
|
100
|
+
classes?: Record<string, unknown>;
|
|
101
|
+
scoped_flags?: ScopedFlags;
|
|
102
|
+
discard_asserts?: boolean;
|
|
103
|
+
module_cache_dir?: string;
|
|
104
|
+
basedir?: string;
|
|
105
|
+
libdir?: string;
|
|
106
|
+
imported_modules?: Record<string, unknown>;
|
|
107
|
+
importing_modules?: Record<string, unknown>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface ScopedFlags {
|
|
111
|
+
dict_literals?: boolean;
|
|
112
|
+
overload_getitem?: boolean;
|
|
113
|
+
bound_methods?: boolean;
|
|
114
|
+
hash_literals?: boolean;
|
|
115
|
+
overload_operators?: boolean;
|
|
116
|
+
truthiness?: boolean;
|
|
117
|
+
jsx?: boolean;
|
|
118
|
+
strict_arithmetic?: boolean;
|
|
119
|
+
[flag: string]: boolean | undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// -- Output Stream Options ----------------------------------------------
|
|
123
|
+
|
|
124
|
+
export interface OutputStreamOptions {
|
|
125
|
+
indent_start?: number;
|
|
126
|
+
indent_level?: number;
|
|
127
|
+
quote_keys?: boolean;
|
|
128
|
+
space_colon?: boolean;
|
|
129
|
+
ascii_only?: boolean;
|
|
130
|
+
width?: number;
|
|
131
|
+
max_line_len?: number;
|
|
132
|
+
ie_proof?: boolean;
|
|
133
|
+
beautify?: boolean;
|
|
134
|
+
source_map?: unknown | null;
|
|
135
|
+
bracketize?: boolean;
|
|
136
|
+
semicolons?: boolean;
|
|
137
|
+
comments?: boolean | ((node: AST_Node) => boolean);
|
|
138
|
+
preserve_line?: boolean;
|
|
139
|
+
omit_baselib?: boolean;
|
|
140
|
+
baselib_plain?: string | null;
|
|
141
|
+
private_scope?: boolean;
|
|
142
|
+
keep_docstrings?: boolean;
|
|
143
|
+
discard_asserts?: boolean;
|
|
144
|
+
module_cache_dir?: string;
|
|
145
|
+
js_version?: number;
|
|
146
|
+
write_name?: boolean;
|
|
147
|
+
omit_function_metadata?: boolean;
|
|
148
|
+
pythonize_strings?: boolean;
|
|
149
|
+
repl_mode?: boolean;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface OutputStream {
|
|
153
|
+
options: Required<OutputStreamOptions>;
|
|
154
|
+
current_col: number;
|
|
155
|
+
current_line: number;
|
|
156
|
+
current_pos: number;
|
|
157
|
+
|
|
158
|
+
print(str: string): void;
|
|
159
|
+
get(): string;
|
|
160
|
+
toString(): string;
|
|
161
|
+
space(): void;
|
|
162
|
+
indent(half?: boolean): void;
|
|
163
|
+
with_indent(col: number, proceed: () => void): void;
|
|
164
|
+
indentation(): string;
|
|
165
|
+
set_indentation(val: number): void;
|
|
166
|
+
newline(): void;
|
|
167
|
+
semicolon(): void;
|
|
168
|
+
force_semicolon(): void;
|
|
169
|
+
next_indent(): number;
|
|
170
|
+
end_statement(): void;
|
|
171
|
+
with_block(cont: () => void): void;
|
|
172
|
+
with_parens(cont: () => void): void;
|
|
173
|
+
with_square(cont: () => void): void;
|
|
174
|
+
comma(): void;
|
|
175
|
+
colon(): void;
|
|
176
|
+
assign(name: string | AST_Node): void;
|
|
177
|
+
current_width(): number;
|
|
178
|
+
should_break(): boolean;
|
|
179
|
+
last(): string;
|
|
180
|
+
print_string(str: string): void;
|
|
181
|
+
print_name(name: string): void;
|
|
182
|
+
make_name(name: string): string;
|
|
183
|
+
make_indent(back?: number): string;
|
|
184
|
+
last_char(): string;
|
|
185
|
+
push_node(node: AST_Node): void;
|
|
186
|
+
pop_node(): AST_Node;
|
|
187
|
+
stack(): AST_Node[];
|
|
188
|
+
parent(n?: number): AST_Node | undefined;
|
|
189
|
+
line(): number;
|
|
190
|
+
col(): number;
|
|
191
|
+
pos(): number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface OutputStreamConstructor {
|
|
195
|
+
new (options?: OutputStreamOptions): OutputStream;
|
|
196
|
+
(options?: OutputStreamOptions): OutputStream;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// -- Tree Shake Context -------------------------------------------------
|
|
200
|
+
|
|
201
|
+
export interface TreeShakeContext {
|
|
202
|
+
parse: CompilerExports["parse"];
|
|
203
|
+
import_dirs?: string[];
|
|
204
|
+
basedir?: string;
|
|
205
|
+
libdir?: string;
|
|
206
|
+
discard_asserts?: boolean;
|
|
207
|
+
module_cache_dir?: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// -- Tokenizer ----------------------------------------------------------
|
|
211
|
+
|
|
212
|
+
export interface Tokenizer {
|
|
213
|
+
next(): AST_Token;
|
|
214
|
+
peek(): AST_Token;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// -- Compiler Exports (from create_compiler) ----------------------------
|
|
218
|
+
|
|
219
|
+
export interface CompilerExports {
|
|
220
|
+
parse(code: string, options?: ParseOptions): AST_Toplevel;
|
|
221
|
+
OutputStream: OutputStreamConstructor;
|
|
222
|
+
tree_shake(ast: AST_Toplevel, context: TreeShakeContext): void;
|
|
223
|
+
tokenizer(code: string, filename?: string): Tokenizer;
|
|
224
|
+
string_template(template: string, vars: Record<string, unknown>): string;
|
|
225
|
+
|
|
226
|
+
DefaultsError: DefaultsErrorConstructor;
|
|
227
|
+
SyntaxError: RapydScriptSyntaxErrorConstructor;
|
|
228
|
+
ImportError: ImportErrorConstructor;
|
|
229
|
+
|
|
230
|
+
ALL_KEYWORDS: string[];
|
|
231
|
+
IDENTIFIER_PAT: RegExp;
|
|
232
|
+
NATIVE_CLASSES: Record<string, Record<string, unknown>>;
|
|
233
|
+
compile_time_decorators: Record<string, unknown>;
|
|
234
|
+
|
|
235
|
+
// All AST node constructors are exported as AST_* properties
|
|
236
|
+
AST_Node: new (...args: unknown[]) => AST_Node;
|
|
237
|
+
AST_Token: new (...args: unknown[]) => AST_Token;
|
|
238
|
+
AST_Toplevel: new (...args: unknown[]) => AST_Toplevel;
|
|
239
|
+
AST_Statement: new (...args: unknown[]) => AST_Node;
|
|
240
|
+
AST_Debugger: new (...args: unknown[]) => AST_Node;
|
|
241
|
+
AST_Directive: new (...args: unknown[]) => AST_Node;
|
|
242
|
+
AST_SimpleStatement: new (...args: unknown[]) => AST_Node;
|
|
243
|
+
AST_AnnotatedAssign: new (...args: unknown[]) => AST_Node;
|
|
244
|
+
AST_Assert: new (...args: unknown[]) => AST_Node;
|
|
245
|
+
AST_Block: new (...args: unknown[]) => AST_Node;
|
|
246
|
+
AST_BlockStatement: new (...args: unknown[]) => AST_Node;
|
|
247
|
+
AST_EmptyStatement: new (...args: unknown[]) => AST_Node;
|
|
248
|
+
AST_StatementWithBody: new (...args: unknown[]) => AST_Node;
|
|
249
|
+
AST_DWLoop: new (...args: unknown[]) => AST_Node;
|
|
250
|
+
AST_Do: new (...args: unknown[]) => AST_Node;
|
|
251
|
+
AST_While: new (...args: unknown[]) => AST_Node;
|
|
252
|
+
AST_ForIn: new (...args: unknown[]) => AST_Node;
|
|
253
|
+
AST_ForJS: new (...args: unknown[]) => AST_Node;
|
|
254
|
+
AST_ListComprehension: new (...args: unknown[]) => AST_Node;
|
|
255
|
+
AST_SetComprehension: new (...args: unknown[]) => AST_Node;
|
|
256
|
+
AST_DictComprehension: new (...args: unknown[]) => AST_Node;
|
|
257
|
+
AST_GeneratorComprehension: new (...args: unknown[]) => AST_Node;
|
|
258
|
+
AST_With: new (...args: unknown[]) => AST_Node;
|
|
259
|
+
AST_WithClause: new (...args: unknown[]) => AST_Node;
|
|
260
|
+
AST_Match: new (...args: unknown[]) => AST_Node;
|
|
261
|
+
AST_MatchPattern: new (...args: unknown[]) => AST_Node;
|
|
262
|
+
AST_MatchWildcard: new (...args: unknown[]) => AST_Node;
|
|
263
|
+
AST_MatchCapture: new (...args: unknown[]) => AST_Node;
|
|
264
|
+
AST_MatchLiteral: new (...args: unknown[]) => AST_Node;
|
|
265
|
+
AST_MatchOr: new (...args: unknown[]) => AST_Node;
|
|
266
|
+
AST_MatchAs: new (...args: unknown[]) => AST_Node;
|
|
267
|
+
AST_MatchStar: new (...args: unknown[]) => AST_Node;
|
|
268
|
+
AST_MatchSequence: new (...args: unknown[]) => AST_Node;
|
|
269
|
+
AST_MatchMapping: new (...args: unknown[]) => AST_Node;
|
|
270
|
+
AST_MatchClass: new (...args: unknown[]) => AST_Node;
|
|
271
|
+
AST_MatchCase: new (...args: unknown[]) => AST_Node;
|
|
272
|
+
AST_Scope: new (...args: unknown[]) => AST_Node;
|
|
273
|
+
AST_Import: new (...args: unknown[]) => AST_Node;
|
|
274
|
+
AST_Imports: new (...args: unknown[]) => AST_Node;
|
|
275
|
+
AST_Decorator: new (...args: unknown[]) => AST_Node;
|
|
276
|
+
AST_Lambda: new (...args: unknown[]) => AST_Node;
|
|
277
|
+
AST_Function: new (...args: unknown[]) => AST_Node;
|
|
278
|
+
AST_Class: new (...args: unknown[]) => AST_Node;
|
|
279
|
+
AST_Method: new (...args: unknown[]) => AST_Node;
|
|
280
|
+
AST_Jump: new (...args: unknown[]) => AST_Node;
|
|
281
|
+
AST_Exit: new (...args: unknown[]) => AST_Node;
|
|
282
|
+
AST_Return: new (...args: unknown[]) => AST_Node;
|
|
283
|
+
AST_Yield: new (...args: unknown[]) => AST_Node;
|
|
284
|
+
AST_Await: new (...args: unknown[]) => AST_Node;
|
|
285
|
+
AST_Throw: new (...args: unknown[]) => AST_Node;
|
|
286
|
+
AST_LoopControl: new (...args: unknown[]) => AST_Node;
|
|
287
|
+
AST_Break: new (...args: unknown[]) => AST_Node;
|
|
288
|
+
AST_Continue: new (...args: unknown[]) => AST_Node;
|
|
289
|
+
AST_If: new (...args: unknown[]) => AST_Node;
|
|
290
|
+
AST_Try: new (...args: unknown[]) => AST_Node;
|
|
291
|
+
AST_Catch: new (...args: unknown[]) => AST_Node;
|
|
292
|
+
AST_Except: new (...args: unknown[]) => AST_Node;
|
|
293
|
+
AST_Finally: new (...args: unknown[]) => AST_Node;
|
|
294
|
+
AST_Else: new (...args: unknown[]) => AST_Node;
|
|
295
|
+
AST_Definitions: new (...args: unknown[]) => AST_Node;
|
|
296
|
+
AST_Var: new (...args: unknown[]) => AST_Node;
|
|
297
|
+
AST_VarDef: new (...args: unknown[]) => AST_Node;
|
|
298
|
+
AST_BaseCall: new (...args: unknown[]) => AST_Node;
|
|
299
|
+
AST_Call: new (...args: unknown[]) => AST_Node;
|
|
300
|
+
AST_ClassCall: new (...args: unknown[]) => AST_Node;
|
|
301
|
+
AST_Super: new (...args: unknown[]) => AST_Node;
|
|
302
|
+
AST_New: new (...args: unknown[]) => AST_Node;
|
|
303
|
+
AST_Seq: new (...args: unknown[]) => AST_Node;
|
|
304
|
+
AST_PropAccess: new (...args: unknown[]) => AST_Node;
|
|
305
|
+
AST_Dot: new (...args: unknown[]) => AST_Node;
|
|
306
|
+
AST_Sub: new (...args: unknown[]) => AST_Node;
|
|
307
|
+
AST_ItemAccess: new (...args: unknown[]) => AST_Node;
|
|
308
|
+
AST_Splice: new (...args: unknown[]) => AST_Node;
|
|
309
|
+
AST_Unary: new (...args: unknown[]) => AST_Node;
|
|
310
|
+
AST_UnaryPrefix: new (...args: unknown[]) => AST_Node;
|
|
311
|
+
AST_Binary: new (...args: unknown[]) => AST_Node;
|
|
312
|
+
AST_Existential: new (...args: unknown[]) => AST_Node;
|
|
313
|
+
AST_Conditional: new (...args: unknown[]) => AST_Node;
|
|
314
|
+
AST_Assign: new (...args: unknown[]) => AST_Node;
|
|
315
|
+
AST_NamedExpr: new (...args: unknown[]) => AST_Node;
|
|
316
|
+
AST_Starred: new (...args: unknown[]) => AST_Node;
|
|
317
|
+
AST_Array: new (...args: unknown[]) => AST_Node;
|
|
318
|
+
AST_Object: new (...args: unknown[]) => AST_Node;
|
|
319
|
+
AST_ExpressiveObject: new (...args: unknown[]) => AST_Node;
|
|
320
|
+
AST_ObjectProperty: new (...args: unknown[]) => AST_Node;
|
|
321
|
+
AST_ObjectKeyVal: new (...args: unknown[]) => AST_Node;
|
|
322
|
+
AST_ObjectSpread: new (...args: unknown[]) => AST_Node;
|
|
323
|
+
AST_Spread: new (...args: unknown[]) => AST_Node;
|
|
324
|
+
AST_Set: new (...args: unknown[]) => AST_Node;
|
|
325
|
+
AST_SetItem: new (...args: unknown[]) => AST_Node;
|
|
326
|
+
AST_Symbol: new (...args: unknown[]) => AST_Node;
|
|
327
|
+
AST_SymbolAlias: new (...args: unknown[]) => AST_Node;
|
|
328
|
+
AST_SymbolDeclaration: new (...args: unknown[]) => AST_Node;
|
|
329
|
+
AST_SymbolVar: new (...args: unknown[]) => AST_Node;
|
|
330
|
+
AST_ImportedVar: new (...args: unknown[]) => AST_Node;
|
|
331
|
+
AST_SymbolNonlocal: new (...args: unknown[]) => AST_Node;
|
|
332
|
+
AST_SymbolFunarg: new (...args: unknown[]) => AST_Node;
|
|
333
|
+
AST_SymbolDefun: new (...args: unknown[]) => AST_Node;
|
|
334
|
+
AST_SymbolLambda: new (...args: unknown[]) => AST_Node;
|
|
335
|
+
AST_SymbolCatch: new (...args: unknown[]) => AST_Node;
|
|
336
|
+
AST_SymbolRef: new (...args: unknown[]) => AST_Node;
|
|
337
|
+
AST_This: new (...args: unknown[]) => AST_Node;
|
|
338
|
+
AST_Constant: new (...args: unknown[]) => AST_Node;
|
|
339
|
+
AST_String: new (...args: unknown[]) => AST_Node;
|
|
340
|
+
AST_Verbatim: new (...args: unknown[]) => AST_Node;
|
|
341
|
+
AST_Number: new (...args: unknown[]) => AST_Node;
|
|
342
|
+
AST_RegExp: new (...args: unknown[]) => AST_Node;
|
|
343
|
+
AST_Atom: new (...args: unknown[]) => AST_Node;
|
|
344
|
+
AST_Null: new (...args: unknown[]) => AST_Node;
|
|
345
|
+
AST_Ellipsis: new (...args: unknown[]) => AST_Node;
|
|
346
|
+
AST_NaN: new (...args: unknown[]) => AST_Node;
|
|
347
|
+
AST_Undefined: new (...args: unknown[]) => AST_Node;
|
|
348
|
+
AST_Hole: new (...args: unknown[]) => AST_Node;
|
|
349
|
+
AST_Infinity: new (...args: unknown[]) => AST_Node;
|
|
350
|
+
AST_Boolean: new (...args: unknown[]) => AST_Node;
|
|
351
|
+
AST_False: new (...args: unknown[]) => AST_Node;
|
|
352
|
+
AST_True: new (...args: unknown[]) => AST_Node;
|
|
353
|
+
AST_JSXElement: new (...args: unknown[]) => AST_Node;
|
|
354
|
+
AST_JSXFragment: new (...args: unknown[]) => AST_Node;
|
|
355
|
+
AST_JSXAttribute: new (...args: unknown[]) => AST_Node;
|
|
356
|
+
AST_JSXSpread: new (...args: unknown[]) => AST_Node;
|
|
357
|
+
AST_JSXText: new (...args: unknown[]) => AST_Node;
|
|
358
|
+
AST_JSXExprContainer: new (...args: unknown[]) => AST_Node;
|
|
359
|
+
|
|
360
|
+
[key: `AST_${string}`]: new (...args: unknown[]) => AST_Node;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// -- Module Exports -----------------------------------------------------
|
|
364
|
+
|
|
365
|
+
export declare function create_compiler(): CompilerExports;
|
|
366
|
+
export declare function set_virtual_files(vf: Record<string, string>): void;
|
|
367
|
+
export declare function clear_virtual_files(): void;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"use strict"; /*jshint node:true */
|
|
8
8
|
|
|
9
9
|
var has_prop = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
|
|
10
|
-
var PYTHON_MODE_FLAGS = ['dict_literals', 'overload_getitem', 'bound_methods', 'hash_literals', 'overload_operators', 'truthiness', 'jsx'];
|
|
10
|
+
var PYTHON_MODE_FLAGS = ['dict_literals', 'overload_getitem', 'bound_methods', 'hash_literals', 'overload_operators', 'truthiness', 'jsx', 'type_enforcement'];
|
|
11
11
|
|
|
12
12
|
function build_scoped_flags(flags_str) {
|
|
13
13
|
var result = Object.create(null);
|
|
@@ -28,8 +28,8 @@ module.exports = function(compiler, baselib, runjs, name, vf_context) {
|
|
|
28
28
|
runjs(print_ast(compiler.parse(''), true));
|
|
29
29
|
runjs('var __name__ = "' + (name || '__embedded__') + '";');
|
|
30
30
|
|
|
31
|
-
function print_ast(ast, keep_baselib, keep_docstrings, js_version, private_scope, write_name,
|
|
32
|
-
var output_options = {omit_baselib:!keep_baselib, write_name:!!write_name, private_scope:!!private_scope, beautify:true, js_version: (js_version || 6), keep_docstrings:keep_docstrings,
|
|
31
|
+
function print_ast(ast, keep_baselib, keep_docstrings, js_version, private_scope, write_name, pythonize_strings) {
|
|
32
|
+
var output_options = {omit_baselib:!keep_baselib, write_name:!!write_name, private_scope:!!private_scope, beautify:true, js_version: (js_version || 6), keep_docstrings:keep_docstrings, pythonize_strings:!!pythonize_strings};
|
|
33
33
|
if (keep_baselib) output_options.baselib_plain = baselib;
|
|
34
34
|
var output = new compiler.OutputStream(output_options);
|
|
35
35
|
ast.print(output);
|
|
@@ -105,8 +105,8 @@ module.exports = function(compiler, baselib, runjs, name, vf_context) {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
function print_ast_with_sourcemap(ast, keep_baselib, keep_docstrings, js_version, private_scope, write_name,
|
|
109
|
-
var output_options = {omit_baselib:!keep_baselib, write_name:!!write_name, private_scope:!!private_scope, beautify:true, js_version:(js_version||6), keep_docstrings:keep_docstrings,
|
|
108
|
+
function print_ast_with_sourcemap(ast, keep_baselib, keep_docstrings, js_version, private_scope, write_name, pythonize_strings, source_name, source_content) {
|
|
109
|
+
var output_options = {omit_baselib:!keep_baselib, write_name:!!write_name, private_scope:!!private_scope, beautify:true, js_version:(js_version||6), keep_docstrings:keep_docstrings, pythonize_strings:!!pythonize_strings};
|
|
110
110
|
if (keep_baselib) output_options.baselib_plain = baselib;
|
|
111
111
|
var raw_mappings = [];
|
|
112
112
|
var output = new compiler.OutputStream(output_options);
|
|
@@ -171,7 +171,7 @@ module.exports = function(compiler, baselib, runjs, name, vf_context) {
|
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
var pythonize_strings = (opts.legacy_rapydscript !== true) ? true : !!opts.pythonize_strings;
|
|
174
|
-
var ans = print_ast(this.toplevel, opts.keep_baselib, opts.keep_docstrings, opts.js_version, opts.private_scope, opts.write_name,
|
|
174
|
+
var ans = print_ast(this.toplevel, opts.keep_baselib, opts.keep_docstrings, opts.js_version, opts.private_scope, opts.write_name, pythonize_strings);
|
|
175
175
|
if (opts.export_main) {
|
|
176
176
|
ans = ans.replace(/^(function\smain)/gm, 'export $1')
|
|
177
177
|
.replace(/^(async\sfunction\smain)/gm, 'export $1');
|
|
@@ -233,7 +233,7 @@ module.exports = function(compiler, baselib, runjs, name, vf_context) {
|
|
|
233
233
|
var result = print_ast_with_sourcemap(
|
|
234
234
|
this.toplevel,
|
|
235
235
|
opts.keep_baselib, opts.keep_docstrings, opts.js_version,
|
|
236
|
-
opts.private_scope, opts.write_name,
|
|
236
|
+
opts.private_scope, opts.write_name,
|
|
237
237
|
pythonize_strings_sm,
|
|
238
238
|
opts.filename || '<input>',
|
|
239
239
|
code
|
package/web-repl/main.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
function compile(code) {
|
|
21
|
-
return web_repl.compile(code, {
|
|
21
|
+
return web_repl.compile(code, {tree_shake: false, export_main: true, virtual_files: VIRTUAL_FILES, legacy_rapydscript: false});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function runjs(code) {
|