Skip to content

Commit

Permalink
fix(swc): Allow overriding specified parser config using .swcrc (#2547
Browse files Browse the repository at this point in the history
)

swc:
 - Merge parser config by enabling each feature. (#2546)
  • Loading branch information
kdy1 authored Oct 26, 2021
1 parent 0e45877 commit 8494f65
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc"
repository = "https://github.com/swc-project/swc.git"
version = "0.79.0"
version = "0.79.1"

[lib]
name = "swc"
Expand Down
17 changes: 17 additions & 0 deletions node-swc/__tests__/transform/api_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const swc = require("../../../");
const path = require("path");

it("should handle minify", () => {
const src = '/* Comment */import foo, {bar} from "foo"';
Expand Down Expand Up @@ -173,4 +174,20 @@ it("should respect `error.filename = false`", async () => {
expect(e).not.toContain("-->")
}

});

it("should merge parser config", async () => {
const filename = path.resolve(
__dirname + "/../../tests/issue-2546/input.ts"
);

const { code } = await swc.transformFile(filename, {
jsc: {
parser: {
syntax: "typescript",
}
}
})

expect(code).not.toBeFalsy()
});
12 changes: 12 additions & 0 deletions node-swc/tests/issue-2546/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
}
}
}
6 changes: 6 additions & 0 deletions node-swc/tests/issue-2546/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { injectable } from 'inversify';


@injectable()
export default abstract class MyClass {
}
43 changes: 42 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,48 @@ impl Merge for bool {

impl Merge for Syntax {
fn merge(&mut self, from: &Self) {
*self = *from;
match (&mut *self, from) {
(Syntax::Es(a), Syntax::Es(b)) => {
a.merge(b);
}
(Syntax::Typescript(a), Syntax::Typescript(b)) => {
a.merge(b);
}
_ => {
*self = *from;
}
}
}
}

impl Merge for swc_ecma_parser::EsConfig {
fn merge(&mut self, from: &Self) {
self.jsx |= from.jsx;
self.class_private_props |= from.class_private_props;
self.class_private_methods |= from.class_private_methods;
self.class_props |= from.class_props;
self.fn_bind |= from.fn_bind;
self.decorators |= from.decorators;
self.decorators_before_export |= from.decorators_before_export;
self.export_default_from |= from.export_default_from;
self.export_namespace_from |= from.export_namespace_from;
self.dynamic_import |= from.dynamic_import;
self.nullish_coalescing |= from.nullish_coalescing;
self.optional_chaining |= from.optional_chaining;
self.import_meta |= from.import_meta;
self.top_level_await |= from.top_level_await;
self.import_assertions |= from.import_assertions;
self.static_blocks |= from.static_blocks;
self.private_in_object |= from.private_in_object;
}
}

impl Merge for swc_ecma_parser::TsConfig {
fn merge(&mut self, from: &Self) {
self.tsx |= from.tsx;
self.decorators |= from.decorators;
self.dynamic_import |= from.dynamic_import;
self.import_assertions |= from.import_assertions;
}
}

Expand Down

1 comment on commit 8494f65

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 8494f65 Previous: 0e45877 Ratio
base_tr_fixer 23452 ns/iter (± 3919) 26844 ns/iter (± 2492) 0.87
base_tr_resolver_and_hygiene 124066 ns/iter (± 22918) 147920 ns/iter (± 23099) 0.84
codegen_es2015 48885 ns/iter (± 7152) 55370 ns/iter (± 5022) 0.88
codegen_es2016 51174 ns/iter (± 9475) 55059 ns/iter (± 6747) 0.93
codegen_es2017 55776 ns/iter (± 11637) 57107 ns/iter (± 6198) 0.98
codegen_es2018 48004 ns/iter (± 8202) 58401 ns/iter (± 5370) 0.82
codegen_es2019 48428 ns/iter (± 7876) 56209 ns/iter (± 5070) 0.86
codegen_es2020 46130 ns/iter (± 15848) 56593 ns/iter (± 5500) 0.82
codegen_es3 49843 ns/iter (± 15594) 58488 ns/iter (± 6033) 0.85
codegen_es5 48228 ns/iter (± 5793) 58570 ns/iter (± 3838) 0.82
config_for_file 13341 ns/iter (± 3231) 15769 ns/iter (± 2091) 0.85
full_es2015 189905607 ns/iter (± 8629357) 209681308 ns/iter (± 12291858) 0.91
full_es2016 147040397 ns/iter (± 19502671) 159214350 ns/iter (± 12130675) 0.92
full_es2017 152174402 ns/iter (± 15671219) 167138723 ns/iter (± 6920525) 0.91
full_es2018 150997561 ns/iter (± 12403039) 167482245 ns/iter (± 9469129) 0.90
full_es2019 150820856 ns/iter (± 11044695) 164994715 ns/iter (± 7151281) 0.91
full_es2020 148839540 ns/iter (± 9779431) 163286383 ns/iter (± 7922561) 0.91
full_es3 214194338 ns/iter (± 27370681) 240865204 ns/iter (± 21398932) 0.89
full_es5 199174112 ns/iter (± 20660707) 226580522 ns/iter (± 12952446) 0.88
parser 645165 ns/iter (± 98968) 708489 ns/iter (± 67701) 0.91
transforms_es2015 1040257 ns/iter (± 270342) 1261108 ns/iter (± 170525) 0.82
transforms_es2016 605822 ns/iter (± 94181) 693189 ns/iter (± 98776) 0.87
transforms_es2017 604355 ns/iter (± 116925) 683616 ns/iter (± 97548) 0.88
transforms_es2018 591547 ns/iter (± 78894) 674653 ns/iter (± 121452) 0.88
transforms_es2019 552480 ns/iter (± 84947) 644524 ns/iter (± 109414) 0.86
transforms_es2020 551249 ns/iter (± 83959) 620427 ns/iter (± 88855) 0.89
transforms_es3 1184917 ns/iter (± 207752) 1374881 ns/iter (± 144867) 0.86
transforms_es5 996086 ns/iter (± 147558) 1180560 ns/iter (± 171105) 0.84
ser_ast_node 164 ns/iter (± 19) 167 ns/iter (± 10) 0.98
ser_serde 182 ns/iter (± 35) 175 ns/iter (± 17) 1.04
emit_colors 14199082 ns/iter (± 18749775) 10830311 ns/iter (± 6530617) 1.31
emit_large 127723948 ns/iter (± 173154790) 106234205 ns/iter (± 159562594) 1.20
base_clone 2363992 ns/iter (± 512628) 2523787 ns/iter (± 210836) 0.94
fold_span 4318154 ns/iter (± 695752) 4336278 ns/iter (± 475372) 1.00
fold_span_panic 4386351 ns/iter (± 534652) 4453357 ns/iter (± 435674) 0.98
visit_mut_span 3138293 ns/iter (± 391239) 3075689 ns/iter (± 231438) 1.02
visit_mut_span_panic 3051228 ns/iter (± 362488) 3286119 ns/iter (± 276008) 0.93
boxing_boxed 164 ns/iter (± 9) 164 ns/iter (± 14) 1
boxing_boxed_clone 76 ns/iter (± 5) 77 ns/iter (± 10) 0.99
boxing_unboxed 148 ns/iter (± 15) 168 ns/iter (± 28) 0.88
boxing_unboxed_clone 73 ns/iter (± 4) 74 ns/iter (± 11) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.