6eDesign / svelte-calendar

A lightweight datepicker with neat animations and a unique UX.
https://6edesign.github.io/svelte-calendar/
MIT License
543 stars 90 forks source link

Use of `arguments` makes recent babel throw a hissyfit #72

Closed antony closed 4 years ago

antony commented 4 years ago

I don't know why this is suddenly happening, but there is no need to use arguments anyway - the method is only used in one place, so we know the arguments.

/zeit/6e58b95/node_modules/svelte-calendar/src/Components/Popover.svelte: Unexpected reserved word 'arguments' (355:2)

09:22:42 AM | 353 | getTranslate, 09:22:42 AM | 354 | doOpen, 09:22:42 AM | > 355 | arguments, 09:22:42 AM | | ^ 09:22:42 AM | 356 | document, 09:22:42 AM | 357 | window, 09:22:42 AM | 358 | Math 09:22:42 AM | SyntaxError: /zeit/6e58b95/node_modules/svelte-calendar/src/Components/Popover.svelte: Unexpected reserved word 'arguments' (355:2) 09:22:42 AM | 353 | getTranslate, 09:22:42 AM | 354 | doOpen, 09:22:42 AM | > 355 | arguments, 09:22:42 AM | | ^ 09:22:42 AM | 356 | document, 09:22:42 AM | 357 | window, 09:22:42 AM | 358 | Math 09:22:42 AM | at Parser.raise (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:6983:17) 09:22:42 AM | at Parser.checkReservedWord (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:10383:14) 09:22:42 AM | at Parser.parseObjectProperty (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:10094:12) 09:22:42 AM | at Parser.parseObjPropValue (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:10114:101) 09:22:42 AM | at Parser.parseObjectMember (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:10038:10) 09:22:42 AM | at Parser.parseObj (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:9958:25) 09:22:42 AM | at Parser.parseExprAtom (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:9580:28) 09:22:42 AM | at Parser.parseExprSubscripts (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:9213:23) 09:22:42 AM | at Parser.parseMaybeUnary (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:9193:21) 09:22:42 AM | at Parser.parseExprOps (/zeit/6e58b95/node_modules/@babel/parser/lib/index.js:9059:23)

6eDesign commented 4 years ago

To be honest: I don't feel great about removing arguments from the codebase simply to fix an issue you're having with babel.

antony commented 4 years ago

@6eDesign It should be removed because it isn't used in the codebase anyway, the only caller of the once argument doesn't pass any arguments.

It's also a strict mode violation, so when es6 is compiled to strict mode ES5, arguments is technically disallowed. It's better to have explicit arguments anyway, if there were any arguments to pass.

Not removing it will mean that nobody who transpiles their codebase for older browsers will be able to use svelte-calendar.

6eDesign commented 4 years ago

I think you're incorrect about arguments being disallowed in strict mode. See the relevant docs here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

Once is a function that accepts another function as a parameter. It's only used, right now, for a function that doesn't have arguments but that can change in the future. Furthermore, AFAIK, arguments is perfectly valid JS (and is used in many libraries) and I don't like the idea of banning it from the codebase.

I'd speculate that the issue you're having has nothing to do with svelte-calendar. It likely has something to do with Babel or the way you've configured Babel and the fix should lie elsewhere, in my opinion.

antony commented 4 years ago

@6eDesign Alright, I'll crack on with it and see if I can find a workaround.

6eDesign commented 4 years ago

@antony great, if you do find a workaround please share. If you can't find a workaround, maybe we could at least update the code to use ...args instead of making the once function unusable for functions that need arguments.

antony commented 4 years ago

Updated to use args.

After a fair bit of investigation, I think the issue was a combination of Svelte 3.19.1 and Babel 7. It seems that Svelte 3.19.2 fixes it (but I have no idea why)