rapydscript-ns 0.9.3 → 0.9.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.
Files changed (98) hide show
  1. package/.agignore +1 -1
  2. package/.github/workflows/ci.yml +38 -38
  3. package/=template.pyj +5 -5
  4. package/CHANGELOG.md +9 -0
  5. package/HACKING.md +103 -103
  6. package/LICENSE +24 -24
  7. package/PYTHON_GAPS.md +48 -116
  8. package/README.md +35 -15
  9. package/TODO.md +1 -26
  10. package/add-toc-to-readme +2 -2
  11. package/bin/export +75 -75
  12. package/bin/rapydscript +0 -0
  13. package/bin/web-repl-export +102 -102
  14. package/build +2 -2
  15. package/language-service/index.js +9 -7
  16. package/package.json +1 -1
  17. package/publish.py +37 -37
  18. package/session.vim +4 -4
  19. package/setup.cfg +2 -2
  20. package/src/ast.pyj +6 -0
  21. package/src/baselib-containers.pyj +23 -1
  22. package/src/baselib-str.pyj +13 -2
  23. package/src/compiler.pyj +36 -36
  24. package/src/errors.pyj +30 -30
  25. package/src/lib/aes.pyj +646 -646
  26. package/src/lib/collections.pyj +227 -3
  27. package/src/lib/copy.pyj +120 -120
  28. package/src/lib/elementmaker.pyj +83 -83
  29. package/src/lib/encodings.pyj +126 -126
  30. package/src/lib/gettext.pyj +569 -569
  31. package/src/lib/itertools.pyj +580 -580
  32. package/src/lib/math.pyj +193 -193
  33. package/src/lib/operator.pyj +11 -11
  34. package/src/lib/pprint.pyj +455 -0
  35. package/src/lib/random.pyj +118 -118
  36. package/src/lib/react.pyj +74 -74
  37. package/src/lib/statistics.pyj +0 -0
  38. package/src/lib/traceback.pyj +63 -63
  39. package/src/lib/uuid.pyj +77 -77
  40. package/src/monaco-language-service/diagnostics.js +2 -2
  41. package/src/monaco-language-service/dts.js +550 -550
  42. package/src/output/codegen.pyj +4 -1
  43. package/src/output/comments.pyj +45 -45
  44. package/src/output/exceptions.pyj +201 -201
  45. package/src/output/jsx.pyj +164 -164
  46. package/src/output/treeshake.pyj +182 -182
  47. package/src/output/utils.pyj +72 -72
  48. package/src/parse.pyj +28 -7
  49. package/src/string_interpolation.pyj +72 -72
  50. package/src/tokenizer.pyj +18 -2
  51. package/src/unicode_aliases.pyj +576 -576
  52. package/src/utils.pyj +192 -192
  53. package/test/_import_one.pyj +37 -37
  54. package/test/_import_two/__init__.pyj +11 -11
  55. package/test/_import_two/level2/deep.pyj +4 -4
  56. package/test/_import_two/other.pyj +6 -6
  57. package/test/_import_two/sub.pyj +13 -13
  58. package/test/aes_vectors.pyj +421 -421
  59. package/test/annotations.pyj +80 -80
  60. package/test/baselib.pyj +23 -0
  61. package/test/chainmap.pyj +185 -0
  62. package/test/decorators.pyj +77 -77
  63. package/test/docstrings.pyj +39 -39
  64. package/test/elementmaker_test.pyj +45 -45
  65. package/test/functions.pyj +151 -151
  66. package/test/generators.pyj +41 -41
  67. package/test/generic.pyj +370 -370
  68. package/test/internationalization.pyj +73 -73
  69. package/test/lint.pyj +164 -164
  70. package/test/loops.pyj +85 -85
  71. package/test/numpy.pyj +734 -734
  72. package/test/pprint.pyj +232 -0
  73. package/test/repl.pyj +121 -121
  74. package/test/scoped_flags.pyj +76 -76
  75. package/test/statistics.pyj +224 -0
  76. package/test/unit/index.js +80 -0
  77. package/test/unit/language-service-completions.js +2 -0
  78. package/test/unit/language-service-dts.js +543 -543
  79. package/test/unit/language-service-hover.js +455 -455
  80. package/test/unit/language-service.js +63 -2
  81. package/test/unit/web-repl.js +323 -0
  82. package/tools/compiler.d.ts +367 -367
  83. package/tools/completer.js +131 -131
  84. package/tools/export.js +4 -2
  85. package/tools/gettext.js +185 -185
  86. package/tools/ini.js +65 -65
  87. package/tools/msgfmt.js +187 -187
  88. package/tools/repl.js +223 -223
  89. package/tools/test.js +118 -118
  90. package/tools/utils.js +128 -128
  91. package/tools/web_repl.js +95 -95
  92. package/try +41 -41
  93. package/web-repl/env.js +196 -196
  94. package/web-repl/index.html +163 -163
  95. package/web-repl/prism.css +139 -139
  96. package/web-repl/prism.js +113 -113
  97. package/web-repl/rapydscript.js +228 -226
  98. package/web-repl/sha1.js +25 -25
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "rapydscript-ns",
3
3
  "description": "Pythonic JavaScript that doesn't suck",
4
4
  "homepage": "https://github.com/ficocelliguy/rapydscript-ns",
5
- "version": "0.9.3",
5
+ "version": "0.9.4",
6
6
  "license": "BSD-2-Clause",
7
7
  "engines": {
8
8
  "node": ">=0.12.0"
package/publish.py CHANGED
@@ -1,37 +1,37 @@
1
- #!/usr/bin/env python
2
- # vim:fileencoding=utf-8
3
- # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
4
-
5
- import subprocess
6
- import os
7
- import shutil
8
- import json
9
-
10
- # Load metadata
11
- base = os.path.dirname(os.path.abspath(__file__))
12
- subprocess.check_call([os.path.join(base, 'build')])
13
- with open('package.json', 'rb') as f:
14
- m = json.load(f)
15
- version = m['version']
16
-
17
- # Update the files in release/ from dev/
18
- shutil.rmtree(os.path.join(base, 'release'))
19
- shutil.copytree(os.path.join(base, 'dev'), os.path.join(base, 'release'))
20
- subprocess.check_call(['git', 'add', os.path.join(base, 'release')])
21
- if subprocess.check_output(
22
- 'git status --porcelain --untracked-files release'.split()).strip():
23
- subprocess.check_call([
24
- 'git', 'commit', '-m', 'Updating release build of compiler'])
25
- subprocess.check_call('git push'.split())
26
-
27
- # Tag the release
28
- subprocess.check_call('git tag -s v{0} -m version-{0}'.format(version).split())
29
- subprocess.check_call(['git', 'push', 'origin', 'v'+version])
30
-
31
- # Update the web REPL
32
- gh_pages = os.path.join(os.path.dirname(base), 'kovidgoyal.github.io')
33
- subprocess.check_call([os.path.join(gh_pages, 'update-rapyd-repl.py')])
34
-
35
- # Publish to NPM
36
- subprocess.check_call(['npm', 'login'])
37
- subprocess.check_call(['npm', 'publish', base])
1
+ #!/usr/bin/env python
2
+ # vim:fileencoding=utf-8
3
+ # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
4
+
5
+ import subprocess
6
+ import os
7
+ import shutil
8
+ import json
9
+
10
+ # Load metadata
11
+ base = os.path.dirname(os.path.abspath(__file__))
12
+ subprocess.check_call([os.path.join(base, 'build')])
13
+ with open('package.json', 'rb') as f:
14
+ m = json.load(f)
15
+ version = m['version']
16
+
17
+ # Update the files in release/ from dev/
18
+ shutil.rmtree(os.path.join(base, 'release'))
19
+ shutil.copytree(os.path.join(base, 'dev'), os.path.join(base, 'release'))
20
+ subprocess.check_call(['git', 'add', os.path.join(base, 'release')])
21
+ if subprocess.check_output(
22
+ 'git status --porcelain --untracked-files release'.split()).strip():
23
+ subprocess.check_call([
24
+ 'git', 'commit', '-m', 'Updating release build of compiler'])
25
+ subprocess.check_call('git push'.split())
26
+
27
+ # Tag the release
28
+ subprocess.check_call('git tag -s v{0} -m version-{0}'.format(version).split())
29
+ subprocess.check_call(['git', 'push', 'origin', 'v'+version])
30
+
31
+ # Update the web REPL
32
+ gh_pages = os.path.join(os.path.dirname(base), 'kovidgoyal.github.io')
33
+ subprocess.check_call([os.path.join(gh_pages, 'update-rapyd-repl.py')])
34
+
35
+ # Publish to NPM
36
+ subprocess.check_call(['npm', 'login'])
37
+ subprocess.check_call(['npm', 'publish', base])
package/session.vim CHANGED
@@ -1,4 +1,4 @@
1
- set wildignore+=*.pyj-cached
2
- set wildignore+=node_modules
3
- imap <F4> ρσ_
4
- cmap <F4> ρσ_
1
+ set wildignore+=*.pyj-cached
2
+ set wildignore+=node_modules
3
+ imap <F4> ρσ_
4
+ cmap <F4> ρσ_
package/setup.cfg CHANGED
@@ -1,2 +1,2 @@
1
- [rapydscript]
2
- globals=assert,RapydScript
1
+ [rapydscript]
2
+ globals=assert,RapydScript
package/src/ast.pyj CHANGED
@@ -1280,6 +1280,12 @@ class AST_Number(AST_Constant):
1280
1280
  'value': "[number] the numeric value"
1281
1281
  }
1282
1282
 
1283
+ class AST_BigInt(AST_Constant):
1284
+ "A BigInt literal (e.g. 42n)"
1285
+ properties = {
1286
+ 'value': "[string] the raw numeric string (without n suffix)"
1287
+ }
1288
+
1283
1289
  class AST_RegExp(AST_Constant):
1284
1290
  "A regexp literal"
1285
1291
  properties = {
@@ -122,9 +122,22 @@ def ρσ_list_sort_key(value):
122
122
  t = jstype(value)
123
123
  if t is 'string' or t is 'number':
124
124
  return value
125
+ # Keep objects that define __lt__ unchanged so ρσ_list_sort_cmp can
126
+ # dispatch the dunder; everything else falls back to a string key.
127
+ if value is not None and value is not undefined and jstype(value.__lt__) is 'function':
128
+ return value
125
129
  return value.toString()
126
130
 
127
131
  def ρσ_list_sort_cmp(a, b, ap, bp):
132
+ # When the elements define __lt__, order them the Pythonic way via
133
+ # ρσ_op_lt (which also handles a reflected __gt__); otherwise compare
134
+ # the precomputed primitive keys directly.
135
+ if a is not None and a is not undefined and jstype(a.__lt__) is 'function':
136
+ if ρσ_op_lt(a, b):
137
+ return -1
138
+ if ρσ_op_lt(b, a):
139
+ return 1
140
+ return ap - bp
128
141
  if a < b:
129
142
  return -1
130
143
  if a > b:
@@ -132,8 +145,17 @@ def ρσ_list_sort_cmp(a, b, ap, bp):
132
145
  return ap - bp
133
146
 
134
147
  def ρσ_list_sort(key=None, reverse=False):
135
- key = key or ρσ_list_sort_key
136
148
  mult = -1 if reverse else 1
149
+ if key is not None and key is not undefined and jstype(key) is 'function' and key.length is 2:
150
+ # A two-argument function is treated as a comparator (à la
151
+ # functools.cmp_to_key) rather than a key function, so a JS-style
152
+ # `.sort((a, b) => ...)` callback works as expected.
153
+ cmpposmap = dict()
154
+ for v'var i=0; i < this.length; i++':
155
+ cmpposmap.set(this[i], i) # noqa:undef
156
+ Array.prototype.sort.call(this, def (a, b): return (mult * key(a, b)) or (cmpposmap.get(a) - cmpposmap.get(b));)
157
+ return
158
+ key = key or ρσ_list_sort_key
137
159
  keymap = dict()
138
160
  posmap = dict()
139
161
  for v'var i=0; i < this.length; i++':
@@ -111,8 +111,19 @@ define_str_func = def(name, func):
111
111
  if func.__argnames__:
112
112
  Object.defineProperty(f, '__argnames__', {'value':v"['string']".concat(func.__argnames__)})
113
113
 
114
- ρσ_orig_split = String.prototype.split.call.bind(String.prototype.split)
115
- ρσ_orig_replace = String.prototype.replace.call.bind(String.prototype.replace)
114
+ # Guard against multiple evaluations of the baselib in the same JS context
115
+ # (e.g. web_repl()/create_compiler() being called repeatedly). Without this,
116
+ # each eval captures the PREVIOUS patched String.prototype.split as ρσ_orig_split,
117
+ # creating a chain that eventually overflows the call stack.
118
+ if v'typeof globalThis !== "undefined" && globalThis._ρσ_orig_split':
119
+ ρσ_orig_split = v'globalThis._ρσ_orig_split'
120
+ ρσ_orig_replace = v'globalThis._ρσ_orig_replace'
121
+ else:
122
+ ρσ_orig_split = String.prototype.split.call.bind(String.prototype.split)
123
+ ρσ_orig_replace = String.prototype.replace.call.bind(String.prototype.replace)
124
+ if v'typeof globalThis !== "undefined"':
125
+ v'globalThis._ρσ_orig_split = ρσ_orig_split'
126
+ v'globalThis._ρσ_orig_replace = ρσ_orig_replace'
116
127
 
117
128
  # format() {{{
118
129
  define_str_func('format', def ():
package/src/compiler.pyj CHANGED
@@ -1,36 +1,36 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD
3
- # Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
- # globals: console
5
-
6
- from utils import DefaultsError, string_template
7
- from errors import ImportError, SyntaxError
8
- from tokenizer import ALL_KEYWORDS, IDENTIFIER_PAT, tokenizer
9
- from parse import parse, NATIVE_CLASSES, compile_time_decorators
10
- from output.stream import OutputStream
11
- from output.codegen import generate_code
12
- from output.treeshake import tree_shake
13
-
14
- generate_code() # create the print methods on the AST nodes
15
-
16
- # The following allows this module to be used from a pure javascript, require()
17
- # based environment like Node.js
18
- if jstype(exports) is 'object':
19
- exports.DefaultsError = DefaultsError
20
- exports.parse = parse
21
- exports.compile_time_decorators = compile_time_decorators
22
- exports.OutputStream = OutputStream
23
- exports.string_template = string_template # noqa:undef
24
- # Needed for REPL and linter
25
- exports.ALL_KEYWORDS = ALL_KEYWORDS
26
- exports.IDENTIFIER_PAT = IDENTIFIER_PAT
27
- exports.NATIVE_CLASSES = NATIVE_CLASSES
28
- exports.ImportError = ImportError
29
- exports.SyntaxError = SyntaxError
30
- exports.tokenizer = tokenizer
31
- exports.tree_shake = tree_shake
32
- # Magic! Export all the AST_* nodes
33
- ast = ρσ_modules['ast']
34
- for ast_node in ast:
35
- if ast_node.substr(0, 4) is 'AST_':
36
- exports[ast_node] = ast[ast_node] # noqa:undef
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD
3
+ # Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
+ # globals: console
5
+
6
+ from utils import DefaultsError, string_template
7
+ from errors import ImportError, SyntaxError
8
+ from tokenizer import ALL_KEYWORDS, IDENTIFIER_PAT, tokenizer
9
+ from parse import parse, NATIVE_CLASSES, compile_time_decorators
10
+ from output.stream import OutputStream
11
+ from output.codegen import generate_code
12
+ from output.treeshake import tree_shake
13
+
14
+ generate_code() # create the print methods on the AST nodes
15
+
16
+ # The following allows this module to be used from a pure javascript, require()
17
+ # based environment like Node.js
18
+ if jstype(exports) is 'object':
19
+ exports.DefaultsError = DefaultsError
20
+ exports.parse = parse
21
+ exports.compile_time_decorators = compile_time_decorators
22
+ exports.OutputStream = OutputStream
23
+ exports.string_template = string_template # noqa:undef
24
+ # Needed for REPL and linter
25
+ exports.ALL_KEYWORDS = ALL_KEYWORDS
26
+ exports.IDENTIFIER_PAT = IDENTIFIER_PAT
27
+ exports.NATIVE_CLASSES = NATIVE_CLASSES
28
+ exports.ImportError = ImportError
29
+ exports.SyntaxError = SyntaxError
30
+ exports.tokenizer = tokenizer
31
+ exports.tree_shake = tree_shake
32
+ # Magic! Export all the AST_* nodes
33
+ ast = ρσ_modules['ast']
34
+ for ast_node in ast:
35
+ if ast_node.substr(0, 4) is 'AST_':
36
+ exports[ast_node] = ast[ast_node] # noqa:undef
package/src/errors.pyj CHANGED
@@ -1,30 +1,30 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
- from __python__ import hash_literals
4
-
5
- class SyntaxError(Error):
6
-
7
- def __init__(self, message, filename, line, col, pos, is_eof):
8
- self.stack = Error().stack
9
- self.message = message
10
- self.line = line
11
- self.col = col
12
- self.pos = pos
13
- self.is_eof = is_eof
14
- self.filename = filename
15
- # The "standard" form for these error attributes
16
- self.lineNumber = line
17
- self.fileName = filename
18
-
19
- def toString(self):
20
- ans = self.message + " (line: " + self.line + ", col: " + self.col + ", pos: " + self.pos + ")"
21
- if self.filename:
22
- ans = self.filename + ':' + ans
23
- if self.stack:
24
- ans += "\n\n" + self.stack
25
- return ans
26
-
27
-
28
- class ImportError(SyntaxError):
29
- pass
30
-
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
+ from __python__ import hash_literals
4
+
5
+ class SyntaxError(Error):
6
+
7
+ def __init__(self, message, filename, line, col, pos, is_eof):
8
+ self.stack = Error().stack
9
+ self.message = message
10
+ self.line = line
11
+ self.col = col
12
+ self.pos = pos
13
+ self.is_eof = is_eof
14
+ self.filename = filename
15
+ # The "standard" form for these error attributes
16
+ self.lineNumber = line
17
+ self.fileName = filename
18
+
19
+ def toString(self):
20
+ ans = self.message + " (line: " + self.line + ", col: " + self.col + ", pos: " + self.pos + ")"
21
+ if self.filename:
22
+ ans = self.filename + ':' + ans
23
+ if self.stack:
24
+ ans += "\n\n" + self.stack
25
+ return ans
26
+
27
+
28
+ class ImportError(SyntaxError):
29
+ pass
30
+