babel / babel-eslint

:tokyo_tower: A wrapper for Babel's parser used for ESLint (renamed to @babel/eslint-parser)

Home Page:https://github.com/babel/babel/tree/main/eslint/babel-eslint-parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I use Private Instance Methods?

weihongyu12 opened this issue · comments

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.

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

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

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

This should be fixed by #711

commented

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

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

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):"

@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"

@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(){}).

@hadnet I'm getting that error as well.

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

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

#523

@pixxet Yes, we have that.

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"

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

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

commented

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

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