Skip to content

Do not assign const variable in error case #20056

Description

@BridgeAR
  • Version: 10.0.0-pre

When using the repl and e.g., writing: const foo = bar() while bar is undefined is going to cause an error. So far so good. The problem is that foo is now assigned even though it would be super nice if that would not be the case due to the error while assigning the variable.

I tried to see how to fix this on my own but it is somewhere in runInContext if I am not mistaken and I have never looked at that part before.

@nodejs/vm @nodejs/repl

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    vmIssues and PRs related to the vm subsystem.
    on Apr 16, 2018
  2. TimothyGu commented on Apr 16, 2018

    @TimothyGu
    Member

    Duplicate of #8309, #8376, #8441, and #16520. This is the spec behavior, and there's no way around it.

  3. vsemozhetbyt commented on Apr 16, 2018

    @vsemozhetbyt
    Contributor

    FWIW, this is also valid for Chrome and Firefox DevTools Console:

    c

    f

  4. BridgeAR commented on Apr 16, 2018

    @BridgeAR
    MemberAuthor

    @TimothyGu for me it is not about spec compliance but about a better way to handle it in the repl. So this issue should be about evaluating to diverge from the spec. I am not sure about the current implementation details and if that is even possible.

  5. devsnek commented on Apr 16, 2018

    @devsnek
    Member

    cc @bmeck your repl proposal makes const not constant right?

  6. bmeck commented on Apr 16, 2018

    @bmeck
    Member

    Mime keeps const unable to be reassigned, but separate inputs can rebind the variable name to a new binding.

  7. BridgeAR commented on Apr 18, 2018

    @BridgeAR
    MemberAuthor

    @bmeck for me having const not possible to be reassigned is the worst thing in the repl ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    replIssues and PRs related to the REPL subsystem.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions