Skip to content

Commit a7f171e

Browse files
committed
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 ---
1 parent 5aae46e commit a7f171e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/node_modules/@stdlib/repl/lib/eager_evaluator.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ var ANSI_RESET = ANSI_COLORS[ 'reset' ];
6565
* @returns {boolean} boolean indicating whether the node is side-effect-free
6666
*/
6767
function traverse( node ) {
68+
var properties;
6869
var fname;
6970
var i;
7071
if ( !node ) {
7172
return false;
7273
}
73-
if ( node.type === 'Literal' || node.type === 'Identifier' ) {
74+
if ( node.type === 'Literal' || node.type === 'Identifier' || ( node.type === 'UnaryExpression' && node.operator !== 'delete' ) ) {
7475
return true;
7576
}
7677
if ( node.type === 'BinaryExpression' ) {
@@ -96,6 +97,21 @@ function traverse( node ) {
9697
}
9798
return true;
9899
}
100+
} else if ( node.type === 'ArrayExpression' ) {
101+
for ( i = 0; i < node.elements.length; i++ ) {
102+
if ( !traverse( node.elements[ i ] ) ) {
103+
return false;
104+
}
105+
}
106+
return true;
107+
} else if ( node.type === 'ObjectExpression' ) {
108+
for ( i = 0; i < node.properties.length; i++ ) {
109+
properties = node.properties;
110+
if ( !traverse( properties[ i ].key ) || !traverse( properties[ i ].value ) ) {
111+
return false;
112+
}
113+
}
114+
return true;
99115
}
100116
return false;
101117
}

0 commit comments

Comments
 (0)