我正在尝试使用“transcrypt -e 6”将一些简单的 Python 代码编译为 Javascript。当我使用 Python 的 re 模块中的 finditer 时,生成的 Javascript 代码在运行时有一个未捕获的异常。
Python:
import re
re_token = re.compile('\w+')
def tokenize(s):
positions = []
for m in re_token.finditer(s):
positions.append(m.start(0))
return positions
print(tokenize('select * from x'))
堆栈跟踪:
Uncaught Function {__class__: ƒ, __args__: Array(1), stack: "No stack trace available", __cause__: null}
(anonymous) @ x.js:2838
(anonymous) @ x.js:53
tokenize @ x.js:3566
(anonymous) @ VM68:1
栈顶元素:
get finditer () {return __get__ (this, function (self, string, pos, endpos) {
if (typeof endpos == 'undefined' || (endpos != null && endpos .hasOwnProperty ("__kwargtrans__"))) {;
var endpos = null;
};
var __except0__ = NotImplementedError ('No Iterator Support in es5');
__except0__.__cause__ = null;
throw __except0__;
});},