Skip to content

Commit 44b640e

Browse files
committed
repl: docs-only deprecation of magic mode
1 parent 6b1d020 commit 44b640e

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

doc/api/deprecations.md

+14
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,20 @@ deprecated. Please use `ServerResponse.prototype.writeHead()` instead.
534534
*Note*: The `ServerResponse.prototype.writeHeader()` method was never documented
535535
as an officially supported API.
536536

537+
<a id="DEP00XX"></a>
538+
### DEP00XX: repl.REPL_MODE_MAGIC and NODE_REPL_MODE=magic
539+
540+
Type: Documentation-only
541+
542+
The `repl` module's `REPL_MODE_MAGIC` constant, used for `replMode` option, has
543+
been deprecated. Its behavior has been functionally identical to that of
544+
`REPL_MODE_SLOPPY` since Node.js v6.0.0, when V8 5.0 was imported. Please use
545+
`REPL_MODE_SLOPPY` instead.
546+
547+
The `NODE_REPL_MODE` environment variable is used to set the underlying
548+
`replMode` of an interactive `node` session. Its default value, `magic`, is
549+
similarly deprecated in favor of `sloppy`.
550+
537551
[alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding
538552
[alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size
539553
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size

doc/api/repl.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,15 @@ changes:
408408
command before writing to `output`. Defaults to [`util.inspect()`][].
409409
* `completer` {Function} An optional function used for custom Tab auto
410410
completion. See [`readline.InterfaceCompleter`][] for an example.
411-
* `replMode` - A flag that specifies whether the default evaluator executes
412-
all JavaScript commands in strict mode, default mode, or a hybrid mode
413-
("magic" mode.) Acceptable values are:
411+
* `replMode` {symbol} A flag that specifies whether the default evaluator
412+
executes all JavaScript commands in strict mode or default (sloppy) mode.
413+
Acceptable values are:
414414
* `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.
415415
* `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is
416416
equivalent to prefacing every repl statement with `'use strict'`.
417-
* `repl.REPL_MODE_MAGIC` - attempt to evaluates expressions in default
418-
mode. If expressions fail to parse, re-try in strict mode.
417+
* `repl.REPL_MODE_MAGIC` - This value is **deprecated**, since enhanced
418+
spec compliance in V8 has rendered magic mode unnecessary. It is now
419+
equivalent to `repl.REPL_MODE_SLOPPY` (documented above).
419420
* `breakEvalOnSigint` - Stop evaluating the current piece of code when
420421
`SIGINT` is received, i.e. `Ctrl+C` is pressed. This cannot be used together
421422
with a custom `eval` function. Defaults to `false`.
@@ -461,8 +462,8 @@ environment variables:
461462
- `NODE_REPL_HISTORY_SIZE` - Defaults to `1000`. Controls how many lines of
462463
history will be persisted if history is available. Must be a positive number.
463464
- `NODE_REPL_MODE` - May be any of `sloppy`, `strict`, or `magic`. Defaults
464-
to `magic`, which will automatically run "strict mode only" statements in
465-
strict mode.
465+
to `sloppy`, which will allow non-strict mode code to be run. `magic` is
466+
**deprecated** and treated as an alias of `sloppy`.
466467

467468
### Persistent History
468469

lib/internal/repl.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ function createRepl(env, opts, cb) {
3939

4040
opts.replMode = {
4141
'strict': REPL.REPL_MODE_STRICT,
42-
'sloppy': REPL.REPL_MODE_SLOPPY,
43-
'magic': REPL.REPL_MODE_MAGIC
42+
'sloppy': REPL.REPL_MODE_SLOPPY
4443
}[String(env.NODE_REPL_MODE).toLowerCase().trim()];
4544

4645
if (opts.replMode === undefined) {
47-
opts.replMode = REPL.REPL_MODE_MAGIC;
46+
opts.replMode = REPL.REPL_MODE_SLOPPY;
4847
}
4948

5049
const historySize = Number(env.NODE_REPL_HISTORY_SIZE);

lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ exports.REPLServer = REPLServer;
633633

634634
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
635635
exports.REPL_MODE_STRICT = Symbol('repl-strict');
636-
exports.REPL_MODE_MAGIC = Symbol('repl-magic');
636+
exports.REPL_MODE_MAGIC = exports.REPL_MODE_SLOPPY;
637637

638638
// prompt is a string to print on each line for the prompt,
639639
// source is a stream to use for I/O, defaulting to stdin/stdout.

0 commit comments

Comments
 (0)