[英]How to use await with traceur compiler on the fly?
I'm needing help to configure my browser to work with trace compiler. 我需要配置浏览器以与跟踪编译器一起使用的帮助。 I have tried of several ways to put a simple async code to work, but with no sucess yet.
我尝试了几种方法来运行简单的异步代码,但是还没有成功。 The code is the following:
代码如下:
<!DOCTYPE html>
<html>
<body>
<h1 id="message"></h1>
<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script type="module">
$traceurRuntime.options = traceur.util.Options.experimental();
console.log("t", traceur, "tr", $traceurRuntime, "tro", $traceurRuntime.options);
function changeTest(text) {
return new Promise().resolve(text+text);
}
async function run(text) {
var newText = await encrypt(text);
}
console.log(run("asdf"));
</script>
</body>
</html>
The traceur compiler link show that it should work is here . traceur编译器链接显示应在此处运行 。
The following error appears: 出现以下错误:
["file:///.../traceur_inline_script_1.js:8:8: Semi-colon expected", "file:///.../traceur_inline_script_1.js:9:9: Semi-colon expected"]
[“ file:///.../traceur_inline_script_1.js:8:8:应使用分号,”“ file:///.../traceur_inline_script_1.js:9:9:应使用分号”]
The tracerRuntimeOptions looks ok: tracerRuntimeOptions看起来不错:
Options {
arrowFunctions: true,
blockBinding: true,
classes: true,
computedPropertyNames: true,
defaultParameters: true…
}
annotations: true
arrayComprehension: true
arrowFunctions: true
asyncFunctions: true
asyncGenerators: true
atscript: (...)
blockBinding: true
classes: true
commentCallback: false
computedPropertyNames: true
debug: false
debugNames: false
defaultParameters: true
destructuring: true
experimental: (...)
exponentiation: true
exportFromExtended: true
forOf: true
forOn: true
freeVariableChecker: false
generatorComprehension: true
generators: true
inputSourceMap: false
lowResolutionSourceMap: false
memberVariables: true
moduleName: "default"
modules: (...)
modules_: "bootstrap"
numericLiterals: true
outputLanguage: "es5"
parseOptions: Object
properTailCalls: true
propertyMethods: true
propertyNameShorthand: true
referrer: ""
require: true
restParameters: true
script: false
sourceMaps: (...)
sourceMaps_: false
sourceRoot: false
sourceRoot_: false
spread: true
symbols: true
templateLiterals: true
transformOptions: Object
typeAssertionModule: null
typeAssertions: false
types: true
unicodeEscapeSequences: true
unicodeExpressions: true
validate: false
__proto__: Options
I tried several variations but no sucess yet. 我尝试了几种变体,但没有成功。 Someone can help me to write a working code?
有人可以帮助我编写有效的代码吗?
Thanks in advance. 提前致谢。
As noted above: 如上所述:
The truth I was misunderstanding how to use the Traceur transpiler.
事实是我误会了如何使用Traceur编译器。 I solved the problem by using something like grunt to compile the file to ECMAScript-7, then used the compiled output in my HTML page.
我通过使用grunt之类的文件将文件编译为ECMAScript-7来解决了该问题,然后在HTML页面中使用了编译后的输出。 The await operator works fine.
等待操作员工作正常。 When I have some time I will explain better, but this is the direction.
有时间的时候,我会解释得更好,但这就是方向。
References 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.