Nyalab / caniuse-api

request the caniuse data to check browsers compatibilities
MIT License
356 stars 27 forks source link

Do not fail when browserslist gives a browser that caniuse-api doesn't know about #45

Closed onigoetz closed 8 years ago

onigoetz commented 8 years ago

Hi,

I ran into a weird case this morning and could track down the source to the following scenario:

browserslist and caniuse-api got a different version of caniuse-db, the one in browserslist being more recent and containing "samsung 4" as a browser.

caniuse-db didn't know about this browser and failed the lookup in isSupported with the following stacktrace:

[16:29:43] TypeError: Cannot read property '4' of undefined
    at /work/foundation/sq-web-assets/sq-gulp/node_modules/postcss-cssnext/node_modules/caniuse-api/dist/index.js:79:34
    at Array.every (native)
    at isSupported (/work/foundation/sq-web-assets/sq-gulp/node_modules/postcss-cssnext/node_modules/caniuse-api/dist/index.js:77:6)
    at /work/foundation/sq-web-assets/sq-gulp/node_modules/postcss-cssnext/lib/index.js:74:117
    at Array.forEach (native)

I added a test to reproduce the case and added a fix as well. If you have a recommendation on a cleaner test I can modify it.

MoOx commented 8 years ago

👍