问题标签 [traceur]

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 投票
0 回答
109 浏览

javascript - 使用任何 ecma6 转译器将现有的 require.js 项目编译为单个工作文件

我们有一个大量使用 require 的现有 ecma5 javascript 项目。在生产中,我们使用 require 的 r.js 将它们全部编译到一个文件中。我们想开始过渡到 ecma6,我们的第一个障碍是将现有代码编译到单个文件中并工作。

我做了一个简单的项目,将一些文本放在正文中。这是 github(可以在那里找到简短的设置说明):

https://github.com/cjbrass/ecma6-test

dev.html 使用 src 文件,并且工作得很好。live.html 使用构建的文件,我们似乎无法让它工作。结构编译任务运行,并生成适当的文件,但 javascript 不起作用。

我们目前正在使用traceur,并且已经尝试过babel,但对两者都没有特别的依恋。我们只想让它与任何 ecma6 转译器一起工作。

我找不到任何好的例子来作为我们工作的基础,所以我们觉得我们在黑暗中飞行,需要一些方向。

0 投票
1 回答
490 浏览

javascript - ES6 在 Firefox、Edge、Vivaldi 中通过 jspm 错误,但在 Chrome、Opera 中有效

我根据 jspm 教程通过jspm + SystemJS + traceur使用 ES6。

在 Chrome 和 Opera 中一切正常,但是,控制台会在其他浏览器中发布各种错误。

火狐:SyntaxError: class is a reserved identifier, uncaught exception: SyntaxError: class is a reserved identifier

边缘:SCRIPT1002: Syntax error, Potentially unhandled rejection [2] Syntax error

维瓦尔第:Unexpected token =>

SystemJS 自述文件指出它甚至可以运行 IE8+。

我的jspm.config.js

并且package.json

据我了解,急于解决这种情况可能有很多原因。也许有人在该设置中遇到了类似的问题。

0 投票
0 回答
119 浏览

javascript - 如何使用带有嵌套目录结构的 Traceur?

我想在我的下一个项目中使用 ES6,为此我使用 Traceur 作为转译器。我让它按照入门指南中描述的方式工作。但是,我想以他们在“离线编译”页面上描述的方式将我的所有源文件编译成单个缩小文件。但我无法让它与嵌套目录结构中组织的多个源文件一起工作。

这是一个解释问题的示例项目。它在根文件夹中有 index.html,在 src 下有两个 .js 文件。

索引.html

src/one.js

src/two.js

正如我所说,如果我在浏览器中打开 index.html,它将正常工作,将 Two 的实例打印到控制台。

但是当我尝试离线编译时,出现以下错误

如您所见,在编译 src/two.js 时,traceur 在输出目录下查找 src/one.js。我在 traceur 上找不到任何选项,可以让我自定义其搜索引用模块的根目录。我也尝试了该--dir选项,但它也失败了。

有什么建议么?

0 投票
0 回答
149 浏览

uglifyjs - SbtWeb:丑化 traceur 的输出

我正在使用 SbtWeb traceur 插件在 Play Framework (sbt/scala) 项目中转换我的代码。这给了我一个 ES5 资源/main.js。然后我想将结果丑化为/main.min.js. 我也添加了 uglify 插件,然后尝试执行以下操作:

pipelineStages := Seq(traceur, uglify)

不幸的是,这不能编译,就像traceurTaskKey 一样,但不是正确的类型。我怎样才能做到这一点?

编辑:看起来更接近正确的方法是这样的:

但是,我现在收到 Javascript 中存在语法错误的 uglify 错误。这必须是因为 uglify 正在尝试处理原始 ES6 源,而不是 traceur 的 ES5 输出。还不知道如何让它工作。

0 投票
1 回答
536 浏览

javascript - Code migration from ES5 to ES2015 with namespace

We have a cross-platform application based on Polymer and Chromium.

Currently all our JavaScript dependencies are maintained in index.html by importing them in the right order! This approach will be a nightmare soon and writing test and to see the test coverage isn't a easy task.

To be future save we decided to jump on ES2015 with it's modularity approach.

Now we need to redesign our JavaScript files to be able to maintain the dependencies between single JavaScript modules. So far so good. But how do we do that to preserve our namespaces, closures etc.?

This is a sample code:

As you can see from the code above the initialization is executed and assigned to app_ns.app. Due to simplicity, the code snippet doesn't show dependencies to other modules but we have those for sure!

So the questions are

  • How to use namespaces in ES2015
  • How to automatically execute closures
  • How to export functions of the modules but not in the global scope!

Using export { xxx }; is exporting all functions inside {...} in the global scope, right? How to bind the exported functions to the correct namespace? In this example to app_ns.app

0 投票
0 回答
88 浏览

javascript - 从带有 ES7 异步和异步生成器函数的 for...on 循环返回时会发生什么?

我正在努力思考以下示例中发生的情况:

return循环内的语句是否for...of取消订阅代表输出的观察者Project#bar

0 投票
0 回答
46 浏览

javascript - 我在哪里可以找到跟踪器选项

我在使用 es6ify 和 browserify 时不断收到异常。这是我的 gulp 代码:

首先,我收到一个关于包含以下内容的文件的错误:

例外是:

出于某种原因,当我设置freeVariableCheckertrue. 现在我得到一个错误:

而且我不明白哪个选项应该解决这个问题。

知道在哪里可以找到有关 traceur 选项的解释吗?
知道如何解决这个问题吗?

谢谢

0 投票
0 回答
143 浏览

javascript - 将 JSX 与 traceur 一起使用

我正在使用带有 es6ify 的 browserify(使用 traceur)。我正在使用 React,并且我有 jsx 文件。
我将{ jsx: true }选项传递给 es6ify,但每当 browserify 看到 jsx 文件时,我都会收到异常。使用 babel 有效。

为了使用 traceur 启用 jsx,我还需要做另一件事吗?

我尝试在 es6ify 之前使用 reactify,但它抱怨 es6 语法如importand export

0 投票
2 回答
522 浏览

ecmascript-6 - 在网页中以编程方式使用 Traceur 加载 ES6 模块

我一直在使用 Traceur 在 ES6 中开发一些项目。在我的 HTML 页面中,我包含了本地 Traceur 资源:

如果之后我在 HTML 中有一个模块,例如:

然后 Traceur 加载该模块,对其进行编译,一切正常。

我现在想从另一个 ES6 模块中以编程方式将 ES6 模块添加到页面(原因有些复杂)。这是我的第一次尝试:

不幸的是,这不起作用,因为我猜 Traceur 不会监视添加的每个脚本标记的页面。

如何让 Traceur 编译和执行脚本?我想我需要在“traceur”或“$traceurRuntime”上调用一些东西,但我还没有找到一个好的在线文档来源。

0 投票
1 回答
1059 浏览

javascript - ES6 + SystemJs - why do I have to use the .js extension to import es6 module?

Why do I have to use the .js extension to import es6 module with systemjs? For instance:

The error message:

GET http://local-host/projects/es6/src/modules 404 (Not Found)Z @ system.js:4(anonymous function) @ system.js:4(anonymous function) @ system.js:4(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:5(anonymous function) @ system.js:4 system.js:4 Uncaught (in promise) Error: Error: XHR error (404 Not Found) loading http://local-host/projects/es6/src/modules(…)

This is my HTML with system.js:

Any ideas what have I missed?