Skip to content

Commit

Permalink
refactor!: migrate from @swc/core to @swc/wasm-web
Browse files Browse the repository at this point in the history
  • Loading branch information
hasundue committed Aug 1, 2024
1 parent de21b79 commit ba944e9
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Transform tests to documentation:

```typescript
assertEquals(
await transform(
transform(
await Deno.readTextFile("./fixtures/input.ts"),
),
await Deno.readTextFile("./fixtures/output.md"),
Expand All @@ -42,7 +42,7 @@ assertEquals(
Parse `describe` and `it` from tests:

```typescript
const describes = await parse(
const describes = parse(
await Deno.readTextFile("./fixtures/input.ts"),
);
assertObjectMatch(describes[0], {
Expand Down
6 changes: 3 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
]
},
"tasks": {
"cache": "deno cache --frozen=false **/*.ts",
"check": "deno fmt -q && deno lint -q && deno check -q **/*.ts",
"doc": "deno run --allow-env --allow-ffi --allow-read --allow-run=deno --allow-sys --allow-write=README.md ./docs/build.ts",
"test": "deno test --allow-env --allow-ffi --allow-read --allow-sys --no-check",
"pre-commit": "deno task check && deno task test && deno task doc"
"pre-commit": "deno task cache && deno task check && deno task test && deno task doc"
},
"imports": {
"@core/match": "jsr:@core/match@^0.3.1",
"@std/assert": "jsr:@std/assert@^1.0.0",
"@std/collections": "jsr:@std/collections@^1.0.0",
"@std/testing": "jsr:@std/testing@^0.225.0",
"@swc/core": "npm:@swc/core@^1.5.24",
"@swc/types": "npm:@swc/types@^0.1.7",
"@swc/wasm-web": "npm:@swc/wasm-web@^1.7.4",
"dedent": "npm:dedent@^1.5.3"
}
}
23 changes: 4 additions & 19 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { match, placeholder as _ } from "@core/match";
import { mapNotNullish } from "@std/collections";
import type { Statement } from "@swc/types";
// @deno-types="@swc/core";
import * as swc from "@swc/core";
import initSwc, { parseSync, type Statement } from "@swc/wasm-web";
import type { Describe } from "./types.ts";

await initSwc();

const describePattern = {
type: "ExpressionStatement",
expression: {
Expand Down Expand Up @@ -43,8 +43,8 @@ type ItPrecursor = {
* Parse a test code string to an array of describe objects.
* @param src The test code string.
*/
export default async function parse(src: string): Promise<Describe[]> {
const { body, span } = await swc.parse(src, {
export default function parse(src: string): Describe[] {
const { body, span } = parseSync(src, {
comments: true,
syntax: "typescript",
});
Expand Down
2 changes: 1 addition & 1 deletion src/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import parse from "./parse.ts";

describe("parse", () => {
it("should parse `describe` and `it` from tests", async () => {
const describes = await parse(
const describes = parse(
await Deno.readTextFile("./fixtures/input.ts"),
);
assertObjectMatch(describes[0], {
Expand Down
6 changes: 3 additions & 3 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export interface TransformOptions extends StringifyOptions {
* @param src The test code string.
* @param options The options for transforming.
*/
export default async function transform(
export default function transform(
src: string,
options: TransformOptions = {},
): Promise<string> {
return stringify(await parse(src), options);
): string {
return stringify(parse(src), options);
}
2 changes: 1 addition & 1 deletion src/transform_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import transform from "./transform.ts";
describe("transform", () => {
it("should transform tests to documentation", async () => {
assertEquals(
await transform(
transform(
await Deno.readTextFile("./fixtures/input.ts"),
),
await Deno.readTextFile("./fixtures/output.md"),
Expand Down

0 comments on commit ba944e9

Please sign in to comment.