swc core transform and minify: working versions (tested 2026-10-17)
Transform TypeScript with JSX to ES2020 using @swc/core transformSync, minify with minifySync and inspect the program AST with parseSync, all offline.
passed4 passed · 0 failed2026-10-17 05:58 UTC- Status
- passed
- Last passed
- 2026-10-17 05:58 UTC
- Tests
- 4 / 4
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
@swc/core@1.16.18@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 39008163431
The code
Exactly the files that passed. Your agent can pull them with get_recipe("swc-core-transform-minify") (install), or see them on GitHub.
package.json
{
"name": "swc-core-transform-minify",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"@swc/core": "1.16.18"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/transform.ts
import type { Options } from "@swc/core";
export const TSX_SOURCE = `type Props = { name: string; age: number };
function Greeting(props: Props) {
const label: string = "Hello " + props.name;
return <div className="greet">{label}</div>;
}
`;
export const PLAIN_TS_SOURCE = `function addNumbers(first: number, second: number): number {
const total: number = first + second;
return total;
}
(globalThis as any).__swcResult = addNumbers(20, 22);
`;
export const TSX_OPTIONS: Options = {
jsc: {
parser: { syntax: "typescript", tsx: true },
target: "es2020",
},
module: { type: "es6" },
};
export const TS_OPTIONS: Options = {
jsc: {
parser: { syntax: "typescript" },
target: "es2020",
},
module: { type: "es6" },
};
test/transform.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { minifySync, parseSync, transformSync } from "@swc/core";
import { PLAIN_TS_SOURCE, TSX_OPTIONS, TSX_SOURCE, TS_OPTIONS } from "../src/transform.ts";
test("strips TypeScript types from TSX input", () => {
const { code } = transformSync(TSX_SOURCE, TSX_OPTIONS);
assert.ok(!code.includes(": string"));
assert.ok(!code.includes(": number"));
assert.ok(!code.includes(": Props"));
assert.ok(!code.includes("type Props"));
assert.ok(code.includes("Hello"));
});
test("lowers JSX and leaves no TSX syntax", () => {
const { code } = transformSync(TSX_SOURCE, TSX_OPTIONS);
assert.ok(!code.includes("<div"));
assert.ok(code.includes("createElement") || code.includes("jsx"));
});
test("parseSync returns a module AST", () => {
const ast = parseSync(TSX_SOURCE, { syntax: "typescript", tsx: true });
assert.equal(ast.type, "Module");
assert.ok(Array.isArray(ast.body));
assert.ok(ast.body.length > 0);
});
test("minifySync output is shorter and still evaluates", () => {
const { code: compiled } = transformSync(PLAIN_TS_SOURCE, TS_OPTIONS);
const { code: compressed } = minifySync(compiled, { compress: true, mangle: true });
assert.ok(compressed.length < compiled.length);
new Function(compressed)();
assert.equal((globalThis as { __swcResult?: number }).__swcResult, 42);
delete (globalThis as { __swcResult?: number }).__swcResult;
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.