Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

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

Closed
dnalborczyk opened this issue May 6, 2019 · 3 comments
Closed

Comments

@dnalborczyk
Copy link
Contributor

dnalborczyk commented May 6, 2019

was just trying to look into: #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 #787 and 3c50b83 but same result.

@dnalborczyk dnalborczyk added the bug label May 6, 2019
@jdalton
Copy link
Member

jdalton commented May 6, 2019

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

@jdalton jdalton added enhancement and removed bug labels May 6, 2019
@dnalborczyk
Copy link
Contributor Author

dnalborczyk commented May 6, 2019

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 #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.

@dnalborczyk dnalborczyk changed the title SyntaxError with public and private static class properties in node.js v12 SyntaxError with public and private static class fields in node.js v12 May 6, 2019
@jdalton
Copy link
Member

jdalton commented May 6, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants