Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: Assignment of _ allowed with warning #5535

Closed
wants to merge 6 commits into from
Closed

repl: Assignment of _ allowed with warning #5535

wants to merge 6 commits into from

Commits on Mar 15, 2016

  1. repl: Assignment of _ allowed with warning

    This commit addresses #5431 by
    changing the way that the repl handles assignment to the global _
    variable.
    
    Prior to this commit, node sets the result of the last expression
    evaluated in the repl to `_`. This causes problems for users of
    underscore, lodash and other packages where it is common to assign
    `_` to the package, e.g. `_ = require('lodash');`.
    
    Changes in this commit now result in the following behavior.
    
    - If unassigned on the repl, `_` continues to refer to the last
      evaluated expression.
    - If assigned, the default behavior of assigning `_` to the last
      evaluated expression is disabled, and `_` now references whatever
      value was explicitly set. A warning is issued on the repl -
      'expression assignment to _ now disabled'.
    - If `_` is assigned multiple times, the warning is only displayed once.
    - When `.clear` is executed in the repl, `_` continues to refer to its
      most recent value, whatever that is (this is per existing behavior).
      If `_` had been explicitly set prior to `.clear` it will not change
      again with the evaluation of the next expression.
    lance committed Mar 15, 2016
    Configuration menu
    Copy the full SHA
    6cc2713 View commit details
    Browse the repository at this point in the history
  2. repl: Reset underscore assignment on .clear

    Ensures that, when invoking `.clear` in a repl, the underscore
    assignment behavior is reset, so that its value is again set to the most
    recently evaluated expression.
    
    Additional tests have been added for the behavior of `let` when underscore
    assignment has been disabled.
    lance committed Mar 15, 2016
    Configuration menu
    Copy the full SHA
    1dd5e2a View commit details
    Browse the repository at this point in the history
  3. doc: Document _ behavior in REPL.

    Adds a line of text about the behavior of `_` in the REPL.
    lance committed Mar 15, 2016
    Configuration menu
    Copy the full SHA
    ca199e2 View commit details
    Browse the repository at this point in the history
  4. repl: Adjust docs for _ usage, and tighten test.

    Incorporating comments from @cjhrig.
    #5535 (comment)
    #5535 (comment)
    lance committed Mar 15, 2016
    Configuration menu
    Copy the full SHA
    4062e62 View commit details
    Browse the repository at this point in the history
  5. repl: Test _ behavior in REPL_MODE_MAGIC mode.

    Add a test based on feedback from @cjihrig. Ensures that when used
    in 'magic' mode, the behavior of `_` assignment is consistent with
    other modes and user expectations.
    lance committed Mar 15, 2016
    Configuration menu
    Copy the full SHA
    428cef6 View commit details
    Browse the repository at this point in the history
  6. repl: Change warning text to a complete sentence.

    When a REPL user explicitly assigns `_` the warning text now reads,
    "Expression assignment to _ now disabled.".
    
    Also removed an unnecessary parameter from a test helper function.
    lance committed Mar 15, 2016
    Configuration menu
    Copy the full SHA
    1471d13 View commit details
    Browse the repository at this point in the history