Skip to content

Commit ad63005

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 ad63005

File tree

24 files changed

+334
-73
lines changed

24 files changed

+334
-73
lines changed

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ __benchmarks_results__/
1616
# Auto-generated fixture outputs
1717
**/fixtures/**/expected.*
1818
**/fixtures/**/error.*
19+
**/fixtures-private-methods/**/expected.*
20+
**/fixtures-private-methods/**/error.*
1921
packages/@lwc/template-compiler/src/__tests__/fixtures/**/ast.json
2022
packages/@lwc/template-compiler/src/__tests__/fixtures/**/metadata.json
2123

2224
# Fixture inputs potentially containing deliberate errors
2325
packages/@lwc/style-compiler/src/__tests__/fixtures/**/actual.css
2426
packages/@lwc/babel-plugin-component/src/__tests__/fixtures/**/actual.js
27+
packages/@lwc/babel-plugin-component/src/__tests__/fixtures-private-methods/**/actual.js
2528

2629
# TODO: Why do these have JS in them?
2730
packages/@lwc/module-resolver/src/__tests__/fixtures/no-config/modules/foo/bar/bar.css

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default tseslint.config(
2929

3030
gitignore(),
3131
{
32-
ignores: ['packages/**/fixtures/**/*.js'],
32+
ignores: ['packages/**/fixtures/**/*.js', 'packages/**/fixtures-*/**/*.js'],
3333
},
3434
js.configs.recommended,
3535
...tseslint.configs.recommendedTypeChecked,
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.

0 commit comments

Comments
 (0)