Language
Python
Rust
JavaScript
JSX
TypeScript
TSX
Go
Java
C#
Ruby is missing from that list on purpose. The command-line tool
supports it, but this page cannot: the Ruby parser (prism) is a C
library, and its sources do not build for the
wasm32-unknown-unknown target this bundle is compiled to.
Ruby is CLI-only.
Python options
Strip # comments
Strip docstrings (empties __doc__: breaks help() and doctests)
Strip type annotations (breaks dataclass/pydantic introspection)
Merge adjacent imports
With every strip flag off, Python formatting is context-lossless:
comments, docstrings and annotations are kept, and only syntactic
noise (whitespace, blank lines, indentation width) is minimized.
Rust options
Strip doc comments (/// and //! — also removes doctests)
Rust is not context-lossless, even with no flags
Regular comments are always dropped.
// and /* */ comments are lost with no
flag set, because the syn token stream the emitter
works from does not preserve them. If a file's //
comments matter to you, keep the original — TokenPress cannot
round-trip them.
Macro body whitespace is minimized. The tokens
inside a macro invocation are preserved exactly, but the
whitespace between them is not. For whitespace-sensitive macros
— stringify! is the common case — this changes the
string produced at runtime. Verification is token-canonical, so
a re-spaced macro body is token-identical to the original and
this class of change is not caught by the verifier.
Doc comments (///, //!) are
kept by default — they are #[doc = "..."]
attributes — and are only removed by the strip option above.
JavaScript/TypeScript options
Strip comments (everything but legal and annotation comments)
JavaScript/TypeScript is not context-lossless, even with no flags
Trailing and inline comments are always dropped.
return a + b; // tail re-emits as
return a+b with no flag set, and so does any comment
in expression position. Only leading, statement-level
comments survive, plus jsdoc (/** */), annotation
comments (#__PURE__) and legal comments
(//!, /*!, @license,
@preserve). Verification cannot detect this: its
canonical form is comment-free by construction.
Stripping removes everything else. With the option
above, only legal and annotation comments remain — not even leading
comments or jsdoc.
JSX text is never compressed. Whitespace inside
element children is semantically significant, so it is emitted
verbatim: JSX/TSX saves tokens on the surrounding JavaScript only.
A comment-only expression container {/* c */} becomes
{} when stripping — valid JSX that renders
identically.
In the browser, verification is internal only (re-parse plus canonical
re-emit equivalence): WebAssembly cannot spawn processes, so the
command-line tool's --verify external, which runs
tsc --noEmit or node --check over the output,
is not available here.
Go options
Strip comments (--go-strip-comments — keeps //go: directives and build constraints)
With that flag off, Go formatting is context-lossless: every comment
survives byte for byte — trailing and inline ones included — and only
whitespace is minimized. With it on, the comments the Go toolchain
reads as instructions are still kept: //go: directives,
/*line*/ and build constraints (//go:build
and the legacy // +build). At either setting a file that
imports "C" is left byte for byte identical, so a cgo file
reports no savings at all.
In the browser, verification is internal only (re-parse plus
AST equivalence): WebAssembly cannot spawn processes, so the
command-line tool's --verify external, which runs
gofmt -e over the output, is not available here.
Java options
Strip comments (--java-strip-comments — deletes Javadoc too)
With that flag off, Java formatting is context-lossless: every comment
survives byte for byte — Javadoc, trailing and inline ones included —
and only whitespace is minimized. With it on there is no keep-list:
javac reads nothing out of a comment, so unlike Go there
are no directives to preserve and the Javadoc of a stripped file goes
with the rest of its comments. At either setting a file whose comments
carry a \uXXXX escape that could decode into a comment
marker is left byte for byte identical — javac decodes
those escapes before lexing and the grammar does not — so such a file
reports no savings at all.
In the browser, verification is internal only (re-parse plus
AST equivalence): WebAssembly cannot spawn processes, so the
command-line tool's --verify external, which runs
javac over the output, is not available here.
C# options
Strip comments (--csharp-strip-comments — deletes /// XML documentation too)
With that flag off, C# formatting is context-lossless: every comment
survives byte for byte — /// XML documentation, trailing
and inline ones included — and only whitespace is minimized. With it on
there is no keep-list, and C# has one more thing to lose than Java:
the grammar gives //, block comments and ///
a single node kind, so an XML documentation comment cannot be
told apart from an ordinary one by kind and the API documentation of a
stripped file goes with the rest of its comments. At either setting a
file where the grammar and a real compiler could disagree about where a
comment ends — a comment crossing an
#if/#endif pair, one carrying a line
terminator the grammar does not honour
(U+0085, U+2028, U+2029), or one
shielding a preprocessor directive from the start of its line — is left
byte for byte identical, so it reports no savings at all.
In the browser, verification is internal only (re-parse plus
AST equivalence): WebAssembly cannot spawn processes, so the
command-line tool's --verify external, which compares the
diagnostics Roslyn's csc reports before and after, is not
available here.
Source code
Loading…
Load sample
Clear