Enable let without version=1.7+ in strict mode

RESOLVED DUPLICATE of bug 932517

Status

()

defect
RESOLVED DUPLICATE of bug 932517
6 years ago
4 years ago

People

(Reporter: cpeterson, Unassigned)

Tracking

(Blocks 1 bug, {dev-doc-complete, feature})

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [DocArea=JS][Docs see comment 17 too])

Attachments

(1 attachment)

This bug is forked from bug 855665. In bug 855665 comment 19, Rick Waldron says:

`let` in strict code is a non-issue, because `let` is reserved in strict code. The committee agreed to move forward with `let` in non-strict code, b/w a lookahead: 

https://github.com/rwaldron/tc39-notes/blob/master/es6/2012-11/nov-29.md#conclusionresolution-6
Blocks: 932517
But we should implement ES6 semantics first.
Depends on: 589199
(In reply to Masatoshi Kimura [:emk] from comment #1)
> But we should implement ES6 semantics first.

This is really important, since it's not a matter of just "switching on" support. Specifically, the semantics are defined in "13.2.1 Let and Const Declarations" need to be implemented and let is incorrectly scoped in for loops:

<script type="application/javascript;version=1.8">
var a = [];
for (let i = 0; i < 5; i++) {
  a.push(function() { return i; });
}
console.log(a[0]() === 0);
</script>

outputs `false`, but should be `true`

There may be other discrepancies, this is just what I know off hand
Blocks: es6:let
Keywords: dev-doc-needed
Whiteboard: [DocArea=JS]
Summary: Enable let without version=1.8 in strict mode → Enable let without version=1.7+ in strict mode
let is currently available in javascript;version=1.7 and 1.8.
It's sad that this is still not working (and making cross browser us of `let` impossible). How can we enable this by default? Chrome reject code with "javascript;version=1.7".
<script src="/myScript.js" type="application/javascript;version=1.8" async></script>
<script src="/myScript.js" language="Javascript1.7" async></script>

Chrome will ignore the first line. Firefox will ignore the second. Together they'll allow development using let.
Wait, why does it work for me in Firefox 38.0.5 in the console without any problems?

(function () {
    'use strict';
    let x = 3;
    {
        let x = 4;
        console.log(x);
    }
    console.log(x);
})();

It prints:
4
3
as expected.
(In reply to Michał Gołębiowski [:m_gol] from comment #6)
> Wait, why does it work for me in Firefox 38.0.5 in the console without any
> problems?

Firefox's web console defaults to JavaScript version 1.8.5, whereas web content defaults to JavaScript 1.5.
This distinction seems troublesome as devs are often trying something in the dev console and assuming that if it works there it works on the Web.

This is the first time I've heard those two are different. What's the reason for that? Does any other browser have such a distinction?

This doesn't seem to be in line with the whole 1JS philosophy that ECMAScript now follows.
AFAIK no other browsers have the concept of versioned scripts, and just impose the latest version on all scripts. Is it not possible for Firefox to do the same? It sounds like it should still be compatible since all other browsers do that already.
That's a good point. It does seem like the Web Console should use the same 1JS available to web content, but perhaps allow developers to test nonstandard JS 1.8.5 features (available to Firefox internals and add-ons) in Firefox's Browser Console.
(In reply to Chris Peterson [:cpeterson] from comment #10)
> That's a good point. It does seem like the Web Console should use the same
> 1JS available to web content, but perhaps allow developers to test
> nonstandard JS 1.8.5 features (available to Firefox internals and add-ons)
> in Firefox's Browser Console.

This approach makes sense to me.  I didn't realize this was happening until today!

I filed bug 1173883 to change the console.
See Also: → 1173883
(In reply to Chris Peterson [:cpeterson] from comment #10)
> That's a good point. It does seem like the Web Console should use the same
> 1JS available to web content, but perhaps allow developers to test
> nonstandard JS 1.8.5 features (available to Firefox internals and add-ons)
> in Firefox's Browser Console.

Wait, we are relying on nonstandard features in production code (i.e., `let` is used everywhere in Gecko's JSMs, etc.)? What is going to happen when we "fix" let? won't potentially our internal code break?
Yes. Bug 950547 has more information about making SpiderMonkey's `let` and `const` compatible with ES6.
I see a lot of talk about why, but no patches on how.  :)  I'm curious what a patch for this would look like.
No longer blocks: es6:let
No longer depends on: 589199
Depends on: es6:let
It would be super useful for Gaia to get this. We're moving a lot of code to ES6 and naturally we want to use `let` to avoid creating another pile of technical debt for years to come.

All our code is in `strict mode`, so we would benefit from it instantly and would be able to stop requiring transpilers which increase entry barrier and tie us to build time operations.
This breaks the web. Let and Const are two of the most supported features of es6, even IE11 supports it, but with Firefox only allowing let behind this script versioning it makes it basically impossible to sanely use well supported es6 features in production cross-browser code. Perfect example, I work on a pretty big AngularJS project at work, and we would love to be able to start implementing ES2015 features, but this bug is currently holding us back.
Duplicate of this bug: 1212722
Note that beside the usual JS documentation, we will need to update this one (Kris just edited it) when this land too: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities

(Posting it here so we don't forget)
Whiteboard: [DocArea=JS] → [DocArea=JS][Docs see comment 17 too]
Here is very simple patch.
How much problem does this patch file produce?
Shu enabled let in sloppy and strict mode at the same time.
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 932517
ooh I have to revise my site compat doc again...
You need to log in before you can comment on or make changes to this bug.