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

Most upvoted comments

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.