我正在处理一个dojo项目(1.11.x),最近开始使用ES6(ES2015)语法,例如const、let和模板文本。在我使用dojo构建这个项目之前,它运行得很好。我有如下错误
ERROR - Parse error. TypeError: redeclaration of const {variable name}
ERROR - Parse error. illegal character
return `<a href="/xxx/xxx/${a}">${b}</a>`;
^是否有任何方法使构建系统识别ES6语法或绕过语法检查?
发布于 2017-01-09 14:24:03
道场1.12 2016年12月发布的最新版本被更新为使用闭包编译器20160911,它支持将ES6转换为ES5。
我在一个项目中有一个项目--旧的ES5模块和ES6中的新模块。
在ES6模块中,必须在开头添加“使用严格”,否则生成失败。
error(307) Failed to evaluate module tagged as pure AMD
(fell back to processing with regular expressions). module: app/es6/Test;
error: SyntaxError: Block-scoped declarations (let, const, function, class)
not yet supported outside strict modeapp/es6/Dialog.js
"use strict"
define(["dijit/ConfirmDialog"], (ConfirmDialog) => {
let id = '1'
const dialog = new ConfirmDialog({
title: "Delete",
content: `Are you sure you want to delete ${id} ?`,
style: "width: 300px"
})
dialog.show()
})然后在app.profile.js中添加optimizeOptions对象
...
optimizeOptions: {
languageIn: 'ECMASCRIPT6',
languageOut: 'ECMASCRIPT5'
},
layerOptimize: "closure.keeplines",
optimize: "closure.keeplines",
cssOptimize: "comments",
mini: true,
stripConsole: "all",
selectorEngine: "lite",
useSourceMaps: false,
...
layers: {
"dojo/dojo": {
includeLocales: [ 'en-us' ],
include: [ "dojo/dojo", "dojo/hash" ],
boot: true,
customBase: true
}
"app/Main": {
includeLocales: [ 'en-us' ],
include: [
'app/Header',
'app/Main'
]
},
...app/Main.js
define(["app/es6/Dialog"], function(Dialog) {
Dialog.show();
});这样,您就可以将ES6集成到当前的Dojo项目中。
我还试图避免在ES6模块中“使用严格”,方法是将languageOut: ECMASCRIPT5_STRICT设置为在此提一提,但它破坏了Dojo本身。
发布于 2018-12-14 10:53:07
由于Dojo1.x上的开发似乎已经停滞,而且无法方便地迁移到Dojo2.x,所以我们不得不想出一个解决方案。我们作为开发人员被困在ES5特性上,仅仅是因为构建过程无法处理它,这真是太荒谬了。
这就是为什么我想出了一个解决办法,到目前为止,这个方法在我们公司还处于测试阶段。对于感兴趣的人,这就是我们如何解决这个问题(并且仍然使用dojo构建过程的核心部分):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<exec executable="java" resolveexecutable="true" failonerror="true">
<arg value="-jar" />
<arg value="${google.closure.compiler.es2017}" />
<arg value="--language_in=ECMASCRIPT_2017" />
<arg value="--language_out=STABLE" />
<arg value="--js" />
<arg value="${dojo.build.path}/build/layers/OriginalLayer.js" />
<arg value="--js_output_file" />
<arg value="${dojo.build.path}/build/layers/MinifiedLayer.js" />
</exec>
</execution>
</executions>
</plugin>
这仍然是实验性的,但最初的结果看起来不错,而且似乎没有回归效果。
https://stackoverflow.com/questions/38557290
复制相似问题