Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

fix: make sort-import-destructures work with long lists #146

Merged
merged 1 commit into from
Feb 10, 2020

Conversation

wincent
Copy link
Contributor

@wincent wincent commented Feb 10, 2020

The old implementation happened to work with short lists but it made too many assumptions about the order in which pairs in the list would be compared. As soon as we tried running this on files with many names being destructured (like the one in the included regression test), then the assumption (that we'd only ever call element in list-order) was invalidated.

V8 actually uses Timsort under the covers (https://v8.dev/blog/array-sort), but that is besides the point. We need to make sure the comparator function passed to sort behaves identically regardless of comparison order.

The old implementation happened to work with short lists but it made too
many assumptions about the order in which pairs in the list would be
compared. As soon as we tried running this on files with many names
being destructured (like the one in the included regression test), then
the assumption (that we'd only ever call element in list-order) was
invalidated.

V8 actually uses Timsort under the covers
(https://v8.dev/blog/array-sort), but that is besides the point. We
need to make sure the comparator function passed to `sort` behaves
identically regardless of comparison order.
@wincent wincent added the bug label Feb 10, 2020
@wincent
Copy link
Contributor Author

wincent commented Feb 10, 2020

brown-paper-bag

@wincent wincent merged commit 6fc9da1 into master Feb 10, 2020
@wincent wincent deleted the wincent/fix-sorting branch February 10, 2020 14:03
wincent added a commit to liferay/liferay-npm-tools that referenced this pull request Feb 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant