node-compat-table icon indicating copy to clipboard operation
node-compat-table copied to clipboard

Node.js 4.x "let basic support" is "Yes" wrongly. It must be "Error"

Open mysticatea opened this issue 6 years ago • 8 comments

image http://node.green/#ES2015-bindings-let

let basic support on Node.js 4.x seems yes, however, I believe it throws syntax error.

$ node -v
v4.9.1
$ cat test.js
function f() {
    let foo = 123;
    return (foo === 123);
}
$ node test.js
~/test.js:2
    let foo = 123;
    ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3

mysticatea avatar May 07 '18 02:05 mysticatea

like the error says, you have to use strict mode[1] for block scoped declarations. they work fine in node 4.9

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

devsnek avatar May 10 '18 00:05 devsnek

@devsnek I know. You are saying about "basic support (strict mode)" entry. It's "yes" in the table correctly.

mysticatea avatar May 10 '18 10:05 mysticatea

cc/ @williamkapke

mysticatea avatar May 22 '18 22:05 mysticatea

Sry, I've been away for awhile.

@mysticatea I see what you're talking about. There are 2 reason why it's like this:

Mimicking how the Kangax test works: https://github.com/kangax/compat-table/blob/3a2e829cbc5026195bb8e2ac2e24c9c0c9f3efd8/build.js#L778-L801

https://github.com/williamkapke/node-compat-table/blob/gh-pages/test.js#L82-L83

It first tries without strict- and then, if failure, tries WITH strict.

Being Green The goal of node.green has always been to try to lean towards showing what is possible with a specific version of node (causing more green than red). Initially, I had even the "Flag" ones as "Yes" and in green! After much debate, I changed that (to how it is today) and decided to draw a line at what could be available by a developer writing code in javascript (as opposed to cmd line flags which isn't a javascript thing).

Adding "use strict"; is something a developer can do in JS to make it work.


An indicator that strict was needed- would certainly be MORE helpful, but alas- I didn't take the time to capture and display that. (it applied to so few things, I couldn't justify getting to it in my backlog)

As always- a PR is welcome!

williamkapke avatar May 22 '18 23:05 williamkapke

@williamkapke In that case, I have a question. Why do you separate basic support and basic support (strict mode)? The separated entries are confusing.

mysticatea avatar May 22 '18 23:05 mysticatea

Ahh... now I fully understand what you're asking about. Sorry I didn't catch that.

Since they're broken out- yes, it seems we could remove the strict fallback test (for node.green's purposes). It's easy enough to remove-- but I wonder how much it will change other test results 🤔

Will need to try it and see!

williamkapke avatar May 23 '18 00:05 williamkapke

Ok. strict mode fallback has been removed.

There were many changes. See: https://github.com/williamkapke/node-compat-table/commit/455b9a23fe11af5f6364091b8f9d2aa6ef23ce6b

Anything seem like a bad side effect?

williamkapke avatar May 25 '18 22:05 williamkapke

Class syntax seems to become Error similar to let/const, but classes don't have (strict mode) entries.

And some entries are using class syntax in their test functions. E.g., Generators: shorthand generator methods, classes. Those will become Yes under strict mode.

mysticatea avatar May 26 '18 13:05 mysticatea