镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Tab completion for block-scoped variables doesn't work in REPL #983

Description

@RB14

Using version 1.4.1 REPL mode, it seems that tab completion for block-scoped variables (i.e. let and const statements) doesn't show suggestions, while tab completion for variables declared with var or otherwise just assigned a value without a deceleration, does show up a list of suggestions.

Of course, this happens in strict mode, or else I couldn't use let and const.

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    on Feb 27, 2015
  2. vkurchatkin commented on Feb 27, 2015

    @vkurchatkin
    Contributor

    A test (run with --use_strict):

    require('assert').equal(require('vm').runInNewContext(`
      let a = 42;
      this.a
    `), 42);

    summoning @domenic.

  3. benjamingr commented on Feb 27, 2015

    @benjamingr
    Member

    I can reproduce this on v1.4.1 on OSX.

    $ ./iojs --use_strict

    let foobar = 40;
    var bazbar = 100;
    foo // hit tab, no autocomplete
    baz // hit tab, autocompletes to bazbar

    The test @vkurchatkin posted also fails.

  4. bnoordhuis commented on Feb 27, 2015

    @bnoordhuis
    Member

    I think this can be explained because of how the REPL does autocompletion: it spawns a nested VM context that contains a copy of the globals from the parent context. var bindings have global scope but let bindings don't, i.e.:

    > var x = 1; typeof global['x']  // 'number'
    > let y = 1; typeof global['y']  // 'undefined'
    

    I can't think of a good fix off the top of my head.

  5. vkurchatkin commented on Feb 27, 2015

    @vkurchatkin
    Contributor

    the question is, this the correct behaviour according to spec?

  6. reopened this on Feb 27, 2015
  7. benjamingr commented on Feb 28, 2015

    @benjamingr
    Member
  8. domenic commented on Mar 1, 2015

    @domenic
    Contributor

    Right, indeed, let and const and class don't add to the global object, but instead to a separate scope contour. Unsure how to deal with this given the implementation details @bnoordhuis mentions.

  9. Fishrock123 commented on Jul 1, 2015

    @Fishrock123
    Contributor

    Is this actually an issue then?

  10. RB14 commented on Jul 1, 2015

    @RB14
    Author

    Well, as the one who opened this ticket, I still find it odd that auto-complete in REPL would work for only var (or should I say old-style) variables, and not for the new kinds of declarations.
    Since auto-complete is a feature of io.js (and node.js), and it's a very useful feature if you ask me, I think this behavior should be fixed (if possible of course).. so I think it should still be considered as an issue.

  11. added
    help wantedIssues that need assistance from volunteers or PRs that need help to proceed.
    confirmed-bugIssues and PRs for confirmed bugs.
    on Mar 11, 2016
  12. jasnell commented on Apr 2, 2016

    @jasnell
    Member

    Appears to be fixed in master. Closing.

  13. 23 remaining items

  14. jgranduel commented on Sep 21, 2017

    @jgranduel

    Hi,
    node-8.5.0 REPL win10... seems to still be an issue. Any news?

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

Metadata

Metadata

Labels

confirmed-bugIssues and PRs for confirmed bugs.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.replIssues and PRs related to the REPL subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions