https://github.com/caoccao/swc4j Skip to content Navigation Menu Toggle navigation Sign in * Product + GitHub Copilot Write better code with AI + Security Find and fix vulnerabilities + Actions Automate any workflow + Codespaces Instant dev environments + Issues Plan and track work + Code Review Manage code changes + Discussions Collaborate outside of code + Code Search Find more, search less Explore + All features + Documentation + GitHub Skills + Blog * Solutions By company size + Enterprises + Small and medium teams + Startups By use case + DevSecOps + DevOps + CI/CD + View all use cases By industry + Healthcare + Financial services + Manufacturing + Government + View all industries View all solutions * Resources Topics + AI + DevOps + Security + Software Development + View all Explore + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners + Executive Insights * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} caoccao / swc4j Public * * Notifications You must be signed in to change notification settings * Fork 3 * Star 127 swc4j (SWC for Java) is an ultra-fast JavaScript and TypeScript compilation and bundling tool on JVM. License Apache-2.0 license 127 stars 3 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 0 * Pull requests 0 * Discussions * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Discussions * Actions * Projects * Security * Insights caoccao/swc4j main BranchesTags [ ] Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 526 Commits .github .github .idea .idea docs docs gradle/wrapper gradle/wrapper rust rust scripts/ts scripts/ts src src .gitignore .gitignore LICENSE LICENSE README.md README.md build.gradle.kts build.gradle.kts gradle.properties gradle.properties gradlew gradlew gradlew.bat gradlew.bat settings.gradle.kts settings.gradle.kts View all files Repository files navigation * README * Apache-2.0 license swc4j Maven Central Discord swc4j Build swc4j (SWC for Java) is an ultra-fast JavaScript and TypeScript compilation and bundling tool on JVM. It is part of the Javet portfolio serving the processing of JavaScript and TypeScript code before the code is executed in Node.js or V8 on JVM. swc4j and Javet Features * Android + Linux + MacOS + Windows * JavaScript, TypeScript, JSX, TSX, etc. * Parse + AST o Visitor o Plugin + Comments + Tokens * Transform + Minify + Multiple Target ES Version + Source Map * Transpile + TS - JS + JSX - JS + TSX - JS + Source Map * Sanitizer + Built-in Object Protection + Keyword Restriction + Function Restriction + Identifier Restriction + Identifier Deletion + Identifier Freeze + Identifier Naming Convention Quick Start Dependency * Add the following dependency to your project or download a snapshot build from the Actions. com.caoccao.javet swc4j 1.3.0 // Gradle Kotlin DSL // Linux + MacOS + Windows implementation("com.caoccao.javet:swc4j:1.3.0") // Android implementation("com.caoccao.javet:swc4j-android:1.3.0") // Gradle Groovy DSL // Linux + MacOS + Windows implementation 'com.caoccao.javet:swc4j:1.3.0' // Android implementation 'com.caoccao.javet:swc4j-android:1.3.0' Transpile * Run the following Java code to transpile TypeScript to JavaScript. // Prepare a simple TypeScript code snippet. String code = "function add(a:number, b:number) { return a+b; }"; // Prepare a script name. URL specifier = new URL("file:///abc.ts"); // Prepare an option with script name and media type. Swc4jTranspileOptions options = new Swc4jTranspileOptions() .setSpecifier(specifier) .setMediaType(Swc4jMediaType.TypeScript); // Transpile the code. Swc4jTranspileOutput output = new Swc4j().transpile(code, options); // Print the transpiled code. System.out.println(output.getCode()); * The transpiled JavaScript code and inline source map are as follows. function add(a, b) { return a + b; } //# sourceMappingURL=data:application/json;base64,... Sanitize * Run the following Java code to sanitize the JavaScript code. JavetSanitizerStatementListChecker checker = new JavetSanitizerStatementListChecker(); // 1. Check if keyword const can be used. String codeString = "const a = 1;"; checker.check(codeString); System.out.println("1. " + codeString + " // Valid."); // 2. Check if keyword var can be used. codeString = "var a = 1;"; try { checker.check(codeString); } catch (JavetSanitizerException e) { System.out.println("2. " + codeString + " // Invalid: " + e.getMessage()); } // 3. Check if Object is mutable. codeString = "Object = {};"; try { checker.check(codeString); } catch (JavetSanitizerException e) { System.out.println("3. " + codeString + " // Invalid: " + e.getMessage()); } * The output is as follows. 1. const a = 1; // Valid. 2. var a = 1; // Invalid: Keyword var is not allowed. 3. Object = {}; // Invalid: Identifier Object is not allowed. Docs * Tutorials * Release Notes Blog * Run TypeScript Directly in Java * Hello Swc4j, Goodbye Antlr * How to Compromise V8 on JVM * Write SWC Plugins in Java: Part 1, Part 2, Part 3 License APACHE LICENSE, VERSION 2.0 About swc4j (SWC for Java) is an ultra-fast JavaScript and TypeScript compilation and bundling tool on JVM. Topics javascript java rust parser typescript compiler jsx transpiler swc tsx tsc transpile javet Resources Readme License Apache-2.0 license Activity Stars 127 stars Watchers 4 watching Forks 3 forks Report repository Releases 15 swc4j v1.3.0 Latest Nov 25, 2024 + 14 releases Sponsor this project * open_collective opencollective.com/caocao * issuehunt issuehunt.io/r/caoccao * https://paypal.me/caoccao?locale.x=en_US Packages 0 No packages published Languages * Java 57.6% * Rust 42.1% * TypeScript 0.3% Footer (c) 2025 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.