standard-things / esm

Tomorrow's ECMAScript modules today!
Other
5.26k stars 146 forks source link

SyntaxError with public and private static class fields in node.js v12 #801

Closed dnalborczyk closed 5 years ago

dnalborczyk commented 5 years ago

was just trying to look into: https://github.com/standard-things/esm/issues/800

node v12.1.0 esm: 3.2.22

repro:

// index.js
class A {
  static someProp = 'someProp'
}
node -r esm index.js

/Users/daniel/dev/repros/esm/800/index.js:10
  static someProp = "someProp";
                  ^

SyntaxError: Invalid or unexpected token
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
// index.js
class A {
  static #somePrivateProp = "somePrivateProp";
}
/Users/daniel/dev/repros/esm/800/index.js:1
SyntaxError: Unexpected character '#' (10:9)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)

also tested latest master with https://github.com/standard-things/esm/issues/787 and https://github.com/standard-things/esm/commit/3c50b8393f353cae131d92dc6c299b75d8ad33dd but same result.

jdalton commented 5 years ago

static props is a companion proposal to the class fields proposal.

dnalborczyk commented 5 years ago

static props is a companion proposal to the class fields proposal.

yeah, that could be. although both are supported by V8 and node.js v12 (commonjs) without a flag. the reference to https://github.com/standard-things/esm/issues/800 was just that I tried to look into it (but it was working just fine), and while I was at it, I tried static (pub+priv) as well to be sure.

on a different note, I wonder if it would be easier/better to use the acorn plugins instead (for anything stage 3 (bigint, class fields, static, etc. )?

essentially those:

"acorn-dynamic-import"
"acorn-import-meta"
"acorn-bigint"
"acorn-class-fields"
"acorn-static-class-features"
"acorn-private-methods"  // maybe not, since not in V8, node.js yet
"acorn-export-ns-from"

update: private methods might be already implemented behind a flag, I haven't looked. https://developers.google.com/web/updates/2018/12/class-fields

We plan on shipping support for private methods and accessors soon.

jdalton commented 5 years ago

Naw, I find their plugins lacking in areas or overly strict in others. Rolling our own provides a balance better suited for esm.