[idea] Changing Parser's language version strategy
See original GitHub issueThe version of ESLint you are using.
master
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.
- Make that espree parses code as the latest language version always.
- ESLint enables the rules which report each syntax like eslint-plugin-es by default.
- The environment such as
env: { es2015: true }
disables those syntax rule set. - 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
andenv.es6
. It’s unified toenv
. - 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 theparser
is espree.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have a few concerns:
espree
– we would effectively have a special case for the default parser. If a user decides to forkespree
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.I think we could improve the “unexpected token” error messages in
espree
separately (or maybe inacorn
), without needing to make this change.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.