question-mark
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.

Bug: "use strict" should not trigger strict mode in ES3

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:36 (34 by maintainers)

github_iconTop GitHub Comments

2reactions
nzakascommented, Dec 28, 2021

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.

1reaction
ljharbcommented, Dec 25, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strict mode - JavaScript - MDN Web Docs
JavaScript's strict mode is a way to opt in to a restricted variant of JavaScript, thereby implicitly opting-out of "sloppy mode".
Read more >
Why is "use strict" a plain string and not a JavaScript reserved ...
That means that a statement such as "use strict"; is syntactically valid ES3 code. Because it is simply a constant value, evaluating it...
Read more >
Deep dive into 'use strict' in JavaScript | Maisie Johnson's blog
It turns out that strict mode is always enabled for modules. I wasn't aware of this behavior. Since modules are a new feature...
Read more >
JavaScript "use strict" - W3Schools
Declaring Strict Mode ; "use strict"; x = 3.14; // This will cause an error because x is not declared ; "use strict";...
Read more >
rollup.js
This will not throw an error if one of the entry point files is not available. ... var version = (function () {...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found