Skip to content

Commit 1629b0a

Browse files
a-chabotclaude
andcommitted
test: add edge case fixture tests for private method invocations
Add comprehensive tests for private method invocations in complex contexts: - arrow-function-callback: Private methods in callbacks (setTimeout, Promise.then) - multiple-invocations-in-expression: Multiple calls in single expressions - conditional-invocation: Ternary operators, logical AND/OR expressions These tests ensure the transform correctly handles all real-world usage patterns. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 95988b9 commit 1629b0a

File tree

9 files changed

+117
-0
lines changed

9 files changed

+117
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
#helper() {
4+
return 42;
5+
}
6+
connectedCallback() {
7+
setTimeout(() => {
8+
const result = this.#helper();
9+
console.log(result);
10+
}, 100);
11+
12+
Promise.resolve().then(() => this.#helper());
13+
}
14+
}

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

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import _tmpl from "./test.html";
2+
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
3+
class Test extends LightningElement {
4+
#helper() {
5+
return 42;
6+
}
7+
connectedCallback() {
8+
setTimeout(() => {
9+
const result = this.#helper();
10+
console.log(result);
11+
}, 100);
12+
Promise.resolve().then(() => this.#helper());
13+
}
14+
/*LWC compiler vX.X.X*/
15+
}
16+
const __lwc_component_class_internal = _registerComponent(Test, {
17+
tmpl: _tmpl,
18+
sel: "lwc-test",
19+
apiVersion: 9999999
20+
});
21+
export default __lwc_component_class_internal;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
#processA() {
4+
return 'A';
5+
}
6+
#processB() {
7+
return 'B';
8+
}
9+
#checkCondition() {
10+
return true;
11+
}
12+
run(enabled) {
13+
const result = enabled ? this.#processA() : this.#processB();
14+
const checked = this.#checkCondition() && this.#processA();
15+
const fallback = this.#checkCondition() || this.#processB();
16+
const nullable = enabled ? this.#processA() : null;
17+
return `${result}-${checked}-${fallback}-${nullable}`;
18+
}
19+
}

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

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import _tmpl from "./test.html";
2+
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
3+
class Test extends LightningElement {
4+
#processA() {
5+
return 'A';
6+
}
7+
#processB() {
8+
return 'B';
9+
}
10+
#checkCondition() {
11+
return true;
12+
}
13+
run(enabled) {
14+
const result = enabled ? this.#processA() : this.#processB();
15+
const checked = this.#checkCondition() && this.#processA();
16+
const fallback = this.#checkCondition() || this.#processB();
17+
const nullable = enabled ? this.#processA() : null;
18+
return `${result}-${checked}-${fallback}-${nullable}`;
19+
}
20+
/*LWC compiler vX.X.X*/
21+
}
22+
const __lwc_component_class_internal = _registerComponent(Test, {
23+
tmpl: _tmpl,
24+
sel: "lwc-test",
25+
apiVersion: 9999999
26+
});
27+
export default __lwc_component_class_internal;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { LightningElement } from 'lwc';
2+
export default class Test extends LightningElement {
3+
#compute(x) {
4+
return x * 2;
5+
}
6+
#getValue() {
7+
return 10;
8+
}
9+
calculate() {
10+
const sum = this.#compute(5) + this.#compute(10);
11+
const combined = this.#getValue() + this.#compute(this.#getValue());
12+
return sum + combined;
13+
}
14+
}

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

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import _tmpl from "./test.html";
2+
import { LightningElement, registerComponent as _registerComponent } from 'lwc';
3+
class Test extends LightningElement {
4+
#compute(x) {
5+
return x * 2;
6+
}
7+
#getValue() {
8+
return 10;
9+
}
10+
calculate() {
11+
const sum = this.#compute(5) + this.#compute(10);
12+
const combined = this.#getValue() + this.#compute(this.#getValue());
13+
return sum + combined;
14+
}
15+
/*LWC compiler vX.X.X*/
16+
}
17+
const __lwc_component_class_internal = _registerComponent(Test, {
18+
tmpl: _tmpl,
19+
sel: "lwc-test",
20+
apiVersion: 9999999
21+
});
22+
export default __lwc_component_class_internal;

0 commit comments

Comments
 (0)