New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES3 reserved words #15017
Comments
Please update your issue to use our bug report template and we will take a look. Thanks. |
I was able to repro, and it seems an issue in acorn. |
Acorn has an option to modify this behavior: https://github.com/acornjs/acorn/tree/master/acorn#interface
Consequently, I'm not sure what was the reasoning for these defaults in We could consider setting |
As an option, instead of parsing error, it can be a new rule that will forbid the usage of ES3 reserved words as variables names. |
This could be also achieved with the existing no-restricted-syntax rule: /* eslint no-restricted-syntax: [
"error",
{
selector: "Identifier[name=/^(?:abstract|boolean|byte|char)$/]",
message: "ES3 reserved word"
}
]*/
var char; // error This configuration disallows the list of reserved words - I added only the first 4 for the example - everywhere where estree spec uses Would this work for you? |
id-denylist also provides similar functionality, though with some exceptions (e.g., property names are allowed). |
@mdjermanovic I know, but I don't think that it's fine to recommend adding the ES3 reserved words list to those rules for all who need ES3 support. |
the easiest way is to use the "parser": "espree",
"parserOptions": { "ecmaVersion": 3, "allowReserved": false} I also agreed this can be the default. oops, sorry it would not be working, as espree do not pass unknown options to acorn: https://github.com/eslint/espree/blob/63bd0bc46adfbcd3a71d4cc222aa3923b76ebcf2/lib/espree.js#L69 |
I agree this isn't an ideal solution, but it's a currently available workaround. We don't have core rules to check syntax, that rule seems more like a candidate for eslint-plugin-es.
This would solve the problem in a non-breaking way, but we aim to avoid exposing Acorn options for various reasons. I think that |
This plugin seems dead. Anyway, this issue looks like an ESLint core problem.
Why not add it to v8 while it's still in beta? |
filed the issue in acorn: acornjs/acorn#1062 to see if they want to change the default. |
espree v8.0.0 has been already released, and the changes in eslint v8.0.0 are already announced. |
Because there’s agreement that this is a bug, I’m marking as accepted. We just need to determine how to proceed. I’m guessing we don’t have a lot of ES3 usage right now, and ES3 code using reserved words will throw a runtime error, so even though this is a breaking change, I think the impact to end users would be minimal. So, we may want to evaluate this a bit differently than other breaking changes. |
We could fix this in Espree as a breaking change, release Espree v9.0.0, and then use Espree 9 in ESLint v8.0.0. |
All of my packages are authored in ES3, and none of them use |
Should we actually set By https://www-archive.mozilla.org/js/language/E262-3.pdf (if that's the right document?):
|
That’s what I was thinking, too.
Yes. Reserved words were completely illegal in ES3. |
Note from marijn about Acorn's default:
|
Opened a PR: eslint/espree#513 |
In yesterday's TSC meeting, we decided to accept this change for ESLint v8.0.0. The change will be made directly in Espree. We'll release Espree v9.0.0 and use Espree v9 in ESLint v8.0.0. Reserved words will also be disallowed in property names, such as This change only affects ESLint users with the default parser and |
Turns out there's ES3 browsers where these reserved words work fine - |
The issue: zloirock/core-js#980
In the code used
char
as a variable name. The ESLint config containsecmaVersion: 3
, till this week here was used the default ESLint parser.char
is a ES3 reserved word:ESLint parsed it without any errors or warnings. However, this code might not work in some ES3 engines.
The text was updated successfully, but these errors were encountered: