@@ -292,6 +292,54 @@ suite('convertPrivateFields', () => {
292292 assert . deepStrictEqual ( result . edits , [ ] ) ;
293293 } ) ;
294294
295+ test ( 'async private method — replacement must not merge with async keyword' , async ( ) => {
296+ // In minified output, there is no space between `async` and `#method`:
297+ // class Foo{async#run(){await Promise.resolve(1)}}
298+ // Replacing `#run` with `$a` naively produces `async$a()` which is a
299+ // single identifier, not `async $a()`. The `await` inside then becomes
300+ // invalid because the method is no longer async.
301+ const code = 'class Foo{async#run(){return await Promise.resolve(1)}call(){return this.#run()}}' ;
302+ const result = convertPrivateFields ( code , 'test.js' ) ;
303+ assert . ok ( ! result . code . includes ( '#run' ) , 'should replace #run' ) ;
304+ // The replacement must NOT fuse with `async` into a single token
305+ assert . doesNotThrow ( ( ) => new Function ( result . code ) , 'transformed code must be valid JS' ) ;
306+ // Verify it actually executes (the async method should still work)
307+ const exec = new Function ( `
308+ ${ result . code }
309+ return new Foo().call();
310+ ` ) ;
311+ const val = await exec ( ) ;
312+ assert . strictEqual ( val , 1 ) ;
313+ } ) ;
314+
315+ test ( 'async private method — space inserted in declaration and not in usage' , ( ) => {
316+ // More readable version: ensure that `async #method()` becomes
317+ // `async $a()` (with space), while `this.#method()` becomes
318+ // `this.$a()` (no extra space needed since `.` separates tokens).
319+ const code = [
320+ 'class Foo {' ,
321+ ' async #doWork() { return await 42; }' ,
322+ ' run() { return this.#doWork(); }' ,
323+ '}' ,
324+ ] . join ( '\n' ) ;
325+ const result = convertPrivateFields ( code , 'test.js' ) ;
326+ assert . ok ( ! result . code . includes ( '#doWork' ) , 'should replace #doWork' ) ;
327+ assert . doesNotThrow ( ( ) => new Function ( result . code ) , 'transformed code must be valid JS' ) ;
328+ } ) ;
329+
330+ test ( 'static async private method — no token fusion' , async ( ) => {
331+ const code = 'class Foo{static async#init(){return await Promise.resolve(1)}static go(){return Foo.#init()}}' ;
332+ const result = convertPrivateFields ( code , 'test.js' ) ;
333+ assert . doesNotThrow ( ( ) => new Function ( result . code ) ,
334+ 'static async private method must produce valid JS, got:\n' + result . code ) ;
335+ const exec = new Function ( `
336+ ${ result . code }
337+ return Foo.go();
338+ ` ) ;
339+ const value = await exec ( ) ;
340+ assert . strictEqual ( value , 1 ) ;
341+ } ) ;
342+
295343 test ( 'heritage clause — extends expression resolves outer private field, not inner' , ( ) => {
296344 const code = [
297345 'class Outer {' ,
0 commit comments