From 5a816a4701211adf84d3f5e09b74c67076c47675 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 20 Jan 2021 00:14:50 -0500 Subject: [PATCH] Ensure all params are numeric This has long been a curse, and I don't know why I didn't resolve it sooner. This makes explicit some of the odd things that this is doing, to maintain the previous behavior. Changing that behavior would be ideal, but ought to be done separately and put behind a feature flag. --- src/current/compiler/js.xsl | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/current/compiler/js.xsl b/src/current/compiler/js.xsl index b605f754..3afaf640 100644 --- a/src/current/compiler/js.xsl +++ b/src/current/compiler/js.xsl @@ -252,9 +252,9 @@ ', - 'default': ' - - ', + 'default': + + , depth: @@ -1776,21 +1776,26 @@ // scalar if ( depth === 0 ) { - return ( input === '' || input === undefined ) ? value : input; + // TODO: error + if ( Array.isArray( input ) ) input = input[0]; + return ( input === '' || input === undefined ) ? value : +input; } - input = input || []; + // TODO: error for both + if (!Array.isArray(input)) input = [input]; + if (depth === 1 && Array.isArray(input[0])) input = input[0]; - // vector or matrix - var i = input.length || 1; - var ret = []; - var value = ( depth === 2 ) ? [ value ] : value; + // TODO: this maintains old behavior, but maybe should be an error; + // we cannot have empty index sets (see design/tpl). + if (input.length === 0) input = [value]; - while ( i-- ) { - ret[i] = ( input[i] === '' || input[i] === undefined ) ? value : input[i]; - } - - return ret; + return input.map( function( x ) { + return ( depth === 2 ) + ? Array.isArray( x ) + ? x.map( function(s) { return +s; } ) + : [ x ] + : ( x === '' || x === undefined ) ? value : +x; + } ); }