Changelog: swc v1.1.15

Bugfixes#

block scoping (#604)#

swc had a serious bug bug.

swc compiled

let functions = [];
for (let i = 0; i < 10; i++) {
functions.push(function() {
console.log(i);
});
}
functions[0]();
functions[7]();

as

var functions = [];
for (var i = 0; i < 10; i++) {
functions.push(function() {
console.log(i);
});
}
functions[0]();
functions[7]();

which is wrong. By tracking idetifier usages in nested function, swc now emits correct output.

New output is very simillar to the one of babel.

var _loop = function(i) {
functions.push(function() {
console.log(i);
});
};
var functions = [];
for (var i = 0; i < 10; i++) _loop(i);
functions[0]();
functions[7]();

hygiene (#604)#

Use-use conflict detection introduced in v1.1.14 had a serious bug. Some identifiers like Object are inherently used multiple time. It resulted in an use-use conflict and there was a bug. By making an use-bind conflict for global objects, swc can handle a code like

function foo(Object) {
Object.foo();
}

It will be compiled as

function foo(Object1) {
Object1.foo();
}

to make other usages of native identifier safe.