Skip to content

Commit a41ab06

Browse files
chore: add correct defaults
1 parent 2eaf274 commit a41ab06

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

src/transform.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import swc from "../lib/wasm.js";
33

44
const DEFAULT_OPTIONS = {
55
mode: "strip-only",
6+
// default transform will only work when mode is "transform"
7+
transform: {
8+
verbatimModuleSyntax: true,
9+
nativeClassProperties: true,
10+
noEmptyExport: true,
11+
importNotUsedAsValues: "preserve",
12+
},
613
} as Options;
714

815
export function transformSync(

test/snapshots/transform.test.js.snapshot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ exports[`should transform TypeScript type annotations and type guards 1`] = `
5353
exports[`test native class properties 1`] = `
5454
"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"
5555
`;
56+
57+
exports[`test noEmptyExport 1`] = `
58+
"const fs = require(\\"fs\\");\\n"
59+
`;

test/transform.test.js

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ test("should perform transformation without source maps", (t) => {
2323

2424
const { code, map } = transformSync(tsCode, {
2525
mode: "transform",
26-
transform: {
27-
verbatimModuleSyntax: true,
28-
},
2926
});
3027

3128
t.assert.snapshot(code);
@@ -45,9 +42,6 @@ test("should perform transformation without source maps and filename", (t) => {
4542
const { code, map } = transformSync(tsCode, {
4643
mode: "transform",
4744
filename: "foo.ts",
48-
transform: {
49-
verbatimModuleSyntax: true,
50-
},
5145
});
5246

5347
t.assert.snapshot(code);
@@ -68,9 +62,6 @@ test("should perform transformation with source maps", (t) => {
6862
mode: "transform",
6963
sourceMap: true,
7064
filename: "foo.ts",
71-
transform: {
72-
verbatimModuleSyntax: true,
73-
},
7465
});
7566

7667
t.assert.snapshot(code);
@@ -90,9 +81,6 @@ test("should perform transformation with source maps no filename", (t) => {
9081
const { code, map } = transformSync(tsCode, {
9182
mode: "transform",
9283
sourceMap: true,
93-
transform: {
94-
verbatimModuleSyntax: true,
95-
},
9684
});
9785

9886
t.assert.snapshot(code);
@@ -114,9 +102,6 @@ test("should perform transformation with error", (t) => {
114102
mode: "transform",
115103
sourceMap: true,
116104
filename: "foo.ts",
117-
transform: {
118-
verbatimModuleSyntax: true,
119-
},
120105
});
121106

122107
t.assert.snapshot(code);
@@ -146,9 +131,6 @@ test("should transform TypeScript class fields", (t) => {
146131
const { code } = transformSync(inputCode, {
147132
mode: "transform",
148133
sourceMap: true,
149-
transform: {
150-
verbatimModuleSyntax: true,
151-
},
152134
});
153135

154136
t.assert.snapshot(code);
@@ -175,9 +157,6 @@ test("should transform TypeScript private class fields", (t) => {
175157
const { code } = transformSync(inputCode, {
176158
mode: "transform",
177159
sourceMap: true,
178-
transform: {
179-
verbatimModuleSyntax: true,
180-
},
181160
});
182161

183162
t.assert.snapshot(code);
@@ -196,9 +175,6 @@ test("should transform TypeScript type annotations and type guards", (t) => {
196175
const { code } = transformSync(inputCode, {
197176
mode: "transform",
198177
sourceMaps: true,
199-
transform: {
200-
verbatimModuleSyntax: true,
201-
},
202178
});
203179

204180
t.assert.snapshot(code);
@@ -232,9 +208,6 @@ test("should transform TypeScript class decorators with multiple decorators", (t
232208
const { code } = transformSync(inputCode, {
233209
mode: "transform",
234210
sourceMap: true,
235-
transform: {
236-
verbatimModuleSyntax: true,
237-
},
238211
});
239212

240213
t.assert.snapshot(code);
@@ -272,9 +245,6 @@ test("should transform TypeScript namespaces with additional functionality", (t)
272245
const { code } = transformSync(inputCode, {
273246
mode: "transform",
274247
sourceMap: true,
275-
transform: {
276-
verbatimModuleSyntax: true,
277-
},
278248
});
279249

280250
t.assert.snapshot(code);
@@ -294,10 +264,17 @@ test("test native class properties", (t) => {
294264
const { code } = transformSync(inputCode, {
295265
mode: "transform",
296266
sourceMap: true,
297-
transform: {
298-
verbatimModuleSyntax: true,
299-
nativeClassProperties: true,
300-
},
267+
});
268+
t.assert.snapshot(code);
269+
});
270+
271+
test("test noEmptyExport", (t) => {
272+
const inputCode = `
273+
import fs = require("fs");
274+
`;
275+
const { code } = transformSync(inputCode, {
276+
mode: "transform",
277+
sourceMap: true,
301278
});
302279
t.assert.snapshot(code);
303280
});

0 commit comments

Comments
 (0)