Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for nativeClassProperties #64

Merged
merged 1 commit into from
Aug 14, 2024
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
6 changes: 4 additions & 2 deletions src/loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "node:assert";
import type { LoadFnOutput, LoadHookContext } from "node:module";
import type { Options } from "../lib/wasm";
import { transformSync } from "./index.ts";

type NextLoad = (
Expand All @@ -22,7 +22,9 @@ export async function load(
});
if (source == null)
throw new Error("Source code cannot be null or undefined");
const { code } = transformSync(source.toString(), { mode: "strip-only" });
const { code } = transformSync(source.toString(), {
mode: "strip-only",
} as Options);
return {
format: format.replace("-typescript", ""),
source: code,
Expand Down
4 changes: 2 additions & 2 deletions src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Options, TransformOutput } from "../lib/wasm";
import swc from "../lib/wasm.js";

const DEFAULT_OPTIONS: Options = {
const DEFAULT_OPTIONS = {
mode: "strip-only",
};
} as Options;

export function transformSync(
source: string,
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 @@ -49,3 +49,7 @@ exports[`should transform TypeScript private class fields 1`] = `
exports[`should transform TypeScript type annotations and type guards 1`] = `
"function isString(value) {\\n return typeof value === 'string';\\n}\\nconst check = isString(\\"hello\\");\\noutput = check;\\n"
`;

exports[`test native class properties 1`] = `
"class Foo {\\n y;\\n x;\\n constructor(y = console.log(2)){\\n this.y = y;\\n this.x = console.log(1);\\n console.log(3);\\n }\\n}\\n"
`;
19 changes: 19 additions & 0 deletions test/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,22 @@ test("should transform TypeScript namespaces with additional functionality", (t)
assert.ok(result.validator);
assert.strictEqual(result.isValid, true);
});

test("test native class properties", (t) => {
const inputCode = `
class Foo {
x = console.log(1)
constructor(public y = console.log(2)) {
console.log(3)
}
}`;
const { code } = transformSync(inputCode, {
mode: "transform",
sourceMap: true,
transform: {
verbatimModuleSyntax: true,
nativeClassProperties: true,
},
});
t.assert.snapshot(code);
});
Loading