You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.4 KiB
Markdown
79 lines
1.4 KiB
Markdown
<br />
|
|
<p align="center">
|
|
<a href="https://github.com/littledivy/deno_swc">
|
|
<img src="https://raw.githubusercontent.com/littledivy/deno_swc/master/assets/deno_swc.png" alt="deno_swc logo" width="310">
|
|
</a>
|
|
<h3 align="center">deno_swc</h3>
|
|
|
|
<p align="center">
|
|
The SWC compiler for Deno.
|
|
</p>
|
|
</p>
|
|
|
|

|
|

|
|
|
|
# Usage
|
|
|
|
`parse()`
|
|
|
|
```typescript
|
|
import { parse, print } from "https://deno.land/x/swc@0.2.1/mod.ts";
|
|
|
|
const code = `const x: string = "Hello, Deno SWC!"`;
|
|
|
|
const ast = parse(code, {
|
|
target: "es2019",
|
|
syntax: "typescript",
|
|
comments: false,
|
|
});
|
|
|
|
// {
|
|
// type: "Module",
|
|
// span: { start: 0, end: 36, ctxt: 0 },
|
|
// body: [
|
|
// {
|
|
// type: "VariableDeclaration",
|
|
// span: [Object],
|
|
// kind: "const",
|
|
// declare: false,
|
|
// declarations: [Array]
|
|
// }
|
|
// ],
|
|
// interpreter: null
|
|
// }
|
|
```
|
|
|
|
`print()`
|
|
|
|
```typescript
|
|
const { code } = print(ast, {
|
|
minify: true,
|
|
module: {
|
|
type: "commonjs",
|
|
},
|
|
});
|
|
|
|
// const x = "Hello, Deno SWC!"
|
|
```
|
|
|
|
...and `transform()`
|
|
|
|
```typescript
|
|
const { code } = transform("const x: number = 2;", {
|
|
jsc: {
|
|
target: "es2016",
|
|
parser: {
|
|
syntax: "typescript",
|
|
},
|
|
},
|
|
});
|
|
|
|
// const x = 2;
|
|
```
|
|
|
|
## Copyright
|
|
|
|
deno_swc is licensed under the MIT license. Please see the [LICENSE](LICENSE)
|
|
file.
|