repl: docs-only deprecation of magic mode
The workaround used in repl to support `let` and `const` in non-strict mode (known as "magic" mode) has been unnecessary since V8 v4.9 / Node.js v6.0.0. This commit doc-deprecate magic mode (which is now entirely equivalent to sloppy mode) in both `repl` module and in `internal/repl`, which is responsible for starting the REPL in `node` interactive mode. PR-URL: https://github.com/nodejs/node/pull/11599 Refs: https://v8project.blogspot.com/2016/01/v8-release-49.html Refs: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V6.md#6.0.0 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
This commit is contained in:
Родитель
b77c89022b
Коммит
3f27f02da0
|
@ -542,6 +542,20 @@ Type: Runtime
|
||||||
The `tls.createSecurePair()` API was deprecated in documentation in Node.js
|
The `tls.createSecurePair()` API was deprecated in documentation in Node.js
|
||||||
0.11.3. Users should use `tls.Socket` instead.
|
0.11.3. Users should use `tls.Socket` instead.
|
||||||
|
|
||||||
|
<a id="DEP0065"></a>
|
||||||
|
### DEP0065: repl.REPL_MODE_MAGIC and NODE_REPL_MODE=magic
|
||||||
|
|
||||||
|
Type: Documentation-only
|
||||||
|
|
||||||
|
The `repl` module's `REPL_MODE_MAGIC` constant, used for `replMode` option, has
|
||||||
|
been deprecated. Its behavior has been functionally identical to that of
|
||||||
|
`REPL_MODE_SLOPPY` since Node.js v6.0.0, when V8 5.0 was imported. Please use
|
||||||
|
`REPL_MODE_SLOPPY` instead.
|
||||||
|
|
||||||
|
The `NODE_REPL_MODE` environment variable is used to set the underlying
|
||||||
|
`replMode` of an interactive `node` session. Its default value, `magic`, is
|
||||||
|
similarly deprecated in favor of `sloppy`.
|
||||||
|
|
||||||
[alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding
|
[alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding
|
||||||
[alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size
|
[alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size
|
||||||
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
|
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
|
||||||
|
|
|
@ -408,14 +408,15 @@ changes:
|
||||||
command before writing to `output`. Defaults to [`util.inspect()`][].
|
command before writing to `output`. Defaults to [`util.inspect()`][].
|
||||||
* `completer` {Function} An optional function used for custom Tab auto
|
* `completer` {Function} An optional function used for custom Tab auto
|
||||||
completion. See [`readline.InterfaceCompleter`][] for an example.
|
completion. See [`readline.InterfaceCompleter`][] for an example.
|
||||||
* `replMode` - A flag that specifies whether the default evaluator executes
|
* `replMode` {symbol} A flag that specifies whether the default evaluator
|
||||||
all JavaScript commands in strict mode, default mode, or a hybrid mode
|
executes all JavaScript commands in strict mode or default (sloppy) mode.
|
||||||
("magic" mode.) Acceptable values are:
|
Acceptable values are:
|
||||||
* `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.
|
* `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.
|
||||||
* `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is
|
* `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is
|
||||||
equivalent to prefacing every repl statement with `'use strict'`.
|
equivalent to prefacing every repl statement with `'use strict'`.
|
||||||
* `repl.REPL_MODE_MAGIC` - attempt to evaluates expressions in default
|
* `repl.REPL_MODE_MAGIC` - This value is **deprecated**, since enhanced
|
||||||
mode. If expressions fail to parse, re-try in strict mode.
|
spec compliance in V8 has rendered magic mode unnecessary. It is now
|
||||||
|
equivalent to `repl.REPL_MODE_SLOPPY` (documented above).
|
||||||
* `breakEvalOnSigint` - Stop evaluating the current piece of code when
|
* `breakEvalOnSigint` - Stop evaluating the current piece of code when
|
||||||
`SIGINT` is received, i.e. `Ctrl+C` is pressed. This cannot be used together
|
`SIGINT` is received, i.e. `Ctrl+C` is pressed. This cannot be used together
|
||||||
with a custom `eval` function. Defaults to `false`.
|
with a custom `eval` function. Defaults to `false`.
|
||||||
|
@ -461,8 +462,8 @@ environment variables:
|
||||||
- `NODE_REPL_HISTORY_SIZE` - Defaults to `1000`. Controls how many lines of
|
- `NODE_REPL_HISTORY_SIZE` - Defaults to `1000`. Controls how many lines of
|
||||||
history will be persisted if history is available. Must be a positive number.
|
history will be persisted if history is available. Must be a positive number.
|
||||||
- `NODE_REPL_MODE` - May be any of `sloppy`, `strict`, or `magic`. Defaults
|
- `NODE_REPL_MODE` - May be any of `sloppy`, `strict`, or `magic`. Defaults
|
||||||
to `magic`, which will automatically run "strict mode only" statements in
|
to `sloppy`, which will allow non-strict mode code to be run. `magic` is
|
||||||
strict mode.
|
**deprecated** and treated as an alias of `sloppy`.
|
||||||
|
|
||||||
### Persistent History
|
### Persistent History
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,11 @@ function createRepl(env, opts, cb) {
|
||||||
|
|
||||||
opts.replMode = {
|
opts.replMode = {
|
||||||
'strict': REPL.REPL_MODE_STRICT,
|
'strict': REPL.REPL_MODE_STRICT,
|
||||||
'sloppy': REPL.REPL_MODE_SLOPPY,
|
'sloppy': REPL.REPL_MODE_SLOPPY
|
||||||
'magic': REPL.REPL_MODE_MAGIC
|
|
||||||
}[String(env.NODE_REPL_MODE).toLowerCase().trim()];
|
}[String(env.NODE_REPL_MODE).toLowerCase().trim()];
|
||||||
|
|
||||||
if (opts.replMode === undefined) {
|
if (opts.replMode === undefined) {
|
||||||
opts.replMode = REPL.REPL_MODE_MAGIC;
|
opts.replMode = REPL.REPL_MODE_SLOPPY;
|
||||||
}
|
}
|
||||||
|
|
||||||
const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
|
const historySize = Number(env.NODE_REPL_HISTORY_SIZE);
|
||||||
|
|
|
@ -633,7 +633,7 @@ exports.REPLServer = REPLServer;
|
||||||
|
|
||||||
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
|
exports.REPL_MODE_SLOPPY = Symbol('repl-sloppy');
|
||||||
exports.REPL_MODE_STRICT = Symbol('repl-strict');
|
exports.REPL_MODE_STRICT = Symbol('repl-strict');
|
||||||
exports.REPL_MODE_MAGIC = Symbol('repl-magic');
|
exports.REPL_MODE_MAGIC = exports.REPL_MODE_SLOPPY;
|
||||||
|
|
||||||
// prompt is a string to print on each line for the prompt,
|
// prompt is a string to print on each line for the prompt,
|
||||||
// source is a stream to use for I/O, defaulting to stdin/stdout.
|
// source is a stream to use for I/O, defaulting to stdin/stdout.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче