node-semver icon indicating copy to clipboard operation
node-semver copied to clipboard

[BUG] remove extraneous this.format() from SemVerConstructor

Open kwasimensah opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

https://github.com/npm/node-semver/blob/e9a1f26e616b2e7a3e14e1803364229980142789/classes/semver.js#L76 calls this.format()

Expected Behavior

https://github.com/npm/node-semver/blob/e9a1f26e616b2e7a3e14e1803364229980142789/classes/semver.js#L76 should not call this.format()

Steps To Reproduce

https://github.com/npm/node-semver/blob/e9a1f26e616b2e7a3e14e1803364229980142789/classes/semver.js#L76 calls this.format()

Environment

All Environments

kwasimensah avatar Jul 22 '22 21:07 kwasimensah

Actually, format writes to this.version :( I'm hunting down spurious allocations in my project and the call to this.format came up in my debugging.

I'm surprised that this function both reads and writes to a property. It may be better to turn version into a getter that calculates the value on the fly but that might impact people who are relying for it to be calculated?

kwasimensah avatar Jul 22 '22 21:07 kwasimensah

I don't see this.format() specifically as a performance issue. As you said, it is required to write this.version. I'm going to close this but keep open #458 to track overall reuse of instances.

lukekarrys avatar Oct 27 '22 17:10 lukekarrys