Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 48acaf4

Browse files
committed
chore(compiler): fix benchmark script
1 parent 8b0c830 commit 48acaf4

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

compiler/benchmark.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { compile, CompileOptions } from 'https://deno.land/x/[email protected]/tsc/compile.ts'
2-
import { colors, createHash, path, walk } from '../deps.ts'
3-
import { initWasm } from './mod.ts'
4-
import { transformSync } from './dist/wasm-pack.js'
2+
import { walk } from 'https://deno.land/[email protected]/fs/walk.ts'
3+
import { resolve } from 'https://deno.land/[email protected]/path/mod.ts'
4+
import { green, red, yellow } from 'https://deno.land/[email protected]/fmt/colors.ts'
5+
import { createHash } from 'https://deno.land/[email protected]/hash/mod.ts'
6+
import init, { transformSync } from './dist/wasm-pack.js'
7+
import getWasmData from './dist/wasm.js'
58

69
function tsc(source: string, opts: any) {
710
const compileOptions: CompileOptions = {
@@ -24,19 +27,19 @@ function tsc(source: string, opts: any) {
2427
* - green: >= 10.0 faster as expected
2528
*/
2629
function colorDiff(d: number) {
27-
let cf = colors.green
30+
let cf = green
2831
if (d < 1) {
29-
cf = colors.red
32+
cf = red
3033
} else if (d < 10) {
31-
cf = colors.yellow
34+
cf = yellow
3235
}
3336
return cf(d.toFixed(2) + 'x')
3437
}
3538

3639
async function benchmark() {
3740
const sourceFiles: Array<{ code: string, filename: string }> = []
3841
const walkOptions = { includeDirs: false, exts: ['ts', '.tsx'], skip: [/[\._](test|d)\.tsx?$/i, /\/compiler\//] }
39-
for await (const { path: filename } of walk(path.resolve('..'), walkOptions)) {
42+
for await (const { path: filename } of walk(resolve('..'), walkOptions)) {
4043
sourceFiles.push({ code: await Deno.readTextFile(filename), filename })
4144
}
4245
console.log(`[benchmark] ${sourceFiles.length} files`)
@@ -92,6 +95,7 @@ async function benchmark() {
9295
}
9396

9497
if (import.meta.main) {
95-
await initWasm()
98+
const wasmData = getWasmData()
99+
await init(wasmData)
96100
await benchmark()
97101
}

compiler/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ if (import.meta.main) {
3737
)
3838
await Deno.writeTextFile(
3939
'./dist/wasm-pack.js',
40-
`import log from "../../shared/log.ts";` + wasmPackJS.replace('console.error(getStringFromWasm0(arg0, arg1));', `
40+
`import { red } from 'https://deno.land/[email protected]/fmt/colors.ts';` + wasmPackJS.replace('console.error(getStringFromWasm0(arg0, arg1));', `
4141
const msg = getStringFromWasm0(arg0, arg1);
4242
if (msg.includes('DiagnosticBuffer(["')) {
4343
const diagnostic = msg.split('DiagnosticBuffer(["')[1].split('"])')[0]
44-
log.error("swc:", diagnostic)
44+
console.error(red("ERROR"), "swc:", diagnostic)
4545
} else {
46-
log.error(msg)
46+
console.error(red("ERROR"), msg)
4747
}
4848
`)
4949
)

compiler/dist/wasm-pack.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import log from "../../shared/log.ts";
1+
import { red } from "https://deno.land/[email protected]/fmt/colors.ts";
22
let wasm;
33

44
const heap = new Array(32).fill(undefined);
@@ -246,9 +246,9 @@ async function init(input) {
246246
const msg = getStringFromWasm0(arg0, arg1);
247247
if (msg.includes('DiagnosticBuffer(["')) {
248248
const diagnostic = msg.split('DiagnosticBuffer(["')[1].split('"])')[0];
249-
log.error("swc:", diagnostic);
249+
console.error(red("ERROR"), "swc:", diagnostic);
250250
} else {
251-
log.error(msg);
251+
console.error(red("ERROR"), msg);
252252
}
253253
} finally {
254254
wasm.__wbindgen_free(arg0, arg1);

0 commit comments

Comments
 (0)