@@ -46,128 +46,7 @@ function transformForwardOnly(source: string, opts = {}) {
4646}
4747
4848describe ( 'private method transform validation' , ( ) => {
49- test ( 'normal private methods round-trip successfully' , ( ) => {
50- const source = `
51- import { LightningElement } from 'lwc';
52- export default class Test extends LightningElement {
53- #privateMethod() {
54- return 42;
55- }
56- }
57- ` ;
58-
59- const result = transformWithFullPipeline ( source ) ;
60- expect ( result . code ) . toContain ( '#privateMethod' ) ;
61- expect ( result . code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
62- } ) ;
63-
64- test ( 'multiple private methods round-trip successfully' , ( ) => {
65- const source = `
66- import { LightningElement } from 'lwc';
67- export default class Test extends LightningElement {
68- #methodA() { return 1; }
69- #methodB() { return 2; }
70- #methodC() { return 3; }
71- }
72- ` ;
73-
74- const result = transformWithFullPipeline ( source ) ;
75- expect ( result . code ) . toContain ( '#methodA' ) ;
76- expect ( result . code ) . toContain ( '#methodB' ) ;
77- expect ( result . code ) . toContain ( '#methodC' ) ;
78- } ) ;
79-
80- test ( 'throws error when collision exists alongside real private methods' , ( ) => {
81- const source = `
82- import { LightningElement } from 'lwc';
83- export default class Test extends LightningElement {
84- #realPrivate() { return 1; }
85- __lwc_component_class_internal_private_fakePrivate() {
86- return 'collision';
87- }
88- }
89- ` ;
90-
91- expect ( ( ) => transformWithFullPipeline ( source ) ) . toThrowError (
92- / c a n n o t s t a r t w i t h r e s e r v e d p r e f i x ` _ _ l w c _ ` \. P l e a s e r e n a m e t h i s f u n c t i o n t o a v o i d c o n f l i c t /
93- ) ;
94- } ) ;
95-
96- test ( 'does not flag methods that do not use the reserved prefix' , ( ) => {
97- const source = `
98- import { LightningElement } from 'lwc';
99- export default class Test extends LightningElement {
100- #privateMethod() { return 1; }
101- normalPublicMethod() { return 2; }
102- _underscoreMethod() { return 3; }
103- }
104- ` ;
105-
106- const result = transformWithFullPipeline ( source ) ;
107- expect ( result . code ) . toContain ( '#privateMethod' ) ;
108- expect ( result . code ) . toContain ( 'normalPublicMethod' ) ;
109- expect ( result . code ) . toContain ( '_underscoreMethod' ) ;
110- } ) ;
111-
112- test ( 'static private method round-trips successfully' , ( ) => {
113- const source = `
114- import { LightningElement } from 'lwc';
115- export default class Test extends LightningElement {
116- static #helper() {
117- return 'static';
118- }
119- }
120- ` ;
121-
122- const result = transformWithFullPipeline ( source ) ;
123- expect ( result . code ) . toContain ( 'static #helper' ) ;
124- expect ( result . code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
125- } ) ;
126-
127- test ( 'class with zero private methods succeeds' , ( ) => {
128- const source = `
129- import { LightningElement } from 'lwc';
130- export default class Test extends LightningElement {
131- publicMethod() { return 1; }
132- anotherPublic() { return 2; }
133- }
134- ` ;
135-
136- const result = transformWithFullPipeline ( source ) ;
137- expect ( result . code ) . toContain ( 'publicMethod' ) ;
138- expect ( result . code ) . toContain ( 'anotherPublic' ) ;
139- expect ( result . code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
140- } ) ;
141-
142- test ( 'error message includes the specific offending method name' , ( ) => {
143- const source = `
144- import { LightningElement } from 'lwc';
145- export default class Test extends LightningElement {
146- __lwc_component_class_internal_private_mySpecificName() {
147- return 'collision';
148- }
149- }
150- ` ;
151-
152- expect ( ( ) => transformWithFullPipeline ( source ) ) . toThrowError (
153- / _ _ l w c _ c o m p o n e n t _ c l a s s _ i n t e r n a l _ p r i v a t e _ m y S p e c i f i c N a m e /
154- ) ;
155- } ) ;
156-
157- test ( 'multiple collision methods throws on first encountered' , ( ) => {
158- const source = `
159- import { LightningElement } from 'lwc';
160- export default class Test extends LightningElement {
161- __lwc_component_class_internal_private_collisionA() { return 1; }
162- __lwc_component_class_internal_private_collisionB() { return 2; }
163- }
164- ` ;
165-
166- expect ( ( ) => transformWithFullPipeline ( source ) ) . toThrowError (
167- / _ _ l w c _ c o m p o n e n t _ c l a s s _ i n t e r n a l _ p r i v a t e _ c o l l i s i o n [ A B ] /
168- ) ;
169- } ) ;
170-
49+ // Kept inline: uses reverse-only pipeline (no forward transform)
17150 test ( 'reverse standalone on clean code succeeds without forward metadata' , ( ) => {
17251 const source = `
17352 class Test {
@@ -179,6 +58,7 @@ describe('private method transform validation', () => {
17958 expect ( result . code ) . toContain ( 'publicMethod' ) ;
18059 } ) ;
18160
61+ // Kept inline: uses reverse-only pipeline (no forward transform)
18262 test ( 'reverse standalone with prefixed method throws collision when metadata is missing' , ( ) => {
18363 const source = `
18464 class Test {
@@ -191,6 +71,7 @@ describe('private method transform validation', () => {
19171 ) ;
19272 } ) ;
19373
74+ // Kept inline: uses custom intermediate Babel plugin in a 4-plugin pipeline
19475 test ( 'Program.exit count mismatch throws when forward-transformed method is removed' , ( ) => {
19576 const PREFIX = '__lwc_component_class_internal_private_' ;
19677
@@ -230,24 +111,7 @@ describe('private method transform validation', () => {
230111 ) . toThrowError ( / P r i v a t e m e t h o d t r a n s f o r m c o u n t m i s m a t c h / ) ;
231112 } ) ;
232113
233- test ( 'private method body with call sites round-trips' , ( ) => {
234- const source = `
235- import { LightningElement } from 'lwc';
236- export default class Test extends LightningElement {
237- #helper() { return 42; }
238- #caller() {
239- return this.#helper() + 1;
240- }
241- }
242- ` ;
243-
244- const result = transformWithFullPipeline ( source ) ;
245- expect ( result . code ) . toContain ( '#helper' ) ;
246- expect ( result . code ) . toContain ( '#caller' ) ;
247- expect ( result . code ) . toContain ( 'this.#helper()' ) ;
248- expect ( result . code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
249- } ) ;
250-
114+ // Kept inline: uses forward-only pipeline (no reverse transform)
251115 test ( 'forward-only output contains correct prefixed names' , ( ) => {
252116 const source = `
253117 import { LightningElement } from 'lwc';
@@ -264,47 +128,7 @@ describe('private method transform validation', () => {
264128 expect ( result . code ) . not . toContain ( '#bar' ) ;
265129 } ) ;
266130
267- test ( 'combined flags (static, async, default param) survive round-trip' , ( ) => {
268- const source = `
269- import { LightningElement } from 'lwc';
270- export default class Test extends LightningElement {
271- static async #fetch(url, opts = {}) {
272- return await fetch(url, opts);
273- }
274- }
275- ` ;
276-
277- const result = transformWithFullPipeline ( source ) ;
278- expect ( result . code ) . toContain ( 'static async #fetch(url, opts = {})' ) ;
279- expect ( result . code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
280- } ) ;
281-
282- test ( 'method ordering is preserved through round-trip' , ( ) => {
283- const source = `
284- import { LightningElement } from 'lwc';
285- export default class Test extends LightningElement {
286- #alpha() { return 'a'; }
287- publicBeta() { return 'b'; }
288- #gamma() { return 'c'; }
289- publicDelta() { return 'd'; }
290- }
291- ` ;
292-
293- const result = transformWithFullPipeline ( source ) ;
294- const code = result . code ! ;
295- const alphaIdx = code . indexOf ( '#alpha' ) ;
296- const betaIdx = code . indexOf ( 'publicBeta' ) ;
297- const gammaIdx = code . indexOf ( '#gamma' ) ;
298- const deltaIdx = code . indexOf ( 'publicDelta' ) ;
299- expect ( alphaIdx ) . toBeGreaterThan ( - 1 ) ;
300- expect ( betaIdx ) . toBeGreaterThan ( - 1 ) ;
301- expect ( gammaIdx ) . toBeGreaterThan ( - 1 ) ;
302- expect ( deltaIdx ) . toBeGreaterThan ( - 1 ) ;
303- expect ( alphaIdx ) . toBeLessThan ( betaIdx ) ;
304- expect ( betaIdx ) . toBeLessThan ( gammaIdx ) ;
305- expect ( gammaIdx ) . toBeLessThan ( deltaIdx ) ;
306- } ) ;
307-
131+ // Kept inline: uses custom intermediate Babel plugin in a 4-plugin pipeline
308132 test ( 'intermediate plugin that modifies method body does not break reverse transform' , ( ) => {
309133 function bodyModifierPlugin ( { types : t } : any ) {
310134 return {
@@ -352,6 +176,7 @@ describe('private method transform validation', () => {
352176 expect ( result . code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
353177 } ) ;
354178
179+ // Kept inline: uses custom intermediate Babel plugin in a 4-plugin pipeline
355180 test ( 'intermediate plugin that adds a prefixed method triggers collision' , ( ) => {
356181 function prefixedMethodInjectorPlugin ( { types : t } : any ) {
357182 let injected = false ;
@@ -393,40 +218,7 @@ describe('private method transform validation', () => {
393218 ) . toThrowError ( / c a n n o t s t a r t w i t h r e s e r v e d p r e f i x ` _ _ l w c _ ` / ) ;
394219 } ) ;
395220
396- test ( 'methods with similar but non-matching prefixes are not reverse-transformed' , ( ) => {
397- const source = `
398- import { LightningElement } from 'lwc';
399- export default class Test extends LightningElement {
400- __lwc_component_class_internal_foo() { return 1; }
401- __lwc_component_class_internal_privatefoo() { return 2; }
402- }
403- ` ;
404-
405- const result = transformWithFullPipeline ( source ) ;
406- const code = result . code ! ;
407- expect ( code ) . toContain ( '__lwc_component_class_internal_foo' ) ;
408- expect ( code ) . toContain ( '__lwc_component_class_internal_privatefoo' ) ;
409- expect ( code ) . not . toContain ( '#foo' ) ;
410- } ) ;
411-
412- test ( 'private method call sites do not leak prefixed names after round-trip' , ( ) => {
413- const source = `
414- import { LightningElement } from 'lwc';
415- export default class Test extends LightningElement {
416- #doWork(x) { return x * 2; }
417- connectedCallback() {
418- const result = this.#doWork(21);
419- console.log(result);
420- }
421- }
422- ` ;
423-
424- const result = transformWithFullPipeline ( source ) ;
425- const code = result . code ! ;
426- expect ( code ) . toContain ( 'this.#doWork(21)' ) ;
427- expect ( code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
428- } ) ;
429-
221+ // Kept inline: uses forward-only pipeline (no reverse transform)
430222 test ( 'forward-only output transforms call sites to prefixed names' , ( ) => {
431223 const source = `
432224 import { LightningElement } from 'lwc';
@@ -445,6 +237,7 @@ describe('private method transform validation', () => {
445237 expect ( code ) . not . toContain ( 'this.#doWork' ) ;
446238 } ) ;
447239
240+ // Kept inline: uses forward-only pipeline (no reverse transform)
448241 test ( 'forward references in call sites are transformed' , ( ) => {
449242 const source = `
450243 import { LightningElement } from 'lwc';
@@ -466,6 +259,7 @@ describe('private method transform validation', () => {
466259 expect ( roundTrip . code ) . not . toContain ( '__lwc_component_class_internal_private_' ) ;
467260 } ) ;
468261
262+ // Kept inline: uses forward-only pipeline to verify occurrence counts
469263 test ( 'multiple invocations of the same private method are all transformed' , ( ) => {
470264 const source = `
471265 import { LightningElement } from 'lwc';
@@ -492,6 +286,7 @@ describe('private method transform validation', () => {
492286 expect ( privateMatches ) . toHaveLength ( 4 ) ;
493287 } ) ;
494288
289+ // Kept inline: uses forward-only pipeline (no reverse transform)
495290 test ( 'cross-method private call sites in forward-only output' , ( ) => {
496291 const source = `
497292 import { LightningElement } from 'lwc';
0 commit comments