blob: 701d27c4e67066f146f27296f6eb495f61fe96e9 [file] [edit]
import { call } from '../node.js';
import { foldConstArgs, foldResult } from './fold.js';
/** @typedef {import('../node.js').Node} Node */
/**
* @param {string} name
* @param {Node[]} args
* @return {Node}
*/
function simplifyMinMax(name, args) {
const fold = foldConstArgs(args);
if (fold !== null) {
const fn = name.toLowerCase() === 'min' ? Math.min : Math.max;
const value = fn(...fold.values);
return foldResult(fold, value);
}
return call(name, args);
}
export { simplifyMinMax };