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/release/signatures.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"ast": "
|
|
3
|
-
"baselib-builtins": "
|
|
4
|
-
"baselib-containers": "
|
|
2
|
+
"ast": "bd34ebcb396f2f9dc488dc8d1a75598b671f9ece",
|
|
3
|
+
"baselib-builtins": "18fb9c66dca26a12b7ae32b5d2b5f7a58ad63eb0",
|
|
4
|
+
"baselib-containers": "bf6aa7eeafaec27b76d9f9f72e141bf14663ead8",
|
|
5
5
|
"baselib-errors": "7f786439249e7d06cc010757f1bbaa6a2c3ea019",
|
|
6
|
-
"baselib-internal": "
|
|
7
|
-
"baselib-itertools": "
|
|
8
|
-
"baselib-str": "
|
|
6
|
+
"baselib-internal": "8922160a548b8d3c4788ebc1cf72a2745c298f6c",
|
|
7
|
+
"baselib-itertools": "db3318ca006882264a90980ba96353bbd9f91d1e",
|
|
8
|
+
"baselib-str": "196dbc0bb11fc3afd7de6979e7d7431aa9122386",
|
|
9
9
|
"compiler": "936b4fdf324101b7cced7efffe5eecf32ca3e4c7",
|
|
10
|
-
"errors": "
|
|
10
|
+
"errors": "eb47dd223483d6c9437fa8d02f86ac6a623064b8",
|
|
11
11
|
"output/__init__": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
|
|
12
|
-
"output/classes": "
|
|
13
|
-
"output/codegen": "
|
|
14
|
-
"output/comments": "
|
|
15
|
-
"output/exceptions": "
|
|
16
|
-
"output/functions": "
|
|
17
|
-
"output/literals": "
|
|
18
|
-
"output/loops": "
|
|
19
|
-
"output/modules": "
|
|
20
|
-
"output/operators": "
|
|
21
|
-
"output/statements": "
|
|
22
|
-
"output/stream": "
|
|
23
|
-
"output/utils": "
|
|
24
|
-
"parse": "
|
|
25
|
-
"string_interpolation": "
|
|
26
|
-
"tokenizer": "
|
|
27
|
-
"unicode_aliases": "
|
|
28
|
-
"utils": "
|
|
29
|
-
"#compiler#": "
|
|
30
|
-
"#compiled_with#": "
|
|
12
|
+
"output/classes": "d06444af4ecb4119d296979b92aeaf8b42ffa620",
|
|
13
|
+
"output/codegen": "47266a3451ad8e9be87cd73495618f45a9a920b4",
|
|
14
|
+
"output/comments": "09bf65d77cf83b4b6508c569d05bb14b057afda9",
|
|
15
|
+
"output/exceptions": "0f0376d6d7d85b592411084fc0858bbc85179a03",
|
|
16
|
+
"output/functions": "7d441400b69bf305a3a7e33e476f9883ad2261a0",
|
|
17
|
+
"output/literals": "acad293455ce75fbde16d0e40e7db721defe211c",
|
|
18
|
+
"output/loops": "34971b8b85f0bd999709e418befead94d84d8e71",
|
|
19
|
+
"output/modules": "8e2cbecb8b74acfd20d1e486773c1226ef8070e4",
|
|
20
|
+
"output/operators": "64fac94127d258625e427bcdfd0e86924359ae89",
|
|
21
|
+
"output/statements": "c6347cb71110cc81d4852f1ad873f1b56f8e287c",
|
|
22
|
+
"output/stream": "035d39dda2370e7b907fc1fa620ecf12fd5b4fe0",
|
|
23
|
+
"output/utils": "58f83e8b97c6b925513a082218e484344dd15736",
|
|
24
|
+
"parse": "50e1e14ce5c44a826dbfde4a044b5a06b1f16b8c",
|
|
25
|
+
"string_interpolation": "c45fd6fb4b4522fc9af002bf9201eb6b452d8d87",
|
|
26
|
+
"tokenizer": "ed1f598741b88b8fdcbb4432d64395ac7b8e8187",
|
|
27
|
+
"unicode_aliases": "f560a085fa8472fc87f57d33f4627d59601bd494",
|
|
28
|
+
"utils": "56324681f9a8d60a658fac1b79b23c7b3b64070f",
|
|
29
|
+
"#compiler#": "25e09d1ae7d2762059339e97c0b51c270e87cc91",
|
|
30
|
+
"#compiled_with#": "25e09d1ae7d2762059339e97c0b51c270e87cc91"
|
|
31
31
|
}
|
package/src/ast.pyj
CHANGED
|
@@ -42,7 +42,8 @@ class AST_Token(AST):
|
|
|
42
42
|
'nlb': 'True iff there was a newline before this token',
|
|
43
43
|
'comments_before': 'True iff there were comments before this token',
|
|
44
44
|
'file': 'The filename in which this token occurs',
|
|
45
|
-
'leading_whitespace':
|
|
45
|
+
'leading_whitespace':
|
|
46
|
+
'The leading whitespace for the line on which this token occurs',
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
|
|
@@ -59,7 +60,9 @@ class AST_Node(AST):
|
|
|
59
60
|
def walk(self, visitor):
|
|
60
61
|
return self._walk(visitor)
|
|
61
62
|
|
|
62
|
-
def _dump(
|
|
63
|
+
def _dump(
|
|
64
|
+
self, depth=100, omit={'start', 'end'}, offset=0, include_name=True
|
|
65
|
+
):
|
|
63
66
|
p = console.log
|
|
64
67
|
reset = '\x1b[0m'
|
|
65
68
|
yellow = '\x1b[33m'
|
|
@@ -83,7 +86,11 @@ class AST_Node(AST):
|
|
|
83
86
|
element._dump(depth - 1, omit, offset + 1, True)
|
|
84
87
|
else:
|
|
85
88
|
for element in self[key]:
|
|
86
|
-
p(
|
|
89
|
+
p(
|
|
90
|
+
pad + ' ' + yellow
|
|
91
|
+
+ element.constructor.name.slice(4)
|
|
92
|
+
+ reset
|
|
93
|
+
)
|
|
87
94
|
p(pad + ' ]')
|
|
88
95
|
else:
|
|
89
96
|
p(pad + ' ' + blue + key + ': ' + reset + '[]')
|
|
@@ -91,15 +98,19 @@ class AST_Node(AST):
|
|
|
91
98
|
if is_node_type(self[key], AST):
|
|
92
99
|
tname = self[key].constructor.name.slice(4)
|
|
93
100
|
if tname is 'Token':
|
|
94
|
-
p(pad + ' ' + blue + key + ': '
|
|
101
|
+
p(pad + ' ' + blue + key + ': '
|
|
102
|
+
+ magenta + tname + reset)
|
|
95
103
|
for property in self[key]:
|
|
96
|
-
p(pad + ' ' + blue + property + ': '
|
|
104
|
+
p(pad + ' ' + blue + property + ': '
|
|
105
|
+
+ reset + self[key][property])
|
|
97
106
|
else:
|
|
98
|
-
p(pad + ' ' + blue + key + ': '
|
|
107
|
+
p(pad + ' ' + blue + key + ': '
|
|
108
|
+
+ yellow + tname + reset)
|
|
99
109
|
if depth > 1:
|
|
100
110
|
self[key]._dump(depth - 1, omit, offset + 1, False)
|
|
101
111
|
elif jstype(self[key]) is 'string':
|
|
102
|
-
p(pad + ' ' + blue + key + ': '
|
|
112
|
+
p(pad + ' ' + blue + key + ': '
|
|
113
|
+
+ green + '"' + self[key] + '"' + reset)
|
|
103
114
|
elif jstype(self[key]) is 'number':
|
|
104
115
|
p(pad + ' ' + blue + key + ': ' + green + self[key] + reset)
|
|
105
116
|
else:
|
|
@@ -128,14 +139,19 @@ class AST_Debugger(AST_Statement):
|
|
|
128
139
|
class AST_Directive(AST_Statement):
|
|
129
140
|
'Represents a directive, like "use strict";'
|
|
130
141
|
properties = {
|
|
131
|
-
'value':
|
|
142
|
+
'value':
|
|
143
|
+
'[string] The value of this directive as a plain string '
|
|
144
|
+
+ "(it's not an AST_String!)",
|
|
132
145
|
'scope': '[AST_Scope/S] The scope that this directive affects',
|
|
133
146
|
}
|
|
134
147
|
|
|
135
148
|
|
|
136
149
|
class AST_SimpleStatement(AST_Statement):
|
|
137
150
|
'A statement consisting of an expression, i.e. a = 1 + 2'
|
|
138
|
-
properties = {
|
|
151
|
+
properties = {
|
|
152
|
+
'body': '[AST_Node] an expression node '
|
|
153
|
+
+ '(should not be instanceof AST_Statement)'
|
|
154
|
+
}
|
|
139
155
|
|
|
140
156
|
def _walk(self, visitor):
|
|
141
157
|
return visitor._visit(self, def ():
|
|
@@ -147,7 +163,8 @@ class AST_Assert(AST_Statement):
|
|
|
147
163
|
"An assert statement, e.g. assert True, 'an error message'"
|
|
148
164
|
properties = {
|
|
149
165
|
'condition': '[AST_Node] the expression that should be tested',
|
|
150
|
-
'message':
|
|
166
|
+
'message':
|
|
167
|
+
'[AST_Node*] the expression that is the error message or None',
|
|
151
168
|
}
|
|
152
169
|
|
|
153
170
|
def _walk(self, visitor):
|
|
@@ -193,8 +210,12 @@ class AST_EmptyStatement(AST_Statement):
|
|
|
193
210
|
|
|
194
211
|
|
|
195
212
|
class AST_StatementWithBody(AST_Statement):
|
|
196
|
-
'Base class for all statements that contain one nested body:
|
|
197
|
-
|
|
213
|
+
'Base class for all statements that contain one nested body: '
|
|
214
|
+
+'`For`, `ForIn`, `Do`, `While`, `With`'
|
|
215
|
+
properties = {
|
|
216
|
+
'body': '[AST_Statement] the body; this should always be '
|
|
217
|
+
+ "present, even if it's an AST_EmptyStatement"
|
|
218
|
+
}
|
|
198
219
|
|
|
199
220
|
def _walk(self, visitor):
|
|
200
221
|
return visitor._visit(self, def ():
|
|
@@ -204,7 +225,10 @@ class AST_StatementWithBody(AST_Statement):
|
|
|
204
225
|
|
|
205
226
|
class AST_DWLoop(AST_StatementWithBody):
|
|
206
227
|
'Base class for do/while statements'
|
|
207
|
-
properties = {
|
|
228
|
+
properties = {
|
|
229
|
+
'condition': '[AST_Node] the loop condition. '
|
|
230
|
+
+ 'Should not be instanceof AST_Statement'
|
|
231
|
+
}
|
|
208
232
|
|
|
209
233
|
def _walk(self, visitor):
|
|
210
234
|
return visitor._visit(self, def ():
|
|
@@ -250,7 +274,9 @@ class AST_ListComprehension(AST_ForIn):
|
|
|
250
274
|
'A list comprehension expression'
|
|
251
275
|
properties = {
|
|
252
276
|
'condition': '[AST_Node] the `if` condition',
|
|
253
|
-
'statement':
|
|
277
|
+
'statement':
|
|
278
|
+
'[AST_Node] statement to perform on each element '
|
|
279
|
+
+ 'before returning it',
|
|
254
280
|
}
|
|
255
281
|
|
|
256
282
|
def _walk(self, visitor):
|
|
@@ -269,7 +295,9 @@ class AST_SetComprehension(AST_ListComprehension):
|
|
|
269
295
|
class AST_DictComprehension(AST_ListComprehension):
|
|
270
296
|
'A set comprehension'
|
|
271
297
|
properties = {
|
|
272
|
-
'value_statement':
|
|
298
|
+
'value_statement':
|
|
299
|
+
'[AST_Node] statement to perform on each value '
|
|
300
|
+
+ 'before returning it',
|
|
273
301
|
'is_pydict': '[bool] True if this comprehension is for a python dict',
|
|
274
302
|
'is_jshash': '[bool] True if this comprehension is for a js hash',
|
|
275
303
|
}
|
|
@@ -331,19 +359,33 @@ class AST_Scope(AST_Block):
|
|
|
331
359
|
class AST_Toplevel(AST_Scope):
|
|
332
360
|
'The toplevel scope'
|
|
333
361
|
properties = {
|
|
334
|
-
'globals':
|
|
362
|
+
'globals':
|
|
363
|
+
'[Object/S] a map of name -> SymbolDef for all undeclared names',
|
|
335
364
|
'baselib': '[Object/s] a collection of used parts of baselib',
|
|
336
|
-
'imports':
|
|
337
|
-
|
|
338
|
-
|
|
365
|
+
'imports':
|
|
366
|
+
'[Object/S] a map of module_id->AST_Toplevel for all '
|
|
367
|
+
+ 'imported modules (this represents all imported '
|
|
368
|
+
+ 'modules across all source files)',
|
|
369
|
+
'imported_module_ids':
|
|
370
|
+
'[string*] a list of module ids that were imported '
|
|
371
|
+
+ 'by this module, specifically',
|
|
372
|
+
'nonlocalvars':
|
|
373
|
+
'[String*] a list of all non-local variable names '
|
|
374
|
+
+ '(names that come from the global scope)',
|
|
339
375
|
'shebang': '[string] If #! line is present, it will be stored here',
|
|
340
|
-
'import_order':
|
|
376
|
+
'import_order':
|
|
377
|
+
'[number] The global order in which this scope was imported',
|
|
341
378
|
'module_id': '[string] The id of this module',
|
|
342
379
|
'exports': '[SymbolDef*] list of names exported from this module',
|
|
343
|
-
'classes':
|
|
344
|
-
|
|
380
|
+
'classes':
|
|
381
|
+
'[Object/S] a map of class names to AST_Class '
|
|
382
|
+
+ 'for classes defined in this module',
|
|
383
|
+
'filename':
|
|
384
|
+
'[string] The absolute path to the file from '
|
|
385
|
+
+ 'which this module was read',
|
|
345
386
|
'srchash': '[string] SHA1 hash of source code, used for caching',
|
|
346
|
-
'comments_after':
|
|
387
|
+
'comments_after':
|
|
388
|
+
'[array] True iff there were comments before this token',
|
|
347
389
|
}
|
|
348
390
|
|
|
349
391
|
|
|
@@ -352,8 +394,12 @@ class AST_Import(AST_Statement):
|
|
|
352
394
|
|
|
353
395
|
properties = {
|
|
354
396
|
'module': "[AST_SymbolVar] name of the module we're importing",
|
|
355
|
-
'key':
|
|
356
|
-
|
|
397
|
+
'key':
|
|
398
|
+
'[string] The key by which this module is stored '
|
|
399
|
+
+ 'in the global modules mapping',
|
|
400
|
+
'alias':
|
|
401
|
+
'[AST_SymbolAlias] The name this module is imported as, '
|
|
402
|
+
+ 'can be None. For import x as y statements.',
|
|
357
403
|
'argnames': '[AST_ImportedVar*] names of objects to be imported',
|
|
358
404
|
'body': '[AST_TopLevel] parsed contents of the imported file',
|
|
359
405
|
}
|
|
@@ -400,9 +446,11 @@ class AST_ArgsDef(AST_Node):
|
|
|
400
446
|
'args': '[AST_SymbolFunarg*] formal positional parameters',
|
|
401
447
|
'starargs': '[AST_SymbolFunarg?] *args parameter, or None',
|
|
402
448
|
'kwargs': '[AST_SymbolFunarg?] **kwargs parameter, or None',
|
|
403
|
-
'defaults':
|
|
449
|
+
'defaults':
|
|
450
|
+
'[Object] map of parameter name to default value expression',
|
|
404
451
|
'has_defaults': '[bool] True if any parameter has a default value',
|
|
405
|
-
'is_simple_func':
|
|
452
|
+
'is_simple_func':
|
|
453
|
+
'[bool] True if no starargs, no kwargs, and no defaults',
|
|
406
454
|
}
|
|
407
455
|
|
|
408
456
|
def _walk(self, visitor):
|
|
@@ -424,9 +472,12 @@ class AST_Lambda(AST_Scope):
|
|
|
424
472
|
'decorators': '[AST_Decorator*] function decorators, if any',
|
|
425
473
|
'is_generator': '[bool*] True iff this function is a generator',
|
|
426
474
|
'is_async': '[bool*] True iff this function is an async function',
|
|
427
|
-
'is_expression':
|
|
428
|
-
|
|
429
|
-
'
|
|
475
|
+
'is_expression':
|
|
476
|
+
'[bool*] True iff this function is a function expression',
|
|
477
|
+
'is_anonymous':
|
|
478
|
+
'[bool*] True iff this function is an anonymous function',
|
|
479
|
+
'return_annotation':
|
|
480
|
+
'[AST_Node?] The return type annotation provided (if any)',
|
|
430
481
|
}
|
|
431
482
|
|
|
432
483
|
def _walk(self, visitor):
|
|
@@ -452,14 +503,26 @@ class AST_Class(AST_Scope):
|
|
|
452
503
|
'init': '[AST_Function] constructor for the class',
|
|
453
504
|
'parent': '[AST_Symbol?] parent class this class inherits from',
|
|
454
505
|
'bases': '[AST_Symbol*] list of base classes this class inherits from',
|
|
455
|
-
'static':
|
|
456
|
-
|
|
506
|
+
'static':
|
|
507
|
+
'[dict] A hash whose keys are names of static '
|
|
508
|
+
+ 'methods for this class',
|
|
509
|
+
'external':
|
|
510
|
+
'[boolean] true if class is declared elsewhere, '
|
|
511
|
+
+ 'but will be within current scope at runtime',
|
|
457
512
|
'bound': '[string*] list of methods that need to be bound to self',
|
|
458
513
|
'decorators': '[AST_Decorator*] function decorators, if any',
|
|
459
514
|
'module_id': '[string] The id of the module this class is defined in',
|
|
460
|
-
'statements':
|
|
461
|
-
|
|
462
|
-
|
|
515
|
+
'statements':
|
|
516
|
+
'[AST_Node*] list of statements in the class scope '
|
|
517
|
+
+ '(excluding method definitions)',
|
|
518
|
+
'dynamic_properties':
|
|
519
|
+
'[dict] map of dynamic property names to property '
|
|
520
|
+
+ 'descriptors of the form {getter:AST_Method, '
|
|
521
|
+
+ 'setter:AST_Method',
|
|
522
|
+
'classvars':
|
|
523
|
+
'[dict] map containing all class variables as keys, '
|
|
524
|
+
+ 'to be used to easily test for existence '
|
|
525
|
+
+ 'of a class variable',
|
|
463
526
|
}
|
|
464
527
|
|
|
465
528
|
def _walk(self, visitor):
|
|
@@ -487,12 +550,16 @@ class AST_Method(AST_Lambda):
|
|
|
487
550
|
|
|
488
551
|
|
|
489
552
|
class AST_Jump(AST_Statement):
|
|
490
|
-
"Base class for “jumps” (for now that's `return`, `throw`, `break`
|
|
553
|
+
"Base class for “jumps” (for now that's `return`, `throw`, `break`"
|
|
554
|
+
+' and `continue`)'
|
|
491
555
|
|
|
492
556
|
|
|
493
557
|
class AST_Exit(AST_Jump):
|
|
494
558
|
'Base class for “exits” (`return` and `throw`)'
|
|
495
|
-
properties = {
|
|
559
|
+
properties = {
|
|
560
|
+
'value': '[AST_Node?] the value returned or thrown by '
|
|
561
|
+
+ 'this statement; could be null for AST_Return'
|
|
562
|
+
}
|
|
496
563
|
|
|
497
564
|
def _walk(self, visitor):
|
|
498
565
|
return visitor._visit(self, def ():
|
|
@@ -547,7 +614,8 @@ class AST_If(AST_StatementWithBody):
|
|
|
547
614
|
'A `if` statement'
|
|
548
615
|
properties = {
|
|
549
616
|
'condition': '[AST_Node] the `if` condition',
|
|
550
|
-
'alternative':
|
|
617
|
+
'alternative':
|
|
618
|
+
'[AST_Statement?] the `else` part, or null if not present',
|
|
551
619
|
}
|
|
552
620
|
|
|
553
621
|
def _walk(self, visitor):
|
|
@@ -615,7 +683,8 @@ class AST_Else(AST_Block):
|
|
|
615
683
|
|
|
616
684
|
# VAR/CONST {{{
|
|
617
685
|
class AST_Definitions(AST_Statement):
|
|
618
|
-
'Base class for `var` or `const` nodes
|
|
686
|
+
'Base class for `var` or `const` nodes '
|
|
687
|
+
+'(variable declarations/initializations)'
|
|
619
688
|
properties = {
|
|
620
689
|
'definitions': '[AST_VarDef*] array of variable definitions'
|
|
621
690
|
}
|
|
@@ -721,7 +790,8 @@ class AST_ClassCall(AST_BaseCall):
|
|
|
721
790
|
|
|
722
791
|
|
|
723
792
|
class AST_New(AST_Call):
|
|
724
|
-
'An object instantiation. Derives from a function call
|
|
793
|
+
'An object instantiation. Derives from a function call '
|
|
794
|
+
+'since it has exactly the same properties'
|
|
725
795
|
|
|
726
796
|
|
|
727
797
|
class AST_Seq(AST_Node):
|
|
@@ -789,7 +859,10 @@ class AST_PropAccess(AST_Node):
|
|
|
789
859
|
'Base class for property access expressions, i.e. `a.foo` or `a["foo"]`'
|
|
790
860
|
properties = {
|
|
791
861
|
'expression': '[AST_Node] the “container” expression',
|
|
792
|
-
'property':
|
|
862
|
+
'property':
|
|
863
|
+
'[AST_Node|string] the property to access. For AST_Dot '
|
|
864
|
+
+ 'this is always a plain string, while for AST_Sub '
|
|
865
|
+
+ "it's an arbitrary AST_Node",
|
|
793
866
|
}
|
|
794
867
|
|
|
795
868
|
|
|
@@ -815,8 +888,12 @@ class AST_Sub(AST_PropAccess):
|
|
|
815
888
|
class AST_ItemAccess(AST_PropAccess):
|
|
816
889
|
'Python index-style property access, i.e. `a.__getitem__("foo")`'
|
|
817
890
|
properties = {
|
|
818
|
-
'assignment':
|
|
819
|
-
|
|
891
|
+
'assignment':
|
|
892
|
+
'[AST_Node or None] Not None if this is an assignment '
|
|
893
|
+
+ '(a[x] = y) rather than a simple access',
|
|
894
|
+
'assign_operator':
|
|
895
|
+
'[String] The operator for a assignment like += '
|
|
896
|
+
+ 'or empty string if plain assignment',
|
|
820
897
|
}
|
|
821
898
|
|
|
822
899
|
def _walk(self, visitor):
|
|
@@ -831,7 +908,9 @@ class AST_ItemAccess(AST_PropAccess):
|
|
|
831
908
|
class AST_Splice(AST_PropAccess):
|
|
832
909
|
'Index-style property access, i.e. `a[3:5]`'
|
|
833
910
|
properties = {
|
|
834
|
-
'property2':
|
|
911
|
+
'property2':
|
|
912
|
+
'[AST_Node] the 2nd property to access - '
|
|
913
|
+
+ 'typically ending index for the array.',
|
|
835
914
|
'assignment': '[AST_Node] The data being spliced in.',
|
|
836
915
|
}
|
|
837
916
|
|
|
@@ -847,8 +926,10 @@ class AST_Unary(AST_Node):
|
|
|
847
926
|
'Base class for unary expressions'
|
|
848
927
|
properties = {
|
|
849
928
|
'operator': '[string] the operator',
|
|
850
|
-
'expression':
|
|
851
|
-
|
|
929
|
+
'expression':
|
|
930
|
+
'[AST_Node] expression that this unary operator applies to',
|
|
931
|
+
'parenthesized':
|
|
932
|
+
'[bool] Whether this unary expression was parenthesized',
|
|
852
933
|
}
|
|
853
934
|
|
|
854
935
|
def _walk(self, visitor):
|
|
@@ -879,8 +960,14 @@ class AST_Binary(AST_Node):
|
|
|
879
960
|
class AST_Existential(AST_Node):
|
|
880
961
|
'Existential operator a?'
|
|
881
962
|
properties = {
|
|
882
|
-
'expression':
|
|
883
|
-
|
|
963
|
+
'expression':
|
|
964
|
+
'[AST_Node] The expression whose existence we need to check',
|
|
965
|
+
'after':
|
|
966
|
+
'[None|string|AST_Node] is None when there is nothing '
|
|
967
|
+
+ 'following this operator, is a string when there is '
|
|
968
|
+
+ 'as AST_PropAccess following this operator, is an '
|
|
969
|
+
+ 'AST_Node if it is used a a shorthand for the '
|
|
970
|
+
+ 'conditional ternary, i.e. a ? b == a if a? else b',
|
|
884
971
|
}
|
|
885
972
|
|
|
886
973
|
def _walk(self, visitor):
|
|
@@ -914,7 +1001,13 @@ class AST_Assign(AST_Binary):
|
|
|
914
1001
|
return is_node_type(
|
|
915
1002
|
self.right,
|
|
916
1003
|
AST_Assign
|
|
917
|
-
) or (
|
|
1004
|
+
) or (
|
|
1005
|
+
is_node_type(self.right, AST_Seq)
|
|
1006
|
+
and (
|
|
1007
|
+
is_node_type(self.right.car, AST_Assign)
|
|
1008
|
+
or is_node_type(self.right.cdr, AST_Assign)
|
|
1009
|
+
)
|
|
1010
|
+
)
|
|
918
1011
|
|
|
919
1012
|
def traverse_chain(self):
|
|
920
1013
|
right = self.right
|
|
@@ -924,7 +1017,9 @@ class AST_Assign(AST_Binary):
|
|
|
924
1017
|
continue
|
|
925
1018
|
if is_node_type(right, AST_Seq):
|
|
926
1019
|
if is_node_type(right.car, AST_Assign):
|
|
927
|
-
right = new AST_Seq({
|
|
1020
|
+
right = new AST_Seq({
|
|
1021
|
+
'car': right.car.right, 'cdr': right.cdr
|
|
1022
|
+
})
|
|
928
1023
|
continue
|
|
929
1024
|
if is_node_type(right.cdr, AST_Assign):
|
|
930
1025
|
right = right.cdr.right
|
|
@@ -940,7 +1035,9 @@ class AST_Assign(AST_Binary):
|
|
|
940
1035
|
if is_node_type(next, AST_Seq):
|
|
941
1036
|
if is_node_type(next.cdr, AST_Assign):
|
|
942
1037
|
assign = next.cdr
|
|
943
|
-
left_hand_sides.push(new AST_Seq({
|
|
1038
|
+
left_hand_sides.push(new AST_Seq({
|
|
1039
|
+
'car': next.car, 'cdr': assign.left
|
|
1040
|
+
}))
|
|
944
1041
|
next = assign.right
|
|
945
1042
|
continue
|
|
946
1043
|
break
|
|
@@ -1003,7 +1100,9 @@ class AST_ObjectProperty(AST_Node):
|
|
|
1003
1100
|
'Base class for literal object properties'
|
|
1004
1101
|
properties = {
|
|
1005
1102
|
'key': '[AST_Node] the property expression',
|
|
1006
|
-
'value':
|
|
1103
|
+
'value':
|
|
1104
|
+
'[AST_Node] property value. For setters and '
|
|
1105
|
+
+ 'getters this is an AST_Function.',
|
|
1007
1106
|
'quoted': '',
|
|
1008
1107
|
}
|
|
1009
1108
|
|
|
@@ -1047,7 +1146,9 @@ class AST_Symbol(AST_Node):
|
|
|
1047
1146
|
'Base class for all symbols'
|
|
1048
1147
|
properties = {
|
|
1049
1148
|
'name': '[string] name of this symbol',
|
|
1050
|
-
'scope':
|
|
1149
|
+
'scope':
|
|
1150
|
+
'[AST_Scope/S] the current scope '
|
|
1151
|
+
+ '(not necessarily the definition scope)',
|
|
1051
1152
|
'thedef': '[SymbolDef/S] the definition of this symbol',
|
|
1052
1153
|
}
|
|
1053
1154
|
|
|
@@ -1057,7 +1158,8 @@ class AST_SymbolAlias(AST_Symbol):
|
|
|
1057
1158
|
|
|
1058
1159
|
|
|
1059
1160
|
class AST_SymbolDeclaration(AST_Symbol):
|
|
1060
|
-
'A declaration symbol (symbol in var/const, function name
|
|
1161
|
+
'A declaration symbol (symbol in var/const, function name '
|
|
1162
|
+
+'or argument, symbol in catch)'
|
|
1061
1163
|
properties = {
|
|
1062
1164
|
'init': '[AST_Node*/S] array of initializers for this declaration.'
|
|
1063
1165
|
}
|
|
@@ -1080,7 +1182,10 @@ class AST_SymbolNonlocal(AST_SymbolDeclaration):
|
|
|
1080
1182
|
|
|
1081
1183
|
class AST_SymbolFunarg(AST_SymbolVar):
|
|
1082
1184
|
'Symbol naming a function argument, possibly with an annotation.'
|
|
1083
|
-
properties = {
|
|
1185
|
+
properties = {
|
|
1186
|
+
'annotation':
|
|
1187
|
+
'[AST_Node?] The annotation provided for this argument (if any)'
|
|
1188
|
+
}
|
|
1084
1189
|
|
|
1085
1190
|
|
|
1086
1191
|
class AST_SymbolDefun(AST_SymbolDeclaration):
|
|
@@ -1197,7 +1302,10 @@ class TreeWalker:
|
|
|
1197
1302
|
|
|
1198
1303
|
def _visit(self, node, descend):
|
|
1199
1304
|
self.stack.push(node)
|
|
1200
|
-
ret = self.visit(
|
|
1305
|
+
ret = self.visit(
|
|
1306
|
+
node,
|
|
1307
|
+
((def (): descend.call(node);) if descend else noop)
|
|
1308
|
+
)
|
|
1201
1309
|
if not ret and descend:
|
|
1202
1310
|
descend.call(node)
|
|
1203
1311
|
|
|
@@ -1237,7 +1345,10 @@ class TreeWalker:
|
|
|
1237
1345
|
AST_UnaryPrefix
|
|
1238
1346
|
) and p.operator is '!' and p.expression is self:
|
|
1239
1347
|
return True
|
|
1240
|
-
if not (
|
|
1348
|
+
if not (
|
|
1349
|
+
is_node_type(p, AST_Binary)
|
|
1350
|
+
and (p.operator is '&&' or p.operator is '||')
|
|
1351
|
+
):
|
|
1241
1352
|
return False
|
|
1242
1353
|
self = p
|
|
1243
1354
|
# }}}
|
|
@@ -1256,7 +1367,8 @@ def has_calls(expression):
|
|
|
1256
1367
|
return False
|
|
1257
1368
|
try:
|
|
1258
1369
|
expression.walk(new TreeWalker(def (node):
|
|
1259
|
-
if is_node_type(node, AST_BaseCall)
|
|
1370
|
+
if (is_node_type(node, AST_BaseCall)
|
|
1371
|
+
or is_node_type(node, AST_ItemAccess)):
|
|
1260
1372
|
raise Found()
|
|
1261
1373
|
))
|
|
1262
1374
|
except Found:
|
package/src/baselib-builtins.pyj
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
# License: BSD
|
|
3
3
|
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
4
4
|
|
|
5
|
-
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol,
|
|
5
|
+
# globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol,
|
|
6
|
+
# globals: ρσ_arraylike, ρσ_list_contains
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
def ρσ_bool(val):
|
|
@@ -23,7 +24,8 @@ def ρσ_int(val, base):
|
|
|
23
24
|
else:
|
|
24
25
|
ans = parseInt(val, base or 10)
|
|
25
26
|
if isNaN(ans):
|
|
26
|
-
raise ValueError(
|
|
27
|
+
raise ValueError(
|
|
28
|
+
'Invalid literal for int with base ' + (base or 10) + ': ' + val)
|
|
27
29
|
return ans
|
|
28
30
|
|
|
29
31
|
|
|
@@ -38,11 +40,18 @@ def ρσ_float(val):
|
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
def ρσ_arraylike_creator():
|
|
41
|
-
names =
|
|
43
|
+
names = (
|
|
44
|
+
'Int8Array Uint8Array Uint8ClampedArray Int16Array' +
|
|
45
|
+
' Uint16Array Int32Array Uint32Array Float32Array' +
|
|
46
|
+
' Float64Array'
|
|
47
|
+
).split(' ')
|
|
42
48
|
if jstype(HTMLCollection) is 'function':
|
|
43
|
-
names = names.concat(
|
|
49
|
+
names = names.concat(
|
|
50
|
+
'HTMLCollection NodeList NamedNodeMap TouchList'.split(' '))
|
|
44
51
|
return def (x):
|
|
45
|
-
if Array.isArray(x) or v'typeof x' is 'string'
|
|
52
|
+
if (Array.isArray(x) or v'typeof x' is 'string'
|
|
53
|
+
or names.indexOf(
|
|
54
|
+
Object.prototype.toString.call(x).slice(8, -1)) > -1):
|
|
46
55
|
return True
|
|
47
56
|
return False
|
|
48
57
|
|
|
@@ -122,7 +131,9 @@ def ρσ_enumerate(iterable):
|
|
|
122
131
|
return v"{'done':true}"
|
|
123
132
|
return ans
|
|
124
133
|
if jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
125
|
-
iterator =
|
|
134
|
+
iterator = (
|
|
135
|
+
iterable.keys() if jstype(Map) is 'function' and
|
|
136
|
+
v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]())
|
|
126
137
|
ans['_iterator'] = iterator
|
|
127
138
|
ans['next'] = def ():
|
|
128
139
|
r = this._iterator.next()
|
|
@@ -151,7 +162,9 @@ def ρσ_reversed(iterable):
|
|
|
151
162
|
def ρσ_iter(iterable):
|
|
152
163
|
# Generate a JavaScript iterator object from iterable
|
|
153
164
|
if jstype(iterable[ρσ_iterator_symbol]) is 'function':
|
|
154
|
-
return
|
|
165
|
+
return (
|
|
166
|
+
iterable.keys() if jstype(Map) is 'function' and
|
|
167
|
+
v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]())
|
|
155
168
|
if ρσ_arraylike(iterable):
|
|
156
169
|
ans = v'{"_i":-1}'
|
|
157
170
|
ans[ρσ_iterator_symbol] = def ():
|
|
@@ -247,7 +260,9 @@ def ρσ_hasattr(obj, name):
|
|
|
247
260
|
if ρσ_arraylike(obj): return obj.length
|
|
248
261
|
if jstype(obj.__len__) is 'function': return obj.__len__()
|
|
249
262
|
return Object.keys(obj).length
|
|
250
|
-
return
|
|
263
|
+
return (
|
|
264
|
+
len if v'typeof Set' is 'function' and
|
|
265
|
+
v'typeof Map' is 'function' else len5)
|
|
251
266
|
)()
|
|
252
267
|
|
|
253
268
|
|
|
@@ -291,9 +306,15 @@ def ρσ_max(*args, **kwargs):
|
|
|
291
306
|
raise TypeError('expected at least one argument')
|
|
292
307
|
|
|
293
308
|
|
|
294
|
-
v'var abs = Math.abs, max = ρσ_max.bind(Math.max)
|
|
295
|
-
v'var
|
|
296
|
-
v'var
|
|
297
|
-
v'var
|
|
298
|
-
v'var
|
|
299
|
-
v'var
|
|
309
|
+
v'var abs = Math.abs, max = ρσ_max.bind(Math.max)'
|
|
310
|
+
v'var min = ρσ_max.bind(Math.min), bool = ρσ_bool, type = ρσ_type'
|
|
311
|
+
v'var float = ρσ_float, int = ρσ_int, arraylike = ρσ_arraylike_creator()'
|
|
312
|
+
v'var ρσ_arraylike = arraylike'
|
|
313
|
+
v'var print = ρσ_print, id = ρσ_id, get_module = ρσ_get_module'
|
|
314
|
+
v'var pow = ρσ_pow, divmod = ρσ_divmod'
|
|
315
|
+
v'var dir = ρσ_dir, ord = ρσ_ord, chr = ρσ_chr, bin = ρσ_bin'
|
|
316
|
+
v'var hex = ρσ_hex, callable = ρσ_callable'
|
|
317
|
+
v'var enumerate = ρσ_enumerate, iter = ρσ_iter, reversed = ρσ_reversed'
|
|
318
|
+
v'var len = ρσ_len'
|
|
319
|
+
v'var range = ρσ_range, getattr = ρσ_getattr, setattr = ρσ_setattr'
|
|
320
|
+
v'var hasattr = ρσ_hasattr'
|