Changelog: swc v1.2.20

Bugfixes#

spack respects swcrc (#964)#

Spack supports .swcrc properly. Just like webpack + babel environment, the configuration is determined per-file. You can even mix tsx, ts, js if you want.

spack handles common js modules properly (#969)#

Previously common js modules were improperly handled. After some very hard work, I managed to fix it and common js imports are transcompiled to compact code.

Spack generates clean code, just like the code below.

function __spack_require__(mod) {
var cache;
return function () {
if (cache) {
return cache;
}
var module = {
exports: {},
};
mod(module, module.exports);
cache = module.exports;
return cache;
};
}
// a-a-a.js
var load = __spack_require__.bind(void 0, function (module, exports) {
module.exports = {
default: "a-a-a",
};
});
// a-b.js
var load1 = __spack_require__.bind(void 0, function (module, exports) {
console.log("a-b");
exports.default = "ab";
});
// a-a.js
var load2 = __spack_require__.bind(void 0, function (module, exports) {
module.exports = load();
});
// b.js
var load3 = __spack_require__.bind(void 0, function (module, exports) {
console.log("b");
});
// c.js
var load4 = __spack_require__.bind(void 0, function (module, exports) {
console.log("c");
});
// a.js
var load5 = __spack_require__.bind(void 0, function (module, exports) {
var aa = load2();
var bb = load1();
load3();
module.exports = {
aa: aa,
bb: bb,
};
});
// entry.js
load5();
var b = load3();
load4();
console.log(b);

Spack is designed to emit bundle as smallest as possible when minified.

You can now use spack to bundle react projects. See an integration test for react in the swc main repository.

lodash-es is supported (#963)#

lodash-es accesses exports even if it's an es module. In order to handle name conflict, swc prevously rename exports to something different.

import root from "./_root.js";
import stubFalse from "./stubFalse.js";
var freeExports =
typeof exports == "object" && exports && !exports.nodeType && exports;
var freeModule =
freeExports && typeof module == "object" && module && !module.nodeType && \;
module;
var moduleExports = freeModule && freeModule.exports === freeExports;
var Buffer = moduleExports ? root.Buffer : undefined;
var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
var isBuffer = nativeIsBuffer || stubFalse;
export default isBuffer;

It's now handled more sensitively to avoid breaking codes.

Parameter decorators (#961)#

Note: this applies to typescript decorators

Previously, decorators on a parameter which does not have initializer were broken.

class Base {
constructor() {
this.action = new Subject();
}
}
class Child extends Base {
@DefineAction() action: Observable<void>;
callApi() {
console.log(this.action);
}
}

It was undefined, which is wrong, and it's now an instance of Subject.