Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

How can I use Private Instance Methods? #728

Closed
weihongyu12 opened this issue Dec 5, 2018 · 19 comments
Closed

How can I use Private Instance Methods? #728

weihongyu12 opened this issue Dec 5, 2018 · 19 comments

Comments

@weihongyu12
Copy link

weihongyu12 commented Dec 5, 2018

Babel 7.2.0 released today has officially supported Private Instance Methods, but when I use it, the project can be successfully built, but there is an error message about ESLint:

error: Parsing error: This experimental syntax requires enabling the parser plugin: 'classPrivateMethods'

The following is my operating environment:

Node.js 10.14.0
npm 6.4.1
Babel 7.2.0
Babel-eslint 10.0.1
Eslint 5.9.0

// babel.config.js
module.exports = {
  presets: [
    '@vue/app',
  ],
  plugins: [
    '@babel/plugin-proposal-private-methods',
  ],
};
// .eslintrc.js
module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: [
    'plugin:vue/recommended',
    '@vue/airbnb',
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  },
  parserOptions: {
    parser: 'babel-eslint',
  },
};

My project is built on Vue, I just want to try Private Instance Methods. I can provide the project code if needed.

@ezdotjs
Copy link

ezdotjs commented Dec 10, 2018

Wondering the same thing here, not using Vue but would love to use #method() in my code as I'm alreayd using # for class properties

@cljnilsson
Copy link

Been trying to do the same with React, no luck.

@weihongyu12
Copy link
Author

I think this is not the reason for the framework, #729 may be solving this issue.

@existentialism
Copy link
Member

This should be fixed by #711

@hzoo
Copy link
Member

hzoo commented Jan 11, 2019

^ fixed by above so should be fixed in the next release (Major)!

@hzoo hzoo closed this as completed Jan 11, 2019
@Skriptach
Copy link

I still got an error

Parsing error: D:\Projects\sexynewtab\app\scripts\interface\iconElementComponent.js: Support for the experimental syntax 'classPrivateProperties' isn't currently enabled (6:3):

  4 | 
  5 | 	window.IconElement = class IconElement extends HTMLElement {
> 6 | 		#type;
    | 		^
  7 | 		constructor(type) {
  8 | 			super();
  9 |eslint

@hadnet
Copy link

hadnet commented Jul 2, 2019

I added babel private method plugin to an ejected create-react-app project and I get a similar Skriptach error but in my case is about private methods: "Support for the experimental syntax 'classPrivateMethods' isn't currently enabled (10:3):"

@Skriptach
Copy link

@hadnet I was able to fix this. Do not use babel.config.js file and babelOptions param in .eslintrc as recommended in Readme. Just converting my babel config to .babelrc format
Also in plugins section of .babelrc declare both "@babel/plugin-proposal-class-properties" and "@babel/plugin-proposal-private-methods"

@hadnet
Copy link

hadnet commented Jul 2, 2019

@Skriptach doing what you said I got this error: "Parsing error: params is not iterable". Just to be clear, this error happens only when trying to implement a private method (#myPrivateMethod(){}).

@stevenvachon
Copy link

@hadnet I'm getting that error as well.

@DullingWine
Copy link

@hadnet and others - is there any around this error? i.e. is there any way currently for babel-eslint to read files using private methods/private variables without flagging it?
-can't seem to use 10.0.2 - says "This experimental syntax requires the enabling..."
-can't use the 11.x babel-eslint beta - says "params is not iterable"

i don't mind putting my babel options in multiple places if it'll help.

@stevenvachon
Copy link

Hello? @hzoo

@pixxet
Copy link

pixxet commented Oct 9, 2019

// babel.config.js
module.exports = {
  plugins: [
    "@babel/plugin-proposal-private-methods"
  ]
};

#523

@stevenvachon
Copy link

@pixxet Yes, we have that.

@debajit
Copy link

debajit commented Nov 7, 2019

This issue is not resolved for me. With private class methods, I still get the error "This experimental syntax requires enabling the parser plugin: 'classPrivateMethods"

@Floppy012
Copy link

Same here. Having the same problem as @debajit

Plugins defined:

"plugins": [
    "@babel/plugin-proposal-private-methods",
    "@babel/plugin-proposal-class-properties"
  ]

babel-eslint Version: 10.0.3

@hadnet
Copy link

hadnet commented Dec 22, 2019

A year has now passed, Babel has finally completed Class private features support but we don't have babel-eslint to support all this. So great..

@kaelzhang
Copy link

kaelzhang commented Dec 23, 2019

@hzoo

This issue should be reopened.

{
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-private-methods"
  ]
}

Setting .babelrc as above does not solve the problem.

@kaicataldo
Copy link
Member

This is actively being worked on for the next major Babel release. Please track progress here.

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

No branches or pull requests