eslint: Bug: "use strict" should not trigger strict mode in ES3
Environment
ESLint version: 8.5.0
What parser are you using?
Default (Espree)
What did you do?
Configuration
{
"parserOptions": {
"ecmaVersion": 3
}
}
"use strict";
alert(00);
What did you expect to happen?
Merry Christmas!
No error is expected here. ES3 has no strict mode, the "use strict"
directive should be ignored, and legacy octal literals like 00
should be always allowed. In fact, the code above works in IE 6…
What actually happened?
Parser error: invalid number (demo link)
Participation
- I am willing to submit a pull request for this issue.
Additional comments
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 36 (34 by maintainers)
Commits related to this issue
- [Fix] pin `eslint` to < `v8.9`, since it breaks ES3 strict mode parsing See https://github.com/eslint/eslint/pull/15595 / https://github.com/eslint/eslint-scope/pull/87 / https://github.com/eslint/es... — committed to ljharb/eslint-config by ljharb 2 years ago
- [Fix] pin `eslint-scope`, since v7.1.1+ breaks ES3 strict mode parsing See https://github.com/eslint/eslint/pull/15595 / https://github.com/eslint/eslint-scope/pull/87 / https://github.com/eslint/esl... — committed to ljharb/eslint-config by ljharb 2 years ago
- fix: "use strict" should not trigger strict mode in es3. fixes https://github.com/eslint/eslint/issues/15456 — committed to eslint/espree by aladdin-add 2 years ago
- fix: "use strict" should not trigger strict mode in es3. fixes https://github.com/eslint/eslint/issues/15456 — committed to eslint/espree by aladdin-add 2 years ago
- fix: "use strict" should not trigger strict mode in es3. fixes https://github.com/eslint/eslint/issues/15456 — committed to eslint/espree by aladdin-add 2 years ago
- fix: "use strict" should not trigger strict mode in es3. fixes https://github.com/eslint/eslint/issues/15456 — committed to eslint/espree by aladdin-add 2 years ago
- fix: "use strict" should not trigger strict mode in ES3 Fixes #15456 — committed to eslint/eslint by mdjermanovic 2 years ago
- fix: "use strict" should not trigger strict mode in ES3 (#15846) Fixes #15456 — committed to eslint/eslint by mdjermanovic 2 years ago
- fix: "use strict" should not trigger strict mode in ES3 (#15846) Fixes #15456 — committed to DeepSourceCorp/eslint by mdjermanovic 2 years ago
- fix: "use strict" should not trigger strict mode in es3. (#547) * fix: "use strict" should not trigger strict mode in es3. fixes https://github.com/eslint/eslint/issues/15456 * chore: add func ... — committed to synvert-hq/espree by aladdin-add 2 years ago
Because this is a parsing error and not a linting error, that means it’s coming from Acorn and not ESLint. I’d suggest opening up an issue on Acorn to see what their response is. They usually have a good reason for seemingly incorrect behavior like this that may not be obvious, and if not, they’ll know the best approach to address it.
I agree there’s some philosophical interest in being able to lint ES3 code and ignore the strict pragma, but as I stated above, I don’t think there’s any use in that being by default. It could certainly be done via an option, if the eslint folks wanted to maintain that complexity.
If you want sloppy mode semantics, then you wouldn’t include the strict pragma. By including it, you’re already writing es5+ code.
It could be done with an option, but the question remains: why is that useful? Sloppy mode semantics are bad and to be avoided anyways, and if you need them, you wouldn’t use the pragma.
Are you deploying code to IE 6, and not to any ES5 engines? I’d love to understand that use case.