简体   繁体   中英

Why Babel parses IIFE of arrow function

As I may see from grammar of ES2015 this expression is not a valid one:

() => { console.log("hello"); } ();

You need at least put parentheses:

(() => { console.log("hello"); }) ();

Chrome fails on first sample with Uncaught SyntaxError: Unexpected token (

But Babel is ok with that. Why?

But Babel is ok with that. Why?

Because Babel is buggy :-) See https://phabricator.babeljs.io/T2118 and https://phabricator.babeljs.io/T2027 . If I understand correctly, it was fixed with Babel 6 - it was a quite breaking change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM