问题标签 [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 回答
103 浏览

python - 了解 Transcrypt 自动测试如何记录代码

自动测试是 Transcrypt 文档不可分割的一部分。但是,我很难理解它们如何揭示预期的行为。例如在: https : //github.com/QQuick/Transcrypt/blob/master/transcrypt/development/automated_tests/transcrypt/proxies/init .py

我真的不知道什么是正确/预期的答案。如何解释如下测试?

0 投票
1 回答
181 浏览

javascript - Transpiling boolean.py package to javascript with Transcrypt

I would like some help transpiling a relatively simple python package called boolean.py (the package does boolean algebra operations) into javascript using transcrypt as my transpiler of choice.

Things I have done so far:

  1. Dropped using inspect module which seems to not be supported by transcrypt
  2. Switched to explicit SuperClassName.__init__() calls instead of super(SuperClassName, self).__init__() in python code because transcrypt only supports simple single-case inheritance (and python 3 syntax).

You can find the current code here in this github branch called transcrypt.

Now, the good news is that boolean.py is essentially a single .py file under boolean/boolean.py, everything else is just python project structure. The bad news is that boolean.py runs on both python2 and python3 and I don't know if that is what causes the current issue that I am about to describe:

Having read the relevant sections of transcrypt docs, I transpile the file:

This gives me a single harmless warning about basestring and creates the __javascript__ folder with boolean.js and boolean.min.js. So far, so good.

Next to the __javascript__ folder I create boolean.html to test:

However, when I load boolean.html in firefox, the console gives a warning:

Instead, what I am expecting to see is a boolean object that has BooleanAlgebra subobject. Refer to hello and pong examples of transcrypt to see that it creates hello and pong objects on window accordingly.

Could you help explain what I am doing wrong here?

0 投票
1 回答
479 浏览

python - Python 3.6 AST 模块无法识别异步方法

Transcrypt Python to JavaScript 编译器中实现协程时,我遇到了以下奇怪的问题。

Transcrypt 使用 CPython 3.6 的本机解析器来生成 AST。对于异步全局函数 defs,它会生成一个 AsyncFunctionDef 节点。但是对于异步方法,它没有!尽管如此,CPython 本身似乎可以正确编译异步方法。

所以下面这段代码使用 CPython 运行,但 Transcrypt 无法运行它,因为 CPython 的 AST 模块生成的 AST 似乎缺少方法的 AsyncFunctionDef 节点(与全局函数相反)。

因此,以下代码不会生成 AsyncFunctionDef 节点:

我错过了什么?官方支持异步方法,不是吗?在PEP 492中找不到任何具体内容。

该示例的完整代码为:

0 投票
1 回答
302 浏览

github - 在自述文件中包含许可证文件

我有一个文件 README.rst 用于 PyPi 和 GitHub。

由于我还想在 GitHub 上包含一个许可证文件,因此它包含以下行:

但是,这既不适用于 PyPi(整个文件未正确解析),也不适用于 GitHub(忽略包含指令)

谁能阐明我做错了什么?

0 投票
1 回答
160 浏览

javascript - 获取 Transcrypt 以输出可读文件

我正在尝试使用 Transcrypt 翻译以下测试代码:

输出是一个 2447 行文件:

我怎样才能让 Transcrypt 为这个输入生成健全的输出?谢谢

0 投票
1 回答
2575 浏览

javascript - 如何在 React Native 应用程序中使用 python 代码?

我想使用 React Native 作为前端和在 python 中实现的核心逻辑。如何实施?是否有用于 js 的 python 包装器,支持 react native

0 投票
1 回答
484 浏览

python - 获取没有垃圾的子进程的输出

Transcrypt Python to JavaScript 编译器中,我使用以下代码通过子进程传输数据:

我的子进程是一个 Windows .bat 文件,其中包含:

capitalize.py 的内容是:

如果变量sourceCode最初包含:

结果变量targetCode将包含:

换句话说,命令的回显被附加到标准输出,正如可以预料的那样。

如果我使用 启动命令文件echo off,则会得到回显,因此无济于事。

如何更改 subprocess.Popen 的代码(或围绕它的代码),使其targetCode仅包含:

我尝试了很多事情,包括echo off在各个地方使用和重新分配标准输出。而且我一直在谷歌上搜索很多,但没有找到解决方案。任何人都知道如何解决这个问题?

[EDIT1] @Mahesh Karia

我试过了:

这在打印 111 后挂起。

[编辑1]

我通过使用可执行文件(从 C++ 翻译)而不是 .bat 或 .py 文件作为过滤器解决了我的问题。这不会产生任何控制台回声。

输入数据必须以终止字符结尾,在这种情况下,我使用了 '\f':

0 投票
1 回答
64 浏览

javascript - 使用 Transcrypt 覆盖方法

在 Python 中,覆盖方法是有效的,例如:

这将打印alternative. 但是在转换为 Javascript 之后,你会得到错误:Uncaught TypeError: Cannot set property original of function....

当然,这与它被转换为:

whereoriginal是一个不能以这种方式覆盖的属性。

有解决方法吗?在某些情况下,具有这种行为可能很有用。此致

0 投票
3 回答
813 浏览

transcrypt - transcrypt 问题 - 无法运行示例程序

按照 transcrypt "getting started" 文档中的说明,我在单独的目录中输入了示例 'hello.html' 和 'hello.py'。

从命令行输入:“transcrypt -b -m hello.py”导致错误消息:“'transcrypt' 未被识别为内部或外部命令、可运行程序或批处理文件。”

我正在使用 python3.6,transcrypt 安装在:C:\program files\python36\lib\site-packages\transcrypt

任何帮助激活示例 hello.html 将不胜感激。

0 投票
1 回答
175 浏览

python - 转加密连接池错误

我对编码和 Web 开发非常陌生。我是一名系统工程师,希望进入 Web 开发方面。我学习了一些 Python 教程并拼凑了一个(可能非常)粗糙的 Python 应用程序。我现在想将该应用程序放在我创建的网站上,这样我就可以允许办公室中的其他人也使用该实用程序。

为此,我安装了 transcrypt,目的是将 python 代码转换为 javascript。运行 transcrypt 时,我得到以下输出:

编译时出错(最后一个有问题的文件):文件 'c:/Scripting/Transcrypt/Meraki.py',第 1 行,在导入:文件 'c:/users/dab404/appdata/local/programs/python/python36/lib /site-packages/requests/ init .py',第 43 行,在导入:文件'c:/users/dab404/appdata/local/programs/python/python36/lib/site-packages/urllib3/ init .py' ,第8行,即: Attempt to import module: connectionpool Can't find any of: c:/Scripting/Transcrypt/connectionpool.py c:/Scripting/Transcrypt/ javascript /connectionpool.mod.js

该错误继续列出它需要运行的大约 10 个其他文件。我不知道如何解决这个问题,如果有人能给我任何帮助,我将不胜感激。

这是我的代码:

谢谢!大卫