Skip to content

alisenola/deno-swc-complier

Repository files navigation


deno_swc logo

deno_swc

The SWC compiler for Deno.

ci

Usage

parse()

import { parse, print } from "https://deno.land/x/[email protected]/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()

const { code } = print(ast, {
  minify: true,
  module: {
    type: "commonjs",
  },
});

// const x = "Hello, Deno SWC!"

...and transform()

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 file.