Skip to main content

swc v1.2.11: Fix for almost all typescript bugs

· 3 min read

Bugfixes#

super statements (#918)#

Thanks to @Brooooooklyn, no statement will be injected before super(). The patch affects code like

export class BadRequestError extends Error {  constructor(public readonly message: string) {    super(message);  }}

by making the call to _definedProperty generated because of public readonly message to be injected after super(message);.

[key: string]: Type is stripped out properly (#922)#

Previously, in the code below,

export abstract class Kernel {  /**   * Multiple variables that will be defined during runtime,   * holding the values of the commands passed from the user   */  [key: string]: any;}

[key: string]: any; was not stripped out properly. This is reported by the deno team, and the bug makes me look for a way to find typescript-related bugs, and as a result, swc@v1.2.11 is full of typescript related patches. I used tests from the official typescript repository to ensure generated ecmascript files are valid.

binding identifier named await (#924)#

I think this will not affect real-world codes, but it's fixed anyway.

function foo(await = await) {  // ???}

was incorrectly parsed as

function foo(this = await) {  // ???}

but it's now fixed.

export declare class (#924)#

Because declare is typically used in .d.ts files, it will not affect many codes. Code like

export declare class Foo {}

should be compiled out, and it is, starting from swc@v1.2.11.

declare var (#924)#

I expect this patch to affect some of codebases.

declare var a: string;

a in the code above is now removed completely.

conditional enum declarations in if (#924)#

Just don't do this. Although swc handles it, it's not the right thing to do.

if (2) enum A {}

sequence expression in key (#924)#

Again, don't do this. You can does not mean you should. Anyway, because swc tries to follow the spec as much as possible, I added some code to handle the code below.

class C extends Base {  [(super(), "prop")]() {}}

Note: The bug will not affect your code if you are targeting es3 or es5.

await in heritage clause (#924)#

Accoarding to the ecmascript spec, the code below is valid.

class A extends (await B) {}

Note: The bug will not affect your code if you are targeting es3 or es5.

optional array / object pattern (#924)#

? in the code below was problematic.

function foo([a, b, c]?) {}
function foo({ a, b, c }?) {}

They should both be compiled as

function foo([a, b, c]) {}

but they were compiled as

function foo([a, b, c]?) {}
function foo({ a, b, c }?) {}

respectively, and the typescript code handler is fixed. If you were using es3 or es5 as a target, the bug will not affect you.