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

doc: some fixes in repl.md #10160

Closed
wants to merge 85 commits into from
Closed
Changes from 7 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
9615910
doc: var => let / const in repl.md
vsemozhetbyt Dec 6, 2016
3e18789
doc: white space unification in repl.md
vsemozhetbyt Dec 6, 2016
743f84d
doc: fix an output example in repl.md
vsemozhetbyt Dec 6, 2016
a7501f2
doc: fix a function name in repl.md
vsemozhetbyt Dec 6, 2016
402c625
doc: name anonymous functions in repl.md
vsemozhetbyt Dec 6, 2016
e20c785
doc: document argument variant in repl.md
vsemozhetbyt Dec 6, 2016
4357059
doc: add the valid link for curl(1) in repl.md
vsemozhetbyt Dec 6, 2016
9c7054b
doc: replace anonymous functions in repl.md
vsemozhetbyt Dec 7, 2016
cdeb85e
test: move long-running test to sequential
Trott Dec 7, 2016
da077ee
test: refactor test-dgram-bind-default-address
mbchoa Dec 1, 2016
22e2c47
build: fix node_g target
danbev Dec 6, 2016
a244147
test: check result of uv_loop_init and uv_write
bnoordhuis Dec 5, 2016
1b25214
test: use const and strictEqual in test-os-homedir-no-envvar
codeVana Dec 1, 2016
61d6293
url: improve URLSearchParams spec compliance
TimothyGu Nov 6, 2016
ac78812
test: refactor test-domain-exit-dispose-again
Ethan-Arrowood Dec 1, 2016
b0c10a2
test: refactor test-domain-from-timer
Dec 1, 2016
586b787
doc: removing extra space in README
italoacasas Dec 7, 2016
df4018e
doc: reword variable declaration note in repl.md
vsemozhetbyt Dec 7, 2016
29b2e88
test: improve test-fs-read-stream.js
jennabelle Nov 16, 2016
c6eae5a
doc: adding missing - in README
italoacasas Dec 7, 2016
8960383
test: refactor test-beforeexit-event
radelmann Dec 4, 2016
83d9cd8
test: refactor test-https-agent-session-reuse
dpaez Dec 3, 2016
fd6999e
test: improves test-tls-client-verify
Dec 1, 2016
57f993d
test: renamed assert.Equal to assert.strictEqual
triscuitoraus Dec 1, 2016
e6a0c39
test: changed assert.equal to assert.strictEqual
zina-olson Dec 1, 2016
558fa1c
test: change assert.equal to assert.strictEqual
Dec 1, 2016
deb9cc0
test: use `assert.strictEqual`
anoff Dec 1, 2016
68488e9
test: fix error in test-cluster-worker-death.js
Dec 1, 2016
1e4b9a1
test: refactor test-crypto-hmac
eudaimos Dec 1, 2016
2d0ce51
doc: update `path.format` description and examples
anoff Dec 1, 2016
6967ed4
test: refactor test-net-keepalive.js
kmccmk9 Dec 1, 2016
df39784
http: verify client method is a string
lucamaraschi Dec 4, 2016
a0a6ff2
doc: add some info on `tty#setRawMode()`
Fishrock123 Dec 6, 2016
6dd0754
test: fix flaky test-net-socket-timeout
Trott Dec 7, 2016
9a5d475
http: remove stale timeout listeners
Nov 1, 2016
f0da38a
test: increase test coverage of BufferList
joyeecheung Dec 1, 2016
444b907
test: refactor test-http-unix-socket
Dec 1, 2016
6aacef7
test: check for error on invalid signal
mattcphillips Dec 1, 2016
a8137dd
tools: add macosx-firwall script to avoid popups
danbev Dec 3, 2016
def6dfb
test: set stdin too for pseudo-tty tests
addaleax Dec 6, 2016
b8fc9a3
test: add stdin-setrawmode.out file
Dec 6, 2016
bc335c0
doc: buffer allocation throws for negative size
joyeecheung Dec 6, 2016
f9aadfb
inspector: move options parsing
Nov 18, 2016
d8c7534
inspector: stop relying on magic strings
Nov 21, 2016
3d24856
doc: revert documenting argument form in repl.md
vsemozhetbyt Dec 9, 2016
cffbb32
doc: add note to parallelize make
Dec 1, 2016
0cd1f54
doc: standardizing on make -j4
Dec 6, 2016
4d11c2c
lib,test: use consistent operator linebreak style
targos Dec 8, 2016
7c2dbd1
tools: enforce consistent operator linebreak style
targos Dec 8, 2016
aa77b76
lib,src: support values > 4GB in heap statistics
bnoordhuis Dec 8, 2016
8dbf1af
test: stream readableListening internal state
italoacasas Dec 1, 2016
8621ccc
test: stream readableState readingMore state
chmln Dec 1, 2016
f5c2c8c
test: improving crypto fips
Dec 1, 2016
9f58e02
test: improve buffer transcode
Dec 1, 2016
a84017a
url, test: including base argument in originFor
joyeecheung Dec 1, 2016
5607228
test: use ES6 in test-debugger-client.js
edsadr Dec 8, 2016
14b0b44
doc: fix typo in code example of 'path' module
pallxk Dec 6, 2016
10929f6
test: fail for missing output files
addaleax Dec 6, 2016
f418a22
doc: modernize child_process example code
vsemozhetbyt Dec 3, 2016
9ee915b
buffer: handle UCS2 `.fill()` properly on BE
addaleax Dec 6, 2016
d4f00fe
buffer: fix single-character string filling
addaleax Nov 29, 2016
c3839f7
tls: fix/annotate connect arg comments
sam-github Nov 18, 2016
d4050b3
tls: document and test option-less createServer
sam-github Nov 21, 2016
475b8db
test: tls key/cert ordering not necessary
sam-github Nov 22, 2016
a28e949
tls: do not refer to secureOptions as flags
sam-github Nov 22, 2016
caa7fa9
doc: rework tls for accuracy and clarity
sam-github Nov 23, 2016
db50307
test: var to const in tls-no-cert-required
sam-github Dec 9, 2016
fa4f158
test: replace var with const in test-require-dot
amarzavery Dec 1, 2016
a8e8708
test: add ES6 and strictEqual to test-fs-truncate
edsadr Dec 7, 2016
499fc7a
test: refactor test-handle-wrap-close-abort
Trott Dec 9, 2016
50cb3a3
doc: document argument variant in the repl.md
vsemozhetbyt Dec 10, 2016
7346e55
test: refactor http pipelined socket test
Trott Dec 9, 2016
10891a1
test: refactor assert.equal, update syntax to ES6
Dec 1, 2016
8bad37a
test: refactor test-https-truncate
Trott Dec 11, 2016
5f18b40
doc: var => let / const in repl.md
vsemozhetbyt Dec 6, 2016
bed9aae
doc: white space unification in repl.md
vsemozhetbyt Dec 6, 2016
9bef034
doc: fix an output example in repl.md
vsemozhetbyt Dec 6, 2016
67c2a7d
doc: fix a function name in repl.md
vsemozhetbyt Dec 6, 2016
d665e39
doc: name anonymous functions in repl.md
vsemozhetbyt Dec 6, 2016
5f31da7
doc: document argument variant in repl.md
vsemozhetbyt Dec 6, 2016
d5861ad
doc: add the valid link for curl(1) in repl.md
vsemozhetbyt Dec 6, 2016
0c32eb5
doc: replace anonymous functions in repl.md
vsemozhetbyt Dec 7, 2016
936263e
doc: reword variable declaration note in repl.md
vsemozhetbyt Dec 7, 2016
588a5d5
doc: revert documenting argument form in repl.md
vsemozhetbyt Dec 9, 2016
10c0137
doc: resolved merge conflict
vsemozhetbyt Dec 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ 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.
declared either implicitly or using the `const` or `let` keywords
are declared at the `global` scope (as well as with the `var` keyword
outside of functions).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a cumbersome distinction between const and var, and `let. Couldn't it just be something like this?

"variables declared either implicitly, or using the const, let, or var keywords are declared at the global scope."

Especially since the phrase is immediately preceded by "Unless otherwise scoped within blocks or functions".

Copy link
Contributor Author

@vsemozhetbyt vsemozhetbyt Dec 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lance But it is exactly this remark — "Unless otherwise scoped within blocks or functions" — that prevents placing const, var, and let in the same list: var is not block scoped. Maybe you or somebody else could propose the whole clear concise sentence there? I am not a native speaker, so I am a bit clumsy there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var is not block scoped

The const and let declarations are block scoped, and the var declaration is function scoped. I think this sentence covers both. I'm not sure if I have a wording that is clearer.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Done.

#### Global and Local Scope

Expand All @@ -96,7 +97,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;
```
Expand All @@ -115,7 +116,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', {
Expand All @@ -140,18 +141,22 @@ 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' ]
[ 'a', 'b', 'c' ]
> _.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
Expand Down Expand Up @@ -182,8 +187,8 @@ 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) {
var result;
function myEval(cmd, context, filename, callback) {
let result;
try {
result = vm.runInThisContext(cmd);
} catch (e) {
Expand Down Expand Up @@ -217,10 +222,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) {
Expand Down Expand Up @@ -275,7 +280,7 @@ function initializeContext(context) {
context.m = 'test';
}

var r = repl.start({prompt: '>'});
const r = repl.start({prompt: '> '});
initializeContext(r.context);

r.on('reset', initializeContext);
Expand All @@ -286,15 +291,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'
>
```
Expand All @@ -321,17 +326,17 @@ 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) {
action: function sayHello(name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't add any value. I'd rather just leave at is it, but do action: function (name) { for coding style's sake

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just thought the docs should promote the style appropriate for the code base:

https://github.com/nodejs/node/pulls?q=is%3Apr+name+anonymous+functions+is%3Aclosed

But if I'm wrong, I'll roll back these two with just space insertion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. Also I do not have strong feelings about this, but in the /lib case it would hae value since stack traces might look nicer. Here showing APIs is the prime thing to do. E.g. you will never see full error handling in programming books. Again. I don't mind that's why I left it as a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Well, if nobody will support the additions, I will change as you advise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but I think we only try to do that in cases where the name is not inferred (well) by V8. Here, .name would just be action without the hint, I think that’s okay.

If you want to change style here, I’d be +1 on just the action(name) { shorthand notation

Copy link
Contributor Author

@vsemozhetbyt vsemozhetbyt Dec 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also a method shorthand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O, I have not seen @addaleax comment)

this.lineParser.reset();
this.bufferedCommand = '';
console.log(`Hello, ${name}!`);
this.displayPrompt();
}
});
replServer.defineCommand('saybye', function() {
replServer.defineCommand('saybye', function sayBye() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also an arrow function.

console.log('Goodbye!');
this.close();
});
Expand Down Expand Up @@ -371,8 +376,9 @@ within the action function for commands registered using the
added: v0.1.91
-->

* `options` {Object}
* `prompt` {String} The input prompt to display. Defaults to `> `.
* `options` {Object | String}
* `prompt` {String} The input prompt to display. Defaults to `> `
(with a trailing space).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(...)-content doesn't add any value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trailing space is not shown in the rendered page, it is wiped out. Is this not somehow confusing?

* `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
Expand Down Expand Up @@ -411,6 +417,8 @@ added: v0.1.91
`SIGINT` is received, i.e. `Ctrl+C` is pressed. This cannot be used together
with a custom `eval` function. Defaults to `false`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add reference to your new name here

Copy link
Contributor Author

@vsemozhetbyt vsemozhetbyt Dec 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This eval is used in multiple places as an abstraction. It is just in the code that it shadows global.


If `options` is a string, then it specifies the input prompt.

Copy link
Contributor

@eljefedelrodeodeljefe eljefedelrodeodeljefe Dec 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know whether this is true. If so it would be a major change in documentation, since also the type is just displaying <Object>

Copy link
Contributor Author

@vsemozhetbyt vsemozhetbyt Dec 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is almost documented in some examples. See:

https://github.com/nodejs/node/blame/master/doc/api/repl.md#L101
https://github.com/nodejs/node/blame/master/doc/api/repl.md#L120

If it is not official API, maybe we should change these fragments too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually how it works, although I don't know how "official" it is. See repl.start and the REPLServer constructor. I do see examples of this usage all over the place. In addition to what @vsemozhetbyt referenced there is another example here.

The `repl.start()` method creates and starts a `repl.REPLServer` instance.

## The Node.js REPL
Expand All @@ -421,7 +429,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);
Expand Down Expand Up @@ -493,7 +501,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> ',
Expand Down Expand Up @@ -535,10 +543,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