From 8d80cee77b211be291421a930f92253ed1ec2054 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Fri, 27 Dec 2024 06:36:22 +0000 Subject: [PATCH 01/38] feat: add draft logic of eager evaluation --- lib/node_modules/@stdlib/repl/lib/defaults.js | 5 +- .../@stdlib/repl/lib/eager_evaluation.js | 267 ++++++++++++++++++ lib/node_modules/@stdlib/repl/lib/main.js | 15 +- .../@stdlib/repl/lib/multiline_handler.js | 8 + 4 files changed, 293 insertions(+), 2 deletions(-) create mode 100644 lib/node_modules/@stdlib/repl/lib/eager_evaluation.js diff --git a/lib/node_modules/@stdlib/repl/lib/defaults.js b/lib/node_modules/@stdlib/repl/lib/defaults.js index 0c0789ec801c..4dd57c009c6d 100644 --- a/lib/node_modules/@stdlib/repl/lib/defaults.js +++ b/lib/node_modules/@stdlib/repl/lib/defaults.js @@ -106,7 +106,10 @@ function defaults() { 'syntaxHighlighting': void 0, // Theme for syntax highlighting: - 'theme': 'stdlib-ansi-basic' + 'theme': 'stdlib-ansi-basic', + + // Flag indicating whether to enable eager Evaluation (note: default depends on whether TTY): + 'eagerEvaluation': void 0 } }; } diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js new file mode 100644 index 000000000000..df585638dabe --- /dev/null +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js @@ -0,0 +1,267 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable no-underscore-dangle, no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var readline = require( 'readline' ); +var inspect = require( 'util' ).inspect; +var logger = require( 'debug' ); +var parse = require( 'acorn' ).parse; +var replace = require( '@stdlib/string/replace' ); +var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var processCommand = require( './process_command.js' ); +var compileCommand = require( './compile_command.js' ); + + +// VARIABLES // + +var debug = logger( 'repl:EE' ); +var AOPTS = { + 'ecmaVersion': 'latest' +}; +var tempDB = { + 'base_sin': { + 'isPure': true + } +}; + + +// MAIN // + +/** +* Constructor for creating a multi-line handler. +* +* @private +* @param {REPL} repl - repl instance +* @param {Object} rli - readline instance +* @param {Boolean} enabled - boolean indicating whether the syntax-highlighter should be initially enabled +* @returns {EagerEvaluator} eager-evaluator instance +*/ +function EagerEvaluator( repl, rli, enabled ) { + this._repl = repl; + this._rli = rli; + this._cmd = repl._cmd; + this._enabled = enabled; + this._isPreview = false; + + return this; +} + +/** +* Callback for handling a "keypress" event. +* +* @name onKeyPress +* @memberof EagerEvaluator.prototype +* @type {Function} +* @param {string} data - input data +* @param {(Object|void)} key - key object +* @returns {void} +* +*/ +setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyPress(data, key) { + var cursorPosition; + var executable; + var nlInd; + var code; + var opts; + var pre; + var res; + var tmp; + + if (!this._enabled || this._rli.line === '' || key.name === 'paste-start' || (key.name === 'o' && key.ctrl) || key.name === 'return') { + return; + } + + code = this._cmd.join('\n') + this._rli.line; + opts = { + 'timeout': this._repl._timeout, + 'displayErrors': false, + 'breakOnSigint': true // Node.js >=6.3.0 + }; + if (!this.isSideEffectFree(code)) { + debug('code have side effect'); + return; + } + debug('try to process command'); + tmp = processCommand(code); + if (tmp instanceof Error) { + debug( 'getting error %s', tmp.message ); + return; + } + debug('try to compile command'); + executable = compileCommand(tmp); + if (executable instanceof Error) { + debug( 'getting error %s', executable.message ); + return; + } + try { + if ( this._repl._sandbox ) { + res = executable.compiled.runInContext( this._repl._context, opts ); + } else { + res = executable.compiled.runInThisContext( opts ); + } + } catch (err) { + debug( 'getting error when executing the command %s', err.message ); + return; + } + + res = inspect(res); + nlInd = res.indexOf('\n'); + if ( nlInd !== -1 ) { + res = res.slice(0, nlInd ) + '...'; + } + cursorPosition = this._rli.cursor; + pre = replace( this._repl._outputPrompt, '%d', (this._repl._count+1).toString() ); + this._repl._ostream.write( '\n\u001b[90m' + pre + res + '\u001b[0m' ); + readline.moveCursor(this._repl._ostream, 0, -1); + readline.cursorTo(this._repl._ostream, cursorPosition + this._repl.promptLength() ); + this._isPreview = true; + executable.raw = code; + this._repl._isEagerEvaluated = true; + this._repl._eagerEvaluatedExecutable = executable; + debug( 'sucess' ); +}); + +/** +* Callback which should be invoked**before** a "keypress" event. +* +* @name beforeKeyPress +* @memberof EagerEvaluator.prototype +* @type {Function} +* @param {string} data - input data +* @param {(Object|void)} key - key object +* @returns {void} +* +*/ +setNonEnumerableReadOnly(EagerEvaluator.prototype, 'beforeKeypress', function beforeKeyPress(data, key) { + var cursorPosition; + + if (!this._isPreview || key.name === 'return' || (key.name === 'o' && key.ctrl) ) { + return; + } + if ( this._isPreview ) { + cursorPosition = this._rli.cursor; + readline.moveCursor( this._repl._ostream, 0, 1 ); + readline.clearLine( this._repl._ostream, 0 ); + readline.moveCursor( this._repl._ostream, 0, -1 ); + readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); + this._isPreview = false; + } + this._repl._isEagerEvaluated = false; + this._repl._eagerEvaluatedExecutable = void 0; +}); + +/** +* Tells weather code is side effect free or not. +* +* @name isSideEffectFree +* @memberof EagerEvaluator.prototype +* @type {Function} +* @param {string} code - input code +* @returns {boolean} - boolean indicate weather code is side effect free or not. +* +*/ +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function isSideEffectFree( code ) { + var ast; + var i; + + try { + ast = parse( code, AOPTS ); + } + catch (err) { + debug( 'getting error when generating AST %S ', err ); + return false; + } + // Iterate from each node in body + for ( i = 0; i < ast.body.length; i++ ) { + if ( !traverse( ast.body[ i ] ) ) { + return false; + } + } + return true; + + /** + * Function which recursivly traverse from the node and tells weather node is side effect free or not. + * + * @private + * @param {JSON} node - ast node. + * @returns {Boolean} - Boolean indicate weather node is side effect free or not. + */ + function traverse(node) { + var fname; + var i; + if ( !node ) { + return false; + } + if ( node.type === 'Literal' || node.type === 'Identifier' || node.type === 'MemberExpression' ) { + return true; + } + if ( node.type === 'BinaryExpression' ) { + if ( traverse( node.left ) && traverse( node.right ) ) { + return true; + } + } + else if ( node.type === 'ExpressionStatement' ) { + if ( traverse( node.expression ) ) { + return true; + } + } + else if ( node.type === 'CallExpression' ) { + fname = getFunctionName( node.callee ); + if ( tempDB[fname] && tempDB[fname].isPure ) { + // Iterating through arguments + for ( i = 0; i < node.arguments.length; i++ ) { + if ( !traverse( node.arguments[ i ] ) ) { + return false; + } + } + return true; + } + } + return false; + } + + /** + * Get the underscore seprate function name for the member function call. + * + * @private + * @param {JSON} node - ast node + * @returns {string} - underscore seprated function name for the member function call + */ + function getFunctionName( node ) { + if ( !node ) { + return ''; + } + if ( node.type === 'MemberExpression' ) { + return getFunctionName(node.object) + '_' + node.property.name; + } + if ( node.type === 'Identifier' ) { + return node.name; + } + return ''; + } +} ); + + +// EXPORTS // + +module.exports = EagerEvaluator; diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index b04bcf12da61..59516eaed027 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -68,6 +68,7 @@ var CompleterEngine = require( './completer_engine.js' ); var PreviewCompleter = require( './completer_preview.js' ); var AutoCloser = require( './auto_close_pairs.js' ); var SyntaxHighlighter = require( './syntax_highlighter.js' ); +var EagerEvaluator = require( './eager_evaluation.js' ); var ALIAS_OVERRIDES = require( './alias_overrides.js' ); var SETTINGS = require( './settings.js' ); var SETTINGS_VALIDATORS = require( './settings_validators.js' ); @@ -159,6 +160,7 @@ function REPL( options ) { opts.settings.completionPreviews = ( opts.settings.completionPreviews === void 0 ) ? opts.isTTY : opts.settings.completionPreviews; // eslint-disable-line max-len opts.settings.autoDisableBracketedPasteOnExit = ( opts.settings.autoDisableBracketedPasteOnExit === void 0 ) ? opts.isTTY : opts.settings.autoDisableBracketedPasteOnExit; // eslint-disable-line max-len opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len + opts.settings.eagerEvaluation = ( opts.settings.eagerEvaluation === void 0 ) ? opts.isTTY : opts.settings.eagerEvaluation; // eslint-disable-line max-len debug( 'Options: %s', JSON.stringify({ 'input': '', @@ -254,6 +256,12 @@ function REPL( options ) { // Initialize an internal flag indicating whether we've received a `SIGINT` signal: setNonEnumerable( this, '_SIGINT', false ); + // Initialize an internal flag indicating whether command is eagerlyEvaluated: + setNonEnumerable( this, '_isEagerEvaluated', false ); + + // Initialize as internal variable for caching the compiled object from eagerEvaluation + setNonEnumerable( this, '_eagerEvaluatedExecutable', void 0 ); + // Initialize an internal variable for caching the result of the last successfully evaluated command: setNonEnumerable( this, '_ans', void 0 ); @@ -293,6 +301,9 @@ function REPL( options ) { // Initialize a syntax-highlighter: setNonEnumerableReadOnly( this, '_syntaxHighlighter', new SyntaxHighlighter( this, this._ostream, this._settings.syntaxHighlighting ) ); + // Initialize a eagerEvaluator: + setNonEnumerableReadOnly( this, '_eagerEvaluator', new EagerEvaluator( this, this._rli, this._settings.eagerEvaluation ) ); + // Cache a reference to the private readline interface `ttyWrite` to allow calling the method when wanting default behavior: setNonEnumerableReadOnly( this, '_ttyWrite', this._rli._ttyWrite ); @@ -363,6 +374,7 @@ function REPL( options ) { completed = self._previewCompleter.beforeKeypress( data, key ); FLG = self._editorActions.beforeKeypress( data, key ); + self._eagerEvaluator.beforeKeypress( data, key ); // If ENTER keypress is encountered or if a preview was completed while navigating, gracefully close the completer... if ( completed || ( key && key.name === 'return' ) ) { self._completerEngine.closeCompleter(); @@ -398,6 +410,7 @@ function REPL( options ) { self._previewCompleter.clear(); } self._completerEngine.onKeypress( data, key ); + self._eagerEvaluator.onKeypress( data, key ); self._multilineHandler.onKeypress( data, key ); self._syntaxHighlighter.onKeypress(); self._previewCompleter.onKeypress( data, key ); @@ -1449,7 +1462,7 @@ setNonEnumerableReadOnly( REPL.prototype, 'settings', function settings() { } nargs = arguments.length; if ( nargs === 0 ) { - return assign( {}, this._settings ); + return assign({}, this._settings ); } name = arguments[ 0 ]; if ( !isString( name ) ) { diff --git a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js index d78009de4959..63e40117f643 100644 --- a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js +++ b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js @@ -621,6 +621,14 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'processLine', function pr return; } this._multiline.active = false; // false until proven otherwise + if ( this._repl._isEagerEvaluated ) { + this.resetInput(); + this._queue.push( this._repl._eagerEvaluatedExecutable ); + drain( this._repl ); + this._repl_isEagerEvaluated = false; + this._repl._eagerEvaluatedExecutable = void 0; + return; + } cmd = this._cmd.join( '\n' ); if ( RE_WHITESPACE.test( cmd ) ) { this.resetInput(); From 4a9205b2f01fd26e6507a387ab9ca7b5074fd787 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Fri, 27 Dec 2024 06:36:41 +0000 Subject: [PATCH 02/38] fix: fixing test failure --- lib/node_modules/@stdlib/repl/lib/main.js | 9 ++++++++- .../repl/test/integration/test.auto_close_pairs.js | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 59516eaed027..148073d1b87e 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -160,7 +160,14 @@ function REPL( options ) { opts.settings.completionPreviews = ( opts.settings.completionPreviews === void 0 ) ? opts.isTTY : opts.settings.completionPreviews; // eslint-disable-line max-len opts.settings.autoDisableBracketedPasteOnExit = ( opts.settings.autoDisableBracketedPasteOnExit === void 0 ) ? opts.isTTY : opts.settings.autoDisableBracketedPasteOnExit; // eslint-disable-line max-len opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len - opts.settings.eagerEvaluation = ( opts.settings.eagerEvaluation === void 0 ) ? opts.isTTY : opts.settings.eagerEvaluation; // eslint-disable-line max-len + + // This is temparary because eager evaluation conflicting with the auto_close_pairs tests. + if ( options && options.settings.eagerEvaluation !== void 0 ) { + opts.settings.eagerEvaluation = options.settings.eagerEvaluation; + } + else { + opts.settings.eagerEvaluation = ( opts.settings.eagerEvaluation === void 0 ) ? opts.isTTY : opts.settings.eagerEvaluation; // eslint-disable-line max-len + } debug( 'Options: %s', JSON.stringify({ 'input': '', diff --git a/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js b/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js index 6a69fdcc52e2..362b51ebd36b 100644 --- a/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js +++ b/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js @@ -145,7 +145,8 @@ function defaultSettings() { 'autoDeletePairs': false, 'autoPage': false, 'completionPreviews': false, - 'syntaxHighlighting': false + 'syntaxHighlighting': false, + 'eagerEvaluation' : false }; } @@ -194,12 +195,12 @@ function assertAutoClose( t, fixture, done ) { // Create an incomplete expression: s = splice( fixture.expression, fixture.cursor ); - // Construct the expected output: expected = spliced2expected( s ); // Emulate the presence of an existing expression: istream.write( s[ 0 ] ); + console.log(`here is the s ${s} and here is the expected ${expected}`) // Move the cursor to where we want to insert a character to trigger auto-close: N = s[ 0 ].length - fixture.cursor; From 4c150920455dfcc7bef78b52584792085bf299c3 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Fri, 27 Dec 2024 07:38:19 +0000 Subject: [PATCH 03/38] fix: fixing test failure --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../repl/test/integration/test.auto_close_pairs.js | 5 +++-- .../repl/test/integration/test.completer_engine.js | 1 + .../repl/test/integration/test.completion_previews.js | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js b/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js index 362b51ebd36b..67e6198e2c58 100644 --- a/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js +++ b/lib/node_modules/@stdlib/repl/test/integration/test.auto_close_pairs.js @@ -146,7 +146,8 @@ function defaultSettings() { 'autoPage': false, 'completionPreviews': false, 'syntaxHighlighting': false, - 'eagerEvaluation' : false + 'eagerEvaluation': false + }; } @@ -195,12 +196,12 @@ function assertAutoClose( t, fixture, done ) { // Create an incomplete expression: s = splice( fixture.expression, fixture.cursor ); + // Construct the expected output: expected = spliced2expected( s ); // Emulate the presence of an existing expression: istream.write( s[ 0 ] ); - console.log(`here is the s ${s} and here is the expected ${expected}`) // Move the cursor to where we want to insert a character to trigger auto-close: N = s[ 0 ].length - fixture.cursor; diff --git a/lib/node_modules/@stdlib/repl/test/integration/test.completer_engine.js b/lib/node_modules/@stdlib/repl/test/integration/test.completer_engine.js index c17512bc9985..ffcc95ba8562 100644 --- a/lib/node_modules/@stdlib/repl/test/integration/test.completer_engine.js +++ b/lib/node_modules/@stdlib/repl/test/integration/test.completer_engine.js @@ -48,6 +48,7 @@ function defaultSettings() { 'autoDisableBracketedPasteOnExit': false, 'completionPreviews': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoPage': false }; } diff --git a/lib/node_modules/@stdlib/repl/test/integration/test.completion_previews.js b/lib/node_modules/@stdlib/repl/test/integration/test.completion_previews.js index ef9840c6d725..6f572938b9a7 100644 --- a/lib/node_modules/@stdlib/repl/test/integration/test.completion_previews.js +++ b/lib/node_modules/@stdlib/repl/test/integration/test.completion_previews.js @@ -47,6 +47,7 @@ tape( 'a REPL instance supports displaying a completion preview of user-defined 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; @@ -92,6 +93,7 @@ tape( 'a REPL instance supports displaying a completion preview for common prefi 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; @@ -138,6 +140,7 @@ tape( 'a REPL instance supports displaying a completion preview for recognized i 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; @@ -183,6 +186,7 @@ tape( 'a REPL instance supports displaying a completion preview when a cursor is 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; @@ -237,6 +241,7 @@ tape( 'a REPL instance supports auto-completing a completion candidate by moving 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; @@ -290,6 +295,7 @@ tape( 'a REPL instance supports auto-completing a completion preview and executi 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; @@ -344,6 +350,7 @@ tape( 'a REPL instance does not display a completion preview when no completion 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; @@ -403,6 +410,7 @@ tape( 'a REPL instance does not display a completion preview once a user enters 'settings': { 'autoPage': false, 'syntaxHighlighting': false, + 'eagerEvaluation': false, 'autoDisableBracketedPasteOnExit': false } }; From e626b19b78e8341d22bbdd23db02fdfda950b043 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Fri, 27 Dec 2024 07:40:47 +0000 Subject: [PATCH 04/38] checking options.setting --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- lib/node_modules/@stdlib/repl/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 148073d1b87e..34a7f16fa3e5 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -161,8 +161,8 @@ function REPL( options ) { opts.settings.autoDisableBracketedPasteOnExit = ( opts.settings.autoDisableBracketedPasteOnExit === void 0 ) ? opts.isTTY : opts.settings.autoDisableBracketedPasteOnExit; // eslint-disable-line max-len opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len - // This is temparary because eager evaluation conflicting with the auto_close_pairs tests. - if ( options && options.settings.eagerEvaluation !== void 0 ) { + // This is temparary because eager evaluation conflicting with the some tests. + if ( options && options.settings && options.settings.eagerEvaluation !== void 0 ) { opts.settings.eagerEvaluation = options.settings.eagerEvaluation; } else { From e43cab185aa39d40ffc82cef823ef020e72945ce Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:15:51 +0530 Subject: [PATCH 05/38] fix: style fix Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- lib/node_modules/@stdlib/repl/lib/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 34a7f16fa3e5..79ffd6ba56a7 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -382,6 +382,7 @@ function REPL( options ) { FLG = self._editorActions.beforeKeypress( data, key ); self._eagerEvaluator.beforeKeypress( data, key ); + // If ENTER keypress is encountered or if a preview was completed while navigating, gracefully close the completer... if ( completed || ( key && key.name === 'return' ) ) { self._completerEngine.closeCompleter(); From b43056de3cc73c4d4c155b2e2b71f0266fdcae1c Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:21:19 +0000 Subject: [PATCH 06/38] chore: update copyright years --- lib/node_modules/@stdlib/repl/lib/eager_evaluation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js index df585638dabe..a7004eedfe9f 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 6c8d7fd506c637866a9e0232565e18debe55214b Mon Sep 17 00:00:00 2001 From: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Date: Mon, 6 Jan 2025 19:24:33 +0530 Subject: [PATCH 07/38] style: fix indentation in manifest.json files PR-URL: https://github.com/stdlib-js/stdlib/pull/4602 Co-authored-by: aayush0325 Reviewed-by: Philipp Burckhardt From 30f7796c42a1020a239e854194b104fd081c4828 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Fri, 24 Jan 2025 14:20:34 +0000 Subject: [PATCH 08/38] fix: fixing clashing in end line of terminal --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/repl/lib/eager_evaluation.js | 35 +++++++++++++------ .../@stdlib/repl/lib/multiline_handler.js | 8 ----- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js index a7004eedfe9f..396c2ca553de 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js @@ -1,3 +1,4 @@ +/* eslint-disable max-len */ /** * @license Apache-2.0 * @@ -87,7 +88,8 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyP var res; var tmp; - if (!this._enabled || this._rli.line === '' || key.name === 'paste-start' || (key.name === 'o' && key.ctrl) || key.name === 'return') { + if (!this._enabled || this._rli.line === '' || key.name === 'paste-start' || + (key.name === 'o' && key.ctrl) || key.name === 'return' || this._repl._completerEngine.isNavigating()) { return; } @@ -153,18 +155,11 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyP * */ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'beforeKeypress', function beforeKeyPress(data, key) { - var cursorPosition; - - if (!this._isPreview || key.name === 'return' || (key.name === 'o' && key.ctrl) ) { + if (!this._isPreview || (key.name === 'o' && key.ctrl) ) { return; } if ( this._isPreview ) { - cursorPosition = this._rli.cursor; - readline.moveCursor( this._repl._ostream, 0, 1 ); - readline.clearLine( this._repl._ostream, 0 ); - readline.moveCursor( this._repl._ostream, 0, -1 ); - readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); - this._isPreview = false; + this.clear(); } this._repl._isEagerEvaluated = false; this._repl._eagerEvaluatedExecutable = void 0; @@ -261,6 +256,26 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function } } ); +/** +* Method to clear the eagerly evaluated text. +* +* @name clear +* @memberof EagerEvaluator.prototype +* @type {Function} +* @returns {void} +* +*/ +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear( ) { + var cursorPosition; + + cursorPosition = this._rli.cursor; + readline.moveCursor( this._repl._ostream, 0, 1 ); + readline.clearLine( this._repl._ostream, 0 ); + readline.moveCursor( this._repl._ostream, 0, -1 ); + readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); + this._isPreview = false; +} ); + // EXPORTS // diff --git a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js index 63e40117f643..d78009de4959 100644 --- a/lib/node_modules/@stdlib/repl/lib/multiline_handler.js +++ b/lib/node_modules/@stdlib/repl/lib/multiline_handler.js @@ -621,14 +621,6 @@ setNonEnumerableReadOnly( MultilineHandler.prototype, 'processLine', function pr return; } this._multiline.active = false; // false until proven otherwise - if ( this._repl._isEagerEvaluated ) { - this.resetInput(); - this._queue.push( this._repl._eagerEvaluatedExecutable ); - drain( this._repl ); - this._repl_isEagerEvaluated = false; - this._repl._eagerEvaluatedExecutable = void 0; - return; - } cmd = this._cmd.join( '\n' ); if ( RE_WHITESPACE.test( cmd ) ) { this.resetInput(); From 72651d0b13b704a32600f701deec5394c96b14ed Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Fri, 24 Jan 2025 14:35:15 +0000 Subject: [PATCH 09/38] fix: removing unnessary conditions check --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluation.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js index 396c2ca553de..e82791df33a7 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js @@ -78,7 +78,7 @@ function EagerEvaluator( repl, rli, enabled ) { * @returns {void} * */ -setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyPress(data, key) { +setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyPress() { var cursorPosition; var executable; var nlInd; @@ -88,8 +88,7 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyP var res; var tmp; - if (!this._enabled || this._rli.line === '' || key.name === 'paste-start' || - (key.name === 'o' && key.ctrl) || key.name === 'return' || this._repl._completerEngine.isNavigating()) { + if (!this._enabled || this._rli.line === '' || this._repl._completerEngine.isNavigating()) { return; } @@ -154,8 +153,8 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyP * @returns {void} * */ -setNonEnumerableReadOnly(EagerEvaluator.prototype, 'beforeKeypress', function beforeKeyPress(data, key) { - if (!this._isPreview || (key.name === 'o' && key.ctrl) ) { +setNonEnumerableReadOnly(EagerEvaluator.prototype, 'beforeKeypress', function beforeKeyPress() { + if (!this._isPreview ) { return; } if ( this._isPreview ) { From 7fce9d32b11acf079df1faa3ec235795b04995df Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sat, 25 Jan 2025 07:54:32 +0000 Subject: [PATCH 10/38] fix: adding suggested changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/repl/lib/defaults.js | 2 +- .../@stdlib/repl/lib/eager_evaluation.js | 30 +++++++++++-------- lib/node_modules/@stdlib/repl/lib/main.js | 7 ----- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/defaults.js b/lib/node_modules/@stdlib/repl/lib/defaults.js index 4dd57c009c6d..0f3a2cc67919 100644 --- a/lib/node_modules/@stdlib/repl/lib/defaults.js +++ b/lib/node_modules/@stdlib/repl/lib/defaults.js @@ -108,7 +108,7 @@ function defaults() { // Theme for syntax highlighting: 'theme': 'stdlib-ansi-basic', - // Flag indicating whether to enable eager Evaluation (note: default depends on whether TTY): + // Flag indicating whether to enable eager evaluation (note: default depends on whether TTY): 'eagerEvaluation': void 0 } }; diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js index e82791df33a7..8ecab1c155d8 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js @@ -35,7 +35,7 @@ var compileCommand = require( './compile_command.js' ); // VARIABLES // -var debug = logger( 'repl:EE' ); +var debug = logger( 'repl:eager_evaluation' ); var AOPTS = { 'ecmaVersion': 'latest' }; @@ -49,7 +49,7 @@ var tempDB = { // MAIN // /** -* Constructor for creating a multi-line handler. +* Constructor for creating a eager evaluator. * * @private * @param {REPL} repl - repl instance @@ -58,10 +58,19 @@ var tempDB = { * @returns {EagerEvaluator} eager-evaluator instance */ function EagerEvaluator( repl, rli, enabled ) { + // Cache a reference to the provided REPL instance: this._repl = repl; + + // Cache a reference to the readline interface: this._rli = rli; + + // Cache a reference to the command array: this._cmd = repl._cmd; + + // Flag indicate weather eagerevaluation is enable or not this._enabled = enabled; + + // Flag indicate weather preview is on terminal or not this._isPreview = false; return this; @@ -78,7 +87,7 @@ function EagerEvaluator( repl, rli, enabled ) { * @returns {void} * */ -setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyPress() { +setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeypress() { var cursorPosition; var executable; var nlInd; @@ -136,9 +145,6 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyP readline.moveCursor(this._repl._ostream, 0, -1); readline.cursorTo(this._repl._ostream, cursorPosition + this._repl.promptLength() ); this._isPreview = true; - executable.raw = code; - this._repl._isEagerEvaluated = true; - this._repl._eagerEvaluatedExecutable = executable; debug( 'sucess' ); }); @@ -153,19 +159,17 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyP * @returns {void} * */ -setNonEnumerableReadOnly(EagerEvaluator.prototype, 'beforeKeypress', function beforeKeyPress() { +setNonEnumerableReadOnly(EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { if (!this._isPreview ) { return; } if ( this._isPreview ) { this.clear(); } - this._repl._isEagerEvaluated = false; - this._repl._eagerEvaluatedExecutable = void 0; }); /** -* Tells weather code is side effect free or not. +* Function to determine if code is side-effect-free. * * @name isSideEffectFree * @memberof EagerEvaluator.prototype @@ -197,8 +201,8 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function * Function which recursivly traverse from the node and tells weather node is side effect free or not. * * @private - * @param {JSON} node - ast node. - * @returns {Boolean} - Boolean indicate weather node is side effect free or not. + * @param {Object} node - ast node + * @returns {Boolean} - boolean indicating whether the node is side effect free or not */ function traverse(node) { var fname; @@ -238,7 +242,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function * Get the underscore seprate function name for the member function call. * * @private - * @param {JSON} node - ast node + * @param {Object} node - ast node * @returns {string} - underscore seprated function name for the member function call */ function getFunctionName( node ) { diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 79ffd6ba56a7..7549c833a34c 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -263,12 +263,6 @@ function REPL( options ) { // Initialize an internal flag indicating whether we've received a `SIGINT` signal: setNonEnumerable( this, '_SIGINT', false ); - // Initialize an internal flag indicating whether command is eagerlyEvaluated: - setNonEnumerable( this, '_isEagerEvaluated', false ); - - // Initialize as internal variable for caching the compiled object from eagerEvaluation - setNonEnumerable( this, '_eagerEvaluatedExecutable', void 0 ); - // Initialize an internal variable for caching the result of the last successfully evaluated command: setNonEnumerable( this, '_ans', void 0 ); @@ -380,7 +374,6 @@ function REPL( options ) { self._autoCloser.beforeKeypress( data, key ); completed = self._previewCompleter.beforeKeypress( data, key ); FLG = self._editorActions.beforeKeypress( data, key ); - self._eagerEvaluator.beforeKeypress( data, key ); // If ENTER keypress is encountered or if a preview was completed while navigating, gracefully close the completer... From 7f23f98a5483d530d066f49a1c0267bf12b97efc Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sat, 25 Jan 2025 08:13:39 +0000 Subject: [PATCH 11/38] style: adding spaces in parenthesis --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/repl/lib/eager_evaluation.js | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js index 8ecab1c155d8..c52f46419bf7 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js @@ -87,7 +87,7 @@ function EagerEvaluator( repl, rli, enabled ) { * @returns {void} * */ -setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeypress() { +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKeypress() { var cursorPosition; var executable; var nlInd; @@ -97,29 +97,29 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyp var res; var tmp; - if (!this._enabled || this._rli.line === '' || this._repl._completerEngine.isNavigating()) { + if ( !this._enabled || this._rli.line === '' || this._repl._completerEngine.isNavigating() ) { return; } - code = this._cmd.join('\n') + this._rli.line; + code = this._cmd.join( '\n' ) + this._rli.line; opts = { 'timeout': this._repl._timeout, 'displayErrors': false, 'breakOnSigint': true // Node.js >=6.3.0 }; - if (!this.isSideEffectFree(code)) { - debug('code have side effect'); + if ( !this.isSideEffectFree( code ) ) { + debug( 'code have side effect' ); return; } - debug('try to process command'); - tmp = processCommand(code); - if (tmp instanceof Error) { + debug( 'try to process command' ); + tmp = processCommand( code ); + if ( tmp instanceof Error ) { debug( 'getting error %s', tmp.message ); return; } - debug('try to compile command'); - executable = compileCommand(tmp); - if (executable instanceof Error) { + debug( 'try to compile command' ); + executable = compileCommand( tmp ); + if ( executable instanceof Error ) { debug( 'getting error %s', executable.message ); return; } @@ -134,16 +134,16 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyp return; } - res = inspect(res); - nlInd = res.indexOf('\n'); + res = inspect( res ); + nlInd = res.indexOf( '\n' ); if ( nlInd !== -1 ) { - res = res.slice(0, nlInd ) + '...'; + res = res.slice( 0, nlInd ) + '...'; } cursorPosition = this._rli.cursor; - pre = replace( this._repl._outputPrompt, '%d', (this._repl._count+1).toString() ); + pre = replace( this._repl._outputPrompt, '%d', ( this._repl._count+1 ).toString() ); this._repl._ostream.write( '\n\u001b[90m' + pre + res + '\u001b[0m' ); - readline.moveCursor(this._repl._ostream, 0, -1); - readline.cursorTo(this._repl._ostream, cursorPosition + this._repl.promptLength() ); + readline.moveCursor( this._repl._ostream, 0, -1 ); + readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); this._isPreview = true; debug( 'sucess' ); }); @@ -159,7 +159,7 @@ setNonEnumerableReadOnly(EagerEvaluator.prototype, 'onKeypress', function onKeyp * @returns {void} * */ -setNonEnumerableReadOnly(EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { if (!this._isPreview ) { return; } @@ -204,7 +204,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function * @param {Object} node - ast node * @returns {Boolean} - boolean indicating whether the node is side effect free or not */ - function traverse(node) { + function traverse( node ) { var fname; var i; if ( !node ) { From 9aa4c3e02d29ead524be416307b014a1d92bd241 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Wed, 29 Jan 2025 17:58:52 +0000 Subject: [PATCH 12/38] refactor: change file name for consistency Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- Signed-off-by: Snehil Shah --- .../repl/lib/{eager_evaluation.js => eager_evaluator.js} | 2 +- lib/node_modules/@stdlib/repl/lib/main.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename lib/node_modules/@stdlib/repl/lib/{eager_evaluation.js => eager_evaluator.js} (99%) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js similarity index 99% rename from lib/node_modules/@stdlib/repl/lib/eager_evaluation.js rename to lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index c52f46419bf7..2ceb24c8c657 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluation.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -35,7 +35,7 @@ var compileCommand = require( './compile_command.js' ); // VARIABLES // -var debug = logger( 'repl:eager_evaluation' ); +var debug = logger( 'repl:eager-evaluator' ); var AOPTS = { 'ecmaVersion': 'latest' }; diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 7549c833a34c..96315a359f7f 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -68,7 +68,7 @@ var CompleterEngine = require( './completer_engine.js' ); var PreviewCompleter = require( './completer_preview.js' ); var AutoCloser = require( './auto_close_pairs.js' ); var SyntaxHighlighter = require( './syntax_highlighter.js' ); -var EagerEvaluator = require( './eager_evaluation.js' ); +var EagerEvaluator = require( './eager_evaluator.js' ); var ALIAS_OVERRIDES = require( './alias_overrides.js' ); var SETTINGS = require( './settings.js' ); var SETTINGS_VALIDATORS = require( './settings_validators.js' ); @@ -1463,7 +1463,7 @@ setNonEnumerableReadOnly( REPL.prototype, 'settings', function settings() { } nargs = arguments.length; if ( nargs === 0 ) { - return assign({}, this._settings ); + return assign( {}, this._settings ); } name = arguments[ 0 ]; if ( !isString( name ) ) { From 7da041f036a5f65252abd88b24036b792c1e0c2f Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Wed, 29 Jan 2025 18:06:04 +0000 Subject: [PATCH 13/38] fix: add guard against invalid class initialization Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 2ceb24c8c657..aba58fae9f23 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -58,6 +58,10 @@ var tempDB = { * @returns {EagerEvaluator} eager-evaluator instance */ function EagerEvaluator( repl, rli, enabled ) { + if ( !(this instanceof EagerEvaluator) ) { + return new EagerEvaluator( repl, rli, enabled ); + } + // Cache a reference to the provided REPL instance: this._repl = repl; From e540283e0ce9a09b09e21d1723531eceada6ba95 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Wed, 29 Jan 2025 18:07:53 +0000 Subject: [PATCH 14/38] refactor: use existing constant for hardcoded values Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index aba58fae9f23..10b106b005e3 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -31,6 +31,7 @@ var replace = require( '@stdlib/string/replace' ); var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var processCommand = require( './process_command.js' ); var compileCommand = require( './compile_command.js' ); +var ANSI_COLORS = require( './ansi_colors.js' ); // VARIABLES // @@ -44,6 +45,8 @@ var tempDB = { 'isPure': true } }; +var ANSI_GRAY = ANSI_COLORS[ 'brightBlack' ]; +var ANSI_RESET = ANSI_COLORS[ 'reset' ]; // MAIN // @@ -145,7 +148,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey } cursorPosition = this._rli.cursor; pre = replace( this._repl._outputPrompt, '%d', ( this._repl._count+1 ).toString() ); - this._repl._ostream.write( '\n\u001b[90m' + pre + res + '\u001b[0m' ); + this._repl._ostream.write( '\n' + ANSI_GRAY + pre + res + ANSI_RESET ); readline.moveCursor( this._repl._ostream, 0, -1 ); readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); this._isPreview = true; From bebc0fe5150237c873491a785bf77de22711498d Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Wed, 29 Jan 2025 18:39:04 +0000 Subject: [PATCH 15/38] refactor: move entangled logic outside and clean ups Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/repl/lib/eager_evaluator.js | 215 +++++++++--------- lib/node_modules/@stdlib/repl/lib/main.js | 6 +- 2 files changed, 114 insertions(+), 107 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 10b106b005e3..f7afd40bfdb2 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -64,6 +64,7 @@ function EagerEvaluator( repl, rli, enabled ) { if ( !(this instanceof EagerEvaluator) ) { return new EagerEvaluator( repl, rli, enabled ); } + debug( 'Creating a new eager-evaluator...' ); // Cache a reference to the provided REPL instance: this._repl = repl; @@ -84,108 +85,17 @@ function EagerEvaluator( repl, rli, enabled ) { } /** -* Callback for handling a "keypress" event. -* -* @name onKeyPress -* @memberof EagerEvaluator.prototype -* @type {Function} -* @param {string} data - input data -* @param {(Object|void)} key - key object -* @returns {void} +* Checks if the code is side-effect-free. * -*/ -setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKeypress() { - var cursorPosition; - var executable; - var nlInd; - var code; - var opts; - var pre; - var res; - var tmp; - - if ( !this._enabled || this._rli.line === '' || this._repl._completerEngine.isNavigating() ) { - return; - } - - code = this._cmd.join( '\n' ) + this._rli.line; - opts = { - 'timeout': this._repl._timeout, - 'displayErrors': false, - 'breakOnSigint': true // Node.js >=6.3.0 - }; - if ( !this.isSideEffectFree( code ) ) { - debug( 'code have side effect' ); - return; - } - debug( 'try to process command' ); - tmp = processCommand( code ); - if ( tmp instanceof Error ) { - debug( 'getting error %s', tmp.message ); - return; - } - debug( 'try to compile command' ); - executable = compileCommand( tmp ); - if ( executable instanceof Error ) { - debug( 'getting error %s', executable.message ); - return; - } - try { - if ( this._repl._sandbox ) { - res = executable.compiled.runInContext( this._repl._context, opts ); - } else { - res = executable.compiled.runInThisContext( opts ); - } - } catch (err) { - debug( 'getting error when executing the command %s', err.message ); - return; - } - - res = inspect( res ); - nlInd = res.indexOf( '\n' ); - if ( nlInd !== -1 ) { - res = res.slice( 0, nlInd ) + '...'; - } - cursorPosition = this._rli.cursor; - pre = replace( this._repl._outputPrompt, '%d', ( this._repl._count+1 ).toString() ); - this._repl._ostream.write( '\n' + ANSI_GRAY + pre + res + ANSI_RESET ); - readline.moveCursor( this._repl._ostream, 0, -1 ); - readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); - this._isPreview = true; - debug( 'sucess' ); -}); - -/** -* Callback which should be invoked**before** a "keypress" event. -* -* @name beforeKeyPress -* @memberof EagerEvaluator.prototype -* @type {Function} -* @param {string} data - input data -* @param {(Object|void)} key - key object -* @returns {void} -* -*/ -setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { - if (!this._isPreview ) { - return; - } - if ( this._isPreview ) { - this.clear(); - } -}); - -/** -* Function to determine if code is side-effect-free. -* -* @name isSideEffectFree +* @private +* @name _isSideEffectFree * @memberof EagerEvaluator.prototype * @type {Function} * @param {string} code - input code -* @returns {boolean} - boolean indicate weather code is side effect free or not. +* @returns {boolean} - boolean indicating whether the code is side-effect-free or not * */ -setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function isSideEffectFree( code ) { +setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', function isSideEffectFree( code ) { var ast; var i; @@ -193,10 +103,10 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function ast = parse( code, AOPTS ); } catch (err) { - debug( 'getting error when generating AST %S ', err ); + debug( 'Encountered an error when generating AST: %s', err ); return false; } - // Iterate from each node in body + // Iterate from each node in the body: for ( i = 0; i < ast.body.length; i++ ) { if ( !traverse( ast.body[ i ] ) ) { return false; @@ -205,11 +115,11 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function return true; /** - * Function which recursivly traverse from the node and tells weather node is side effect free or not. + * Recursively traverses the node to determine whether the node is side-effect-free or not. * * @private * @param {Object} node - ast node - * @returns {Boolean} - boolean indicating whether the node is side effect free or not + * @returns {Boolean} - boolean indicating whether the node is side-effect=free or not */ function traverse( node ) { var fname; @@ -233,7 +143,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function else if ( node.type === 'CallExpression' ) { fname = getFunctionName( node.callee ); if ( tempDB[fname] && tempDB[fname].isPure ) { - // Iterating through arguments + // Iterating through arguments: for ( i = 0; i < node.arguments.length; i++ ) { if ( !traverse( node.arguments[ i ] ) ) { return false; @@ -246,11 +156,11 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function } /** - * Get the underscore seprate function name for the member function call. + * Gets a function name representing identifier and member expression nodes. * * @private * @param {Object} node - ast node - * @returns {string} - underscore seprated function name for the member function call + * @returns {string} - function name representing the node */ function getFunctionName( node ) { if ( !node ) { @@ -267,15 +177,16 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'isSideEffectFree', function } ); /** -* Method to clear the eagerly evaluated text. +* Clears eagerly-evaluated output. * +* @private * @name clear * @memberof EagerEvaluator.prototype * @type {Function} * @returns {void} * */ -setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear( ) { +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { var cursorPosition; cursorPosition = this._rli.cursor; @@ -286,6 +197,100 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear( ) { this._isPreview = false; } ); +/** +* Callback which should be invoked **before** a "keypress" event. +* +* @private +* @name beforeKeypress +* @memberof EagerEvaluator.prototype +* @type {Function} +* @param {string} data - input data +* @param {(Object|void)} key - key object +* @returns {void} +* +*/ +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { + if (!this._isPreview ) { + return; + } + if ( this._isPreview ) { + this.clear(); + } +}); + +/** +* Callback for handling a "keypress" event. +* +* @private +* @name onKeypress +* @memberof EagerEvaluator.prototype +* @type {Function} +* @param {string} data - input data +* @param {(Object|void)} key - key object +* @returns {void} +* +*/ +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKeypress() { + var cursorPosition; + var executable; + var nlInd; + var code; + var opts; + var pre; + var res; + var tmp; + + if ( !this._enabled || this._rli.line === '' ) { + return; + } + + code = this._cmd.join( '\n' ) + this._rli.line; + opts = { + 'timeout': this._repl._timeout, + 'displayErrors': false, + 'breakOnSigint': true // Node.js >=6.3.0 + }; + if ( !this._isSideEffectFree( code ) ) { + debug( 'code have side effect' ); + return; + } + debug( 'try to process command' ); + tmp = processCommand( code ); + if ( tmp instanceof Error ) { + debug( 'getting error %s', tmp.message ); + return; + } + debug( 'try to compile command' ); + executable = compileCommand( tmp ); + if ( executable instanceof Error ) { + debug( 'getting error %s', executable.message ); + return; + } + try { + if ( this._repl._sandbox ) { + res = executable.compiled.runInContext( this._repl._context, opts ); + } else { + res = executable.compiled.runInThisContext( opts ); + } + } catch (err) { + debug( 'getting error when executing the command %s', err.message ); + return; + } + + res = inspect( res ); + nlInd = res.indexOf( '\n' ); + if ( nlInd !== -1 ) { + res = res.slice( 0, nlInd ) + '...'; + } + cursorPosition = this._rli.cursor; + pre = replace( this._repl._outputPrompt, '%d', ( this._repl._count+1 ).toString() ); + this._repl._ostream.write( '\n' + ANSI_GRAY + pre + res + ANSI_RESET ); + readline.moveCursor( this._repl._ostream, 0, -1 ); + readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); + this._isPreview = true; + debug( 'sucess' ); +}); + // EXPORTS // diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 96315a359f7f..94a7af1d675c 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-restricted-syntax, no-invalid-this, no-underscore-dangle, max-lines, max-lines-per-function */ +/* eslint-disable no-restricted-syntax, no-invalid-this, no-underscore-dangle, max-lines, max-lines-per-function, max-statements */ 'use strict'; @@ -411,7 +411,9 @@ function REPL( options ) { self._previewCompleter.clear(); } self._completerEngine.onKeypress( data, key ); - self._eagerEvaluator.onKeypress( data, key ); + if ( !self._completerEngine.isNavigating() ) { + self._eagerEvaluator.onKeypress( data, key ); + } self._multilineHandler.onKeypress( data, key ); self._syntaxHighlighter.onKeypress(); self._previewCompleter.onKeypress( data, key ); From cf2eaa7baab398a6b8935d6e9056da9c25bdd2b0 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 30 Jan 2025 03:39:08 +0000 Subject: [PATCH 16/38] fix: add stricter timeout and clean ups Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/repl/lib/eager_evaluator.js | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index f7afd40bfdb2..9cb93c2e693e 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -40,6 +40,11 @@ var debug = logger( 'repl:eager-evaluator' ); var AOPTS = { 'ecmaVersion': 'latest' }; +var ROPTS = { + 'timeout': 400, // (in milliseconds) shouldn't be much noticeable when naturally typing + 'displayErrors': false, + 'breakOnSigint': true // Node.js >=6.3.0 +}; var tempDB = { 'base_sin': { 'isPure': true @@ -57,14 +62,14 @@ var ANSI_RESET = ANSI_COLORS[ 'reset' ]; * @private * @param {REPL} repl - repl instance * @param {Object} rli - readline instance -* @param {Boolean} enabled - boolean indicating whether the syntax-highlighter should be initially enabled -* @returns {EagerEvaluator} eager-evaluator instance +* @param {Boolean} enabled - boolean indicating whether the eager evaluator should be initially enabled +* @returns {EagerEvaluator} eager evaluator instance */ function EagerEvaluator( repl, rli, enabled ) { if ( !(this instanceof EagerEvaluator) ) { return new EagerEvaluator( repl, rli, enabled ); } - debug( 'Creating a new eager-evaluator...' ); + debug( 'Creating a new eager evaluator...' ); // Cache a reference to the provided REPL instance: this._repl = repl; @@ -75,11 +80,11 @@ function EagerEvaluator( repl, rli, enabled ) { // Cache a reference to the command array: this._cmd = repl._cmd; - // Flag indicate weather eagerevaluation is enable or not + // Initialize a flag indicating whether the eager evaluator is enabled: this._enabled = enabled; - // Flag indicate weather preview is on terminal or not - this._isPreview = false; + // Initialize a flag indicating whether we are currently previewing eagerly-evaluated output: + this._isPreviewing = false; return this; } @@ -92,7 +97,7 @@ function EagerEvaluator( repl, rli, enabled ) { * @memberof EagerEvaluator.prototype * @type {Function} * @param {string} code - input code -* @returns {boolean} - boolean indicating whether the code is side-effect-free or not +* @returns {boolean} - boolean indicating whether the code is side-effect-free * */ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', function isSideEffectFree( code ) { @@ -102,8 +107,8 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', functio try { ast = parse( code, AOPTS ); } - catch (err) { - debug( 'Encountered an error when generating AST: %s', err ); + catch ( err ) { + debug( 'Encountered an error when generating AST: %s', err.message ); return false; } // Iterate from each node in the body: @@ -119,7 +124,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', functio * * @private * @param {Object} node - ast node - * @returns {Boolean} - boolean indicating whether the node is side-effect=free or not + * @returns {Boolean} - boolean indicating whether the node is side-effect-free */ function traverse( node ) { var fname; @@ -194,7 +199,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { readline.clearLine( this._repl._ostream, 0 ); readline.moveCursor( this._repl._ostream, 0, -1 ); readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); - this._isPreview = false; + this._isPreviewing = false; } ); /** @@ -210,10 +215,10 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { * */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { - if (!this._isPreview ) { + if (!this._isPreviewing ) { return; } - if ( this._isPreview ) { + if ( this._isPreviewing ) { this.clear(); } }); @@ -235,7 +240,6 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey var executable; var nlInd; var code; - var opts; var pre; var res; var tmp; @@ -245,35 +249,31 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey } code = this._cmd.join( '\n' ) + this._rli.line; - opts = { - 'timeout': this._repl._timeout, - 'displayErrors': false, - 'breakOnSigint': true // Node.js >=6.3.0 - }; + debug( 'Eagerly evaluating: %s', code ); if ( !this._isSideEffectFree( code ) ) { - debug( 'code have side effect' ); + debug( 'Code is not side-effect free, exiting eager-evaluation.' ); return; } debug( 'try to process command' ); tmp = processCommand( code ); if ( tmp instanceof Error ) { - debug( 'getting error %s', tmp.message ); + debug( 'Error encountered when processing command: %s', tmp.message ); return; } - debug( 'try to compile command' ); + debug( 'Trying to compile command' ); executable = compileCommand( tmp ); if ( executable instanceof Error ) { - debug( 'getting error %s', executable.message ); + debug( 'Error encountered when compiling command: %s', executable.message ); return; } try { if ( this._repl._sandbox ) { - res = executable.compiled.runInContext( this._repl._context, opts ); + res = executable.compiled.runInContext( this._repl._context, ROPTS ); } else { - res = executable.compiled.runInThisContext( opts ); + res = executable.compiled.runInThisContext( ROPTS ); } - } catch (err) { - debug( 'getting error when executing the command %s', err.message ); + } catch ( err ) { + debug( 'Encountered an error when executing the command: %s', err.message ); return; } @@ -287,7 +287,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey this._repl._ostream.write( '\n' + ANSI_GRAY + pre + res + ANSI_RESET ); readline.moveCursor( this._repl._ostream, 0, -1 ); readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); - this._isPreview = true; + this._isPreviewing = true; debug( 'sucess' ); }); From 81becd2cc6c8a4bdf86108776d0df83f55d60546 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 30 Jan 2025 03:58:26 +0000 Subject: [PATCH 17/38] fix: update incorrect logic for handling multiline inputs Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 9 ++++++++- lib/node_modules/@stdlib/repl/lib/main.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 9cb93c2e693e..9b585ad24c22 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -29,6 +29,8 @@ var logger = require( 'debug' ); var parse = require( 'acorn' ).parse; var replace = require( '@stdlib/string/replace' ); var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var deepCopy = require( '@stdlib/utils/copy' ); +var max = require( '@stdlib/math/base/special/max' ); var processCommand = require( './process_command.js' ); var compileCommand = require( './compile_command.js' ); var ANSI_COLORS = require( './ansi_colors.js' ); @@ -240,6 +242,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey var executable; var nlInd; var code; + var cmd; var pre; var res; var tmp; @@ -248,7 +251,11 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey return; } - code = this._cmd.join( '\n' ) + this._rli.line; + // Build the final command: + cmd = deepCopy( this._cmd ); + cmd[ max( cmd.length - 1, 0 ) ] = this._rli.line; // eager-evaluation should only work when on the last line, hence updating the last index + + code = cmd.join( '\n' ); debug( 'Eagerly evaluating: %s', code ); if ( !this._isSideEffectFree( code ) ) { debug( 'Code is not side-effect free, exiting eager-evaluation.' ); diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 94a7af1d675c..7d27616d0b67 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -411,10 +411,10 @@ function REPL( options ) { self._previewCompleter.clear(); } self._completerEngine.onKeypress( data, key ); + self._multilineHandler.onKeypress( data, key ); if ( !self._completerEngine.isNavigating() ) { self._eagerEvaluator.onKeypress( data, key ); } - self._multilineHandler.onKeypress( data, key ); self._syntaxHighlighter.onKeypress(); self._previewCompleter.onKeypress( data, key ); } From 28c0f8d0e57b9132b6a96bf3b5d8ee035712c52d Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 30 Jan 2025 04:19:02 +0000 Subject: [PATCH 18/38] style: update debug logs Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 9b585ad24c22..913a2e39023b 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -258,16 +258,16 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey code = cmd.join( '\n' ); debug( 'Eagerly evaluating: %s', code ); if ( !this._isSideEffectFree( code ) ) { - debug( 'Code is not side-effect free, exiting eager-evaluation.' ); + debug( 'Code is not side-effect free, exiting eager-evaluation...' ); return; } - debug( 'try to process command' ); + debug( 'Trying to process command...' ); tmp = processCommand( code ); if ( tmp instanceof Error ) { debug( 'Error encountered when processing command: %s', tmp.message ); return; } - debug( 'Trying to compile command' ); + debug( 'Trying to compile command...' ); executable = compileCommand( tmp ); if ( executable instanceof Error ) { debug( 'Error encountered when compiling command: %s', executable.message ); From 998db529843c82c034644c71e06e0db0566d37b6 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Thu, 30 Jan 2025 06:05:53 +0000 Subject: [PATCH 19/38] feat: add logic to setting to toggle eagerevaluator --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/repl/lib/eager_evaluator.js | 26 +++++++++++++++++++ lib/node_modules/@stdlib/repl/lib/main.js | 16 ++++++------ lib/node_modules/@stdlib/repl/lib/settings.js | 4 +++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 913a2e39023b..ecc3f320d8c5 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -204,6 +204,32 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { this._isPreviewing = false; } ); +/** +* Disable the eager-evaluator. +* +* @name disable +* @memberof EagerEvaluator.prototype +* @type {Function} +* @returns {EagerEvaluator} eager-evaluator instance +*/ +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disable', function disable() { + this._enabled = false; + return this; +}); + +/** +* Enables the eager-evaluator. +* +* @name enable +* @memberof EagerEvaluator.prototype +* @type {Function} +* @returns {EagerEvaluator} eager-evaluator instance +*/ +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'enable', function enable() { + this._enabled = true; + return this; +}); + /** * Callback which should be invoked **before** a "keypress" event. * diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 7d27616d0b67..9c042002b0f6 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -109,6 +109,7 @@ var debug = logger( 'repl' ); * @param {boolean} [options.settings.completionPreviews] - boolean indicating whether to enable completion previews for auto-completion * @param {boolean} [options.settings.autoDisableBracketedPasteOnExit] - boolean indicating whether to automatically disable bracketed-paste upon exiting the REPL * @param {boolean} [options.settings.syntaxHighlighting] - boolean indicating whether to enable syntax highlighting +* @param {boolean} [options.settings.eagerEvaluation] - boolean indicating whether to enable eagerEvaluation * @param {string} [options.settings.theme] - initial color theme for syntax highlighting * @throws {Error} must provide valid options * @returns {REPL} REPL instance @@ -160,14 +161,7 @@ function REPL( options ) { opts.settings.completionPreviews = ( opts.settings.completionPreviews === void 0 ) ? opts.isTTY : opts.settings.completionPreviews; // eslint-disable-line max-len opts.settings.autoDisableBracketedPasteOnExit = ( opts.settings.autoDisableBracketedPasteOnExit === void 0 ) ? opts.isTTY : opts.settings.autoDisableBracketedPasteOnExit; // eslint-disable-line max-len opts.settings.syntaxHighlighting = ( opts.settings.syntaxHighlighting === void 0 ) ? opts.isTTY : opts.settings.syntaxHighlighting; // eslint-disable-line max-len - - // This is temparary because eager evaluation conflicting with the some tests. - if ( options && options.settings && options.settings.eagerEvaluation !== void 0 ) { - opts.settings.eagerEvaluation = options.settings.eagerEvaluation; - } - else { - opts.settings.eagerEvaluation = ( opts.settings.eagerEvaluation === void 0 ) ? opts.isTTY : opts.settings.eagerEvaluation; // eslint-disable-line max-len - } + opts.settings.eagerEvaluation = ( opts.settings.eagerEvaluation === void 0 ) ? opts.isTTY : opts.settings.eagerEvaluation; // eslint-disable-line max-len debug( 'Options: %s', JSON.stringify({ 'input': '', @@ -1524,6 +1518,12 @@ setNonEnumerableReadOnly( REPL.prototype, 'settings', function settings() { } else { this._multilineHandler.disableBracketedPaste(); } + } else if ( name === 'eagerEvaluation' ) { + if ( value ) { + this._eagerEvaluator.enable(); + } else { + this._eagerEvaluator.disable(); + } } return this; diff --git a/lib/node_modules/@stdlib/repl/lib/settings.js b/lib/node_modules/@stdlib/repl/lib/settings.js index 53a38eaffc00..b9af4285f0eb 100644 --- a/lib/node_modules/@stdlib/repl/lib/settings.js +++ b/lib/node_modules/@stdlib/repl/lib/settings.js @@ -56,6 +56,10 @@ var SETTINGS = { 'desc': 'Enable syntax highlighting.', 'type': 'boolean' }, + 'eagerEvaluation': { + 'desc': 'Enable eager evaluation', + 'type': 'boolean' + }, 'theme': { 'desc': 'Set the syntax highlighting theme.', 'type': 'string' From 36619b0b001f12473b3cdfe45609f4b3d67f3eea Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 30 Jan 2025 14:35:21 +0000 Subject: [PATCH 20/38] fix: make timeout even stricter Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index ecc3f320d8c5..494d7313e5c2 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -43,7 +43,7 @@ var AOPTS = { 'ecmaVersion': 'latest' }; var ROPTS = { - 'timeout': 400, // (in milliseconds) shouldn't be much noticeable when naturally typing + 'timeout': 100, // (in milliseconds) shouldn't be much noticeable when naturally typing 'displayErrors': false, 'breakOnSigint': true // Node.js >=6.3.0 }; From 0f19131d4fdda5d51cee3ffca14a6d7c78b72d59 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Thu, 30 Jan 2025 14:43:07 +0000 Subject: [PATCH 21/38] style: clean ups Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 10 +++++----- lib/node_modules/@stdlib/repl/lib/main.js | 2 +- lib/node_modules/@stdlib/repl/lib/settings.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 494d7313e5c2..5eb0a00b6e1f 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -59,7 +59,7 @@ var ANSI_RESET = ANSI_COLORS[ 'reset' ]; // MAIN // /** -* Constructor for creating a eager evaluator. +* Constructor for creating an eager evaluator. * * @private * @param {REPL} repl - repl instance @@ -205,12 +205,12 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { } ); /** -* Disable the eager-evaluator. +* Disable the eager evaluator. * * @name disable * @memberof EagerEvaluator.prototype * @type {Function} -* @returns {EagerEvaluator} eager-evaluator instance +* @returns {EagerEvaluator} eager evaluator instance */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disable', function disable() { this._enabled = false; @@ -218,12 +218,12 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disable', function disable( }); /** -* Enables the eager-evaluator. +* Enables the eager evaluator. * * @name enable * @memberof EagerEvaluator.prototype * @type {Function} -* @returns {EagerEvaluator} eager-evaluator instance +* @returns {EagerEvaluator} eager evaluator instance */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'enable', function enable() { this._enabled = true; diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index 9c042002b0f6..bfac2b5aed10 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -109,7 +109,7 @@ var debug = logger( 'repl' ); * @param {boolean} [options.settings.completionPreviews] - boolean indicating whether to enable completion previews for auto-completion * @param {boolean} [options.settings.autoDisableBracketedPasteOnExit] - boolean indicating whether to automatically disable bracketed-paste upon exiting the REPL * @param {boolean} [options.settings.syntaxHighlighting] - boolean indicating whether to enable syntax highlighting -* @param {boolean} [options.settings.eagerEvaluation] - boolean indicating whether to enable eagerEvaluation +* @param {boolean} [options.settings.eagerEvaluation] - boolean indicating whether to enable eager evaluation * @param {string} [options.settings.theme] - initial color theme for syntax highlighting * @throws {Error} must provide valid options * @returns {REPL} REPL instance diff --git a/lib/node_modules/@stdlib/repl/lib/settings.js b/lib/node_modules/@stdlib/repl/lib/settings.js index b9af4285f0eb..429e21b3d1a5 100644 --- a/lib/node_modules/@stdlib/repl/lib/settings.js +++ b/lib/node_modules/@stdlib/repl/lib/settings.js @@ -57,7 +57,7 @@ var SETTINGS = { 'type': 'boolean' }, 'eagerEvaluation': { - 'desc': 'Enable eager evaluation', + 'desc': 'Enable eager evaluation.', 'type': 'boolean' }, 'theme': { From 412fba3213910542be39033b9c3c48c91a78f5f6 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sat, 1 Feb 2025 03:39:28 +0000 Subject: [PATCH 22/38] style: clean ups --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/repl/lib/eager_evaluator.js | 144 +++++++++--------- lib/node_modules/@stdlib/repl/lib/main.js | 2 +- 2 files changed, 70 insertions(+), 76 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 5eb0a00b6e1f..263add65cff3 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -29,7 +29,7 @@ var logger = require( 'debug' ); var parse = require( 'acorn' ).parse; var replace = require( '@stdlib/string/replace' ); var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var deepCopy = require( '@stdlib/utils/copy' ); +var copy = require( '@stdlib/array/base/copy' ); var max = require( '@stdlib/math/base/special/max' ); var processCommand = require( './process_command.js' ); var compileCommand = require( './compile_command.js' ); @@ -43,7 +43,7 @@ var AOPTS = { 'ecmaVersion': 'latest' }; var ROPTS = { - 'timeout': 100, // (in milliseconds) shouldn't be much noticeable when naturally typing + 'timeout': 100, // // (in milliseconds) this controls how long eagerly evaluated commands have to execute; we need to avoid setting this too high in order to avoid eager evaluation interfering with the UX when naturally typing 'displayErrors': false, 'breakOnSigint': true // Node.js >=6.3.0 }; @@ -108,8 +108,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', functio try { ast = parse( code, AOPTS ); - } - catch ( err ) { + } catch ( err ) { debug( 'Encountered an error when generating AST: %s', err.message ); return false; } @@ -120,67 +119,6 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', functio } } return true; - - /** - * Recursively traverses the node to determine whether the node is side-effect-free or not. - * - * @private - * @param {Object} node - ast node - * @returns {Boolean} - boolean indicating whether the node is side-effect-free - */ - function traverse( node ) { - var fname; - var i; - if ( !node ) { - return false; - } - if ( node.type === 'Literal' || node.type === 'Identifier' || node.type === 'MemberExpression' ) { - return true; - } - if ( node.type === 'BinaryExpression' ) { - if ( traverse( node.left ) && traverse( node.right ) ) { - return true; - } - } - else if ( node.type === 'ExpressionStatement' ) { - if ( traverse( node.expression ) ) { - return true; - } - } - else if ( node.type === 'CallExpression' ) { - fname = getFunctionName( node.callee ); - if ( tempDB[fname] && tempDB[fname].isPure ) { - // Iterating through arguments: - for ( i = 0; i < node.arguments.length; i++ ) { - if ( !traverse( node.arguments[ i ] ) ) { - return false; - } - } - return true; - } - } - return false; - } - - /** - * Gets a function name representing identifier and member expression nodes. - * - * @private - * @param {Object} node - ast node - * @returns {string} - function name representing the node - */ - function getFunctionName( node ) { - if ( !node ) { - return ''; - } - if ( node.type === 'MemberExpression' ) { - return getFunctionName(node.object) + '_' + node.property.name; - } - if ( node.type === 'Identifier' ) { - return node.name; - } - return ''; - } } ); /** @@ -191,7 +129,6 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', functio * @memberof EagerEvaluator.prototype * @type {Function} * @returns {void} -* */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { var cursorPosition; @@ -212,7 +149,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { * @type {Function} * @returns {EagerEvaluator} eager evaluator instance */ -setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disable', function disable() { +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disables', function disable() { this._enabled = false; return this; }); @@ -240,7 +177,6 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'enable', function enable() * @param {string} data - input data * @param {(Object|void)} key - key object * @returns {void} -* */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { if (!this._isPreviewing ) { @@ -261,12 +197,11 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function b * @param {string} data - input data * @param {(Object|void)} key - key object * @returns {void} -* */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKeypress() { var cursorPosition; var executable; - var nlInd; + var index; var code; var cmd; var pre; @@ -278,7 +213,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey } // Build the final command: - cmd = deepCopy( this._cmd ); + cmd = copy( this._cmd ); cmd[ max( cmd.length - 1, 0 ) ] = this._rli.line; // eager-evaluation should only work when on the last line, hence updating the last index code = cmd.join( '\n' ); @@ -311,9 +246,9 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey } res = inspect( res ); - nlInd = res.indexOf( '\n' ); - if ( nlInd !== -1 ) { - res = res.slice( 0, nlInd ) + '...'; + index = res.indexOf( '\n' ); + if ( index !== -1 ) { + res = res.slice( 0, index ) + '...'; } cursorPosition = this._rli.cursor; pre = replace( this._repl._outputPrompt, '%d', ( this._repl._count+1 ).toString() ); @@ -321,9 +256,68 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey readline.moveCursor( this._repl._ostream, 0, -1 ); readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); this._isPreviewing = true; - debug( 'sucess' ); + debug( 'Successfully evaluated command.' ); }); +/** + * Recursively traverses the node to determine whether the node is side-effect-free or not. + * + * @private + * @param {Object} node - ast node + * @returns {Boolean} - boolean indicating whether the node is side-effect-free + */ +function traverse( node ) { + var fname; + var i; + if ( !node ) { + return false; + } + if ( node.type === 'Literal' || node.type === 'Identifier' || node.type === 'MemberExpression' ) { + return true; + } + if ( node.type === 'BinaryExpression' ) { + if ( traverse( node.left ) && traverse( node.right ) ) { + return true; + } + } else if ( node.type === 'ExpressionStatement' ) { + if ( traverse( node.expression ) ) { + return true; + } + } else if ( node.type === 'CallExpression' ) { + fname = getFunctionName( node.callee ); + if ( tempDB[fname] && tempDB[fname].isPure ) { + // Examine each function argument for potential side-effects... + for ( i = 0; i < node.arguments.length; i++ ) { + if ( !traverse( node.arguments[ i ] ) ) { + return false; + } + } + return true; + } + } + return false; +} + +/** + * Gets a function name representing identifier and member expression nodes. + * + * @private + * @param {Object} node - ast node + * @returns {string} - function name representing the node + */ +function getFunctionName( node ) { + if ( !node ) { + return ''; + } + if ( node.type === 'MemberExpression' ) { + return getFunctionName( node.object ) + '_' + node.property.name; + } + if ( node.type === 'Identifier' ) { + return node.name; + } + return ''; +} + // EXPORTS // diff --git a/lib/node_modules/@stdlib/repl/lib/main.js b/lib/node_modules/@stdlib/repl/lib/main.js index bfac2b5aed10..8298dd1a723d 100644 --- a/lib/node_modules/@stdlib/repl/lib/main.js +++ b/lib/node_modules/@stdlib/repl/lib/main.js @@ -296,7 +296,7 @@ function REPL( options ) { // Initialize a syntax-highlighter: setNonEnumerableReadOnly( this, '_syntaxHighlighter', new SyntaxHighlighter( this, this._ostream, this._settings.syntaxHighlighting ) ); - // Initialize a eagerEvaluator: + // Initialize an eager evaluator: setNonEnumerableReadOnly( this, '_eagerEvaluator', new EagerEvaluator( this, this._rli, this._settings.eagerEvaluation ) ); // Cache a reference to the private readline interface `ttyWrite` to allow calling the method when wanting default behavior: From b884fa6df385a4fc2556e132d14cc20854fe9125 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sat, 1 Feb 2025 03:47:36 +0000 Subject: [PATCH 23/38] style: clean up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 263add65cff3..b65d545d92dc 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -139,17 +139,17 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { readline.moveCursor( this._repl._ostream, 0, -1 ); readline.cursorTo( this._repl._ostream, cursorPosition + this._repl.promptLength() ); this._isPreviewing = false; -} ); +}); /** -* Disable the eager evaluator. +* Disables the eager evaluator. * * @name disable * @memberof EagerEvaluator.prototype * @type {Function} * @returns {EagerEvaluator} eager evaluator instance */ -setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disables', function disable() { +setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disable', function disable() { this._enabled = false; return this; }); From 2e03eb3b4b6f02189de420bf596efe12f79b425c Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sat, 1 Feb 2025 03:51:06 +0000 Subject: [PATCH 24/38] style: clean up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index b65d545d92dc..860486c38048 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -119,7 +119,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', functio } } return true; -} ); +}); /** * Clears eagerly-evaluated output. From a40a99a9c3b78f78b2f56a59531df437932d23b9 Mon Sep 17 00:00:00 2001 From: Snehil Shah Date: Sat, 1 Feb 2025 18:03:06 +0000 Subject: [PATCH 25/38] style: correctly place functions Signed-off-by: Snehil Shah --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/repl/lib/eager_evaluator.js | 123 +++++++++--------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 860486c38048..143b6e4190d5 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -43,7 +43,7 @@ var AOPTS = { 'ecmaVersion': 'latest' }; var ROPTS = { - 'timeout': 100, // // (in milliseconds) this controls how long eagerly evaluated commands have to execute; we need to avoid setting this too high in order to avoid eager evaluation interfering with the UX when naturally typing + 'timeout': 100, // (in milliseconds) this controls how long eagerly evaluated commands have to execute; we need to avoid setting this too high in order to avoid eager evaluation interfering with the UX when naturally typing 'displayErrors': false, 'breakOnSigint': true // Node.js >=6.3.0 }; @@ -56,6 +56,68 @@ var ANSI_GRAY = ANSI_COLORS[ 'brightBlack' ]; var ANSI_RESET = ANSI_COLORS[ 'reset' ]; +// FUNCTIONS // + +/** +* Recursively traverses the node to determine whether the node is side-effect-free or not. +* +* @private +* @param {Object} node - ast node +* @returns {Boolean} - boolean indicating whether the node is side-effect-free +*/ +function traverse( node ) { + var fname; + var i; + if ( !node ) { + return false; + } + if ( node.type === 'Literal' || node.type === 'Identifier' || node.type === 'MemberExpression' ) { + return true; + } + if ( node.type === 'BinaryExpression' ) { + if ( traverse( node.left ) && traverse( node.right ) ) { + return true; + } + } else if ( node.type === 'ExpressionStatement' ) { + if ( traverse( node.expression ) ) { + return true; + } + } else if ( node.type === 'CallExpression' ) { + fname = getFunctionName( node.callee ); + if ( tempDB[fname] && tempDB[fname].isPure ) { + // Examine each function argument for potential side-effects... + for ( i = 0; i < node.arguments.length; i++ ) { + if ( !traverse( node.arguments[ i ] ) ) { + return false; + } + } + return true; + } + } + return false; +} + +/** +* Gets a function name representing identifier and member expression nodes. +* +* @private +* @param {Object} node - ast node +* @returns {string} - function name representing the node +*/ +function getFunctionName( node ) { + if ( !node ) { + return ''; + } + if ( node.type === 'MemberExpression' ) { + return getFunctionName( node.object ) + '_' + node.property.name; + } + if ( node.type === 'Identifier' ) { + return node.name; + } + return ''; +} + + // MAIN // /** @@ -259,65 +321,6 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey debug( 'Successfully evaluated command.' ); }); -/** - * Recursively traverses the node to determine whether the node is side-effect-free or not. - * - * @private - * @param {Object} node - ast node - * @returns {Boolean} - boolean indicating whether the node is side-effect-free - */ -function traverse( node ) { - var fname; - var i; - if ( !node ) { - return false; - } - if ( node.type === 'Literal' || node.type === 'Identifier' || node.type === 'MemberExpression' ) { - return true; - } - if ( node.type === 'BinaryExpression' ) { - if ( traverse( node.left ) && traverse( node.right ) ) { - return true; - } - } else if ( node.type === 'ExpressionStatement' ) { - if ( traverse( node.expression ) ) { - return true; - } - } else if ( node.type === 'CallExpression' ) { - fname = getFunctionName( node.callee ); - if ( tempDB[fname] && tempDB[fname].isPure ) { - // Examine each function argument for potential side-effects... - for ( i = 0; i < node.arguments.length; i++ ) { - if ( !traverse( node.arguments[ i ] ) ) { - return false; - } - } - return true; - } - } - return false; -} - -/** - * Gets a function name representing identifier and member expression nodes. - * - * @private - * @param {Object} node - ast node - * @returns {string} - function name representing the node - */ -function getFunctionName( node ) { - if ( !node ) { - return ''; - } - if ( node.type === 'MemberExpression' ) { - return getFunctionName( node.object ) + '_' + node.property.name; - } - if ( node.type === 'Identifier' ) { - return node.name; - } - return ''; -} - // EXPORTS // From f2f4c9b8b4acbe50f82322ed7b9e6d025aea927a Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:21:28 -0800 Subject: [PATCH 26/38] docs: fix return type Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 143b6e4190d5..752082426f91 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -63,7 +63,7 @@ var ANSI_RESET = ANSI_COLORS[ 'reset' ]; * * @private * @param {Object} node - ast node -* @returns {Boolean} - boolean indicating whether the node is side-effect-free +* @returns {boolean} boolean indicating whether the node is side-effect-free */ function traverse( node ) { var fname; From 08c68e5ad374a12174bd144daaa2708cf67c23d4 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:21:52 -0800 Subject: [PATCH 27/38] docs: update description Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 752082426f91..116a57871699 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -59,7 +59,7 @@ var ANSI_RESET = ANSI_COLORS[ 'reset' ]; // FUNCTIONS // /** -* Recursively traverses the node to determine whether the node is side-effect-free or not. +* Recursively traverses the node to determine whether the node is side-effect-free. * * @private * @param {Object} node - ast node From 858478280585914b5ab25878140843be68f011e9 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:22:19 -0800 Subject: [PATCH 28/38] docs: remove hyphen Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 116a57871699..733ee8d1a62c 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -102,7 +102,7 @@ function traverse( node ) { * * @private * @param {Object} node - ast node -* @returns {string} - function name representing the node +* @returns {string} function name representing the node */ function getFunctionName( node ) { if ( !node ) { From 888931465c2cfefdfa59d7a989bd9ee84cdb2081 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:23:28 -0800 Subject: [PATCH 29/38] docs: update description Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 733ee8d1a62c..f8edcee0de13 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -98,7 +98,7 @@ function traverse( node ) { } /** -* Gets a function name representing identifier and member expression nodes. +* Resolves the function name associated with a provided AST node. * * @private * @param {Object} node - ast node From 69b4fe10b156a3f4a67b440cc42d2d4f4b4527aa Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:24:04 -0800 Subject: [PATCH 30/38] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index f8edcee0de13..f7e886d2fecb 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -1,4 +1,3 @@ -/* eslint-disable max-len */ /** * @license Apache-2.0 * @@ -17,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable no-underscore-dangle, no-restricted-syntax, no-invalid-this */ +/* eslint-disable no-underscore-dangle, no-restricted-syntax, no-invalid-this, max-len */ 'use strict'; From d81e24fddc0572ef44b297a7ee16610d19f3f4e8 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:25:27 -0800 Subject: [PATCH 31/38] docs: fix type Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index f7e886d2fecb..e4f06862a543 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -125,7 +125,7 @@ function getFunctionName( node ) { * @private * @param {REPL} repl - repl instance * @param {Object} rli - readline instance -* @param {Boolean} enabled - boolean indicating whether the eager evaluator should be initially enabled +* @param {boolean} enabled - boolean indicating whether the eager evaluator should be initially enabled * @returns {EagerEvaluator} eager evaluator instance */ function EagerEvaluator( repl, rli, enabled ) { From 726037349ee1505881f326e257d4c6c7d45e8953 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:27:03 -0800 Subject: [PATCH 32/38] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index e4f06862a543..d7e92ba9ea78 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -153,15 +153,14 @@ function EagerEvaluator( repl, rli, enabled ) { } /** -* Checks if the code is side-effect-free. +* Checks whether provided code is free of side-effects. * * @private * @name _isSideEffectFree * @memberof EagerEvaluator.prototype * @type {Function} * @param {string} code - input code -* @returns {boolean} - boolean indicating whether the code is side-effect-free -* +* @returns {boolean} boolean indicating whether provided code is free of side-effects */ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', function isSideEffectFree( code ) { var ast; From 35382da53aeb888bc9d3a44e72f69891e8c53e77 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:27:51 -0800 Subject: [PATCH 33/38] docs: remove comment Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index d7e92ba9ea78..1ea74e8cb3fb 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -172,7 +172,6 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, '_isSideEffectFree', functio debug( 'Encountered an error when generating AST: %s', err.message ); return false; } - // Iterate from each node in the body: for ( i = 0; i < ast.body.length; i++ ) { if ( !traverse( ast.body[ i ] ) ) { return false; From 55392c80e7d46caf9dbd826b02b4d63e51645753 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:29:41 -0800 Subject: [PATCH 34/38] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 1ea74e8cb3fb..90eccc88b0d9 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -203,6 +203,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'clear', function clear() { /** * Disables the eager evaluator. * +* @private * @name disable * @memberof EagerEvaluator.prototype * @type {Function} @@ -216,6 +217,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'disable', function disable( /** * Enables the eager evaluator. * +* @private * @name enable * @memberof EagerEvaluator.prototype * @type {Function} From ba011642a728866c5274a3947313a1436f45d2dd Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:30:20 -0800 Subject: [PATCH 35/38] style: fix missing space Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 90eccc88b0d9..219fb09ec598 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -240,7 +240,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'enable', function enable() * @returns {void} */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { - if (!this._isPreviewing ) { + if ( !this._isPreviewing ) { return; } if ( this._isPreviewing ) { From e94acec38a046264649587acf0b45f99a1912769 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:31:26 -0800 Subject: [PATCH 36/38] refactor: remove unnecessary branch Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index 219fb09ec598..bf92fd879ad1 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -240,9 +240,6 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'enable', function enable() * @returns {void} */ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'beforeKeypress', function beforeKeypress() { - if ( !this._isPreviewing ) { - return; - } if ( this._isPreviewing ) { this.clear(); } From c63d4f51343ec611419f5e7ddb0a01f84b9eb42f Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:33:08 -0800 Subject: [PATCH 37/38] refactor: update debug message Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index bf92fd879ad1..df02bda3c4c3 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -277,7 +277,7 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey code = cmd.join( '\n' ); debug( 'Eagerly evaluating: %s', code ); if ( !this._isSideEffectFree( code ) ) { - debug( 'Code is not side-effect free, exiting eager-evaluation...' ); + debug( 'Unable to perform eager-evaluation due to potential side-effects. Skipping...' ); return; } debug( 'Trying to process command...' ); From 6393eaf851d3997493199cbf3162a8b4b7f2e003 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 02:34:10 -0800 Subject: [PATCH 38/38] refactor: update debug messages Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/eager_evaluator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js index df02bda3c4c3..c743dd6b786b 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -280,13 +280,13 @@ setNonEnumerableReadOnly( EagerEvaluator.prototype, 'onKeypress', function onKey debug( 'Unable to perform eager-evaluation due to potential side-effects. Skipping...' ); return; } - debug( 'Trying to process command...' ); + debug( 'Processing command...' ); tmp = processCommand( code ); if ( tmp instanceof Error ) { debug( 'Error encountered when processing command: %s', tmp.message ); return; } - debug( 'Trying to compile command...' ); + debug( 'Compiling command...' ); executable = compileCommand( tmp ); if ( executable instanceof Error ) { debug( 'Error encountered when compiling command: %s', executable.message );