【问题标题】:UglifyJS: error when using optional chaining syntaxUglifyJS:使用可选链接语法时出错
【发布时间】:2021-03-13 22:02:25
【问题描述】:

我正在通过 UglifyJS 发送一个脚本,其中包含 optional changing syntax 的几个实例。在浏览器中,这种语法完美无缺。但是,UglifyJS 在文件上产生以下错误:

Parse error at /Users/username/Developer/script.js:84,32
               node.children[0]?.tagName === "P";
                                ^
ERROR: Unexpected token: punc «.»
    at JS_Parse_Error.get (eval at <anonymous> (/opt/homebrew/lib/node_modules/uglify-js/tools/node.js:18:1), <anonymous>:71:23)
    at fatal (/opt/homebrew/lib/node_modules/uglify-js/bin/uglifyjs:428:27)
    at run (/opt/homebrew/lib/node_modules/uglify-js/bin/uglifyjs:366:9)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/uglify-js/bin/uglifyjs:275:5)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

我已经浏览了文档,但我不确定要添加哪些参数(如果有的话)来完成这项工作。

【问题讨论】:

    标签: javascript uglifyjs


    【解决方案1】:

    UglifyJS 很可能还不支持可选链运算符?.。 我找不到解析器的source code 中列出的运算符。

    该工具的作者建议在 UglifyJS 之前对具有异国情调 JS 语法的文件使用 BabelJS 等转译器。

    该运算符于 2020 年 6 月被添加到 ECMAScript 标准中(相同的 ?? 运算符,但仅在 18 天前,即 2021 年 2 月 23 日,对 UglifyJS 的支持是 added)。

    【讨论】:

    猜你喜欢
    • 2022-01-23
    • 2021-02-06
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多