standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.27k stars 147 forks source link

Class static field support is broken [esm@3.2.25] #858

Closed rqbazan closed 4 years ago

rqbazan commented 4 years ago

How to reproduce?

> node -r esm -e "class A { static a = 1 }; console.log(A.a);"

[eval]:1
class A { static a = 1 }; console.log(A.a);

SyntaxError: Unexpected token =
    at new Script (vm.js:83:7)
    at Object.createScript (vm.js:277:10)
    at Object.<anonymous> ([eval]-wrapper:6:22)

Environment

Workaround

class A {
...
}

A.someProp = ...
dnalborczyk commented 4 years ago

static fields are not supported in node.js v10.16.0. you can verify without using esm:

node -e "class A { static a = 1 }; console.log(A.a);"

[eval]:1
class A { static a = 1 }; console.log(A.a);
                   ^

SyntaxError: Unexpected token =
    at new Script (vm.js:83:7)
    at createScript (vm.js:277:10)
    at Object.runInThisContext (vm.js:329:10)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at evalScript (internal/bootstrap/node.js:590:27)
    at startup (internal/bootstrap/node.js:265:9)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

though it works with e.g. node.js v12+

rqbazan commented 4 years ago

@dnalborczyk thanks for the clarification