fix(codegen): print # before private identifier in TS signature key (#25938)

`TSPropertySignature` and `TSMethodSignature` were printing a `PrivateIdentifier` key as `key.name`, dropping the `#`, so `interface I { #x: number }` was printed as `interface I { x: number }`.

This PR switches `oxc_codegen` to delegating to the `PrivateIdentifier` printer, as every other property key site already does. It also applies the same thing to JS printer `oxc-codegen`.

This is not legal syntax anyway - TS rejects it with TS18016, and Oxc parser with "Private identifier '#x' is not allowed in property names" - so this is only reachable from a recovered parse or a hand-built AST. But, since we have this code, it might as well do what you'd expect it to.
This commit is contained in:
overlookmotel committed 2026-08-20 15:16:07 +00:00
1 parent 1193c9dbaf
commit a185ac3ff3
2 files changed
+3 -2

No files matched your search

+2 -2
View File
@@ -3802,7 +3802,7 @@ impl Gen for TSSignature<'_> {
key.print(p, ctx);
}
PropertyKey::PrivateIdentifier(key) => {
p.print_str(key.name.as_str());
key.print(p, ctx);
}
PropertyKey::StringLiteral(key) => {
p.print_string_literal(key, false);
@@ -3853,7 +3853,7 @@ impl Gen for TSPropertySignature<'_> {
key.print(p, ctx);
}
PropertyKey::PrivateIdentifier(key) => {
p.print_str(key.name.as_str());
key.print(p, ctx);
}
PropertyKey::StringLiteral(key) => {
p.print_string_literal(key, false);
@@ -525,6 +525,7 @@ function printSignatureKey(key: ESTree.PropertyKey, state: State, ctx: number):
writeWithMap(state, key.name, CAT_IDENT, key);
break;
case "PrivateIdentifier":
writeWithMapNoLast(state, "#", key);
write(state, key.name, CAT_IDENT);
break;
case "Literal":