Changelog: swc v1.1.13

Bugfixes#

Class methods (#579)#

There was a bug of swc that identifiers in the body of class methods are not handled by resolver pass. It results in a bug and it's now fixed.

jsx container (#584)#

Previously you cannot get the span of {4}. Instead, you can only get span of 4.

const t = <test other={4} />;

This is fixed by a pr, and you can now get the span of jsx expression container.

hygiene (#591)#

Initialization of exported variable is now properly handled. Previously,

export class Example {
@foo() bar = "1";
@foo() baz = "2";
}

was miscompiled, while

class Example {
@foo() bar = "1";
@foo() baz = "2";
}

is compiled correctly (and tested). I added some tests to prevent regression.

New features#

TypePredicate.asserts (#567)#

Starting with v1.1.13, swc can parse asserts type predicate.

function isString(x: unknown): asserts x is string {
if (typeof x !== "string") throw new Error("Not a string.");
}

This is a feature of typescript 3.7. Also note that type is changed slightly.

export interface TsTypePredicate extends Node, HasSpan {
type: "TsTypePredicate";
// This is added
asserts: boolean;
paramName: TsThisTypeOrIdent;
typeAnnotation: TsTypeAnnotation;
}

Span improvements#

Thanks to @dsherret, there are more span improvements.

TypePredicate (#580)#

Previously starts of span of some type predicates started too early and it's now fixed so that the span points type predicate correctly.

Class (#581)#

  • Spans of class members and classes should include decorators.
  • Fix hi position for class parameter properties.
  • Fix span of members with accessibility.

Jsx (#582)#

Span of jsx opening element, closing element, spread child, and expression containers are fixed.