mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-15 06:39:17 +00:00
fix(packages/codegen): print accessibility modifiers before abstract (#26402)
`packages/codegen` emits invalid TypeScript for abstract accessors with an explicit accessibility modifier. The JavaScript printer writes `abstract` before `public` or `protected`, but TypeScript requires accessibility to come first and reports TS1029 for the generated declaration.
For example, this valid input:
```ts
abstract class C {
public abstract accessor x: number;
protected abstract accessor y: string;
}
```
was printed as:
```ts
abstract class C {
abstract public accessor x: number;
abstract protected accessor y: string;
}
```
The printer now preserves the valid modifier order:
```ts
abstract class C {
public abstract accessor x: number;
protected abstract accessor y: string;
}
```
`printAccessorProperty` now emits accessibility before `abstract`, matching the neighboring method and property printers. The same ordering also handles declarations such as `protected abstract override accessor x: number` and applies to both the ordinary and source-map-enabled builds.
This brings the JavaScript printer in line with the Rust codegen correction in #26392. The change is confined to accessor modifier ordering; subsequent `static`, `override`, and `accessor` emission and source-map anchoring retain their existing behavior.
This commit is contained in:
1 parent
4e76602fdd
commit
a111b5b340
2 files changed
+21
-5
No files matched your search
@@ -393,17 +393,17 @@ function printAccessorProperty(node: AccessorPropertyNode, state: State): void {
|
||||
const { decorators } = node;
|
||||
if (decorators != null && decorators.length > 0) printDecorators(decorators, state);
|
||||
|
||||
if (TS && (node.type === "TSAbstractAccessorProperty" || node.abstract)) {
|
||||
printSpaceBeforeIdentifier(state);
|
||||
write(state, "abstract ", CAT_OTHER);
|
||||
}
|
||||
|
||||
if (TS && node.accessibility != null) {
|
||||
printSpaceBeforeIdentifier(state);
|
||||
writeNoLast(state, node.accessibility);
|
||||
write(state, " ", CAT_OTHER);
|
||||
}
|
||||
|
||||
if (TS && (node.type === "TSAbstractAccessorProperty" || node.abstract)) {
|
||||
printSpaceBeforeIdentifier(state);
|
||||
write(state, "abstract ", CAT_OTHER);
|
||||
}
|
||||
|
||||
if (node.static) {
|
||||
printSpaceBeforeIdentifier(state);
|
||||
write(state, "static ", CAT_OTHER);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
abstract class C extends B {
|
||||
public abstract accessor x: number;
|
||||
protected abstract accessor y: string;
|
||||
public abstract override accessor z: number;
|
||||
protected abstract override accessor w: string;
|
||||
abstract accessor a: number;
|
||||
}
|
||||
|
||||
class D extends B {
|
||||
public static accessor x = 1;
|
||||
protected static accessor y = 1;
|
||||
private accessor z = 1;
|
||||
public override accessor w = 1;
|
||||
accessor #a = 1;
|
||||
public accessor b!: number;
|
||||
}
|
||||
Reference in new issue
Block a user