Re:Sweet.js – Hygienic Macros for JavaScript
by chocolateboy on Tuesday July 04, 2017 @03:53PM
(#14697891)
> My dreams of having the safe navigation operator from Coffeescript (a?.b?.c) must yet remain unfulfilled...
Not for long: https://github.com/babel/babel/pull/5813
Re:Sweet.js – Hygienic Macros for JavaScript
by btown on Wednesday July 05, 2017 @12:31AM
(#14699994)
You just made my day :)
Re:Sweet.js – Hygienic Macros for JavaScript
by scribu on Tuesday July 04, 2017 @03:10PM
(#14697679)
That raises a question: What's stopping Babel from using Sweet.js instead of a custom parser?
Are there any transpilers that do use Sweet.js?
Re:Sweet.js – Hygienic Macros for JavaScript
by zeckalpha on Sunday July 09, 2017 @09:15PM
(#14732728)
Contracts.coffee IIRC, uses Sweet for Contracts.
Well "a.b.c" violates the principle that you should never access a property more than one level deep anyway ;)
But in this case it's pretty straightforward to write a function like "get('b', 'c')(a)" or use a lib like lodash [1]
Re:Sweet.js – Hygienic Macros for JavaScript
by btown on Wednesday July 05, 2017 @12:36AM
(#14700002)
The Law of Demeter doesn't always apply neatly, especially when you're introspecting JSON sent over the wire and you don't have a "class" with object oriented behavior for each sub object (at best, they're strongly typed). And the runtime overhead AND verbosity of a function may not be ideal, with the string parsing required in lodash and the awkward syntax of the curried function. Something that compiles natively in a DRY way to a && a.b ... would be used widely imo.
https://github.com/babel/babylon/blob/master/src/parser/expr...