es-tooling / module-replacements-codemods

MIT License
188 stars 26 forks source link

fix: wrong substitution in `array.prototype.entries` #35

Closed MeLlamoPablo closed 4 months ago

MeLlamoPablo commented 4 months ago

This PR fixes a bug in the array.prototype.entries codemod that attempts to substitute the const entries = require('array.prototype.entries') import with [].entries(). It incorrectly derives the name of the native entries method in the Array prototype from the name of the import identifier. Therefore if I import:

const entries = require('array.prototype.entries')

My code becomes:

[].arrayEntries()

This PR also adds a fixture to cover the non-standard import name case.

thepassle commented 4 months ago

Good catch!

It seems like theres 1 failing test, could you fix that and update the PR? Thanks! 🙂

MeLlamoPablo commented 4 months ago

Sure thing, I'll take a look soon!

MeLlamoPablo commented 4 months ago

@thepassle tests work locally for me now, looks like it was an issue with my IDE forcing a new line at the end

thepassle commented 4 months ago

Oh nice, thanks for fixing :) And thanks for the PR!