node icon indicating copy to clipboard operation
node copied to clipboard

Flag to disable const enforcement

Open togakangaroo opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe.

This sounds silly as I'm the biggest cheerleader for const but I do run into one situation.

I like to do repl-driven-development where I have my code file along with a side-by-side repl that I can throw lines or regions to with a keystroke. Unfortunately, if the line in question uses const, this will fail since I'm trying to redeclare const.

Describe the solution you'd like I would like to be able to add a flag to this nodejs session - perhaps --loose-declarations or --const-and-let-as-var and have const (and ideally let) work the same as var

Describe alternatives you've considered Alternately, this could be set with an environment variable or simply be the default in repl sessions. It would be great to get it rolled into v8 and have it also work in devtools on web, but that's probably asking too much

togakangaroo avatar Dec 17 '20 03:12 togakangaroo

This behavior is determined by the specification/let-and-const-declarations-static-semantics-early-errors. Instead of const, you can use var

By @devsnek comments, I found let redeclaration is also supported by Chrome 80

Lxxyx avatar Dec 17 '20 03:12 Lxxyx

This (well at least let redeclaration) would be provided by us transitioning to using V8 repl mode in our default repl. You may find https://github.com/nodejs/repl interesting in the meantime.

const redeclaration isn't implemented anywhere yet, though it's been brought up a couple times.

devsnek avatar Dec 17 '20 03:12 devsnek

Hi all. Any update on this? Chrome 97 console will happily let you redeclare even const and for dev purposes this seems like the desired REPL behavior. Any plans to just rely on the V8 repl? What are the show stoppers here? Inability to redeclare let and const etc hinder PL development where you'd like to target ES6 but provide for a dynamic dev experience. Atm if I were to compile a PL to es6 and allow repl-driven development it would absolutely work when hooked to Chrome V8 REPL and would SyntaxError in Nodejs. Put differently Chrome lets you live-develop and redefine things at top-level, while Nodejs essentially demands stop-the-world-throw-away-state and recompile, which is meh.

Relevant issues from Chromium. Looks like Node repl has been brought up there at some point. As far as I can tell built-in DevTools repl is already there, Node isn't making use of it:

https://bugs.chromium.org/p/chromium/issues/detail?id=1004193 https://bugs.chromium.org/p/v8/issues/detail?id=6903

vkz avatar Feb 04 '22 11:02 vkz

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

github-actions[bot] avatar Aug 04 '22 01:08 github-actions[bot]

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.

github-actions[bot] avatar Sep 03 '22 01:09 github-actions[bot]