美文网首页
Unexpected lexical declaration i

Unexpected lexical declaration i

作者: 前端小哥之旅 | 来源:发表于2022-02-14 15:09 被阅读0次

打包项目的时候发现报这个错,百度了一翻后发现该规则禁止词法声明 (let、const、function 和 class) 出现在 case或default 子句中。

为了保证词法声明语句只在当前 case 语句中有效,不被未执行到的 同名变量、函数执行,要将子句包裹{}中。

例如:

 switch(foo){

           case 1:

             {

              letx=1;

               break;

         }

}

参考:eslint官方文档

相关文章

网友评论

      本文标题:Unexpected lexical declaration i

      本文链接:https://www.haomeiwen.com/subject/bcwthqtx.html