相关疑难解决方法(0)

Eslint 无法识别使用 nodejs 12 的私有字段声明

Eslint 不会识别类声明中标有 # 的私有字段,即使我使用的是 NodeJS 版本 12(支持它们)。

我正在运行 NodeJS v12.7.0。我已经搜索了所有 DuckDuckGo 和 Google,但在 eslint 中找不到一个插件或选项来告诉它接受私有字段符号 (#)。我已经emca设置为 version 10

class MyClass {
   #foo = 'bar';
   #bar = 'foo';

   constructor(foo, bar) {
      this.#foo = foo;
      this.#bar = bar;
   }
   ...
};
Run Code Online (Sandbox Code Playgroud)

当我运行eslint上面的代码时,我得到:

2:3 error Parsing error: Unexpected character '#'

我正在处理的项目不使用 Babel,我不想仅仅为了使私有字段工作而必须包含它。任何想法如何使这项工作无需求助于使用 Babel?

(当然没有反对 Babel,只是在这个特定的项目上我不想要它)。

private private-members node.js eslint

13
推荐指数
3
解决办法
7048
查看次数

标签 统计

eslint ×1

node.js ×1

private ×1

private-members ×1