Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the sort comparator #48

Merged
merged 1 commit into from
Oct 22, 2019
Merged

Conversation

wirthi
Copy link
Contributor

@wirthi wirthi commented Apr 27, 2018

The comparator function of Array.prototype.sort expects two arguments to compare (https://tc39.github.io/ecma262/#sec-array.prototype.sort)

The previous implementation used a 1-element comparator, which always returns the length of the first element. That this resulted in the correct ordering in a test is pure luck.

@ryan-roemer ryan-roemer merged commit 79c7f20 into FormidableLabs:master Oct 22, 2019
@ryan-roemer
Copy link
Member

Great find and thanks!

@ryan-roemer
Copy link
Member

Released in babel-plugin-transform-define@1.3.2

Published differences:

$ publish-diff -o babel-plugin-transform-define@1.3.1 -n babel-plugin-transform-define@1.3.2 --filter='lib/index.js'
Index: lib/index.js
===================================================================
--- lib/index.js	babel-plugin-transform-define@1.3.1
+++ lib/index.js	babel-plugin-transform-define@1.3.2
@@ -76,10 +76,10 @@
   return traverse(obj).paths().filter(function (arr) {
     return arr.length;
   }).map(function (arr) {
     return arr.join(".");
-  }).sort(function (elem) {
-    return elem.length;
+  }).sort(function (a, b) {
+    return b.length - a.length;
   });
 };
 
 /**

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.

None yet

2 participants