Changelog: swc v1.2.46


Enums in namespaces (#1340)#

swc had support for namespaces since v1.2.46. But the support was not complete and enums were not handled properly. v1.2.46 adds support for enums, so the code below works as expected.

namespace Test {
export enum DummyValues {
A = "A",
B = "B",

Private class properties (#1353)#

Previously, swc didn't compile some of accesses to private properties of classes. This is fixed as of v1.2.46, by visiting all children in the ast visitor.

Block scoping (#1353)#

Preivously, swc miscompiled some of loops including

function combineOverlappingMatches(matches) {
let hasOverlaps = false;
for (let i = matches.length - 1; i >= 0; i--) {
let currentMatch = matches[i];
let overlap = matches.find((match) => {
return (
match !== currentMatch && match.itemsType === currentMatch.itemsType
if (overlap) {
hasOverlaps = true;
matches.splice(i, 1);
if (hasOverlaps) {

This is now fixed by making block statement transparent in point of view of the block scoping visitor. As this fix applies to all block statements, swc would not break such loops.

This in complex async arrow (#1353)#

Previously, swc errornously changed this in the asynchronous arrow function below.

class A {
val = "1";
async foo() {
try {
return await (async (x) => x + this.val)("a"); // this is undefined
// return await Promise.all(['a', 'b'].map(async (x) => x + this.val)); // this is undefined
} catch (e) {
throw e;
new A().foo();

This is fixed as of v1.2.46. Now swc uses quite general logic for handling such code, and I expect it not to break asynchronous arrows anymore.

bundler: Reserved word as an ident (#1346)#

As the bundler of swc is falttening bundler just like rollup, it had some code to handle difference of identifier context. For example, instanceof in the code below is valid,

import * as foo from "./util";
const x = foo.instanceof;

while instanceof in the code below is invalid.

const instanceof = function () {
// ...

The bundler renames instanceof in below to something different, but it had a bug related to object patterns in assignments. This is now fixed and the bundler will not break code using reserved works in object patterns.

New feautres#

Support for legacy decorators on methods with computed keys (#1347)#

swc now supports typescript code like

class Foo {
[bar]() {}

which uses decorator with computed keys.

Support for TypeScript 4.2 (#1330)#

swc now supports parsing and transcompiling typescript 4.2 files.