GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.38k stars 84 forks source link

Unexpected token in legacy file-open and directory-open #58

Closed haexhub closed 3 years ago

haexhub commented 3 years ago

Hi,

I'm using browser-fs-access with nuxt and got an error about unexpected tokens in legacy/file-open.mjs and legacy-directory-open.mjs.

export default async( e={})=>new Promise(((t,n)=>{const i=document.createElement("input");i.type="file";const s=[...e.mimeTypes?e.mimeTypes:[],e.extensions?e.extensions:[]].join();let c;i.multiple=e.multiple||!1,i.accept=s||"";const l=()=>c(n);e.setupLegacyCleanupAndRejection&&(c=e.setupLegacyCleanupAndRejection(l)), i.addEventListener("change",(()=>{c?.(),t(i.multiple?Array.from(i.files):i.files[0])})),i.click()}));

The problem is the ? Operator

c?.(),t(i.multiple?Array.from(i.files):i.files[0])})),i.click() // doesn't work c(),t(i.multiple?Array.from(i.files):i.files[0])})),i.click() // works

I'm not sure why webpack is complaining about, because it's valid javascript.

tomayac commented 3 years ago

Thanks for the report. Just released v0.19.2 that fixes this.

haexhub commented 3 years ago

Wow. What an amazing response time! :1st_place_medal: Thank you very much! Could you please explain me the problem a bit bit more? Why is the optional chaining not working here?

tomayac commented 3 years ago

Probably in your webpack config you target browsers that don't match the compatibility of the feature.