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/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,15 +139,18 @@ 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':
|
|
132
|
-
|
|
142
|
+
'value':
|
|
143
|
+
'[string] The value of this directive as a plain string '
|
|
144
|
+
+ "(it's not an AST_String!)",
|
|
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
151
|
properties = {
|
|
139
|
-
'body': '[AST_Node] an expression node
|
|
152
|
+
'body': '[AST_Node] an expression node '
|
|
153
|
+
+ '(should not be instanceof AST_Statement)'
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
def _walk(self, visitor):
|
|
@@ -149,7 +163,8 @@ class AST_Assert(AST_Statement):
|
|
|
149
163
|
"An assert statement, e.g. assert True, 'an error message'"
|
|
150
164
|
properties = {
|
|
151
165
|
'condition': '[AST_Node] the expression that should be tested',
|
|
152
|
-
'message':
|
|
166
|
+
'message':
|
|
167
|
+
'[AST_Node*] the expression that is the error message or None',
|
|
153
168
|
}
|
|
154
169
|
|
|
155
170
|
def _walk(self, visitor):
|
|
@@ -195,9 +210,11 @@ class AST_EmptyStatement(AST_Statement):
|
|
|
195
210
|
|
|
196
211
|
|
|
197
212
|
class AST_StatementWithBody(AST_Statement):
|
|
198
|
-
'Base class for all statements that contain one nested body:
|
|
213
|
+
'Base class for all statements that contain one nested body: '
|
|
214
|
+
+'`For`, `ForIn`, `Do`, `While`, `With`'
|
|
199
215
|
properties = {
|
|
200
|
-
'body':
|
|
216
|
+
'body': '[AST_Statement] the body; this should always be '
|
|
217
|
+
+ "present, even if it's an AST_EmptyStatement"
|
|
201
218
|
}
|
|
202
219
|
|
|
203
220
|
def _walk(self, visitor):
|
|
@@ -209,7 +226,8 @@ class AST_StatementWithBody(AST_Statement):
|
|
|
209
226
|
class AST_DWLoop(AST_StatementWithBody):
|
|
210
227
|
'Base class for do/while statements'
|
|
211
228
|
properties = {
|
|
212
|
-
'condition': '[AST_Node] the loop condition.
|
|
229
|
+
'condition': '[AST_Node] the loop condition. '
|
|
230
|
+
+ 'Should not be instanceof AST_Statement'
|
|
213
231
|
}
|
|
214
232
|
|
|
215
233
|
def _walk(self, visitor):
|
|
@@ -256,7 +274,9 @@ class AST_ListComprehension(AST_ForIn):
|
|
|
256
274
|
'A list comprehension expression'
|
|
257
275
|
properties = {
|
|
258
276
|
'condition': '[AST_Node] the `if` condition',
|
|
259
|
-
'statement':
|
|
277
|
+
'statement':
|
|
278
|
+
'[AST_Node] statement to perform on each element '
|
|
279
|
+
+ 'before returning it',
|
|
260
280
|
}
|
|
261
281
|
|
|
262
282
|
def _walk(self, visitor):
|
|
@@ -275,7 +295,9 @@ class AST_SetComprehension(AST_ListComprehension):
|
|
|
275
295
|
class AST_DictComprehension(AST_ListComprehension):
|
|
276
296
|
'A set comprehension'
|
|
277
297
|
properties = {
|
|
278
|
-
'value_statement':
|
|
298
|
+
'value_statement':
|
|
299
|
+
'[AST_Node] statement to perform on each value '
|
|
300
|
+
+ 'before returning it',
|
|
279
301
|
'is_pydict': '[bool] True if this comprehension is for a python dict',
|
|
280
302
|
'is_jshash': '[bool] True if this comprehension is for a js hash',
|
|
281
303
|
}
|
|
@@ -337,19 +359,33 @@ class AST_Scope(AST_Block):
|
|
|
337
359
|
class AST_Toplevel(AST_Scope):
|
|
338
360
|
'The toplevel scope'
|
|
339
361
|
properties = {
|
|
340
|
-
'globals':
|
|
362
|
+
'globals':
|
|
363
|
+
'[Object/S] a map of name -> SymbolDef for all undeclared names',
|
|
341
364
|
'baselib': '[Object/s] a collection of used parts of baselib',
|
|
342
|
-
'imports':
|
|
343
|
-
|
|
344
|
-
|
|
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)',
|
|
345
375
|
'shebang': '[string] If #! line is present, it will be stored here',
|
|
346
|
-
'import_order':
|
|
376
|
+
'import_order':
|
|
377
|
+
'[number] The global order in which this scope was imported',
|
|
347
378
|
'module_id': '[string] The id of this module',
|
|
348
379
|
'exports': '[SymbolDef*] list of names exported from this module',
|
|
349
|
-
'classes':
|
|
350
|
-
|
|
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',
|
|
351
386
|
'srchash': '[string] SHA1 hash of source code, used for caching',
|
|
352
|
-
'comments_after':
|
|
387
|
+
'comments_after':
|
|
388
|
+
'[array] True iff there were comments before this token',
|
|
353
389
|
}
|
|
354
390
|
|
|
355
391
|
|
|
@@ -358,8 +394,12 @@ class AST_Import(AST_Statement):
|
|
|
358
394
|
|
|
359
395
|
properties = {
|
|
360
396
|
'module': "[AST_SymbolVar] name of the module we're importing",
|
|
361
|
-
'key':
|
|
362
|
-
|
|
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.',
|
|
363
403
|
'argnames': '[AST_ImportedVar*] names of objects to be imported',
|
|
364
404
|
'body': '[AST_TopLevel] parsed contents of the imported file',
|
|
365
405
|
}
|
|
@@ -406,9 +446,11 @@ class AST_ArgsDef(AST_Node):
|
|
|
406
446
|
'args': '[AST_SymbolFunarg*] formal positional parameters',
|
|
407
447
|
'starargs': '[AST_SymbolFunarg?] *args parameter, or None',
|
|
408
448
|
'kwargs': '[AST_SymbolFunarg?] **kwargs parameter, or None',
|
|
409
|
-
'defaults':
|
|
449
|
+
'defaults':
|
|
450
|
+
'[Object] map of parameter name to default value expression',
|
|
410
451
|
'has_defaults': '[bool] True if any parameter has a default value',
|
|
411
|
-
'is_simple_func':
|
|
452
|
+
'is_simple_func':
|
|
453
|
+
'[bool] True if no starargs, no kwargs, and no defaults',
|
|
412
454
|
}
|
|
413
455
|
|
|
414
456
|
def _walk(self, visitor):
|
|
@@ -430,9 +472,12 @@ class AST_Lambda(AST_Scope):
|
|
|
430
472
|
'decorators': '[AST_Decorator*] function decorators, if any',
|
|
431
473
|
'is_generator': '[bool*] True iff this function is a generator',
|
|
432
474
|
'is_async': '[bool*] True iff this function is an async function',
|
|
433
|
-
'is_expression':
|
|
434
|
-
|
|
435
|
-
'
|
|
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)',
|
|
436
481
|
}
|
|
437
482
|
|
|
438
483
|
def _walk(self, visitor):
|
|
@@ -458,14 +503,26 @@ class AST_Class(AST_Scope):
|
|
|
458
503
|
'init': '[AST_Function] constructor for the class',
|
|
459
504
|
'parent': '[AST_Symbol?] parent class this class inherits from',
|
|
460
505
|
'bases': '[AST_Symbol*] list of base classes this class inherits from',
|
|
461
|
-
'static':
|
|
462
|
-
|
|
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',
|
|
463
512
|
'bound': '[string*] list of methods that need to be bound to self',
|
|
464
513
|
'decorators': '[AST_Decorator*] function decorators, if any',
|
|
465
514
|
'module_id': '[string] The id of the module this class is defined in',
|
|
466
|
-
'statements':
|
|
467
|
-
|
|
468
|
-
|
|
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',
|
|
469
526
|
}
|
|
470
527
|
|
|
471
528
|
def _walk(self, visitor):
|
|
@@ -493,13 +550,15 @@ class AST_Method(AST_Lambda):
|
|
|
493
550
|
|
|
494
551
|
|
|
495
552
|
class AST_Jump(AST_Statement):
|
|
496
|
-
"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`)'
|
|
497
555
|
|
|
498
556
|
|
|
499
557
|
class AST_Exit(AST_Jump):
|
|
500
558
|
'Base class for “exits” (`return` and `throw`)'
|
|
501
559
|
properties = {
|
|
502
|
-
'value': '[AST_Node?] the value returned or thrown by
|
|
560
|
+
'value': '[AST_Node?] the value returned or thrown by '
|
|
561
|
+
+ 'this statement; could be null for AST_Return'
|
|
503
562
|
}
|
|
504
563
|
|
|
505
564
|
def _walk(self, visitor):
|
|
@@ -555,7 +614,8 @@ class AST_If(AST_StatementWithBody):
|
|
|
555
614
|
'A `if` statement'
|
|
556
615
|
properties = {
|
|
557
616
|
'condition': '[AST_Node] the `if` condition',
|
|
558
|
-
'alternative':
|
|
617
|
+
'alternative':
|
|
618
|
+
'[AST_Statement?] the `else` part, or null if not present',
|
|
559
619
|
}
|
|
560
620
|
|
|
561
621
|
def _walk(self, visitor):
|
|
@@ -623,7 +683,8 @@ class AST_Else(AST_Block):
|
|
|
623
683
|
|
|
624
684
|
# VAR/CONST {{{
|
|
625
685
|
class AST_Definitions(AST_Statement):
|
|
626
|
-
'Base class for `var` or `const` nodes
|
|
686
|
+
'Base class for `var` or `const` nodes '
|
|
687
|
+
+'(variable declarations/initializations)'
|
|
627
688
|
properties = {
|
|
628
689
|
'definitions': '[AST_VarDef*] array of variable definitions'
|
|
629
690
|
}
|
|
@@ -729,7 +790,8 @@ class AST_ClassCall(AST_BaseCall):
|
|
|
729
790
|
|
|
730
791
|
|
|
731
792
|
class AST_New(AST_Call):
|
|
732
|
-
'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'
|
|
733
795
|
|
|
734
796
|
|
|
735
797
|
class AST_Seq(AST_Node):
|
|
@@ -797,7 +859,10 @@ class AST_PropAccess(AST_Node):
|
|
|
797
859
|
'Base class for property access expressions, i.e. `a.foo` or `a["foo"]`'
|
|
798
860
|
properties = {
|
|
799
861
|
'expression': '[AST_Node] the “container” expression',
|
|
800
|
-
'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",
|
|
801
866
|
}
|
|
802
867
|
|
|
803
868
|
|
|
@@ -823,8 +888,12 @@ class AST_Sub(AST_PropAccess):
|
|
|
823
888
|
class AST_ItemAccess(AST_PropAccess):
|
|
824
889
|
'Python index-style property access, i.e. `a.__getitem__("foo")`'
|
|
825
890
|
properties = {
|
|
826
|
-
'assignment':
|
|
827
|
-
|
|
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',
|
|
828
897
|
}
|
|
829
898
|
|
|
830
899
|
def _walk(self, visitor):
|
|
@@ -839,8 +908,10 @@ class AST_ItemAccess(AST_PropAccess):
|
|
|
839
908
|
class AST_Splice(AST_PropAccess):
|
|
840
909
|
'Index-style property access, i.e. `a[3:5]`'
|
|
841
910
|
properties = {
|
|
842
|
-
'property2':
|
|
843
|
-
|
|
911
|
+
'property2':
|
|
912
|
+
'[AST_Node] the 2nd property to access - '
|
|
913
|
+
+ 'typically ending index for the array.',
|
|
914
|
+
'assignment': '[AST_Node] The data being spliced in.',
|
|
844
915
|
}
|
|
845
916
|
|
|
846
917
|
def _walk(self, visitor):
|
|
@@ -855,8 +926,10 @@ class AST_Unary(AST_Node):
|
|
|
855
926
|
'Base class for unary expressions'
|
|
856
927
|
properties = {
|
|
857
928
|
'operator': '[string] the operator',
|
|
858
|
-
'expression':
|
|
859
|
-
|
|
929
|
+
'expression':
|
|
930
|
+
'[AST_Node] expression that this unary operator applies to',
|
|
931
|
+
'parenthesized':
|
|
932
|
+
'[bool] Whether this unary expression was parenthesized',
|
|
860
933
|
}
|
|
861
934
|
|
|
862
935
|
def _walk(self, visitor):
|
|
@@ -887,8 +960,14 @@ class AST_Binary(AST_Node):
|
|
|
887
960
|
class AST_Existential(AST_Node):
|
|
888
961
|
'Existential operator a?'
|
|
889
962
|
properties = {
|
|
890
|
-
'expression':
|
|
891
|
-
|
|
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',
|
|
892
971
|
}
|
|
893
972
|
|
|
894
973
|
def _walk(self, visitor):
|
|
@@ -919,9 +998,15 @@ class AST_Assign(AST_Binary):
|
|
|
919
998
|
'An assignment expression — `a = b + 5`'
|
|
920
999
|
|
|
921
1000
|
def is_chained(self):
|
|
922
|
-
return is_node_type(
|
|
923
|
-
|
|
924
|
-
|
|
1001
|
+
return is_node_type(
|
|
1002
|
+
self.right,
|
|
1003
|
+
AST_Assign
|
|
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
|
+
)
|
|
925
1010
|
)
|
|
926
1011
|
|
|
927
1012
|
def traverse_chain(self):
|
|
@@ -932,7 +1017,9 @@ class AST_Assign(AST_Binary):
|
|
|
932
1017
|
continue
|
|
933
1018
|
if is_node_type(right, AST_Seq):
|
|
934
1019
|
if is_node_type(right.car, AST_Assign):
|
|
935
|
-
right = new AST_Seq({
|
|
1020
|
+
right = new AST_Seq({
|
|
1021
|
+
'car': right.car.right, 'cdr': right.cdr
|
|
1022
|
+
})
|
|
936
1023
|
continue
|
|
937
1024
|
if is_node_type(right.cdr, AST_Assign):
|
|
938
1025
|
right = right.cdr.right
|
|
@@ -948,7 +1035,9 @@ class AST_Assign(AST_Binary):
|
|
|
948
1035
|
if is_node_type(next, AST_Seq):
|
|
949
1036
|
if is_node_type(next.cdr, AST_Assign):
|
|
950
1037
|
assign = next.cdr
|
|
951
|
-
left_hand_sides.push(new AST_Seq({
|
|
1038
|
+
left_hand_sides.push(new AST_Seq({
|
|
1039
|
+
'car': next.car, 'cdr': assign.left
|
|
1040
|
+
}))
|
|
952
1041
|
next = assign.right
|
|
953
1042
|
continue
|
|
954
1043
|
break
|
|
@@ -1011,7 +1100,9 @@ class AST_ObjectProperty(AST_Node):
|
|
|
1011
1100
|
'Base class for literal object properties'
|
|
1012
1101
|
properties = {
|
|
1013
1102
|
'key': '[AST_Node] the property expression',
|
|
1014
|
-
'value':
|
|
1103
|
+
'value':
|
|
1104
|
+
'[AST_Node] property value. For setters and '
|
|
1105
|
+
+ 'getters this is an AST_Function.',
|
|
1015
1106
|
'quoted': '',
|
|
1016
1107
|
}
|
|
1017
1108
|
|
|
@@ -1055,8 +1146,10 @@ class AST_Symbol(AST_Node):
|
|
|
1055
1146
|
'Base class for all symbols'
|
|
1056
1147
|
properties = {
|
|
1057
1148
|
'name': '[string] name of this symbol',
|
|
1058
|
-
'scope':
|
|
1059
|
-
|
|
1149
|
+
'scope':
|
|
1150
|
+
'[AST_Scope/S] the current scope '
|
|
1151
|
+
+ '(not necessarily the definition scope)',
|
|
1152
|
+
'thedef': '[SymbolDef/S] the definition of this symbol',
|
|
1060
1153
|
}
|
|
1061
1154
|
|
|
1062
1155
|
|
|
@@ -1065,7 +1158,8 @@ class AST_SymbolAlias(AST_Symbol):
|
|
|
1065
1158
|
|
|
1066
1159
|
|
|
1067
1160
|
class AST_SymbolDeclaration(AST_Symbol):
|
|
1068
|
-
'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)'
|
|
1069
1163
|
properties = {
|
|
1070
1164
|
'init': '[AST_Node*/S] array of initializers for this declaration.'
|
|
1071
1165
|
}
|
|
@@ -1089,7 +1183,8 @@ class AST_SymbolNonlocal(AST_SymbolDeclaration):
|
|
|
1089
1183
|
class AST_SymbolFunarg(AST_SymbolVar):
|
|
1090
1184
|
'Symbol naming a function argument, possibly with an annotation.'
|
|
1091
1185
|
properties = {
|
|
1092
|
-
'annotation':
|
|
1186
|
+
'annotation':
|
|
1187
|
+
'[AST_Node?] The annotation provided for this argument (if any)'
|
|
1093
1188
|
}
|
|
1094
1189
|
|
|
1095
1190
|
|
|
@@ -1207,7 +1302,10 @@ class TreeWalker:
|
|
|
1207
1302
|
|
|
1208
1303
|
def _visit(self, node, descend):
|
|
1209
1304
|
self.stack.push(node)
|
|
1210
|
-
ret = self.visit(
|
|
1305
|
+
ret = self.visit(
|
|
1306
|
+
node,
|
|
1307
|
+
((def (): descend.call(node);) if descend else noop)
|
|
1308
|
+
)
|
|
1211
1309
|
if not ret and descend:
|
|
1212
1310
|
descend.call(node)
|
|
1213
1311
|
|
|
@@ -1242,9 +1340,15 @@ class TreeWalker:
|
|
|
1242
1340
|
if is_node_type(p, AST_If) and p.condition is self
|
|
1243
1341
|
or is_node_type(p, AST_Conditional) and p.condition is self
|
|
1244
1342
|
or is_node_type(p, AST_DWLoop) and p.condition is self
|
|
1245
|
-
or is_node_type(
|
|
1343
|
+
or is_node_type(
|
|
1344
|
+
p,
|
|
1345
|
+
AST_UnaryPrefix
|
|
1346
|
+
) and p.operator is '!' and p.expression is self:
|
|
1246
1347
|
return True
|
|
1247
|
-
if not (
|
|
1348
|
+
if not (
|
|
1349
|
+
is_node_type(p, AST_Binary)
|
|
1350
|
+
and (p.operator is '&&' or p.operator is '||')
|
|
1351
|
+
):
|
|
1248
1352
|
return False
|
|
1249
1353
|
self = p
|
|
1250
1354
|
# }}}
|
|
@@ -1263,7 +1367,8 @@ def has_calls(expression):
|
|
|
1263
1367
|
return False
|
|
1264
1368
|
try:
|
|
1265
1369
|
expression.walk(new TreeWalker(def (node):
|
|
1266
|
-
if is_node_type(node, AST_BaseCall)
|
|
1370
|
+
if (is_node_type(node, AST_BaseCall)
|
|
1371
|
+
or is_node_type(node, AST_ItemAccess)):
|
|
1267
1372
|
raise Found()
|
|
1268
1373
|
))
|
|
1269
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'
|