Skip to content

Commit f284247

Browse files
committed
feat: add unsupported private member errors and fixture e2e tests
Add LWC1214 error for unsupported private member types (fields and accessor methods). Update the forward transform to throw informative errors instead of silently passing through. Replace affected unit tests with error-expectation tests. Add fixture-based end-to-end tests that run the full pipeline (forward transform, LWC plugin, class-properties plugin, reverse transform) to verify private methods survive round-trip. Made-with: Cursor
1 parent d4f93e4 commit f284247

File tree

23 files changed

+332
-74
lines changed

23 files changed

+332
-74
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
#validate(input) {
4+
return input != null;
5+
}
6+
#transform(input) {
7+
return String(input).trim();
8+
}
9+
#process(input) {
10+
if (this.#validate(input)) {
11+
return this.#transform(input);
12+
}
13+
return null;
14+
}
15+
connectedCallback() {
16+
this.#process('hello');
17+
}
18+
}

packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/multiple-private-methods/error.json

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import _tmpl from "./test.html";
2+
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
3+
class Test extends LightningElement {
4+
#validate(input) {
5+
return input != null;
6+
}
7+
#transform(input) {
8+
return String(input).trim();
9+
}
10+
#process(input) {
11+
if (this.#validate(input)) {
12+
return this.#transform(input);
13+
}
14+
return null;
15+
}
16+
connectedCallback() {
17+
this.#process('hello');
18+
}
19+
/*LWC compiler vX.X.X*/
20+
}
21+
const __lwc_component_class_internal = _registerComponent(Test, {
22+
tmpl: _tmpl,
23+
sel: "lwc-test",
24+
apiVersion: 9999999
25+
});
26+
export default __lwc_component_class_internal;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LightningElement, api } from 'lwc';
2+
export default class Test extends LightningElement {
3+
@api label = 'default';
4+
count = 0;
5+
6+
#increment() {
7+
this.count++;
8+
}
9+
10+
handleClick() {
11+
this.#increment();
12+
}
13+
}

packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/private-method-with-public-members/error.json

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { registerDecorators as _registerDecorators } from "lwc";
2+
import _tmpl from "./test.html";
3+
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
4+
class Test extends LightningElement {
5+
constructor(...args) {
6+
super(...args);
7+
this.label = 'default';
8+
this.count = 0;
9+
}
10+
#increment() {
11+
this.count++;
12+
}
13+
handleClick() {
14+
this.#increment();
15+
}
16+
/*LWC compiler vX.X.X*/
17+
}
18+
_registerDecorators(Test, {
19+
publicProps: {
20+
label: {
21+
config: 0
22+
}
23+
},
24+
fields: ["count"]
25+
});
26+
const __lwc_component_class_internal = _registerComponent(Test, {
27+
tmpl: _tmpl,
28+
sel: "lwc-test",
29+
apiVersion: 9999999
30+
});
31+
export default __lwc_component_class_internal;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
#privateHelper() {
4+
return 42;
5+
}
6+
connectedCallback() {
7+
const val = this.#privateHelper();
8+
console.log(val);
9+
}
10+
}

packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/simple-private-method/error.json

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import _tmpl from "./test.html";
2+
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
3+
class Test extends LightningElement {
4+
#privateHelper() {
5+
return 42;
6+
}
7+
connectedCallback() {
8+
const val = this.#privateHelper();
9+
console.log(val);
10+
}
11+
/*LWC compiler vX.X.X*/
12+
}
13+
const __lwc_component_class_internal = _registerComponent(Test, {
14+
tmpl: _tmpl,
15+
sel: "lwc-test",
16+
apiVersion: 9999999
17+
});
18+
export default __lwc_component_class_internal;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
static async #fetchData(url) {
4+
const response = await fetch(url);
5+
return response.json();
6+
}
7+
async connectedCallback() {
8+
const data = await Test.#fetchData('/api/data');
9+
console.log(data);
10+
}
11+
}

0 commit comments

Comments
 (0)