Skip to content

Commit d4f93e4

Browse files
committed
test: add test cases for rogue #privateNames not sneaking through
Validate that private method call sites, private field references in method bodies, and mixed field/method classes all behave correctly through the transform pipeline without leaking prefixed names. Made-with: Cursor
1 parent 7e51945 commit d4f93e4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

packages/@lwc/babel-plugin-component/src/__tests__/private-method-transform.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,4 +618,55 @@ describe('private method transform validation', () => {
618618
expect(result.code).toContain('#increment');
619619
expect(result.code).not.toContain('__lwc_component_class_internal_private_');
620620
});
621+
622+
test('private method call sites do not leak prefixed names after round-trip', () => {
623+
const source = `
624+
import { LightningElement } from 'lwc';
625+
export default class Test extends LightningElement {
626+
#doWork(x) { return x * 2; }
627+
connectedCallback() {
628+
const result = this.#doWork(21);
629+
console.log(result);
630+
}
631+
}
632+
`;
633+
634+
const result = transformWithFullPipeline(source);
635+
const code = result.code!;
636+
expect(code).toContain('this.#doWork(21)');
637+
expect(code).not.toContain('__lwc_component_class_internal_private_');
638+
});
639+
640+
test('private field reference in method body survives round-trip', () => {
641+
const source = `
642+
import { LightningElement } from 'lwc';
643+
export default class Test extends LightningElement {
644+
#state = { ready: false };
645+
#init() {
646+
this.#state.ready = true;
647+
}
648+
}
649+
`;
650+
651+
const result = transformWithFullPipeline(source);
652+
const code = result.code!;
653+
expect(code).toContain('#init');
654+
expect(code).toContain('this.#state.ready = true');
655+
expect(code).not.toContain('__lwc_component_class_internal_private_');
656+
});
657+
658+
test('forward transform only renames method declarations, not field declarations', () => {
659+
const source = `
660+
import { LightningElement } from 'lwc';
661+
export default class Test extends LightningElement {
662+
#secret = 42;
663+
#getSecret() { return this.#secret; }
664+
}
665+
`;
666+
667+
const result = transformForwardOnly(source);
668+
const code = result.code!;
669+
expect(code).toContain('__lwc_component_class_internal_private_getSecret');
670+
expect(code).toContain('#secret');
671+
});
621672
});

0 commit comments

Comments
 (0)