Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import swc from "../lib/wasm.js";

const DEFAULT_OPTIONS = {
mode: "strip-only",
// default transform will only work when mode is "transform"
transform: {
verbatimModuleSyntax: true,
nativeClassProperties: true,
noEmptyExport: true,
importNotUsedAsValues: "preserve",
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I think the only behavioral change this PR will achieve on Node is to fix nodejs/node#54514 via the addition of noEmptyExport: true

The rest is just codifying existing usage. Similarly you could add:

Suggested change
},
useDefineForClassFields: true,
},

In TypeScript, VMS replaces that need to set INUAV. But I don't know if that's the case in SWC so keeping it fully explicit (as you have now) until we hear otherwise from SWC folk seems good.

Copy link
Member Author

@marco-ippolito marco-ippolito Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently useDefineForClassFields does not exist in configuration

} as Options;

export function transformSync(
Expand Down
4 changes: 4 additions & 0 deletions test/snapshots/transform.test.js.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ exports[`should transform TypeScript type annotations and type guards 1`] = `
exports[`test native class properties 1`] = `
"class Foo {\\n y;\\n x = console.log(1);\\n constructor(y = console.log(2)){\\n this.y = y;\\n console.log(3);\\n }\\n}\\n"
`;

exports[`test noEmptyExport 1`] = `
"const fs = require(\\"fs\\");\\n"
`;
45 changes: 11 additions & 34 deletions test/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ test("should perform transformation without source maps", (t) => {

const { code, map } = transformSync(tsCode, {
mode: "transform",
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand All @@ -45,9 +42,6 @@ test("should perform transformation without source maps and filename", (t) => {
const { code, map } = transformSync(tsCode, {
mode: "transform",
filename: "foo.ts",
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand All @@ -68,9 +62,6 @@ test("should perform transformation with source maps", (t) => {
mode: "transform",
sourceMap: true,
filename: "foo.ts",
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand All @@ -90,9 +81,6 @@ test("should perform transformation with source maps no filename", (t) => {
const { code, map } = transformSync(tsCode, {
mode: "transform",
sourceMap: true,
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand All @@ -114,9 +102,6 @@ test("should perform transformation with error", (t) => {
mode: "transform",
sourceMap: true,
filename: "foo.ts",
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand Down Expand Up @@ -146,9 +131,6 @@ test("should transform TypeScript class fields", (t) => {
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMap: true,
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand All @@ -175,9 +157,6 @@ test("should transform TypeScript private class fields", (t) => {
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMap: true,
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand All @@ -196,9 +175,6 @@ test("should transform TypeScript type annotations and type guards", (t) => {
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMaps: true,
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand Down Expand Up @@ -232,9 +208,6 @@ test("should transform TypeScript class decorators with multiple decorators", (t
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMap: true,
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand Down Expand Up @@ -272,9 +245,6 @@ test("should transform TypeScript namespaces with additional functionality", (t)
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMap: true,
transform: {
verbatimModuleSyntax: true,
},
});

t.assert.snapshot(code);
Expand All @@ -294,10 +264,17 @@ test("test native class properties", (t) => {
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMap: true,
transform: {
verbatimModuleSyntax: true,
nativeClassProperties: true,
},
});
t.assert.snapshot(code);
});

test("test noEmptyExport", (t) => {
const inputCode = `
import fs = require("fs");
`;
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMap: true,
});
t.assert.snapshot(code);
});