Changelog: swc v1.2.10


Error recovery for parser (#896)#

export type * from "../typings";

The code above is invalid, but tsc accepts it and print an error message for it. I decided to follow the behavior of tsc and I modified the parser to accept it.

codegen of private properties (#903)#

Because some runtimes support private properties, I implemented printing logic for private properties.

An example use case is deno, which uses v8.

codegen of optional catch parameters (#904)#

try {
m.append(key, value);
} catch {
// Pass

This was problematic if you use only typescript stripper. Code generator for a catch clause emitted (, ) regardless of existence of the parameter.

Now you can use the optional catch binding syntax without the optional catch binding pass.

nested optional catch parameters (#904)#

Previously, the code below was miscompled, because the transform didn't visit children.

try {
// Write our response!
await writeResponse(this.w, r);
} catch {
try {
// Eagerly close on error.
} catch {
// Pass
err = e;

This is fixed by visiting children.

readonly class properties (#915)#

Previously swc miscompiled readonly properties.

// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { LogLevels, getLevelByName, getLevelName } from "./levels.ts";
export class Logger {
readonly #loggerName; // <---- offending line
constructor(loggerName, levelName, options = {}) {
this.#loggerName = loggerName;
this.#level = getLevelByName(levelName);
this.#handlers = options.handlers || [];

Readonly is now properly handled.

codegen of template literals with escape (#916)#

deno contains lots of template literals with escape sequences. By using it as a test suite, I and Bartek fixed lots of buf related to it.


Handling of quotes (#910)#

Previously, swc ignored the original quote of a string literal. This was intentional, and the purpose is to make output smaller by reducing the number of backslashes. But it is too bad for rust users, so I changed swc_ecma_codegen to preserve quotes.

No duplicate comments (#856)#

The bug is occured by two facts

  • swc did not check for duplicate comments.
  • TypeScript parser requires backtracking.

While backtracking, swc simply added comments to the comment storage, and didn't care about duplicate comments. If backtracking is successful, there's no problem. But if backtracking fails, cursor of the lexer goes back without removing comments. This is fixed by tracking last position of comments. Now there's two cursor in the lexer - one for code, one for comments. The comments cursor does not go back, so even if backtracking is failed, it remains as-is and duplicated comments are simply ignored.