Skip to content

Commit 679e65d

Browse files
committed
fixup!
1 parent 5d9a2e0 commit 679e65d

4 files changed

Lines changed: 63 additions & 62 deletions

File tree

doc/api/repl.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,6 @@ undefined
232232
undefined
233233
```
234234

235-
One known limitation of using the `await` keyword in the REPL is that
236-
it will invalidate the lexical scoping of the `const` keywords.
237-
238-
For example:
239-
240-
```console
241-
> const m = await Promise.resolve(123)
242-
undefined
243-
> m
244-
123
245-
> m = await Promise.resolve(234)
246-
234
247-
// redeclaring the constant does error
248-
> const m = await Promise.resolve(345)
249-
Uncaught SyntaxError: Identifier 'm' has already been declared
250-
```
251-
252235
### Reverse-i-search
253236

254237
<!-- YAML

test/parallel/test-repl-custom-eval-previews.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,20 @@ function getReplRunOutput(inputStr, replOptions) {
2929

3030
input.emit('data', inputStr);
3131

32-
input.run(['']);
32+
if (!replOptions.preview) {
33+
input.run(['']);
34+
return;
35+
}
36+
37+
const afterEcho = output.accumulator;
38+
let attempts = 0;
39+
(function waitForPreview() {
40+
if (output.accumulator !== afterEcho || ++attempts > 100) {
41+
input.run(['']);
42+
return;
43+
}
44+
setImmediate(waitForPreview);
45+
})();
3346
});
3447
}
3548

test/parallel/test-repl-definecommand.js

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import '../common/index.mjs';
2+
import { startNewREPLServer } from '../common/repl.js';
3+
import assert from 'node:assert';
4+
5+
const { replServer, output, run } = startNewREPLServer({
6+
prompt: '> ',
7+
terminal: true,
8+
});
9+
10+
replServer.defineCommand('say1', {
11+
help: 'help for say1',
12+
action: function (thing) {
13+
this.output.accumulator = '';
14+
this.output.write(`hello ${thing}\n`);
15+
this.displayPrompt();
16+
},
17+
});
18+
19+
replServer.defineCommand('say2', function () {
20+
this.output.accumulator = '';
21+
this.output.write('hello from say2\n');
22+
this.displayPrompt();
23+
});
24+
25+
await run(['.help\n']);
26+
assert.match(output.accumulator, /\n\.say1 {5}help for say1\n/);
27+
assert.match(output.accumulator, /\n\.say2\n/);
28+
29+
await run(['.say1 node developer\n']);
30+
assert.ok(
31+
output.accumulator.startsWith('hello node developer\n'),
32+
`say1 output starts incorrectly: "${output.accumulator}"`,
33+
);
34+
assert.ok(
35+
output.accumulator.includes('> '),
36+
`say1 output does not include prompt: "${output.accumulator}"`,
37+
);
38+
39+
await run(['.say2 node developer\n']);
40+
assert.ok(
41+
output.accumulator.startsWith('hello from say2\n'),
42+
`say2 output starts incorrectly: "${output.accumulator}"`,
43+
);
44+
assert.ok(
45+
output.accumulator.includes('> '),
46+
`say2 output does not include prompt: "${output.accumulator}"`,
47+
);
48+
49+
replServer.close();

0 commit comments

Comments
 (0)