Repository navigation
Description
Describe the bug
After upgrading rstack from 0.9.0 to 0.9.1, rs fmt silently removes the with { type: "text" } clause from a TypeScript 7.1 ambient module declaration inside an MDX code block. The command exits successfully, but the output changes the declaration's meaning.
This surfaced in web-infra-dev/rslib#2028: pnpm lint passes, while pnpm check fails on the English and Chinese static-assets documentation because the formatter expects the attribute clause to be removed.
Minimal reproduction
Create example.mdx:
```ts
declare module "*" with { type: "text" } {
const content: string;
export default content;
}
```With rstack@0.9.1 installed, run:
rs fmt example.mdxNo Rstack configuration or additional formatter plugins are needed. I reproduced this using the installed CLI binaries in a temporary directory outside the Rslib repository.
Actual behavior
The command reports successful formatting and exits with code 0. The code block becomes:
declare module "*" {
const content: string;
export default content;
}Removing the attribute clause changes which imports the ambient declaration matches; this is a semantic change, not a formatting change.
Expected behavior
Preserve the ambient module import attributes when formatting. If the syntax is not fully supported, preserve the embedded code block or report an unsupported-syntax error instead of silently dropping part of the declaration.
Version comparison and investigation
The same MDX input was tested with both installed CLI versions:
| Dependency / behavior | Before | After |
|---|---|---|
| Rstack | 0.9.0 | 0.9.1 |
Rstack's @swc-next/parser dependency |
0.4.1 | 0.6.1 |
| Rstack's Prettier dependency | 3.9.10 | 3.9.10 |
rs fmt example.mdx |
Leaves the code block unchanged | Removes the attribute clause |
Rstack uses its SWC parser plugin together with Prettier's ESTree printer.
- With 0.9.0, formatting the declaration directly as
.d.tsfails to parse atwith; the MDX code-block path preserves the original text. - With 0.9.1, SWC parses the declaration successfully. Inspecting its AST confirms that
TSModuleDeclaration.attributescontains thetype: "text"information. - The installed Prettier 3.9.10 printer for
TSModuleDeclarationprints the module kind, identifier, and body, but does not printattributes. The attribute clause is lost during printing. - Calling Rstack's formatter directly with a
.d.tsfilepath also reproduces the attribute loss in 0.9.1.
This appears to be a parser/printer compatibility gap exposed by the parser upgrade: the parser now accepts syntax that the printer does not yet preserve.
The Rslib PR also upgrades the root Prettier dependency to 3.10.1, but I verified that Rstack's formatter resolves its own Prettier 3.9.10 dependency. The isolated CLI reproduction does not require the root Prettier upgrade.
Environment
- macOS, arm64
- Node.js 26.13.0
- pnpm 12.18.0
- Rstack 0.9.1 (compared against 0.9.0)
Workaround
Adding {/* prettier-ignore */} immediately before the affected MDX code block preserves the declaration. This is the local workaround in Rslib; it does not fix the formatter itself.
Activity
chenjiahan commentedon Nov 13, 2026
This syntax was introduced in TypeScript 7.1, and Prettier's ESTree printer does not support it yet.
Its module declaration printer in 3.10.1 still omits the
attributesfield.I also checked Prettier 3.9.10 without plugins: it reports a parse error for a standalone
.d.tsfile.