Changelog: swc v1.1.5

dynamic import with es3 target#

Previously, swc converts import() to _import() as import is a keyword in es3. But, as import() can be stripped out in many way, swc now emits import if jsc.parser.dynamicImport is true.

script parser#

Previously, swc only allows parsing a file as module. Now there's an option to parse file as a script.

import { transformSync } from "@swc/core";
const code = transformSync(`with(foo){}`, {
isModule: false

typescript parser improvement#

swc_ecma_parser can now parse typescript compiler and rxjs.

arrow expression in conditional expressions#

From now, complex code like

export const assertEachNode = shouldAssert(AssertionLevel.Normal)
? (nodes: Node[], test: (node: Node) => boolean, message?: string): void =>
test === undefined || every(nodes, test),
message || "Unexpected node.",
() => `Node array did not pass test '${getFunctionName(test)}'.`,
: noop;

can be parsed.

import type#

swc_ecma_parser now supports import types. It means,

const tty = require("tty") as typeof import("tty");
let a: typeof import("fs");

are valid.

yield object#

Also, codes like

function* gen() {
yield {};

become valid.