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

refactor: optimize code #504

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Range {
range = range.replace(re[t.CARETTRIM], caretTrimReplace)

// normalize spaces
range = range.split(/\s+/).join(' ')
range = range.replace(/ +/g, ' ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change means it will no longer select non-space whitespace characters, including tabs and other unicode whitespace chars.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should provide tests to protect it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, there should be tests, but few projects are willing to change behavior just because there’s not a test yet.


// At this point, the range is completely trimmed and
// ready to be split into comparators.
Expand Down
2 changes: 1 addition & 1 deletion ranges/to-comparators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const Range = require('../classes/range')
// Mostly just for testing and legacy API reasons
const toComparators = (range, options) =>
new Range(range, options).set
.map(comp => comp.map(c => c.value).join(' ').trim().split(' '))
.map(comp => comp.map(c => c.value.trim()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't exactly the same thing - [' a ', ' b '] would have previously produced ['a ', ' b'] but will now produce ['a', 'b'].

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all tests are passed


module.exports = toComparators