在库中调用另一个函数时内部函数的语法错误 [英] Syntax Error on internal function when calling another function in a library

查看:113
本文介绍了在库中调用另一个函数时内部函数的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了引用库的脚本问题。我的问题不是连接到库,而是我的脚本调用了一个函数,但是当它运行时,它在我未引用的函数上出错了。

I am having an issue with a script that references a library. My issue is not connecting to the library, its that my script calls a function, but when it runs, it errors out on a function that I am not referencing.

In工作表A,我有以下代码:

In sheet A, I have this code:

function DataPull() {

  MasterScriptLibrary.DataPullBillable()

}

MasterScriptLibrary (项目的全名是2020 Master Script Library),我有2个不同的函数(它们彼此互不引用),分别称为 convertPersonnel DataPullBillable

In MasterScriptLibrary (project's full name is 2020 Master Script Library), I have 2 distinct functions (they don't reference each other at all) called convertPersonnel and DataPullBillable.

从工作表A运行上述函数时,我收到一条错误消息:

When the above function runs from sheet A, I get an error message:


语法错误。 (第66行,文件 convertPersonnel,项目 2020年主脚本库)

Syntax error. (line 66, file "convertPersonnel", project "2020 Master Script Library")

库的第66行:

var data = activeRange.filter(element => element.join("") != "");

你知道这里可能发生什么吗?

Any idea what could be happening here?

推荐答案

问题

在Google Apps脚本项目中需要库时,它将在调用脚本的环境。因此,如果调用脚本的运行时不支持该库使用的任何语言功能/语法,则会抛出相应的错误。

When a library is required in Google Apps Script project, it is run in the environment of the calling script. Thus, if any of the language features / syntax used by the library are not supported by the runtime of the calling script, it will throw a corresponding error.

运行时

自GAS从犀牛 V8 运行时是由于尝试使用ES6功能引起的(某些功能甚至在较旧的功能中也受支持,但是自全面检查以来,开发人员的资源列表已被删除)。

One of the most common issues since GAS switched from Rhino to V8 runtime is caused by trying to use ES6 features (some were supported even in the older one, but the comprehensive list is gone from the developers resource since the overhaul).

语法错误

您正在尝试使用旧版运行时不支持的语法,因此 SyntaxError 。该消息直接指向问题(第66行),但未提供有关错误原因的信息,因此混淆是可以理解的(它是有效的ES6语法的事实)。

You are trying to use syntax not supported in the older runtime, hence the SyntaxError. The message points directly to the issue (line 66) but does not provide info on what is wrong, so the confusion is understandable (the fact that it is valid ES6 syntax adds to it).


实际的问题是箭头功能的存在。

检查运行时间

要检查使用了哪个运行时间(除了牌匾位于如果使用脚本编辑器,则在顶部),打开清单文件( appsscript.json )并找到 runtimeVersion 字段,可以设置为 V8或 DEPRECATED_ES5(犀牛)。

To check which runtime is used (apart from the plaque at the top if using script editor), open manifest file (appsscript.json) and find the runtimeVersion field, it will be set to either "V8" or "DEPRECATED_ES5" (Rhino).

较新的脚本一定会使用V8,但是您必须手动迁移较旧的版本,方法是将上述字段设置为 V8 (也可以根据需要降级)或在运行菜单中选择选项。

Newer scripts are guaranteed to use V8, but you have to migrate older ones manually by either setting the abovementioned field to V8 (you can also "downgrade" as needed) or selecting the option in "Run" menu.

这篇关于在库中调用另一个函数时内部函数的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆