Skip to content

Commit

Permalink
Fix edge case of since query (fix browserslist#646) (browserslist#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and zhouyu9527 committed Jul 4, 2022
1 parent 2096f30 commit 5ff0c9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -209,7 +209,8 @@ function filterByYear(since, context) {
var data = byName(name, context)
if (!data) return selected
var versions = Object.keys(data.releaseDate).filter(function (v) {
return data.releaseDate[v] >= since
var date = data.releaseDate[v]
return date !== null && date >= since
})
return selected.concat(versions.map(nameMapper(data.name)))
}, [])
Expand Down
13 changes: 11 additions & 2 deletions test/since.test.js
Expand Up @@ -14,6 +14,15 @@ beforeEach(() => {
2: 1483228800, // Sun, 01 Jan 2017 00:00:00 +0000
3: 1485907200 // Wed, 01 Feb 2017 00:00:00 +0000
}
},
safari: {
name: 'safari',
versions: ['TP'],
released: [],
releaseDate: {
1: 1451606400, // Fri, 01 Jan 2016 00:00:00 +0000
TP: null // unreleased
}
}
}
console.warn = function (...args) {
Expand All @@ -28,11 +37,11 @@ afterEach(() => {
})

it('selects versions released on year boundaries', () => {
expect(browserslist('since 1970')).toEqual(['ie 3', 'ie 2', 'ie 1'])
expect(browserslist('since 1970')).toEqual(['ie 3', 'ie 2', 'ie 1', 'safari 1'])
})

it('is case insensitive', () => {
expect(browserslist('Since 1970')).toEqual(['ie 3', 'ie 2', 'ie 1'])
expect(browserslist('Since 1970')).toEqual(['ie 3', 'ie 2', 'ie 1', 'safari 1'])
})

it('selects versions released on year and month boundaries', () => {
Expand Down

0 comments on commit 5ff0c9d

Please sign in to comment.