Changelog: swc v1.1.10: preset-env

preset-env (#421)#

swc gets ability to detect required transforms and polyfills based on target. Target includes browser with specific version ("chrome 49"), or complex query ("last 2 versions").

{
"env": {
"mode": "entry",
"targets": "last 2 versions",
"coreJs": 3
}
}

would enable transformations and inject polyfills to run code on last 2 versions of browsers and node js.

If you want to use existing browserslist config, you can just omit targets.

{
"env": {
"mode": "entry",
"coreJs": 3
}
}

This will follow browserslist queries of the project.

See docs for more information.

parser bugfixes#

span of from clauses (#535)#

Span of "test"; in

export * from "test";

incorrectly contained the span of ;. swc can now parses it correctly.

declare (#538)#

Some users uses swc's parser within their rust project, and reported an error.

export declare function test(): string;

Note that this had no effects on users who use swc via javascript api.

comments (#541)#

/*pre:1*/
test(/*lost:2*/);
test(123 /*post:3*/);
test(/*pre:4*/ 123);
test(/*pre:5*/ 123 /*post:6*/);
test(/*pre:7*/ 123, /*pre:8*/ 456);
test(123 /*post:9*/, 456 /*post:10*/);

is now compiled as

/*pre:1*/
test();
test(123 /*post:3*/);
test(/*pre:4*/ 123);
test(/*pre:5*/ 123 /*post:6*/);
test(/*pre:7*/ 123, /*pre:8*/ 456);
test(123 /*post:9*/, 456 /*post:10*/);

Originally, it was compiled as

/*pre:1*/
test();
test(
/*post:3*/
123
);
test(123);
test(
/*post:6*/
123
);
test(123, 456);
test(
/*post:9*/
123 /*post:10*/,
456
);