Node: REPL Await invalidates `const`

Created on 14 Dec 2017  路  7Comments  路  Source: nodejs/node

  • Version: HEAD
  • Platform: all
  • Subsystem: repl

The REPL makes const variables not const if await appears in the input:

const x = 1; x = 2; await 0; x
doc help wanted known limitation

Most helpful comment

Known issue. See https://github.com/nodejs/node/pull/15566:

While this works well for var, it doesn't for top-level let and const (let and const still work as expected in blocks), which will lose their lexical specialness (or constantness) with this approach. However, I simply can't think of any good way to support top-level let and const fully. (Note, DevTools has the same problem; try const a = await Promise.resolve(1); back-to-back multiple times.) If you've got an idea, please comment!

The RFC at the end is still active!

All 7 comments

Known issue. See https://github.com/nodejs/node/pull/15566:

While this works well for var, it doesn't for top-level let and const (let and const still work as expected in blocks), which will lose their lexical specialness (or constantness) with this approach. However, I simply can't think of any good way to support top-level let and const fully. (Note, DevTools has the same problem; try const a = await Promise.resolve(1); back-to-back multiple times.) If you've got an idea, please comment!

The RFC at the end is still active!

working on fix in https://github.com/bmeck/node/tree/env-record-repl-await , also fixes some other bugs

I'm unable to replicate this. Any chance this never went out in a release without a subsequent fix? Should this be closed? Or am I just testing wrong somehow?

Ah, never mind, I see I need to use the --experimental-repl-await flag. Seeing the bug now.

@Trott is the --experimental-repl-await flag supposed to work now?
Because I can't have the --experimental-repl-await working properly.

$ node --experimental-modules --experimental-repl-await src/login.js
(node:484) ExperimentalWarning: The ESM module loader is experimental.
file:///opt/src/login.js:8
    const browser = await puppeteer.launch({
                    ^^^^^

SyntaxError: Unexpected reserved word
    at Loader.moduleStrategy (internal/modules/esm/translators.js:84:18)
    at async link (internal/modules/esm/module_job.js:36:21)

--experimental-repl-await only enables top-level await within the repl (that's why it has repl in the name).

Oh so there's no way to have top level-await in a script now, correct?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mcollina picture mcollina  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

jmichae3 picture jmichae3  路  3Comments

cong88 picture cong88  路  3Comments

Icemic picture Icemic  路  3Comments