简体   繁体   English

Babel为什么解析箭头功能的IIFE

[英]Why Babel parses IIFE of arrow function

As I may see from grammar of ES2015 this expression is not a valid one: 从ES2015的语法中可以看出,该表达式不是有效的表达式:

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

You need at least put parentheses: 您至少需要加上括号:

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

Chrome fails on first sample with Uncaught SyntaxError: Unexpected token ( Chrome出现第一个样本时出现Uncaught SyntaxError: Unexpected token (

But Babel is ok with that. 但是Babel对此表示同意。 Why? 为什么?

But Babel is ok with that. 但是Babel对此表示同意。 Why? 为什么?

Because Babel is buggy :-) See https://phabricator.babeljs.io/T2118 and https://phabricator.babeljs.io/T2027 . 由于Babel越野车:-)参见https://phabricator.babeljs.io/T2118https://phabricator.babeljs.io/T2027 If I understand correctly, it was fixed with Babel 6 - it was a quite breaking change. 如果我理解正确,Babel 6已解决该问题-这是一个非常重大的变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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