Skip to content

Private methods do not compile #5011

Open
@argomez

Description

@argomez

Description

Would like to use private class methods, including get/set methods. However this fails to compile.

Steps to Reproduce

https://stackblitz.com/edit/salesforce-lwc-hzkzus?file=src%2Fmodules%2Fx%2Fcounter%2Fcounter.js

import { LightningElement, api } from 'lwc';

export default class extends LightningElement {
    @api label;

    counter = 0;

    #increment() {
        this.counter++;
    }
    decrement() {
        this.counter--;
    }
}

Expected Results

Component compiles and renders as expected, with the increment function on the x-counter component being private.

Actual Results

rollup v4.28.0
bundles src/main.js → dist/main.js...
[!] (plugin rollup-plugin-lwc-compiler) Error: SyntaxError: LWC1007: /home/projects/salesforce-lwc-uug6np/src/modules/x/counter/counter.js: Class private methods are not enabled. Please add `@babel/plugin-transform-private-methods` to your configuration.

Browsers Affected

Brave latest
v1.73.97 (Dec 4, 2024)

Version

-"lwc": "8.11.0",

Possible Solution

I assume this plugin needs to be added here but not sure
https://github.com/salesforce/lwc/blob/master/packages/%40lwc/compiler/src/transformers/javascript.ts

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions