最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable eslint parsing error message - Stack Overflow

programmeradmin3浏览0评论

In my code I have a conditional export:

if (process.env.NODE_ENV === 'testing')
  export myFunc;

In es6 this statement is not allowed because imports and exports should be top-level, but using babel with some plugins and webpack this condition is eliminated at build-time, so in my resulting code this export is either top-level or not present.

But eslint reports a parsing error and I want to get rid of it. /*eslint-disable */ doesn't work, because, well, it's not a rule violation, it's a parsing error. Is there a possible workaround?

P.S.: I know I can monjs it, but I want to stick with es6.

In my code I have a conditional export:

if (process.env.NODE_ENV === 'testing')
  export myFunc;

In es6 this statement is not allowed because imports and exports should be top-level, but using babel with some plugins and webpack this condition is eliminated at build-time, so in my resulting code this export is either top-level or not present.

But eslint reports a parsing error and I want to get rid of it. /*eslint-disable */ doesn't work, because, well, it's not a rule violation, it's a parsing error. Is there a possible workaround?

P.S.: I know I can monjs it, but I want to stick with es6.

Share Improve this question edited Feb 22, 2016 at 6:27 loganfsmyth 162k31 gold badges346 silver badges258 bronze badges asked Jan 31, 2016 at 12:48 aushaush 2,1081 gold badge15 silver badges24 bronze badges 2
  • Is your eslint configured to parse es6? eslint/docs/user-guide/… – Radosław Miernik Commented Jan 31, 2016 at 13:29
  • @RadosławM, sure, that's why it reports about wrong es6 syntax – aush Commented Jan 31, 2016 at 13:35
Add a ment  | 

2 Answers 2

Reset to default 2

I know I can monjs it, but I want to stick with es6.

Really, you aren't pliant with ES6 specification, so... you need to monjs it.

The Idea behind a transpiler is that you'll can disable it when the next specification es actual.

In this case, your code won't work in a full ES6 environment.

There is no workaround.

Using non-top level imports will not work with native ES6 implementations. Babel allows it because it transpiles to CommonJS require, but it is technically not allowed in ES6.

eslint issue and according espree issue

发布评论

评论列表(0)

  1. 暂无评论