do...while 循环中无法理解的意外标记错误

Incomprehensible unexpected token error in do...while loop

这可能是我第一次使用 do...while 循环。我不知道它有什么问题:

const randomLetter
do {  
  randomLetter = String.fromCharCode(97 + 26 * Math.random() | 0)
} while (state.lettersFound.includes(randomLetter))

在第 do { 行,我遇到了一些 unexpected token 语法错误。为什么?

syntax for declaring a constant是:

const 标识符 = 初始化器

解析器期望在标识符 (randomLetter) 后看到等号 =,但意外地看到关键字 do.

所以,错误信息和错误位置是正确的:非预期的token是关键字do,错误发生在token do.

注意:根据解析器的不同,错误消息或多或少有帮助,例如我在 Node.js 13.1.0 / V8 7.8:

中得到这个
Thrown:
const randomLetter
      ^^^^^^^^^^^^

SyntaxError: Missing initializer in const declaration

注意:这与 无关:任何不是等号的 = 都会触发类似的语法错误。

注意: 不可能与此有任何关系,因为它显然是语法/解析错误和 ECMAScript(就像几乎所有语言,当然还有所有主流语言)不允许库更改语言的基本语法。