Changelog: swc v1.2.21

General improvements#

Support optional named tuple elements (#982)#

TypeScript 4 allows

type Foo = [first: number, second?: string, ...rest: any[]];

and swc now supports it.

Better error messages (#980)#

Error messages were crpytic, mainly because I'm too lazy. Anyway, it's finally got improved.

error: Unexpected token Some(Semi)
--> $DIR/tests/typescript-errors/type-arguments/input.ts:1:9
|
1 | new A<T>;

becomes

error: Unexpected token `;`. Expected this, import, async, function, [ for array literal, { for object literal, @ for decorator, function, class, null, true, false, number, bigint, string, regexp, ` for template literal, (, or an identifier
--> $DIR/tests/typescript-errors/type-arguments/input.ts:1:9
|
1 | new A<T>;

Performance improvement#

Performance of swc is improved (#992)#

Previously, swc spend all time moving the memory with memmove. I've managed to remove some memmoves. Also, panic cases are handled properly.

For example, I changed code from

let prev = match self.cur.take() {
Some(t) => t,
None => unreachable!(
"Current token is `None`. Parser should not call bump()without knowing current \
token"
),
};

to

#[cold]
#[inline(never)]
fn invalid_state() -> ! {
unreachable!(
"Current token is `None`. Parser should not call bump() without knowing current \
token"
)
}
let prev = match self.cur.take() {
Some(t) => t,
None => invalid_state(),
};

This technique aids cpu cache issue.

sse2 is enabled#

It drastically reduces times used to memmove.

Performance of spack is improved (#992, #972)#

Some design flaws are fixed, it's fully parallelzed, and it does not transform files from node_modules.

Binary size is reduced (#973)#

Some useless allocations are removed, some memmoves are removed. Also, merging of reexports in spack now works in parallel manner.