py2ecma 0.0.2.post4.dev0__py3-none-any.whl → 0.0.2.post9.dev0__py3-none-any.whl

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.
py2ecma/arguments.py CHANGED
@@ -56,6 +56,12 @@ def arg_parser() -> argparse.ArgumentParser:
56
56
  " the current directory.",
57
57
  metavar="dir",
58
58
  )
59
+ parser.add_argument(
60
+ "--imports",
61
+ dest="imports",
62
+ metavar="output.js",
63
+ help="List of imports that can be injected at the top of the bundle file",
64
+ )
59
65
  parser.add_argument(
60
66
  "-c",
61
67
  "--clean",
@@ -25,6 +25,16 @@ class SetComp(Node):
25
25
  elt: Node
26
26
  generators: List[Node]
27
27
 
28
+ def code(self):
29
+ yield "__set_comprehension__("
30
+ yield "("
31
+ yield self.generators[-1].target
32
+ yield ") => ("
33
+ yield self.elt
34
+ yield "), ["
35
+ yield self.join(", ", self.generators)
36
+ yield "])"
37
+
28
38
 
29
39
  @dataclass
30
40
  class GeneratorComp(Node):
@@ -8,7 +8,7 @@ class Node:
8
8
  def code(self):
9
9
  raise NotImplementedError(
10
10
  "Itermediate node type '{}'".format(self.__class__.__name__)
11
- + " is missing the code() method override"
11
+ + f" is missing the code() method override, issue is present in {self.__file__}"
12
12
  )
13
13
 
14
14
  @staticmethod
@@ -600,6 +600,8 @@ def class_body(tree, name, module, file_):
600
600
 
601
601
  def visit_FunctionDef(self, node):
602
602
  decorators = [n.id for n in node.decorator_list]
603
+ print("====================================================")
604
+ print(self.file)
603
605
  return CD.Method(
604
606
  __file__=self.file,
605
607
  name=node.name,
py2ecma/conf.py CHANGED
@@ -8,6 +8,7 @@ class TranspilerConfig:
8
8
  input_file: Path
9
9
  output_file: Path
10
10
  build_dir: Path
11
+ imports: Path | None
11
12
 
12
13
  clean_build: bool
13
14
  recursive: bool
@@ -22,6 +23,8 @@ class TranspilerConfig:
22
23
  self.input_file = Path(argparser.input)
23
24
  self.output_file = Path(argparser.output_file)
24
25
  self.build_dir = Path(argparser.build_dir)
26
+ self.imports = Path(argparser.imports) \
27
+ if argparser.imports is not None else None
25
28
 
26
29
  self.clean_build = argparser.clean
27
30
  self.recursive = argparser.recursive
@@ -76,7 +76,7 @@ def getdeps(filename):
76
76
  continue
77
77
  path = find_import_src(mod, filename)
78
78
  if path is None:
79
- logger.error("Could not find origin of module({})".format(mod))
79
+ logger.error(f"Could not find origin of module({mod}) for file {filename}")
80
80
  raise ImportError("Could not find: {}".format(mod))
81
81
  logger.info('dependency found: "{}"'.format(path))
82
82
  filepaths.append(path)
@@ -337,3 +337,4 @@ function __attribute__(cls, attr, value) {
337
337
  function __super__(t, o) {
338
338
 
339
339
  }
340
+ var Union = type(()=>{})
@@ -28,6 +28,31 @@ var __list_comprehension__ = (elt, generators, li) => {
28
28
  return li;
29
29
  }
30
30
 
31
+
32
+ var __set_comprehension__ = (elt, generators, li) => {
33
+ if (li === undefined) {
34
+ li = set();
35
+ }
36
+ if (generators.length > 1) {
37
+ var generator = generators[0];
38
+ for (let el of __Iterator__(generator.iter)) {
39
+ if (generator.ifs(el)) {
40
+ var tail = generators.slice(1);
41
+ tail[0].iter = el;
42
+ __set_comprehension__(elt, tail, li);
43
+ }
44
+ }
45
+ } else {
46
+ var generator = generators[0];
47
+ for (let el of __Iterator__(generator.iter)) {
48
+ if (generator.ifs(el)) {
49
+ li.add(elt(el));
50
+ }
51
+ }
52
+ }
53
+ return li;
54
+ }
55
+
31
56
  var __dict_comprehension__ = (elt, val, generators, li) => {
32
57
  if (li === undefined) {
33
58
  var li = dict();
@@ -1,4 +1,5 @@
1
1
  import os
2
+ from pathlib import Path
2
3
 
3
4
  from ..filesystem import loadsrc
4
5
 
@@ -50,10 +51,11 @@ def src_strings():
50
51
  return loadsrc(filepath)
51
52
 
52
53
 
53
- def jssources() -> str:
54
+ def jssources(imports: str | Path | None = None) -> str:
54
55
  return "\n".join(
55
56
  [
56
57
  src_base(),
58
+ loadsrc(str(imports)) if imports else "",
57
59
  src_exceptions(),
58
60
  src_builtins(),
59
61
  src_classes(),
@@ -1,10 +1,12 @@
1
1
  import ast
2
+ from pathlib import Path
2
3
 
3
4
  from .jsloader import jssources
4
5
 
5
6
 
6
- def package(cache):
7
- all = jssources() + "var __exports__ = {};\n"
7
+ def package(cache, imports: Path | None):
8
+
9
+ all = jssources(imports) + "var __exports__ = {};\n"
8
10
  for dep, src in cache.items():
9
11
  dep = dep.replace(".__init__", "")
10
12
  wsrc = wrap_iife(src)
@@ -1,8 +1,6 @@
1
- import _thread
2
- import builtins
1
+ #import _thread
3
2
  import copy
4
3
  import functools
5
- import inspect
6
4
  import keyword
7
5
  import re
8
6
  import sys
@@ -375,7 +373,7 @@ def _recursive_repr(user_function):
375
373
 
376
374
  @functools.wraps(user_function)
377
375
  def wrapper(self):
378
- key = id(self), _thread.get_ident()
376
+ key = id(self)
379
377
  if key in repr_running:
380
378
  return "..."
381
379
  repr_running.add(key)
@@ -397,8 +395,6 @@ def _create_fn(name, args, body, *, globals=None, locals=None, return_type=MISSI
397
395
  # __builtins__ may be the "builtins" module or
398
396
  # the value of its "__dict__",
399
397
  # so make sure "__builtins__" is the module.
400
- if globals is not None and "__builtins__" not in globals:
401
- globals["__builtins__"] = builtins
402
398
  return_annotation = ""
403
399
  if return_type is not MISSING:
404
400
  locals["_return_type"] = return_type
@@ -1005,9 +1001,9 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen):
1005
1001
  # we're here the overwriting is unconditional.
1006
1002
  cls.__hash__ = hash_action(cls, field_list)
1007
1003
 
1008
- if not getattr(cls, "__doc__"):
1009
- # Create a class doc-string.
1010
- cls.__doc__ = cls.__name__ + str(inspect.signature(cls)).replace(" -> None", "")
1004
+ #if not getattr(cls, "__doc__"):
1005
+ # # Create a class doc-string.
1006
+ # cls.__doc__ = cls.__name__ + str(inspect.signature(cls)).replace(" -> None", "")
1011
1007
 
1012
1008
  return cls
1013
1009
 
py2ecma/modules/types.py CHANGED
@@ -26,6 +26,7 @@ def _g():
26
26
 
27
27
 
28
28
  GeneratorType = type(_g())
29
+ Union = type(_g())
29
30
 
30
31
 
31
32
  def _c():
py2ecma/transpiler.py CHANGED
@@ -47,6 +47,7 @@ def transpiler(
47
47
  input_file: Path,
48
48
  output_file: Path,
49
49
  build_dir: Path,
50
+ imports: Path | None,
50
51
  clean_build: bool = False,
51
52
  minimize: bool = False,
52
53
  recursive: bool = True,
@@ -126,7 +127,7 @@ def transpiler(
126
127
  return __inner__
127
128
 
128
129
  def bundler(src_cache, output_file):
129
- bundle = package(src_cache)
130
+ bundle = package(src_cache, imports)
130
131
  if not minimize:
131
132
  import jsbeautifier # type: ignore
132
133
 
@@ -166,6 +167,7 @@ class Transpiler:
166
167
  input_file=self.config.input_file,
167
168
  output_file=self.config.output_file,
168
169
  build_dir=self.config.build_dir,
170
+ imports=self.config.imports,
169
171
  clean_build=self.config.clean_build,
170
172
  minimize=self.config.minimize,
171
173
  recursive=self.config.recursive,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py2ecma
3
- Version: 0.0.2.post4.dev0
3
+ Version: 0.0.2.post9.dev0
4
4
  Summary: # py2ecma
5
5
  Author-email: "Morten B. Rasmussen" <mbr@bitekspressen.dk>
6
6
  License-File: LICENSE-2.0.txt
@@ -1,43 +1,43 @@
1
1
  py2ecma/__init__.py,sha256=cO2VZ6o_Q-SlivDPmKCFxAwfWDmYMCOUy0x5hf89qG4,104
2
2
  py2ecma/__main__.py,sha256=d3djoNjV8aE7CTI3aWYUuwtKAtjwFjN33qdOgwY6CYQ,3746
3
- py2ecma/arguments.py,sha256=-PnNiW7lQ63DjSPQgsxnx7ZGBNPHNSkyyeymQqC2UNQ,4237
4
- py2ecma/conf.py,sha256=FPO4bX5QQtyLH_oUiUlHFtPv94TNPLMRjM3QNvwK5BU,1319
3
+ py2ecma/arguments.py,sha256=aqkWOxW9Xmtoy_zP4uMxQbDBOJJ4cNIaVcDUNeidC7o,4425
4
+ py2ecma/conf.py,sha256=68KB5UCr6h_af4XPlbcJjqtf-o970IFbe6ctGwBlRDE,1448
5
5
  py2ecma/filesystem.py,sha256=u9EVkD7FO1ZjXUbvsOdQNZd3Dv3dryc7jiFY-DBS1bo,3632
6
6
  py2ecma/get_logger.py,sha256=ddtDk-qBpQDglBDJ-1OlKxTnPrPmy1RnRsrKhoed2Gs,1679
7
7
  py2ecma/main.py,sha256=jKaaI_Bfht4NY-Ipqz5gJE_QD46kLSUK-IwXN3QX5Zg,1053
8
8
  py2ecma/progress.py,sha256=axxU-RFr5YOIzm97mZqwFV4_pDCEOMSIz9u-Bw1R0Uo,2463
9
9
  py2ecma/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- py2ecma/transpiler.py,sha256=mr2qwyl9-8C5_0dNMsNXwDjnu9XU_a0FQynsk2ZsBwI,6031
10
+ py2ecma/transpiler.py,sha256=B3XdADomuB63CZFM5sx_fO8VUkjxvOXzDVIQJsxCFps,6111
11
11
  py2ecma/codegenerator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  py2ecma/codegenerator/enums.py,sha256=X9bxx8GwK34QBs0sAc7e03VP14S0xXB7XRQ5asMrHIM,421
13
13
  py2ecma/codegenerator/nameconverter.py,sha256=BArqOsi6Rz7z3KFIsOjbD5haxskX8SVB6QCT5IZNCgo,183
14
14
  py2ecma/codegenerator/optimizer.py,sha256=8KB16vJ6FLPSovT-iEZ4cQmJmTUzia1Z1ygzZx0j3Pc,3337
15
- py2ecma/codegenerator/parser.py,sha256=NooTfy4-1mbbQWCcoWak0GP3NHTF0agcp3nuLDFBJwY,19649
15
+ py2ecma/codegenerator/parser.py,sha256=EiFcvNXgXuLWnbU9O6yYXfsZogr0B9nksgkozy85rMY,19752
16
16
  py2ecma/codegenerator/specialcases.py,sha256=shGyq6GkwBKDp6l-1f7pFsPCqp-zlVSUzqbnz0WfCmg,285
17
17
  py2ecma/codegenerator/traversers.py,sha256=WDPH1bYU7QuQcf2u3qAcfJoOX4XoUr3ESrvRyqy42GI,2415
18
18
  py2ecma/codegenerator/nintermediate/__init__.py,sha256=_QBYRhsMtSaoTdYVDm1jym69cJdlAVvDE82we-G27Cw,514
19
19
  py2ecma/codegenerator/nintermediate/asyncs.py,sha256=fHOddXWTH7ruzJZ5j8rjRGnqwmquCL1hgOLV1-bApQE,457
20
20
  py2ecma/codegenerator/nintermediate/classes.py,sha256=LHKCp7-cJ8X8NcWfGc7myCW5yJbT7hm78R8hKu-OyCo,8906
21
- py2ecma/codegenerator/nintermediate/comprehensions.py,sha256=0Tq-SJsR4DYVtITKPLIoyHeOzP4ZogJ5yk3dadfIO3o,1375
21
+ py2ecma/codegenerator/nintermediate/comprehensions.py,sha256=XvxoehlwIG5LepQ9f25EGm9fIIYbACriyJBE1urU7GU,1627
22
22
  py2ecma/codegenerator/nintermediate/controlflow.py,sha256=ft4TaVcN0DmCp7hICHYDFSF-vVeVoF-uYlRb8asBurk,2542
23
23
  py2ecma/codegenerator/nintermediate/expressions.py,sha256=eipRGyNqhCued2VBiWIyKW4ym31H0l_iH4yigeJIkYs,5068
24
24
  py2ecma/codegenerator/nintermediate/functions.py,sha256=N7hPqDD6iKR-CUmE601YIRTuBdZp-4E41EXT_UVu6XA,5099
25
25
  py2ecma/codegenerator/nintermediate/imports.py,sha256=euum89D_ijnRdNHPVhL5xJsA7NDdl-C1XkRtrsxHtd4,1246
26
26
  py2ecma/codegenerator/nintermediate/literals.py,sha256=9Pf4mMwZQLbOkrb5pCbW5FrkYyR4UYgd-tc1DDIeVK4,2580
27
27
  py2ecma/codegenerator/nintermediate/module.py,sha256=nlL0Z131ooP2cI1l_Pzks2UdbjbHOnzpMkUGqhFrmiM,2757
28
- py2ecma/codegenerator/nintermediate/node.py,sha256=f-cscR0Oc0uREgDlYrCXhsiRDVnfMupuqMGZRB_J7ZE,650
28
+ py2ecma/codegenerator/nintermediate/node.py,sha256=pW584VqL10LGyvXc6kDdvl9GgsFFQHoa4E09OO0pdAo,688
29
29
  py2ecma/codegenerator/nintermediate/statements.py,sha256=iqXiu2hGVqmGS16kxI94XYX06wrR52Wt95TUcrwobJw,1942
30
30
  py2ecma/codegenerator/nintermediate/subscripting.py,sha256=1uS2CWpu1l4QpaMn5B7R4XaBs95KWkb0Te8acREA6CM,1130
31
31
  py2ecma/codegenerator/nintermediate/variables.py,sha256=Z8lyxyzBknWW-JhF4300GLIi3m7o9J314wU0oqARPqo,359
32
32
  py2ecma/dependency/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
33
  py2ecma/dependency/excludes.py,sha256=zFr_YDFC3JrMFsgMMFMWtu4_k_V6-uJgjiJ3jcfEPFA,129
34
- py2ecma/dependency/getdeps.py,sha256=XTUyzwXRtu8AHCBCrRdDpZMsFa0ZSwBFZkG2d_v9RLQ,2555
34
+ py2ecma/dependency/getdeps.py,sha256=n3DlxkwwfExR2S4-b7R8LYOukJUa6JD14Z8BN-1u7EU,2567
35
35
  py2ecma/dependency/sortedset.py,sha256=1DTuDbM-InmvvV05wCC9dF0JnNZAPEsZ7nY2ngEoaNo,1633
36
36
  py2ecma/dependency/spec.py,sha256=J0UFMEly9jFUVV_ph8Mh0dODYvPkhtVcwYqpTTE7ZuE,1746
37
37
  py2ecma/javascript/base.js,sha256=5l88yppGN8NFk8W03FaY1jaLkc5D9tJic6cMQwpmtx8,14
38
- py2ecma/javascript/builtins.js,sha256=CTVXkmjXCaX5vLM_8xBdkE63rLbq6CTCNCi3bM5twSA,9690
38
+ py2ecma/javascript/builtins.js,sha256=dsRroAHx0jVa1_ybYPFcl0jI98yLex0Ru451sf8COsM,9715
39
39
  py2ecma/javascript/classes.js,sha256=u9FMZg8GYTrSeRVVijnAQSKEhTBnviS_2Dk7MV9WTYY,3663
40
- py2ecma/javascript/comprehensions.js,sha256=CgUl5baoYKXE3A6jFNZPckOCVlTTKNPD7inhgmRACt0,1530
40
+ py2ecma/javascript/comprehensions.js,sha256=1efYnxS_tbUVjQcL6g6YHWv2Wp8VkshnlZPGdoEnDpI,2190
41
41
  py2ecma/javascript/dict.js,sha256=nY3VLMj4AENiFIOY5mUZiNVavRgfAYFSrfVOugVLf9c,3596
42
42
  py2ecma/javascript/exceptions.js,sha256=v9sUGaZOnOSp2McX6dUoZzqMTz_ObHGpVFBsQxGRds4,1253
43
43
  py2ecma/javascript/list.js,sha256=GrCdWi1g_v4LT1xvKJ6Jvyvm6V6qeeqdeYWfbkC9yCE,5069
@@ -46,15 +46,15 @@ py2ecma/javascript/strings.js,sha256=8UMw-ZqQByOO1Zezfu1oAQDyiVNAyh63gy3gjW3ihak
46
46
  py2ecma/lexer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  py2ecma/lexer/syntaxtree.py,sha256=Fv96CboPqYOsLx6p_MJAprSdgw75Ut0-8hpiFFinYrc,97
48
48
  py2ecma/linker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
- py2ecma/linker/jsloader.py,sha256=SjoywgVgv_eO5wfqa_tJPBVMICjheIUCmrVhzqPaExo,1566
50
- py2ecma/linker/packager.py,sha256=XLBgZIVzkxqSc9hhFgJRQpk3qnvq5gGi1SffRh-wWTM,2629
49
+ py2ecma/linker/jsloader.py,sha256=mcIZ8jZu-i3yUoTIGMu2UNlU4gQLuU0KD_nbFRjt4yQ,1678
50
+ py2ecma/linker/packager.py,sha256=lp4eTJ56_vt_cx00gfILhPCAQqxsLjNW-KenWORJ42s,2684
51
51
  py2ecma/minimizer/__init__.py,sha256=olElkudzBUt6t1e4XTK43zC2PvIAuCqvNm6jR1M22OQ,68
52
52
  py2ecma/minimizer/closure.py,sha256=nCeIhP9Z0P9D23z_gUC7nhNXmyhOk-DRy3dfEM9nMdQ,1208
53
53
  py2ecma/modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  py2ecma/modules/codecs.py,sha256=qZF40YjS7viZSuSld8XuxWEQyWTZdp0oaJ1QTs__8f4,31840
55
55
  py2ecma/modules/collections.py,sha256=pMDHdBuKRV7KBZBERJIgPSCDo_Vr6SQeQcxtZS6Hg-0,47690
56
56
  py2ecma/modules/copy.py,sha256=MPrJxnzxQlK4fVbP0O1_mWoxL2Fb0V3Ao-fJNwi3VRc,1502
57
- py2ecma/modules/dataclasses.py,sha256=v1dPMMFihjiylPwmSr36iXhEmQagoPOA06bTsgS195E,47457
57
+ py2ecma/modules/dataclasses.py,sha256=tquw8-DECW8uS57OOQSg3DprMHsltOLT_JBKL6HzkFM,47304
58
58
  py2ecma/modules/datetime.py,sha256=5Yie6SUzoK0Tcj2KSfVxsXOKHwGJ8xC93jBnZ8hWLv0,64920
59
59
  py2ecma/modules/enum.py,sha256=WEKXEJoFKNbNQmUF_sWvY3AeQvkkOI-BrmBcugU1Drs,34265
60
60
  py2ecma/modules/functools.py,sha256=IgzH2k3akFlRDzANHkUrIj6CS6fIjhnl1EwYXeXge0E,32584
@@ -69,13 +69,13 @@ py2ecma/modules/sre_parse.py,sha256=eyd91zFcF6_SZB2MIL9QWr5n9Cfa6sLLdKYLBRX6JT8,
69
69
  py2ecma/modules/stubs.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
70
70
  py2ecma/modules/sys.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
71
71
  py2ecma/modules/time.py,sha256=eOKGgG8CtUfNR8EvXujdXVZy5565-z3rcN01VHDsO3Q,15545
72
- py2ecma/modules/types.py,sha256=VVpPhLE68OHfUGdZ1yspu5YStnirgQd8jyZoLfAt5rw,7646
72
+ py2ecma/modules/types.py,sha256=M1G-mjiRdPVdxRvYX_m6FIpn-BT5MB9TN5OLzc2EDrw,7665
73
73
  py2ecma/modules/re_/__init__.py,sha256=TgD5M2oW6huaeXOzzY2MpqCO9FLoll-258dKpsG99Kw,26420
74
74
  py2ecma/modules/re_/translate.py,sha256=sFyHTZTTL6Yr-D-e2vTIBgEcOLqpJz_9q7NsDn68FMs,10041
75
75
  py2ecma/watcher/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
76
76
  py2ecma/watcher/autocompile.py,sha256=HIXUYVu_9M-kGcN0i44L4gAb5gX3Npfho7D1slHwLoc,1409
77
- py2ecma-0.0.2.post4.dev0.dist-info/METADATA,sha256=I1Ty9ZcMWVQeIzV81AR9mj_1RQlxqqRu60lM-mvNA00,878
78
- py2ecma-0.0.2.post4.dev0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
79
- py2ecma-0.0.2.post4.dev0.dist-info/entry_points.txt,sha256=kZlFWLMxNs9wAL9VvTEILNxTdyC3liyWU9gpzxCLfD8,46
80
- py2ecma-0.0.2.post4.dev0.dist-info/licenses/LICENSE-2.0.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
81
- py2ecma-0.0.2.post4.dev0.dist-info/RECORD,,
77
+ py2ecma-0.0.2.post9.dev0.dist-info/METADATA,sha256=VI_SJo4yPHtZjMyzU0CszgEaTE63nY-k2ji3sONm3aI,878
78
+ py2ecma-0.0.2.post9.dev0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
79
+ py2ecma-0.0.2.post9.dev0.dist-info/entry_points.txt,sha256=kZlFWLMxNs9wAL9VvTEILNxTdyC3liyWU9gpzxCLfD8,46
80
+ py2ecma-0.0.2.post9.dev0.dist-info/licenses/LICENSE-2.0.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
81
+ py2ecma-0.0.2.post9.dev0.dist-info/RECORD,,