Changelog: swc v1.2.36

Bugfixes#

export * as ns (#1142)#

swc now handle export * as ns from 'foo'; by default, if you are targeting < es2020.

Also, spack and swc_bundler now supports it directly.

conditional expression in await (#1133)#

swc errornously removed parenthesis of conditional expression in await expressions.

scope of optional chaining (#1136)#

Previously, swc miscompiled the code below.

const PATCHES = new Map();
const ident = "foo";
const patch = PATCHES.get(ident)?.();

This was compiled as

var _obj = PATCHES.get(ident),
ref;
const PATCHES = new Map();
const ident = "foo";
const patch = (ref = _obj) === null || ref === void 0 ? void 0 : ref.call(_obj);

Which results in a runtime error. This is caused by sharing variable buffer. It's fixed by using two variable buffers.

computed keys in object literal (#1140)#

The hygiene pass of swc had a bug. The bug was that it does not visit key in { [key]: value }.

This is fixed, and code like below works properly.

const categories = [{ key: "apple" }, { key: "banana" }, { key: "strawberry" }];
const item = "some item";
const catNames = categories.reduce((a, item) => {
return { ...a, [item.key.toString()]: item };
}, {});

bundler: deglob imports correctly (#1139)#

import * as circular2 from "./circular2.ts";
export function f1(): void {
console.log("f1");
}
circular2.f2();

Previously, the code above was bundled as

export function f1() {
console.log("f1");
}
circular2.f2();
circular1.f1();

which is clearly wrong. It's now fixed.

bundler: aliased imports (#1138)#

This bug occurs if nested export is mixed with aliased import.

a.ts:

export const a = "a";

l.ts:

export { a } from "./a.ts";

entry.ts:

import { a as defaultA } from "./l.ts";
const o: { a?: string } = {};
const { a = defaultA } = o;
console.log(a);

This resulted in

const o = {};
const { a = defaultA } = o;
console.log(a);

which is wrong. It's now fixed and swc_bundler now supports quite complex imports.