错误 - [JSC_UNDEFINED_VARIABLE] 变量 previousPage 未声明 - Google 闭包编译器

ERROR - [JSC_UNDEFINED_VARIABLE] variable previousPage is undeclared - Google Closure Compiler

我正在使用 Google 闭包模板编译 2 个 JS 文件。出于某种原因,它根本不喜欢我的箭头功能。例如:

// let showCurrentPage;
showCurrentPage = (i) => {
    currentPage = i;
    paginationCountLogic(bookMarksArray);
}

如果我更改为不同的函数类型,例如:

    let showCurrentPage = function(i) {
        currentPage = i;
        paginationCountLogic(bookMarksArray);
    }

我的函数在我的 JS 文件中可用或被识别。

'showCurrentPage' is declared but its value is never read.ts(6133)

我的代码工作正常,没有编译。我已经用谷歌搜索了几个小时,但我似乎无法解决这个问题。

我什至尝试更改我的 NPM 命令,从 ES6 编译到 ES5。但这似乎并不能解决问题:

npx google-closure-compiler --js=app.js --js=pagination.js  --compilation_level ADVANCED_OPTIMIZATIONS --language_in ECMASCRIPT6  --language_out ECMASCRIPT5 --js_output_file=minified.js

有什么想法吗?

这是实际错误:

pagination.js:43: ERROR - [JSC_UNDEFINED_VARIABLE] variable showCurrentPage is undeclared
    showCurrentPage = (i) => {
    ^^^^^^^^^^^^^^^

我通过另一个问题得到了这个答案。但事实证明这是原因:

The cause is probably that the compiler doesn't see the function being called. Part of the advanced compilation is removing unused code and renaming the methods/variables.

Within your js or html it is never called because the function call is only defined in a string value here :

for (var i = 0; i < individualPagesArray.length; i++) {
   document.getElementById("numbers").innerHTML += `<button onclick=showCurrentPage(${i+1})>` + individualPagesArray[i] + `</button>`;
}

你可以通过重写这个很简单地解决这个问题:

window.showCurrentPage = (i) => {

对此:

window['showCurrentPage'] = (i) => {

参见:https://developers.google.com/closure/compiler/docs/api-tutorial3#removal