Changelog: swc v1.2.57

Imrpovements#

Perfoemance (#1673)#

This pr adds lots of fast path for es2015 passes, and the addition of fast-paths removes lots of useless memcpy calls. The time used for es2015 -> es5 transforms is reduced about 33%. (It's now 50% faster).

Codegen of class expressions (#1660)#

Previously swc compiled

console.log(
class {
run() {}
}
);

as

console.log(
(function () {
var _class = /*#__PURE__*/ (function () {
"use strict";
function _class() {
_classCallCheck(this, _class);
}
_createClass(_class, [
{
key: "run",
value: function run() {},
},
]);
return _class;
})();
return _class;
})()
);

which is not optimal.

Starting from swc v1.2.57, swc emits

console.log(/*#__PURE__*/ function() {
"use strict";
function _class() {
_classCallCheck(this, _class);
}
_createClass(...);
return _class;
}()
);

New features#

Pure comment for classes pass. (#1646)#

swc now emits /*#__PURE__*/ for classes to help javascript minifiers.

TypeScript: override with static (#1663)#

Implemented by @g-plane.

TypeScript: Support override in parameter properties (#1667)#

Implemented by @g-plane.

Internals#

This section contains internal improvements, which are mostly done for the new typesciprt checker I'm working on.

Function declarations in ts modules (#1665)#

Previously, swc didn't identified F2s in below code.

module M {
export class A {
name: string;
}
export function F2(x: number): string {
return x.toString();
}
}
module N {
export class A {
id: number;
}
export function F2(x: number): string {
return x.toString();
}
}

This bug resulted in a bug of stc, the typescript type checker I'm working on.

Function declarations in arrow expressions (#1666)#

Previously, the ts_resolver pass did not distinguish two bar in code below. The bug does not affect swc users because the bug only occurs when two separate arrow expressions contains a function named identically.

var f3 = <T, U extends T>(x: T, y: U) => {
function bar<V extends T, W extends U>() {
var g = <X extends W, Y extends V>(a: X, b: Y): T => {
x = y;
return y;
};
}
};
var f4 = <U extends T, T>(x: T, y: U) => {
function bar<V extends T, W extends U>() {
var g = <X extends W, Y extends V>(a: X, b: Y): T => {
x = y;
return y;
};
}
};

For of/in loops (#1672)#

Previously, the ts_resolver pass did not distinguish v in code below.

for (const v of new FooIterator()) {
const v = 0; // new scope
}

This bug is theoritically possible to affect real world codes, but it would not. So it is listed on the misc section.