Skip to main content

Changelog: swc v1.2.91

路 One min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/192?closed=1

Bugfixes#

hygiene (#2297)#

There was an edge case I missed.

Fixed (again) by #2299.

parser: JSX (#2264)#

Previously swc sometimes collect the jsx text below as comments.

const t = <Switch>// 1 /* 2 */</Switch>;

Fixed by #2255.

parser: Function in tsx (#2237)#

Previously the parser of swc failed to parse the input below.

import React from "react";
export function Results() {  return (    <div>      {[].map(() => {        function onClick(): void {}
        return null;      })}    </div>  );}

Fixed by #2255.

sourceMap: true in .swcrc (#2194)#

Fixed by #2292.

Changelog: swc v1.2.89

路 One min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/190?closed=1

Improvements#

wasm: paths, baseUrl, hygiene#

Now @swc/wasm supports jsc.paths and jsc.baseUrl. Additionally, it now renames variables correctly.

Implemented by #2279.

Bugfixes#

hygiene (#2211)#

Previously the hygiene pass didn't consider child scope correctly.

Fixed by #2266.

codegen: Sourcemap of string literals (#2253)#

SourceMaps were off by one.

Fixed by #2256.

codegen: static before readonly#

Previously the code emitted readonly before static.

Fixed by @dsherret and by #2271

minifier: Variable merging (#2262)#

Previously the minifier wrongly dropped some variables.

Fixed by @dsherret and by #2271

opt-chain: ES2019#

Previously swc treated it as a pass for ES2018, but now it's treated as a pass for ES2019.

Fixed by #2247.

Changelog: swc v1.2.88

路 One min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/189?closed=1

Improvements#

minifier#

I ported some more minification rules.

Bugfixes#

typescript: import = (#2234)#

Previously swc miscompiled

import polygons = Shapes.Polygons;let sq = new polygons.Square();

Fixed by #2249.

this in class properties (#2228)#

Previsouly, swc broke code if a class property in a child class uses this.

e.g.

export default class extends Wepy {  events = {    "abc: click": function abcClick() {      this.data = 123;      console.log("abc");    },  };
  setData() {    this.data = 456;  }}

Fixed by #2249.

minifier: RegExp#

The minifier had a bug related to handling of RegExp, and it could break some codes.

Fixed by #2229.

Changelog: swc v1.2.86

路 One min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/187?closed=1

Improvements#

this in arrow expressions (#2212)#

swc now emits similar output to babel instead of using bind.

Implemented by #2222.

Bugfixes#

unary with exponential operation (#2191)#

swc now wraps an unary expression before an exponentation operator.

Fixed by #2222.

parser: Ternary (#2196)#

swc can now parse

export const reproValue = true  ? {}  : {      reproFunc: (_: any): any => {},    };

correctly.

Fixed by #2222.

stack overflow (#2223)#

Previously swc throwed an error if a Program is too large.

Fixed by #2222.

jsc.paths (#2050)#

Finally swc correctly implements support for paths and baseUrl.

Fixed by #2227.

Changelog: swc v1.2.85

路 One min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/186?closed=1

Improvements#

minifier (#21083)#

Lots of rules are implemeneted.

Bugfixes#

minifier: Empty return (#2214)#

Previously swc broke code like

function f(a, b) {  if (a) {    if (b) return;    foo();  }  bar();}

Fixed by #2183.

codegen: unary minus (#2213)#

Preivsouly swc broke code like

function f(a, b, c) {  return a - -b * c;}

if minification is enabled.

Fixed by #2183.

typescript: re-export of type (#2219)#

Previsouly swc didn't remove export { TestInfo } in the code below.

import type { TestInfo } from "./config";
export { TestInfo };

Fixed by #2220.

Changelog: swc v1.2.84

路 One min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/184?closed=1

Improvements#

hygiene: Less renaming of variables (#1600)#

swc uses special system for managing identifiers. The system modifies lots of identifiers, even when it's not required. This is now fixed and swc renames only if required.

Implemented by #2193.

Bugfixes#

Variables in for-in loops (#2164)#

Previously, swc dropped some variables declared in for-in loops in async functions, when targeting es5 or lower.

Fixed by #2181.

parser: arrow in cond (#2174)#

Previously, swc tried to parse the code below as function expression with a typescript type annotation.

const x = {  prop: isCorrect ? (fn) => ({}) : (fn) => true,};

Fixed by #2178.

jsx: <> with single child (#2177)#

Previously swc did not produce optimal code for

export var App = function () {  return (    <>      <div>1</div>    </>  );};

Fixed by #2178.

Changelog: swc v1.2.83

路 2 min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/184?closed=1

Improvements#

sourcemap#

Now swc does not emit sourceContents in situations where sources is enough. Additionally, swc now emits names properly.

Bugfixes#

|| in await (#2155)#

Fixed by #2157

minify: Options for terser compat (#2153)#

When using @swc/core via yarn resolution, it may resulted in an error because of some terser options. swc now accepts this option and ignores them (for now), so it does not result in a json deserialization error.

Fixed by #2158

parser: Generics with jsx (#2161)#

Previously, swc failed to pares

const x = <P extends object>(  a: React.ComponentType<P>): React.ComponentType<P & { a: string }> => React.memo();

Fixed by #2166

codegen: Assignment as an arrow body (#2163)#

Previously swc could break code like

() => ({ foo } = bar());

Fixed by #2166

expr_simplifier: Assignments with operator (#2165)#

Previsouly swc mis-optimized

var bit = 0;var sum = 0;sum += (bit ^= 1) ? 0 : 1;sum += (bit ^= 1) ? 0 : 1;console.log(sum);

because it didn't check the operator of assignment while caculating value of an expression.

Fixed by #2166

Changelog: swc v1.2.81

路 One min read

To see full list of patches, please visit https://github.com/swc-project/swc/milestone/182?closed=1

Improvements#

Support for new.target (#1179)#

swc now supports transforming new.target. It uses test suite from babel, and all tests are passing.

Implemented by #2129.

jsc.experimental.optimizeHygiene (#1600, #2137)#

Previously swc renamed lots of variable, but you can now speficy jsc.experimental.optimizeHygiene to make swc rename only if required.

Implemented by #2145.

Bugfixes#

bundler: Reexports from common js modules (#2124)#

Previously the bundler fails to handle esm reexports from cjs modules.

Fixed by #2143.

misc#

Typo: strictMode in typings#

Fixed by @Songkeys and by #2116.

Typo: ExportNamespaceSpecifier in typings#

Fixed by @ifiokjr and by #2136.

Typo: externalModules in typings#

Fixed by @ifiokjr and by #2135.