From 61f4eab7315d71be068b2ca0ccf6d69356acc47c Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 13 Dec 2016 01:28:33 +0200 Subject: [PATCH 1/6] doc: var => let / const in repl.md --- doc/api/repl.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 9ff416e004f4b3..ce8ddacc393423 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -78,15 +78,15 @@ The default evaluator supports direct evaluation of JavaScript expressions: ```js > 1 + 1 2 -> var m = 2 +> const m = 2 undefined > m + 1 3 ``` -Unless otherwise scoped within blocks (e.g. `{ ... }`) or functions, variables -declared either implicitly or using the `var` keyword are declared at the -`global` scope. +Unless otherwise scoped within blocks or functions, variables declared +either implicitly, or using the `const`, `let`, or `var` keywords +are declared at the global scope. #### Global and Local Scope @@ -96,7 +96,7 @@ it to the `context` object associated with each `REPLServer`. For example: ```js const repl = require('repl'); -var msg = 'message'; +const msg = 'message'; repl.start('> ').context.m = msg; ``` @@ -115,7 +115,7 @@ To specify read-only globals, context properties must be defined using ```js const repl = require('repl'); -var msg = 'message'; +const msg = 'message'; const r = repl.start('> '); Object.defineProperty(r.context, 'm', { @@ -183,7 +183,7 @@ to the provided callback function: ```js function eval(cmd, context, filename, callback) { - var result; + let result; try { result = vm.runInThisContext(cmd); } catch (e) { @@ -275,7 +275,7 @@ function initializeContext(context) { context.m = 'test'; } -var r = repl.start({prompt: '>'}); +const r = repl.start({prompt: '>'}); initializeContext(r.context); r.on('reset', initializeContext); @@ -321,7 +321,7 @@ The following example shows two new commands added to the REPL instance: ```js const repl = require('repl'); -var replServer = repl.start({prompt: '> '}); +const replServer = repl.start({prompt: '> '}); replServer.defineCommand('sayhello', { help: 'Say hello', action: function(name) { @@ -430,7 +430,7 @@ without passing any arguments (or by passing the `-i` argument): ```js $ node -> a = [1, 2, 3]; +> const a = [1, 2, 3]; [ 1, 2, 3 ] > a.forEach((v) => { ... console.log(v); @@ -502,7 +502,7 @@ socket, and a TCP socket: ```js const net = require('net'); const repl = require('repl'); -var connections = 0; +let connections = 0; repl.start({ prompt: 'Node.js via stdin> ', From 94ff2e1abdfac2e796d982cfd34dc9179e8be8fe Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 13 Dec 2016 01:34:49 +0200 Subject: [PATCH 2/6] doc: white space unification in repl.md Add an infix space in an argument list. Change `>` into `> ` in code bits and output examples. Explicitly clarify that default REPL prompt contains a trailing space. --- doc/api/repl.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index ce8ddacc393423..55549b259467ab 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -217,10 +217,10 @@ following example, for instance, simply converts any input text to upper case: ```js const repl = require('repl'); -const r = repl.start({prompt: '>', eval: myEval, writer: myWriter}); +const r = repl.start({prompt: '> ', eval: myEval, writer: myWriter}); function myEval(cmd, context, filename, callback) { - callback(null,cmd); + callback(null, cmd); } function myWriter(output) { @@ -275,7 +275,7 @@ function initializeContext(context) { context.m = 'test'; } -const r = repl.start({prompt: '>'}); +const r = repl.start({prompt: '> '}); initializeContext(r.context); r.on('reset', initializeContext); @@ -286,15 +286,15 @@ reset to its initial value using the `.clear` command: ```js $ ./node example.js ->m +> m 'test' ->m = 1 +> m = 1 1 ->m +> m 1 ->.clear +> .clear Clearing context... ->m +> m 'test' > ``` @@ -372,7 +372,8 @@ added: v0.1.91 --> * `options` {Object | String} - * `prompt` {String} The input prompt to display. Defaults to `> `. + * `prompt` {String} The input prompt to display. Defaults to `> ` + (with a trailing space). * `input` {Readable} The Readable stream from which REPL input will be read. Defaults to `process.stdin`. * `output` {Writable} The Writable stream to which REPL output will be From 38b4cb409837d833bcbf8e33e2044f644d383003 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 13 Dec 2016 01:39:28 +0200 Subject: [PATCH 3/6] doc: fix an output example in repl.md Make `_` reassignment example match more with the current output. Extend the example for more clarity. --- doc/api/repl.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 55549b259467ab..3568edf66ff841 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -140,6 +140,7 @@ global or scoped variable, the input `fs` will be evaluated on-demand as The default evaluator will, by default, assign the result of the most recently evaluated expression to the special variable `_` (underscore). +Explicitly setting `_` to a value will disable this behavior. ```js > [ 'a', 'b', 'c' ] @@ -147,11 +148,14 @@ evaluated expression to the special variable `_` (underscore). > _.length 3 > _ += 1 +Expression assignment to _ now disabled. +4 +> 1 + 1 +2 +> _ 4 ``` -Explicitly setting `_` to a value will disable this behavior. - ### Custom Evaluation Functions When a new `repl.REPLServer` is created, a custom evaluation function may be From 36ba6b861bc3dbe264e2c398d0fda64e57c045f0 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 13 Dec 2016 01:41:18 +0200 Subject: [PATCH 4/6] doc: fix a function name in repl.md `eval` => `myEval` to not shadow the global `eval` --- doc/api/repl.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 3568edf66ff841..549aa4d2b0c988 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -186,7 +186,7 @@ multi-line input, the eval function can return an instance of `repl.Recoverable` to the provided callback function: ```js -function eval(cmd, context, filename, callback) { +function myEval(cmd, context, filename, callback) { let result; try { result = vm.runInThisContext(cmd); From 0eb327d5f19e3b3cae5e2b47ab8af0d0efdefc60 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 13 Dec 2016 01:43:37 +0200 Subject: [PATCH 5/6] doc: replace anonymous functions in repl.md Replaced with an object shorthand and an arrow function. --- doc/api/repl.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 549aa4d2b0c988..8069d3e9a877f8 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -328,14 +328,14 @@ const repl = require('repl'); const replServer = repl.start({prompt: '> '}); replServer.defineCommand('sayhello', { help: 'Say hello', - action: function(name) { + action(name) { this.lineParser.reset(); this.bufferedCommand = ''; console.log(`Hello, ${name}!`); this.displayPrompt(); } }); -replServer.defineCommand('saybye', function() { +replServer.defineCommand('saybye', () => { console.log('Goodbye!'); this.close(); }); From ceee0d8184b1ff565dbaf01dd2796516a0608560 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Tue, 13 Dec 2016 01:46:10 +0200 Subject: [PATCH 6/6] doc: add the valid link for curl(1) in repl.md The current autoinserted link leads to 404 page. --- doc/api/repl.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/api/repl.md b/doc/api/repl.md index 8069d3e9a877f8..1b03ba47a25d99 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -85,7 +85,7 @@ undefined ``` Unless otherwise scoped within blocks or functions, variables declared -either implicitly, or using the `const`, `let`, or `var` keywords +either implicitly or using the `const`, `let`, or `var` keywords are declared at the global scope. #### Global and Local Scope @@ -549,10 +549,11 @@ possible to connect to a long-running Node.js process without restarting it. For an example of running a "full-featured" (`terminal`) REPL over a `net.Server` and `net.Socket` instance, see: https://gist.github.com/2209310 -For an example of running a REPL instance over curl(1), +For an example of running a REPL instance over [curl(1)][], see: https://gist.github.com/2053342 [stream]: stream.html [`util.inspect()`]: util.html#util_util_inspect_object_options [`readline.Interface`]: readline.html#readline_class_interface [`readline.InterfaceCompleter`]: readline.html#readline_use_of_the_completer_function +[curl(1)]: https://curl.haxx.se/docs/manpage.html