问题标签 [transcrypt]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
156 浏览

python - 转码和放大镜代码

我试图通过 Transcrypt 将放大镜的 Javascript 程序移植到 Python 代码。不幸的是,我无法摆脱完全覆盖整个图像的放大镜框架。原始代码位于:https ://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_image_zoom

我用它做的 Python 代码是:

这是它的html:

有什么想法可能是错的吗?如果注释掉该行:

我根本看不到框架,它至少可以工作一半。但是在放大的空间周围有边界会很好。

0 投票
2 回答
78 浏览

transcrypt - Transcrypt 和 TranscryptFrame

现在,我正在开发一个名为 TranscryptFrame 的用于 transcrypt 的常用函数的包装器。我得到一个编译器错误,我想知道我们是否可以通过任何方式解决这个问题,也许只是代码中的一些小改动就可以让事情正常进行。

您需要在工作目录中有最新的 TranscryptFrame.py 文件进行编译。您可以在此处找到它:https ://github.com/bunkahle/Transcrypt-Examples/blob/master/dom/TranscryptFrame.py - 请随时建议对此文件或错误报告的更改或改进。它可能在将来的某个时候作为图书馆提供。

所以这里的代码甚至没有编译,我得到错误不能分配给函数调用。

这是运行它的html:

0 投票
1 回答
307 浏览

jquery - Transcrypt and Javascript this with jQuery

我想将此示例 html 文档翻译为 Transcrypt:

我的代码导致 hide.py:

运行 hide.html 时:

我收到错误 TypeError: (intermediate value).apply is not a function in the console window。

0 投票
1 回答
204 浏览

javascript - 无法以默认方式导出以在 chrome 版本 64.0.3282.186(官方构建)(64 位)上工作

我正在研究将 ES6 导入/导出添加到Transcrypt Python to JavaScript 编译器。作为为此目的的实验,我有以下代码:

和 testmodule.js:

和 testmain.js:

我得到:

使用正常的命名导出(因此没有默认值)它可以正常工作。我究竟做错了什么?

此外,如果我将 testmain.js 更改为以下内容,则它可以工作:

似乎 Chrome 对这个词没有做任何事情default,除了把它当作一个完全普通的名字吗?但这与以下内容相矛盾:

https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

0 投票
0 回答
133 浏览

javascript - 如何列出 ES 6 模块的所有导出名称以实现 Python 的“全局”功能

为了使Transcrypt Python to JavaScript 编译器适合使用 ES6 模块,我必须实现 Pythonglobals函数。

目前在转译期间,所有全局变量都被记住在一个名为__all__. 函数globals仅列出该变量的内容。

但是对于模块,所有导出的变量和函数都以单词为前缀export。所以我猜想 JS 解释器内部的某个地方有一个导出名称的列表或字典。

是否有可能以某种方式访问​​它,因此__all__不再需要该列表,从而产生更精简的目标代码?

[编辑]

当然,可以使用显式 ES6 导出列表代替export前缀。但 Transcrypt 也允许内联 JavaScript。并且从那里导出的带有export前缀的变量不会在该列表中,因此它不会是完整的。

0 投票
1 回答
83 浏览

javascript - 转加密预处理器

我想要一条建议:我想设置一个 python 开发环境,这样我就可以在 Python 中使用最多的代码,然后用 python 或使用 Transcrypt 编译它。为了给这个添加更多的盐,我想在使用 Python 编译时使用一些 py / pyd,在使用 Transcrypt 时使用一些 py / js。因此,我认为我需要一种预处理器来设置一个包装器,以根据选择的编译器直接调用 pyd 或 js 的方法。

在 python 和 Transcrypt 中可以进行这种预处理吗?

如果我不清楚,请随时告诉我。

非常感谢你的帮助

0 投票
1 回答
55 浏览

firefox - 无法让源地图在 Firefox 中工作

对于即将发布的Transcrypt Python to JS 编译器版本,添加了对 ES6 模块的支持。但是我无法让源映射在 Firefox 中工作,而在 Chrome 中它们可以完美地工作。我正在使用 Firefox Developer Edition 59.0b13(64 位) 我的问题是(Python)源文件没有显示在调试器的 Sources 窗格中。以下文件都在同一个目录中,由 node.js http-server 提供服务:

Python源码:

转成js:

和地图:

有人看到缺少什么吗?该页面在 Firefox 中看起来不错。只有地图不起作用。

0 投票
0 回答
249 浏览

javascript - 无法让模块在 node.js 中工作

我正在尝试使用 node.js v9.10.1 中的 ES 6 模块运行程序,使用该--experimental-modules选项。请注意,不使用 ES 6 模块的版本运行良好。

该模块是使用Transcrypt Python to JavaScript 编译器分支模块生成的。

它有以下代码:

错误报告说:

不太相关,但为了完整起见,该模块是从以下位置转译的:

0 投票
1 回答
461 浏览

javascript - ES6 named import introduces a const?

In implementing the Python module mechanism on top of ES6 modules for the Transcrypt Python to JavaScript compiler, I am faced with the following problem:

There are a large number of standard functions imported from the Python runtime module, like e.g. the Python input function (implemented in JS), which can be made available using named imports (since they shouldn't have to be prefixed with anything in the user code, so input rather than __runtime__.input, to be consistent with Python).

In Python it's allowed to rebind named imports. So I define another function input, which will override the one from the runtime. But if I do so in JS, I get an error:

Identifier 'input' has already been declared

It seems that all imported names are regarded as JS consts, so non-rebindable according to this article. I can think of several clever workarounds, like importing under an alias and then assigning to a module global var rather than const, but like to keep things simple, so my question is:

  • Am I right that JS named imports are consts, so non-rebindable (and if so, just curious, anyone knows WHY)? Where can I find details on this?
  • Is there a simple way to circumvent that and still put them in the global namespace of the importing module, but override them at will?
0 投票
2 回答
321 浏览

javascript - Python - 无法导入模块“PIL”

我已经编写了代码来压缩 .py 文件中的图像,并尝试使用 transcrypt 进行编译以转换为 JS 文件。在此过程中,我收到以下错误(屏幕截图)但是如果我使用 IDE 单独运行 .py 文件,它可以正常工作并压缩图像。

代码:

错误 :

截屏