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

Commit c5386a1

Browse files
author
Wenjie Xia
committed
refactor(compiler): clean up
1 parent e79dc70 commit c5386a1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

compiler/mod.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { existsFileSync } from '../shared/fs.ts'
33
import type { ImportMap } from '../types.ts'
44
import { VERSION } from '../version.ts'
55
import { checksum } from './dist/wasm-checksum.js'
6-
import { default as init_wasm, transformSync } from './dist/wasm-pack.js'
6+
import init, { transformSync } from './dist/wasm-pack.js'
77

88
export interface SWCOptions {
99
target?: 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020'
@@ -29,17 +29,17 @@ interface DependencyDescriptor {
2929
isDynamic: boolean,
3030
}
3131

32-
export interface TransformRet {
32+
export interface TransformResult {
3333
code: string
34-
map?: string
3534
deps: DependencyDescriptor[]
3635
inlineStyles: Record<string, { type: string, quasis: string[], exprs: string[] }>
36+
map?: string
3737
}
3838

3939
/**
4040
* transpile code synchronously by swc.
4141
*
42-
* ```javascript
42+
* ```tsx
4343
* transpileSync(`
4444
* export default App() {
4545
* return <h1>Hello World</h1>
@@ -52,8 +52,11 @@ export interface TransformRet {
5252
* }
5353
* })
5454
* ```
55+
*
56+
* @param {string} code - code string.
57+
* @param {object} opts - transform options.
5558
*/
56-
export function transpileSync(code: string, opts?: TransformOptions): TransformRet {
59+
export function transpileSync(code: string, opts?: TransformOptions): TransformResult {
5760
return transformSync(code, opts)
5861
}
5962

@@ -65,17 +68,17 @@ export const initWasm = async (denoCacheDir: string) => {
6568
const cachePath = `${cacheDir}/compiler.${checksum}.wasm`
6669
if (existsFileSync(cachePath)) {
6770
const wasmData = await Deno.readFile(cachePath)
68-
await init_wasm(wasmData)
71+
await init(wasmData)
6972
} else {
7073
const { default: getWasmData } = await import('./dist/wasm.js')
7174
const wasmData = getWasmData()
72-
await init_wasm(wasmData)
75+
await init(wasmData)
7376
await ensureDir(cacheDir)
7477
await Deno.writeFile(cachePath, wasmData)
7578
}
7679
}
7780

7881
/**
79-
* wasm build checksum.
82+
* The wasm build checksum.
8083
*/
8184
export const buildChecksum = checksum

0 commit comments

Comments
 (0)