Skip to content

Commit 95988b9

Browse files
committed
test: add and refine private-methods fixture tests
Add 5 new fixtures (does-not-flag-non-reserved-prefix, zero-private-methods, multiple-collisions, cross-method-private-calls, similar-prefixes), simplify multiple-private-methods, and rename static-async-private-method to static-private-method. Made-with: Cursor
1 parent 6305eaa commit 95988b9

File tree

21 files changed

+141
-41
lines changed

21 files changed

+141
-41
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
#helper() {
4+
return 42;
5+
}
6+
#caller() {
7+
return this.#helper() + 1;
8+
}
9+
}

packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/static-async-private-method/error.json renamed to packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/cross-method-private-calls/error.json

File renamed without changes.

packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/static-async-private-method/expected.js renamed to packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/cross-method-private-calls/expected.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import _tmpl from "./test.html";
22
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
33
class Test extends LightningElement {
4-
static async #fetchData(url) {
5-
const response = await fetch(url);
6-
return response.json();
4+
#helper() {
5+
return 42;
76
}
8-
async connectedCallback() {
9-
const data = await Test.#fetchData('/api/data');
10-
console.log(data);
7+
#caller() {
8+
return this.#helper() + 1;
119
}
1210
/*LWC compiler vX.X.X*/
1311
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
#privateMethod() {
4+
return 1;
5+
}
6+
normalPublicMethod() {
7+
return 2;
8+
}
9+
_underscoreMethod() {
10+
return 3;
11+
}
12+
}

packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/does-not-flag-non-reserved-prefix/error.json

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import _tmpl from "./test.html";
2+
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
3+
class Test extends LightningElement {
4+
#privateMethod() {
5+
return 1;
6+
}
7+
normalPublicMethod() {
8+
return 2;
9+
}
10+
_underscoreMethod() {
11+
return 3;
12+
}
13+
/*LWC compiler vX.X.X*/
14+
}
15+
const __lwc_component_class_internal = _registerComponent(Test, {
16+
tmpl: _tmpl,
17+
sel: "lwc-test",
18+
apiVersion: 9999999
19+
});
20+
export default __lwc_component_class_internal;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
__lwc_component_class_internal_private_collisionA() {
4+
return 1;
5+
}
6+
__lwc_component_class_internal_private_collisionB() {
7+
return 2;
8+
}
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"message": "Method '__lwc_component_class_internal_private_collisionA' cannot start with reserved prefix `__lwc_`. Please rename this function to avoid conflict."
3+
}

packages/@lwc/babel-plugin-component/src/__tests__/fixtures/private-methods/multiple-collisions/expected.js

Whitespace-only changes.
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { LightningElement } from 'lwc';
22
export default class Test extends LightningElement {
3-
#validate(input) {
4-
return input != null;
3+
#method1() {
4+
return 1;
55
}
6-
#transform(input) {
7-
return String(input).trim();
6+
#method2() {
7+
return 2;
88
}
9-
#process(input) {
10-
if (this.#validate(input)) {
11-
return this.#transform(input);
12-
}
13-
return null;
14-
}
15-
connectedCallback() {
16-
this.#process('hello');
9+
#method3() {
10+
return 3;
1711
}
1812
}

0 commit comments

Comments
 (0)