rapydscript-ns 0.9.4 → 0.9.5

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.
@@ -1,34 +1,34 @@
1
1
  {
2
- "ast": "1f915bd707f37c2eca90633cbe291b6c030e68a3",
2
+ "ast": "9c7c4c0132da3d1e4af19a00c1c0387423484a82",
3
3
  "baselib-builtins": "1be74e1e78642c5cbf448f8f2a94aae0f1a3d59c",
4
4
  "baselib-bytes": "057ab581c276ef03ce91fecdd4213e412198251c",
5
- "baselib-containers": "6c480319b9d2ba5d2ee9376e02b67fcd45375912",
6
- "baselib-errors": "c7e514d89ad79f2da41fe924f5ad93fc6f2cdf8e",
7
- "baselib-internal": "19a95012b2bc1d18c47262ac908a6017e5092f49",
5
+ "baselib-containers": "b25e5a999657f3195573679b9eb544cba48c52ba",
6
+ "baselib-errors": "b4c055341bca1943ede820c5d179cfa7e08bb3fe",
7
+ "baselib-internal": "11fb673a8eef58fad100c43e83ef5274e4b6694e",
8
8
  "baselib-itertools": "268b7b7af79506e9a01023e8cd3b1741599bb6a5",
9
- "baselib-str": "3fa63a0bf3bcf91cba4666093c3960633c6eed2e",
10
- "compiler": "4c728d81b441b4b9c590f9330271f54b47cc11eb",
11
- "errors": "d1b33848d19b141e19cc079cf78421f29b6d2c05",
12
- "output/__init__": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
13
- "output/classes": "469c47511692e04eb1bc2b079af3f65b47165865",
14
- "output/codegen": "69151b2cd53ff8b3270a122c65e1a0f56735150e",
15
- "output/comments": "78ec38d8b34da96c078653e2d0d4049d7003906b",
16
- "output/exceptions": "d45bc62bc6b011bae182ed7c8df8ea5e392f6fb8",
17
- "output/functions": "263416b49c60c78abee42fef83ec460e886fb243",
18
- "output/jsx": "0a174c39378155c19dfa669e833c14d63190127b",
19
- "output/literals": "287ec4222c79f1ebfa2c6efae925e794cbb931ab",
20
- "output/loops": "1c9bbd6a2772dd2fc287c0b1aebfac7f5426eb27",
21
- "output/modules": "8383da8f58a79921d24e4e0261360a7d0708c4db",
22
- "output/operators": "8f7b1cf4f8a91102fc04104f8a799dcd8849963e",
23
- "output/statements": "94ee0cd084f22aea451b96eb1a9a831084cc4267",
24
- "output/stream": "9bd250ebb7ee43374d69c24357f8c985f95397d4",
25
- "output/treeshake": "c1d65269ff21cfd046e947755a3489d0e670a74a",
26
- "output/utils": "595968f96f6fdcc51eb41c34d64c92bb595e3cb1",
27
- "parse": "d4ad97b80e3cbf810c55285bd47281bedfe027f9",
28
- "string_interpolation": "bff1cc76d772d24d35707f6c794f38734ca08376",
29
- "tokenizer": "7b8fb7855dc09aeeb16f6a513ae664951dd070e1",
30
- "unicode_aliases": "79ac6eaa5e6be44a5397d62c561f854a8fe7528e",
31
- "utils": "c1666db819aa7c8db38697e34e18362e3cb45869",
32
- "#compiler#": "ce0d8d902910ca87ffa150b4d56775144ed6ec25",
33
- "#compiled_with#": "ce0d8d902910ca87ffa150b4d56775144ed6ec25"
9
+ "baselib-str": "0183cdb36d8bee149e6bd50f03017e5baa1c49e6",
10
+ "compiler": "bb16e915c60dc4ffb5bfe98bef411736d19fa297",
11
+ "errors": "257eca38b6de987e5fd80672bec9b9981847e1bd",
12
+ "output\\classes": "fd465d02dc11e532be40d3d45d14bf57bc668ed0",
13
+ "output\\codegen": "aaf15f93f7ab0de23d9076cc5b1a9a415ffe5690",
14
+ "output\\comments": "63b39620f9d6f407aa2d4ddb557d1c60ef296b05",
15
+ "output\\exceptions": "e7d9119550403e6c5730d40b9bc9c923a23d6eb7",
16
+ "output\\functions": "263416b49c60c78abee42fef83ec460e886fb243",
17
+ "output\\jsx": "14f32c048301965de7764c5b74b651bc279de937",
18
+ "output\\literals": "287ec4222c79f1ebfa2c6efae925e794cbb931ab",
19
+ "output\\loops": "1c9bbd6a2772dd2fc287c0b1aebfac7f5426eb27",
20
+ "output\\modules": "8383da8f58a79921d24e4e0261360a7d0708c4db",
21
+ "output\\operators": "8f7b1cf4f8a91102fc04104f8a799dcd8849963e",
22
+ "output\\statements": "94ee0cd084f22aea451b96eb1a9a831084cc4267",
23
+ "output\\stream": "9bd250ebb7ee43374d69c24357f8c985f95397d4",
24
+ "output\\treeshake": "4a490ba097739d924db9e3cd9eb7718db5e24cae",
25
+ "output\\utils": "e957919bfccb9a3ab510d824a8f2ee3fc2689795",
26
+ "output\\__init__": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
27
+ "parse": "d3f79e2e958219ddea28d483e8b337abd16793f1",
28
+ "string_interpolation": "88dce6c2c5ee75126a6838a1506841c6531a0d15",
29
+ "tokenizer": "4a043b2805688a59a21eb99e57567c52ee7b3952",
30
+ "unicode_aliases": "7fbcbc9c24adcb2e33fac8d69aaafe5047fcc2c2",
31
+ "utils": "35a2a707c841da851e18c64edac54e7c20b7dfc9",
32
+ "#compiler#": "a8443467a8034f2a29d201a7264eb0cdbe61ff4e",
33
+ "#compiled_with#": "a8443467a8034f2a29d201a7264eb0cdbe61ff4e"
34
34
  }
package/src/ast.pyj CHANGED
@@ -605,6 +605,7 @@ class AST_Class(AST_Scope):
605
605
  'has_new': "[boolean] true if the class defines a __new__ method",
606
606
  'has_attr_dunders': "[boolean] true if the class defines any of __getattr__/__setattr__/__delattr__/__getattribute__",
607
607
  'class_kwargs': "[array] keyword arguments from class header (e.g. class C(Base, key=val):) as [[key_node, value_node], ...]",
608
+ 'slots': "[array|null] list of __slots__ attribute names, null if not defined",
608
609
  }
609
610
 
610
611
  def _walk(self, visitor):
@@ -93,7 +93,10 @@ def ρσ_list_remove(value):
93
93
  raise ValueError(value + ' not in list')
94
94
 
95
95
  def ρσ_list_to_string():
96
- return '[' + this.join(', ') + ']'
96
+ ans = v'[]'
97
+ for v'var i = 0; i < this.length; i++':
98
+ ans.push(ρσ_repr(this[i]))
99
+ return '[' + ans.join(', ') + ']'
97
100
 
98
101
  def ρσ_list_insert(index, val):
99
102
  if index < 0:
@@ -511,7 +514,13 @@ Object.defineProperties(ρσ_set.prototype, {
511
514
  r = iterator.next()
512
515
 
513
516
  ρσ_set.prototype.toString = ρσ_set.prototype.__repr__ = ρσ_set.prototype.__str__ = ρσ_set.prototype.inspect = def():
514
- return '{' + list(this).join(', ') + '}'
517
+ ans = v'[]'
518
+ iterator = this.jsset.values()
519
+ r = iterator.next()
520
+ while not r.done:
521
+ ans.push(ρσ_repr(r.value))
522
+ r = iterator.next()
523
+ return '{' + ans.join(', ') + '}'
515
524
 
516
525
  ρσ_set.prototype.__eq__ = def(other):
517
526
  if v'!other || !other.jsset':
@@ -653,7 +662,13 @@ Object.defineProperties(ρσ_frozenset.prototype, {
653
662
  return ans
654
663
 
655
664
  ρσ_frozenset.prototype.toString = ρσ_frozenset.prototype.__repr__ = ρσ_frozenset.prototype.__str__ = ρσ_frozenset.prototype.inspect = def():
656
- return 'frozenset({' + list(this).join(', ') + '})'
665
+ ans = v'[]'
666
+ iterator = this.jsset.values()
667
+ r = iterator.next()
668
+ while not r.done:
669
+ ans.push(ρσ_repr(r.value))
670
+ r = iterator.next()
671
+ return 'frozenset({' + ans.join(', ') + '})'
657
672
 
658
673
  ρσ_frozenset.prototype.__eq__ = def(other):
659
674
  if v'!other || !other.jsset':
@@ -8,8 +8,9 @@ v'var _ρσ_NativeError = Error'
8
8
 
9
9
  class Exception(Error):
10
10
 
11
- def __init__(self, message):
12
- self.message = message
11
+ def __init__(self):
12
+ self.args = v'Array.prototype.slice.call(arguments)'
13
+ self.message = self.args[0] if self.args.length > 0 else ''
13
14
  self.stack = v'_ρσ_NativeError'().stack
14
15
  self.name = self.constructor.name
15
16
 
@@ -57,7 +58,7 @@ def _is_exc_class(obj):
57
58
  class ExceptionGroup(Exception):
58
59
 
59
60
  def __init__(self, message, exceptions):
60
- Exception.__init__(self, message)
61
+ Exception.__init__(self, message, exceptions)
61
62
  self.exceptions = exceptions if exceptions else []
62
63
 
63
64
  def subgroup(self, condition):
@@ -385,37 +385,49 @@ def ρσ_op_pow(a, b):
385
385
  def ρσ_op_and(a, b):
386
386
  if a is not None and jstype(a.__and__) is 'function': return a.__and__(b)
387
387
  if b is not None and jstype(b.__rand__) is 'function': return b.__rand__(a)
388
- if (jstype(a) is 'bigint') is not (jstype(b) is 'bigint'):
389
- raise TypeError("unsupported operand type(s) for &: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
390
- return v'a & b'
388
+ ta = jstype(a)
389
+ tb = jstype(b)
390
+ if (ta is 'number' or ta is 'boolean') and (tb is 'number' or tb is 'boolean'): return v'a & b'
391
+ if ta is 'bigint' and tb is 'bigint': return v'a & b'
392
+ raise TypeError("unsupported operand type(s) for &: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
391
393
 
392
394
  def ρσ_op_or(a, b):
393
395
  if a is not None and jstype(a.__or__) is 'function': return a.__or__(b)
394
396
  if b is not None and jstype(b.__ror__) is 'function': return b.__ror__(a)
395
- if (jstype(a) is 'bigint') is not (jstype(b) is 'bigint'):
396
- raise TypeError("unsupported operand type(s) for |: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
397
- return v'a | b'
397
+ ta = jstype(a)
398
+ tb = jstype(b)
399
+ if ta is 'object' and tb is 'object' and a is not None and b is not None and not Array.isArray(a) and not Array.isArray(b) and v'a.constructor === Object' and v'b.constructor === Object':
400
+ return Object.assign({}, a, b)
401
+ if (ta is 'number' or ta is 'boolean') and (tb is 'number' or tb is 'boolean'): return v'a | b'
402
+ if ta is 'bigint' and tb is 'bigint': return v'a | b'
403
+ raise TypeError("unsupported operand type(s) for |: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
398
404
 
399
405
  def ρσ_op_xor(a, b):
400
406
  if a is not None and jstype(a.__xor__) is 'function': return a.__xor__(b)
401
407
  if b is not None and jstype(b.__rxor__) is 'function': return b.__rxor__(a)
402
- if (jstype(a) is 'bigint') is not (jstype(b) is 'bigint'):
403
- raise TypeError("unsupported operand type(s) for ^: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
404
- return v'a ^ b'
408
+ ta = jstype(a)
409
+ tb = jstype(b)
410
+ if (ta is 'number' or ta is 'boolean') and (tb is 'number' or tb is 'boolean'): return v'a ^ b'
411
+ if ta is 'bigint' and tb is 'bigint': return v'a ^ b'
412
+ raise TypeError("unsupported operand type(s) for ^: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
405
413
 
406
414
  def ρσ_op_lshift(a, b):
407
415
  if a is not None and jstype(a.__lshift__) is 'function': return a.__lshift__(b)
408
416
  if b is not None and jstype(b.__rlshift__) is 'function': return b.__rlshift__(a)
409
- if (jstype(a) is 'bigint') is not (jstype(b) is 'bigint'):
410
- raise TypeError("unsupported operand type(s) for <<: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
411
- return v'a << b'
417
+ ta = jstype(a)
418
+ tb = jstype(b)
419
+ if (ta is 'number' or ta is 'boolean') and (tb is 'number' or tb is 'boolean'): return v'a << b'
420
+ if ta is 'bigint' and tb is 'bigint': return v'a << b'
421
+ raise TypeError("unsupported operand type(s) for <<: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
412
422
 
413
423
  def ρσ_op_rshift(a, b):
414
424
  if a is not None and jstype(a.__rshift__) is 'function': return a.__rshift__(b)
415
425
  if b is not None and jstype(b.__rrshift__) is 'function': return b.__rrshift__(a)
416
- if (jstype(a) is 'bigint') is not (jstype(b) is 'bigint'):
417
- raise TypeError("unsupported operand type(s) for >>: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
418
- return v'a >> b'
426
+ ta = jstype(a)
427
+ tb = jstype(b)
428
+ if (ta is 'number' or ta is 'boolean') and (tb is 'number' or tb is 'boolean'): return v'a >> b'
429
+ if ta is 'bigint' and tb is 'bigint': return v'a >> b'
430
+ raise TypeError("unsupported operand type(s) for >>: '" + ρσ_arith_type_name(a) + "' and '" + ρσ_arith_type_name(b) + "'")
419
431
 
420
432
  # Ordered-comparison operator overloading helpers.
421
433
  # ρσ_op_lt dispatches __lt__ (forward) then __gt__ (reflected), handles lists
@@ -505,15 +517,22 @@ def ρσ_list_iadd(a, b):
505
517
  # Unary operator overloading helpers
506
518
  def ρσ_op_neg(a):
507
519
  if a is not None and jstype(a.__neg__) is 'function': return a.__neg__()
508
- return -a
520
+ ta = jstype(a)
521
+ if ta is 'number' or ta is 'boolean' or ta is 'bigint': return -a
522
+ raise TypeError("bad operand type for unary -: '" + ρσ_arith_type_name(a) + "'")
509
523
 
510
524
  def ρσ_op_pos(a):
511
525
  if a is not None and jstype(a.__pos__) is 'function': return a.__pos__()
512
- return +a
526
+ ta = jstype(a)
527
+ if ta is 'number' or ta is 'boolean': return +a
528
+ if ta is 'bigint': return a
529
+ raise TypeError("bad operand type for unary +: '" + ρσ_arith_type_name(a) + "'")
513
530
 
514
531
  def ρσ_op_invert(a):
515
532
  if a is not None and jstype(a.__invert__) is 'function': return a.__invert__()
516
- return ~a
533
+ ta = jstype(a)
534
+ if ta is 'number' or ta is 'boolean' or ta is 'bigint': return ~a
535
+ raise TypeError("bad operand type for unary ~: '" + ρσ_arith_type_name(a) + "'")
517
536
 
518
537
  # Augmented-assignment helpers: try __i<op>__ first, fall back to binary op
519
538
  def ρσ_op_iadd(a, b):
@@ -550,6 +569,11 @@ def ρσ_op_iand(a, b):
550
569
 
551
570
  def ρσ_op_ior(a, b):
552
571
  if a is not None and jstype(a.__ior__) is 'function': return a.__ior__(b)
572
+ ta = jstype(a)
573
+ tb = jstype(b)
574
+ if ta is 'object' and tb is 'object' and a is not None and b is not None and not Array.isArray(a) and not Array.isArray(b) and v'a.constructor === Object' and v'b.constructor === Object':
575
+ Object.assign(a, b)
576
+ return a
553
577
  return ρσ_op_or(a, b)
554
578
 
555
579
  def ρσ_op_ixor(a, b):
@@ -766,6 +790,11 @@ v'var ρσ_proxy_target_symbol = typeof Symbol === "function" ? Symbol("ρσ_pro
766
790
  if jstype(target.__setattr__) is 'function':
767
791
  target.__setattr__.call(receiver, prop, value)
768
792
  return True
793
+ # __slots__ enforcement: check if the class restricts instance attributes.
794
+ if jstype(prop) is 'string' and prop[0] is not 'ρ':
795
+ slots = v'target.constructor && target.constructor.prototype.__ρσ_slots__'
796
+ if slots and not v'slots.hasOwnProperty(prop)':
797
+ raise AttributeError("'" + (target.constructor.__name__ or 'object') + "' object has no attribute '" + prop + "'")
769
798
  # Pass 'target' as receiver (not proxy) to avoid infinite recursion through the Proxy set trap.
770
799
  return v'Reflect.set(target, prop, value, target)'
771
800
  ,
@@ -23,7 +23,7 @@ def ρσ_repr_js_builtin(x, as_array):
23
23
  keys = Object.keys(x)
24
24
  for v'var k = 0; k < keys.length; k++':
25
25
  key = keys[k]
26
- ans.push(JSON.stringify(key) + ':' + ρσ_repr(x[key]))
26
+ ans.push(ρσ_repr(key) + ': ' + ρσ_repr(x[key]))
27
27
  return b[0] + ans.join(', ') + b[1]
28
28
 
29
29
  def ρσ_html_element_to_string(elem):
@@ -49,6 +49,8 @@ def ρσ_repr(x):
49
49
  ans = x.__repr__()
50
50
  elif x is True or x is False:
51
51
  ans = 'True' if x else 'False'
52
+ elif jstype(x) is 'string':
53
+ ans = "'" + x.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t") + "'"
52
54
  elif Array.isArray(x):
53
55
  ans = ρσ_repr_js_builtin(x, True)
54
56
  elif jstype(x) is 'function':
@@ -452,7 +452,8 @@ export class CompletionEngine {
452
452
  }
453
453
  // Walk remaining path segments through member types
454
454
  for (let i = 1; i < parts.length && ti; i++) {
455
- const member = ti.members ? ti.members.get(parts[i]) : null;
455
+ const all = this._dts.getAllMembers(ti);
456
+ const member = all.get(parts[i]) || null;
456
457
  if (!member) { ti = null; break; }
457
458
  if (member.members) {
458
459
  ti = member;
@@ -462,8 +463,9 @@ export class CompletionEngine {
462
463
  ti = null;
463
464
  }
464
465
  }
465
- if (ti && ti.members) {
466
- for (const [name, member] of ti.members) {
466
+ if (ti) {
467
+ const all_members = this._dts.getAllMembers(ti);
468
+ for (const [name, member] of all_members) {
467
469
  if (!ctx.prefix || name.startsWith(ctx.prefix)) {
468
470
  items.push(_dts_member_to_item(member, range, monacoKind));
469
471
  }
@@ -583,13 +585,16 @@ export class CompletionEngine {
583
585
  const member_ti = this._dts.getMemberInfo(object_path, method_name);
584
586
  if (member_ti && member_ti.return_type) {
585
587
  const return_ti = this._dts.getGlobal(resolve_first_type(member_ti.return_type));
586
- if (return_ti && return_ti.members) {
587
- scope_matched = true;
588
- for (const [name, member] of return_ti.members) {
589
- if (!ctx.prefix || name.startsWith(ctx.prefix)) {
590
- if (!seen.has(name)) {
591
- seen.add(name);
592
- items.push(_dts_member_to_item(member, range, monacoKind));
588
+ if (return_ti) {
589
+ const rt_members = this._dts.getAllMembers(return_ti);
590
+ if (rt_members.size > 0) {
591
+ scope_matched = true;
592
+ for (const [name, member] of rt_members) {
593
+ if (!ctx.prefix || name.startsWith(ctx.prefix)) {
594
+ if (!seen.has(name)) {
595
+ seen.add(name);
596
+ items.push(_dts_member_to_item(member, range, monacoKind));
597
+ }
593
598
  }
594
599
  }
595
600
  }
@@ -606,8 +611,9 @@ export class CompletionEngine {
606
611
  if (ti && !ti.members && ti.return_type) {
607
612
  ti = this._dts.getGlobal(resolve_first_type(ti.return_type));
608
613
  }
609
- if (ti && ti.members) {
610
- for (const [name, member] of ti.members) {
614
+ if (ti) {
615
+ const all_members = this._dts.getAllMembers(ti);
616
+ for (const [name, member] of all_members) {
611
617
  if (!ctx.prefix || name.startsWith(ctx.prefix)) {
612
618
  if (!seen.has(name)) {
613
619
  seen.add(name);
@@ -642,8 +648,9 @@ export class CompletionEngine {
642
648
  }
643
649
  if (member_ti && member_ti.return_type) {
644
650
  const return_ti = this._dts.getGlobal(resolve_first_type(member_ti.return_type));
645
- if (return_ti && return_ti.members) {
646
- for (const [name, member] of return_ti.members) {
651
+ if (return_ti) {
652
+ const all_members = this._dts.getAllMembers(return_ti);
653
+ for (const [name, member] of all_members) {
647
654
  if (!ctx.prefix || name.startsWith(ctx.prefix)) {
648
655
  seen.add(name);
649
656
  items.push(_dts_member_to_item(member, range, monacoKind));