首页 > 解决方案 > 箭头函数在大括号后用括号编译

问题描述

我有一个节点模块导入到我的 nuxtjs 应用程序中,其中包含这段代码:

shortcodes = await Promise.all(presets.map(preset => {
  let promise;

  if (preset.includes('/')) {
    const [customLocale, customPreset] = preset.split('/');
    promise = fetchShortcodes(customLocale, customPreset, opts);
  } else {
    promise = fetchShortcodes(locale, preset, opts);
  } // Ignore as the primary dataset should still load

  return promise.catch(() => ({}));
}));

但是,当我构建项目时,它会被编译成一种语法,该语法会引发有关意外令牌“{”的错误。原因是这段代码的构建代码如下所示:

f=await Promise.all(c.map((o=>{let n;if(o.includes("/")){const[e,t]=o.split("/");n=l(e,t,d)}else n=l(e,o,d);return n.catch((()=>({})))})))

您可以注意到o( preset) 前面有一个新括号。右括号几乎一直在最后。到目前为止,我不知道为什么会这样。我会很高兴我能得到任何关于如何移除一个支架或至少将它关闭在正确位置的指示。

标签: javascriptnuxt.jsnode-modulesarrow-functions

解决方案


推荐阅读