lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.9k stars 137 forks source link

Spread operator doesn't work on Safari. #12

Closed JJPowell closed 5 years ago

JJPowell commented 5 years ago

I'm using MiniSearch for a front-end web app and it's been great so far so thanks for your work! Unfortunately when I started testing other browsers to make sure things worked I discovered the spread operator doesn't work on Safari. I changed maybe 10 or 12 lines of code to instead use Object.assign() and it seems to have fixed the issue. I'm relatively new to Javascript so there may be a better way to handle this but things seem to be working properly after my changes so I didn't look into it any further.

lucaong commented 5 years ago

Hi, and thanks for taking the time to file an issue :)

Support for the spread operator (and ES6 syntax support in general) doesn’t depend on libraries. It depends on browsers, so normally developers use transpilers like Babel to convert their JS code automatically into well-supported syntax.

MiniSearch is transpiled, so the resulting source code shouldn’t contain any spread operator or unsupported syntax. Is the spread operator you are talking about in MiniSearch code or in your code?

If it is in MiniSearch code, how are you including MiniSearch in your project?

If it is in your code, you should consider using a transpiler, or avoid ES5/6 syntax entirely, but that is a generic issue with JS and browsers, not an issue caused by MiniSearch. Unless you copied your code from some example in the documentation, in which case I should probably change it in order not to confuse people.

JJPowell commented 5 years ago

The spread operator is definitely in my version of the source code and I haven't touched any of the internals until yesterday when I first noticed this issue. Unfortunately it's been a few months since I set it up and I didn't take notes on what I did to get it working so my memory is a little hazy. I remember going through the manual build process with yarn but I had some issues with that whole process so I don't remember if I actually used what yarn created or just copied the source in your example page. The JS file I'm using actually has all of your example code in it so if the results from yarn don't include that then I guess I'm probably using the source from your example page.

lucaong commented 5 years ago

I see, thanks. So if I understand correctly, you are not reporting a bug in the library, but more an observation/question about spread operator support? If so, I will close the issue, as you found the solution already.

I will soon add a CDN-hosted pre-built file, to make it easier for users that do not use npm/yarn to require the library. Generally copy/pasting the whole example code won’t work, because the example is built with Babel/webpack.

lucaong commented 5 years ago

Hi @JJPowell , as a follow up to your issue, you can now import MiniSearch in your project using a CDN, as shown in the README:

<script src="https://cdn.jsdelivr.net/npm/minisearch@2.0.4/dist/minisearch.min.js"></script>

That should give you a pre-compiled and minified version of the library.