From a7f171ec70543e30e461d82b2c56e478a0f24e3e Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Tue, 4 Feb 2025 05:26:28 +0000 Subject: [PATCH] feat: add logic for eager-evaluation of unary, array and object literal --- 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 --- --- .../@stdlib/repl/lib/eager_evaluator.js | 18 +++++++++++++++++- 1 file changed, 17 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 25a24d61d86b..c8cd708df713 100644 --- a/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js +++ b/lib/node_modules/@stdlib/repl/lib/eager_evaluator.js @@ -65,12 +65,13 @@ var ANSI_RESET = ANSI_COLORS[ 'reset' ]; * @returns {boolean} boolean indicating whether the node is side-effect-free */ function traverse( node ) { + var properties; var fname; var i; if ( !node ) { return false; } - if ( node.type === 'Literal' || node.type === 'Identifier' ) { + if ( node.type === 'Literal' || node.type === 'Identifier' || ( node.type === 'UnaryExpression' && node.operator !== 'delete' ) ) { return true; } if ( node.type === 'BinaryExpression' ) { @@ -96,6 +97,21 @@ function traverse( node ) { } return true; } + } else if ( node.type === 'ArrayExpression' ) { + for ( i = 0; i < node.elements.length; i++ ) { + if ( !traverse( node.elements[ i ] ) ) { + return false; + } + } + return true; + } else if ( node.type === 'ObjectExpression' ) { + for ( i = 0; i < node.properties.length; i++ ) { + properties = node.properties; + if ( !traverse( properties[ i ].key ) || !traverse( properties[ i ].value ) ) { + return false; + } + } + return true; } return false; }