Changelog: swc v1.2.37


ascii-only output (#1191)#

Previously [swc] emitted utf-8 output and had some bug related to escape, but[swc] now emits only ascii characters.

error instead of panic (#1170)#

Previously [swc] panicked if the parse is called with the code below.

const toString: (local)(this: Function) => string) = undefined;

This behavior is wrong and [swc] now emits error instead of panicking.

codegen bug of if (#1185)#

Previously [swc] emitted a wrong output for the code below.

if (...) {}
else foo++;

Thanks to @braddunbar, it's now fixed and the generated code works as expected.

typeof helper issue (#1183)#

typeof helper had a bug which occurs in a runtime without Symbol. It's fixed by @wessberg.

invalid escapes in template literals (#1175)#

According to es2018 specification, the code below is valid.


But previously, [swc] could not parse it. This is now fixed by @braddunbar.

error recoveries (#1189)#

The parser of [swc] can now recover from strict-mode violations.

It means, even if your file has some errors, you can still get ast although it's not valid. As one purpose of [swc] is being a basic building block, this is big win.

dce bug (#1157)#

The dead code elimination pass had a bug related to class properties, and it's now fixed.

Now code like below works well after optimizing.

export interface D {
resolve: any;
reject: any;
export function d(): D {
let methods;
const promise = new Promise((resolve, reject) => {
methods = { resolve, reject };
return Object.assign(promise, methods);

hygiene bug (#1144)#

[swc] had a bug which makes default value in object patterns miscompiled. This is now fixed.


Starting from [deno]@1.5, there's an option --no-check in options of deno bundle. It uses swc_bundler, which is a general implementation of a web asset bundler. While integrating, the [deno] team reported many bugs and those are all fixed.

import and export from a module (#1152)#

Previously the bundler failed to process code below.

import { a as defaultA, O } from "./m.ts";
export { O } from "./m.ts";
interface AOptions {
a?(): void;
c?: O;
class A {
#a: () => void;
#c?: O;
constructor(o: AOptions = {}) {
const { a = defaultA, c } = o;
this.#a = a;
this.#c = c;
a() {
c() {
let a = new A();

This is because there was no logic to handle exports and imports from a module. This is fixed by adding such logic.

computed access to namespace imports (#1159)#

This made[email protected]/examples/server.ts work after bundling.

determinisctic output (#1166)#

For reliability, I made the output of swc_bundler deterministic.

pass ordering (#1171)#

The pass ordering was wrong, and resulted in a bug, which prevents[email protected]/examples/sseServer.ts from working after bundling.

export * (#1154)#

The bundler of [swc] had a bug related to export * where a function or a class is exported. This is fixed by applying same rule as variable exports.

codegen of single arg arrow functions (#1186)#

Thanks to @braddunbar, [swc] now prints arrow function with single arguement properly.

TypeScript 4.1#

as in mapped type (#1151)#

Thanks to @g-plane, the code below now works.

let map: { [P in string as string]: number };

template literal type (#1190)#

Thanks to @g-plane, the code below now works.

type MultiLine = `
some value
type WithTypes = `with-a-${string}`;
type WithTypes2 = `with-a-${MyAlias}-end`;

intrinsic type (#1193)#

Thanks to @g-plane, the code below now works.

let i: intrinsic;