Changelog: swc v1.2.58


codegen: \r\n in template literals. (#1707)#

This happens only if your target is es2016 or upper. This issue is reported via a deno issue, and

const content1 = `first line\r\nsecond line\r\nthird line`;
const content2 = `first line
second line
third line`;
console.log({ content1, content2 });

now works properly.

fixer: null ?? (undefined && true). (#1709)#

This issue is reported via a deno issue. This is fixed by explicitly handling a ?? (b && c).

optimizer: Preserve optional chaining expressions. (#1688)#

({ notafunction: null }?.notafunction?.());
({ notafunction: null }?.notafunction());
({ notafunction: null }.notafunction?.());

swc preivously didn't handle optional chaining expresison propely and had break the codes above. It's now fixed.

optimizer: Side-effects of [x, y][0]. (#1674)#

Previously the optimizer of swc had a bug which breaks code like

let foo = "info";
var bar = [foo, (foo = "other")][0];
console.log(foo == "other");
console.log(bar == "info");

It's now fixed.

parser: Non-identifier names in getters. (#1671)#

const thing = {
get "a-b"() {
return "abc";

Due to a bug, swc previously faild to parse the code above. It's now fixed.

parser: Class member named declare (#1671)#

class A {
private declare() {}

The code above now works properly.

compat: async-to-generator (#1721, #1722)#

swc now compiles

async function* lol() {
yield 1;
yield 2;
async function main() {
for await (const x of lol()) {


(async function main() {


react: Remove panic call (#1683)#

const config = {
test: /\.[jt]sx?$/i,
exclude: /[\\/]node_modules[\\/]/,
use: [
loader: "swc-loader",
options: {
jsc: {
target: "es5",
parser: {
tsx: true,
decorators: true,
syntax: "typescript",
dynamicImport: true,
transform: {
react: {
runtime: "automatic",
externalHelpers: true,

swc had a bug in new jsx pass which resulted in an exception thrown. It's now fixed.

parser: Type-only import equals (#1695)#

import type React = require("react");

This is valid syntax since typescript 4.2, but swc didn't support it.

Fixed by @g-plance.

compat: Private methods (#1694, #1702, #1711)#

Previously swc had a bug related to private class methods.

preset-env: Update compat data (#1704, #1719)#

The compatibility data was outdated.

typescript: Preserved module context (#1698, #1706)#

tsc emits

export {};


export type Foo = number;

while other tools do not preserve the information that the file is module.

Because swc prefers the bahavior of tsc over the one of babel, swc now emits export {} for type-only modules.

wasm-web: Support for bundlers (#1675)#

The @swc/wasm-web package now use correct command while publishing so it has correct data in package.json.

api: Types for react pass. (#1720)#

Fixed by @Brooooooklyn.