Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[idea] Changing Parser's language version strategy

See original GitHub issue

The version of ESLint you are using.


The problem you want to solve.

Currently, espree parses code as ES5 by default. We give parserOptions.ecmaVersion option to change that behavior. In this strategy, users have sometimes seen non-understandable error messages such as “unexpected token”, and we cannot disable each syntax individually to avoid making the parser more complex.

Your take on the correct solution to problem.

  1. Make that espree parses code as the latest language version always.
  2. ESLint enables the rules which report each syntax like eslint-plugin-es by default.
  3. The environment such as env: { es2015: true } disables those syntax rule set.
  4. Users can disable each syntax rule individually (e.g. rules: { "no-async-iteration": "off" }).

I think that this strategy has some pros:

  • We can make more understandable message instead of “unexpected token”.
  • We can disable each syntax individually.
  • We can make the parser simpler by removing version switch.
  • We can solve the confusion between parserOptions.ecmaVersion and env.es6. It’s unified to env.
  • It can detect the use of new built-in’s static methods such as Object.assign.

On the other hand, this strategy has some cons:

  • This is definitely a breaking change that users have to modify their config.
  • The breaking changes in new language versions probably break CI builds of users. Though I believe that it’s very rare case in order to avoid breaking the Web.
  • Adding new rules which report new syntax probably is a breaking change. In that case, it makes hard to add new syntax support. It’s OK if the syntax rules are enabled by default only when the parser is espree.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

not-an-aardvarkcommented, May 5, 2018

I have a few concerns:

  • It seems confusing for the rules to only be enabled by default when using espree – we would effectively have a special case for the default parser. If a user decides to fork espree or switch to a different parser because they want to add some feature, they might not realize that some rules have been disabled when they switch to their fork.
  • It seems like it could cause confusion if these rules are enabled by default, because no other rules are enabled by default.

I think we could improve the “unexpected token” error messages in espree separately (or maybe in acorn), without needing to make this change.

eslint-deprecated[bot]commented, Dec 20, 2018

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strategy to support two dialects for same programming ...
I'm developing a programming language support plugin for IntelliJ IDEA. I want to add a support for programming languages A (already implemented) ...
Read more >
Strategies for parsing a format with different versions? - help
Does anyone know of strategies that can be used when writing a parser for a format which has gone through several versions over...
Read more >
A Guide To Parsing: Algorithms And Terminology
An in-depth coverage of parsing terminology an issues, together with an explanation for each one of the major algorithms and when to use...
Read more >
How to support different language versions in my lexer/parser
I am working on modifying an existing grammar for a language and there is a new version of the language, introducing new keywords...
Read more >
Parsing: a timeline -- V3.1 - GitHub Pages
Chomsky demolishes the idea that natural language grammar can be modeled ... C. J. H. Parsing Techniques: A Practical Guide, 2nd edition ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found