Skip to content

feat(lodash): add max/min/maxBy/minBy/clamp/inRange/random to manifest#982

Merged
proggeramlug merged 1 commit into
mainfrom
worktree-agent-aa9ef4af84576daa5
May 18, 2026
Merged

feat(lodash): add max/min/maxBy/minBy/clamp/inRange/random to manifest#982
proggeramlug merged 1 commit into
mainfrom
worktree-agent-aa9ef4af84576daa5

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Summary

Direct follow-up to PR #966 (sum/mean/sumBy/meanBy/head/last/tail). After #966 unblocked lodash.sum, the next bare-lodash sweep tripped on _.max:

Error: `lodash.max` is not implemented in Perry

This PR adds the seven extrema + utility methods end-to-end (runtime + manifest + codegen wiring).

  • Runtime (crates/perry-stdlib/src/lodash.rs): new js_lodash_max / js_lodash_min / js_lodash_max_by / js_lodash_min_by. clamp / in_range / random runtime helpers already existed.
  • Manifest (crates/perry-api-manifest/src/entries.rs): seven new method_sig rows.
  • Dispatch (crates/perry-codegen/src/lower_call.rs): six new NativeModSig rows (clamp was already wired).
  • FFI decls (crates/perry-codegen/src/runtime_decls.rs): four new declare_function rows (the existing three: clamp / in_range / random were already declared).

max([]) / min([]) / maxBy([], 'k') / minBy([], 'k') return undefined (NaN-boxed). maxBy/minBy accept the property-shorthand iteratee form only — same restriction as sumBy/meanBy from #966; function iteratees return undefined until closure-call plumbing across the FFI boundary lands as a follow-up.

Test plan

test-files/test_lodash_max_min.ts matches node --experimental-strip-types byte-for-byte:

5
1
{ n: 5 }
{ n: 1 }
5
0
3
true
false

Known follow-up

compilePackages: ["lodash"] (compile lodash from node_modules rather than dispatching through the native manifest) crashes at runtime with TypeError: Cannot read properties of undefined (reading 'call') — same V8-fallback-style issue blocking other compile-as-package smokes (#678 territory), unrelated to this PR. The bare-import path (which is what the manifest + native dispatch is actually for) works correctly.

- New runtime exports js_lodash_max/_min/_max_by/_min_by in
  perry-stdlib (clamp/in_range/random already existed).
- Manifest rows for all seven (max/min/maxBy/minBy/clamp/inRange/random).
- NativeModSig rows for the six new dispatches in lower_call.rs
  (clamp was already there).
- declare_function decls for the four new symbols
  (clamp/in_range/random already declared).
- test-files/test_lodash_max_min.ts matches node --experimental-strip-types
  byte-for-byte: 5 / 1 / { n: 5 } / { n: 1 } / 5 / 0 / 3 / true / false.

maxBy/minBy currently accept the property-shorthand iteratee form only;
function iteratees return undefined until closure-call plumbing across
the FFI boundary lands as a follow-up (same restriction as sumBy/meanBy
from PR #966).
@proggeramlug proggeramlug merged commit 3db1b68 into main May 18, 2026
5 of 9 checks passed
@proggeramlug proggeramlug deleted the worktree-agent-aa9ef4af84576daa5 branch May 18, 2026 02:54
proggeramlug added a commit that referenced this pull request May 18, 2026
PRs #966, #967, #982, #984 added entries to perry-api-manifest::API_MANIFEST
(stream EventEmitter instance methods, stream.prototype, lodash
inRange/max/maxBy/mean/meanBy/min/minBy/random/sum/sumBy/tail) without
rerunning ./scripts/regen_api_docs.sh. Drift has been blocking the
api-docs-drift gate on every subsequent PR; unblocking the next batch.

Coverage moves from 870 → 898 entries across 71 modules. Mechanical
regen, no manifest edits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant