Skip to content

Commit 7e51945

Browse files
committed
test: add test cases for private fields passing through unchanged
Verify that private fields (#count, #name) are not affected by the private method transform, both alone and alongside private methods. Made-with: Cursor
1 parent a2d3e4b commit 7e51945

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,33 @@ describe('private method transform validation', () => {
589589
expect(code).toContain('__lwc_component_class_internal_privatefoo');
590590
expect(code).not.toContain('#foo');
591591
});
592+
593+
test('private fields are not transformed', () => {
594+
const source = `
595+
import { LightningElement } from 'lwc';
596+
export default class Test extends LightningElement {
597+
#count = 0;
598+
#name = 'test';
599+
}
600+
`;
601+
602+
const result = transformWithFullPipeline(source);
603+
expect(result.code).not.toContain('__lwc_component_class_internal_private_');
604+
});
605+
606+
test('private fields alongside private methods are handled correctly', () => {
607+
const source = `
608+
import { LightningElement } from 'lwc';
609+
export default class Test extends LightningElement {
610+
#count = 0;
611+
#increment() {
612+
this.#count++;
613+
}
614+
}
615+
`;
616+
617+
const result = transformWithFullPipeline(source);
618+
expect(result.code).toContain('#increment');
619+
expect(result.code).not.toContain('__lwc_component_class_internal_private_');
620+
});
592621
});

0 commit comments

Comments
 (0)