feat(helpers): resolve functions from prototypes in fake - #3970
feat(helpers): resolve functions from prototypes in fake#3970hugosmoreira wants to merge 4 commits into
Conversation
✅ Deploy Preview for fakerjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #3970 +/- ##
==========================================
- Coverage 98.91% 98.88% -0.03%
==========================================
Files 924 924
Lines 3224 3229 +5
Branches 585 569 -16
==========================================
+ Hits 3189 3193 +4
- Misses 31 32 +1
Partials 4 4
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR improves helpers.fake / fakeEval expression resolution so member access continues after generated primitive values and callable members are invoked with the correct receiver (this), fixing failures when chaining prototype methods (e.g., toISOString, trim, toPrecision).
Changes:
- Extend property resolution to box primitive generated values so properties and prototype members can be accessed after faker method calls.
- Bind callable resolved members to their source value to preserve correct receiver semantics.
- Add documentation and regression tests covering property/method chaining and constructor-chain safety.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/modules/helpers/eval.ts |
Updates the resolver to box primitives for property lookup and bind callable properties to the generated value. |
src/modules/helpers/module.ts |
Documents member/property chaining behavior for helpers.fake. |
test/modules/helpers.spec.ts |
Adds regression coverage for helpers.fake chaining on primitives and prototype methods. |
test/modules/helpers-eval.spec.ts |
Adds regression coverage for fakeEval chaining (implicit/explicit calls) and extends the GHSA constructor-chain safety suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
fakeEvalfakeEvalandhelpers.fakeRoot cause
The expression resolver only followed properties on objects. When a Faker method returned a primitive, the chain stopped; when it returned an object method such as
Date.prototype.toISOString, the method was later invoked without its receiver.The resolver now boxes supported primitives for property lookup and binds callable properties to the generated value. Functions returned by functions still use the existing recursive resolution path, preserving the constructor-chain protection added for GHSA-qxc2-j82w-r537.
Validation
pnpm run preflightCloses #3465
This contribution was developed and validated with OpenAI Codex assistance.