Changelog: swc v1.2.54

Bugfixes#

typescript: async override (#1558)#

swc now supports async override in addition to override async.

class Base {
method1() {}
method2() {}
}
class Test extends Base {
public override async method1() {
return Promise.resolve(1);
}
public async override method2() {
return Promise.resolve(1);
}
}

dce bug (#1533)#

Previously swc had a bug that causes a usage of a variable in the discriminant of a switch statement not treated as a usage. It's now fixed and code like below works even if the optimizer is enabled.

var this_will_disappear; // <-- this variable declaration disappears
function a(x) {
switch (this_will_disappear) {
case x:
return;
}
}
function b() {
c();
}
function c() {
b();
d();
}
function d() {
a();
}

SIGILL (#1583)#

swc used aes feature of cpus as an optimization, but it caused SIGILL on a user's pc. So I disabled aes feature.

Logical nullish assigments (#1570)#

const a: { [a: string]: string } = {};
a.b ??= "1";
console.log(a); // expect: { b: '1' }

The code above was miscompieled by swc, but it's now fixed.

Order of statements regarding imports (#1457)#

swc now preserve order of statements even if there are some imports. This is to fix code like

import {
setGlobalOptions,
plugin,
buildSchema,
addModelToTypegoose,
deleteModel,
} from "@typegoose/typegoose";
import * as typegoose from "@typegoose/typegoose";
// typegoose.mongoose.set('debug', true);
setGlobalOptions({
options: {
allowMixed: typegoose.Severity.ALLOW,
},
schemaOptions: {
timestamps: {
createdAt: "created_at",
updatedAt: "updated_at",
},
},
});
import { schemas } from "./schemas";

Syntax context of super classes (#1586)#

swc had a bug which makes

class Foo {}
class Test extends Foo {
foo() {
console.log(Foo);
}
}
Foo = 3;
new Foo().foo();

to emit Foo instead of 3.

It's fixed by @devongovett.

Statement order of default imports. (#1568)#

To workaroudn a bug of webpack, I modified order of statements generated from export default functions.

Thankfully, @josteph explained the problem and suggested the way to fix.

Mixed import of default (#1525)#

import { Component, default as React } from "react";
class X extends Component {}
React.render(document.getElementById("root"), <X></X>);

swc previously miscompied this, because it wasn't careful enough about default as Foo-style imports. It's fixed and swc now emits

var _react = _interopRequireWildcard(require("react"));
class X extends _react.Component {}
_react.default.render(
document.getElementById("root"),
/*#__PURE__*/ _react.default.createElement(X, null)
);

which is correct.

SourceMaps (#1581)#

swc had a bug related to inline source maps and as a result it generated empty sourcemap. It's fixed.

Parameter property decorators (#1456)#

swc had a bug in logic for determining if it should work. While checking existance of decortor, swc didn't check decorators of typescript parameter properties.

As a result, decorator didn't work if all constructor parameters are parameter properties. It's now fixed and decorators are properly applied.

Fix for arguments (#1585)#

There was a bug of swc which may break some codes using arguments in arrow functions.

It could break codes like

function test() {
return () => arguments[0];
}

Fixed by @devongovett.

Fix for decorators (#1362)#

Fixed as a part of decorator fixes.