Skip to content

Commit

Permalink
feat(es/transforms/compat): Add loose mode to parameters (#2911)
Browse files Browse the repository at this point in the history
swc_ecma_utils:
 - Make `WrapperState` implement `Clone`.

swc_ecma_transforms_compat:
 - `paramters`: Fix handling of non-loose mode. (Closes #2800, Closes #2825)
  • Loading branch information
Austaras authored Dec 2, 2021
1 parent 4e214ce commit 1555ceb
Show file tree
Hide file tree
Showing 147 changed files with 1,988 additions and 1,374 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/swc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ impl<'a, 'b, P: swc_ecma_visit::Fold> PassBuilder<'a, 'b, P> {
template_literal: compat::es2015::template_literal::Config {
ignore_to_primitive: self.loose,
mutable_template: self.loose
},
parameters: compat::es2015::parameters::Config {
ignore_function_length: self.loose,
}
}
),
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/deno-10014/case1/output/index.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mappings": "AAAA,MAAM,CAAC,CAAa;SAEXA,CAAC,GAAG,CAAC;IACVC,CAAC;AACL,CAAC;SAEQA,CAAC,CAACC,KAAS,EAAE,CAAC;QAAZA,CAAC,GAADA,KAAS,cAAL,KAAK,GAATA,KAAS;IAChB,EAAE,EAAEA,CAAC,EAAE,CAAC;QACJ,KAAK,CAAC,GAAG,CAACC,KAAK,CAAC,CAAO;IAC3B,CAAC;IACDF,CAAC,EAAE,CAAC;AACR,CAAC;AAEDD,CAAC",
"mappings": "AAAA,MAAM,CAAC,CAAa;SAEXA,CAAC,GAAG,CAAC;IACVC,CAAC;AACL,CAAC;SAEQA,CAAC,GAAY,CAAC;QAAZC,CAAC,oEAAG,KAAK;IAChB,EAAE,EAAEA,CAAC,EAAE,CAAC;QACJ,KAAK,CAAC,GAAG,CAACC,KAAK,CAAC,CAAO;IAC3B,CAAC;IACDF,CAAC,EAAE,CAAC;AACR,CAAC;AAEDD,CAAC",
"names": [
"a",
"t",
Expand Down
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/deno-10014/case1/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import "./errors.ts";
function a() {
t();
}
function t(param) {
var x = param === void 0 ? false : param;
function t() {
var x = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
if (x) {
throw new Error("Hello");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/swc/tests/fixture/issue-2022/full/output/index.js

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

6 changes: 3 additions & 3 deletions crates/swc/tests/fixture/issue-2022/no-opt/output/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function example(param, param1, param2) {
var a = param === void 0 ? 'click' : param, b = param1 === void 0 ? {
} : param1, c = param2 === void 0 ? 1 : param2;
export function example() {
var a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 'click', b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
}, c = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
console.log(a, b, c);
}
4 changes: 2 additions & 2 deletions crates/swc/tests/fixture/issue-2170/case1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function foo(param, param1) {
var arg1 = param === void 0 ? 1 : param, arg2 = param1 === void 0 ? 1 : param1;
function foo() {
var arg1 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1, arg2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @target: es2017
// @noEmitHelpers: true
function f(param) {
var _await = param === void 0 ? _await : param;
function f() {
var _await = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _await;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @target: es2017
// @noEmitHelpers: true
function f(param) {
var _await = param === void 0 ? _await : param;
function f() {
var _await = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _await;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @target: ES5
// @lib: es5,es2015.promise
// @noEmitHelpers: true
function f(param) {
var _await = param === void 0 ? _await : param;
function f() {
var _await = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _await;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @target: ES5
// @lib: es5,es2015.promise
// @noEmitHelpers: true
function f(param) {
var _await = param === void 0 ? _await : param;
function f() {
var _await = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _await;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
function f(param) {
var _await = param === void 0 ? _await : param;
function f() {
var _await = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _await;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @target: ES6
// @noEmitHelpers: true
function f(param) {
var _await = param === void 0 ? _await : param;
function f() {
var _await = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : _await;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var C = function C() {
var C;
})();
var x = "";
(function(param, param1) {
(function(param) {
var tmp = param[/*#__PURE__*/ (_class1 = function(C) {
"use strict";
_inherits(_class, C);
Expand All @@ -98,6 +98,6 @@ var x = "";
return _super.apply(this, arguments);
}
return _class;
}(C), _class1.x = 1, _class1).x], b = tmp === void 0 ? "" : tmp, d = param1 === void 0 ? x : param1;
}(C), _class1.x = 1, _class1).x], b = tmp === void 0 ? "" : tmp, d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x;
var x1;
})();
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _class, _class1, C = function() {
}
return _class;
})(C)).x = 1, _class).x];
}(), (function(param, param1) {
}(), (function(param) {
(void 0)[((_class1 = (function(C) {
"use strict";
_inherits(_class, C);
Expand All @@ -68,5 +68,5 @@ var _class, _class1, C = function() {
return _classCallCheck(this, _class), _super.apply(this, arguments);
}
return _class;
})(C)).x = 1, _class1).x];
})(C)).x = 1, _class1).x], arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
})();
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var C = function C() {
var C;
})();
var x = "";
(function(param, param1) {
(function(param) {
var tmp = param[/*#__PURE__*/ (_class1 = function(C) {
"use strict";
_inherits(_class, C);
Expand All @@ -98,6 +98,6 @@ var x = "";
return _super.apply(this, arguments);
}
return _class;
}(C), _class1.x = 1, _class1).x], b = tmp === void 0 ? "" : tmp, d = param1 === void 0 ? x : param1;
}(C), _class1.x = 1, _class1).x], b = tmp === void 0 ? "" : tmp, d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x;
var x1;
})();
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _class, _class1, C = function() {
}
return _class;
})(C)).x = 1, _class).x];
}(), (function(param, param1) {
}(), (function(param) {
(void 0)[((_class1 = (function(C) {
"use strict";
_inherits(_class, C);
Expand All @@ -68,5 +68,5 @@ var _class, _class1, C = function() {
return _classCallCheck(this, _class), _super.apply(this, arguments);
}
return _class;
})(C)).x = 1, _class1).x];
})(C)).x = 1, _class1).x], arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
})();
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ var C = function C() {
"use strict";
_classCallCheck(this, C);
};
(function(param) {
var b = param === void 0 ? (_class2 = /*#__PURE__*/ function(C) {
(function() {
var b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : (_class2 = /*#__PURE__*/ function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
Expand All @@ -84,12 +84,12 @@ var C = function C() {
return _super.apply(this, arguments);
}
return _class;
}(C), _class2.x = 1, _class2) : param;
}(C), _class2.x = 1, _class2);
var C1;
})();
var x = "";
(function(param, param1) {
var b = param === void 0 ? (_class1 = /*#__PURE__*/ function(C) {
(function() {
var b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : (_class1 = /*#__PURE__*/ function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
Expand All @@ -98,6 +98,6 @@ var x = "";
return _super.apply(this, arguments);
}
return _class;
}(C), _class1.x = 1, _class1) : param, d = param1 === void 0 ? x : param1;
}(C), _class1.x = 1, _class1), d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x;
var x1;
})();
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ var _class2, _class1, C1 = function() {
"use strict";
_classCallCheck(this, C1);
};
!function(param) {
(_class2 = (function(C) {
!function() {
arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : (_class2 = (function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
Expand All @@ -59,14 +59,14 @@ var _class2, _class1, C1 = function() {
}
return _class;
})(C1)).x = 1;
}(), (function(param, param1) {
(_class1 = (function(C) {
}(), (function() {
arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : (_class1 = (function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
function _class() {
return _classCallCheck(this, _class), _super.apply(this, arguments);
}
return _class;
})(C1)).x = 1;
})(C1)).x = 1, arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
})();
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ var C = function C() {
"use strict";
_classCallCheck(this, C);
};
(function(param) {
var b = param === void 0 ? (_class2 = /*#__PURE__*/ function(C) {
(function() {
var b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : (_class2 = /*#__PURE__*/ function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
Expand All @@ -84,12 +84,12 @@ var C = function C() {
return _super.apply(this, arguments);
}
return _class;
}(C), _class2.x = 1, _class2) : param;
}(C), _class2.x = 1, _class2);
var C1;
})();
var x = "";
(function(param, param1) {
var b = param === void 0 ? (_class1 = /*#__PURE__*/ function(C) {
(function() {
var b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : (_class1 = /*#__PURE__*/ function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
Expand All @@ -98,6 +98,6 @@ var x = "";
return _super.apply(this, arguments);
}
return _class;
}(C), _class1.x = 1, _class1) : param, d = param1 === void 0 ? x : param1;
}(C), _class1.x = 1, _class1), d = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : x;
var x1;
})();
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ var _class2, _class1, C1 = function() {
"use strict";
_classCallCheck(this, C1);
};
!function(param) {
(_class2 = (function(C) {
!function() {
arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : (_class2 = (function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
Expand All @@ -59,14 +59,14 @@ var _class2, _class1, C1 = function() {
}
return _class;
})(C1)).x = 1;
}(), (function(param, param1) {
(_class1 = (function(C) {
}(), (function() {
arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : (_class1 = (function(C) {
"use strict";
_inherits(_class, C);
var _super = _createSuper(_class);
function _class() {
return _classCallCheck(this, _class), _super.apply(this, arguments);
}
return _class;
})(C1)).x = 1;
})(C1)).x = 1, arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
})();
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var _class1;
// @target: esnext,es2015,es5
// @noTypesAndSymbols: true
// https://github.com/microsoft/TypeScript/issues/36295
(function(param) {
var b = param === void 0 ? (_class1 = function _class() {
(function() {
var b = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : (_class1 = function _class() {
"use strict";
_classCallCheck(this, _class);
}, _class1.x = 1, _class1) : param;
}, _class1.x = 1, _class1);
})();
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(function _class() {
"use strict";
!function(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}(this, _class);
}).x = 1;
var _class1;
!function() {
arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : (_class1 = function _class() {
"use strict";
!function(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}(this, _class);
}).x = 1;
}();
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ function _classCallCheck(instance, Constructor) {
throw new TypeError("Cannot call a class as a function");
}
}
var C = function C(param) {
var C = function C() {
"use strict";
var x = param === void 0 ? this : param;
var x = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this;
_classCallCheck(this, C);
};
var D = function D(param) {
var D = function D() {
"use strict";
var x = param === void 0 ? this : param;
var x = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this;
_classCallCheck(this, D);
};
var E = function E(param) {
var E = function E() {
"use strict";
var x = param === void 0 ? this : param;
var x = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this;
_classCallCheck(this, E);
this.x = x;
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}
var C = function(param) {
var C = function() {
"use strict";
_classCallCheck(this, C);
}, D = function(param) {
arguments.length > 0 && void 0 !== arguments[0] && arguments[0], _classCallCheck(this, C);
}, D = function() {
"use strict";
_classCallCheck(this, D);
}, E = function(param) {
arguments.length > 0 && void 0 !== arguments[0] && arguments[0], _classCallCheck(this, D);
}, E = function() {
"use strict";
_classCallCheck(this, E), this.x = void 0 === param ? this : param;
var x = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : this;
_classCallCheck(this, E), this.x = x;
};
Loading

2 comments on commit 1555ceb

@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: 1555ceb Previous: 4e214ce Ratio
base_tr_fixer 22939 ns/iter (± 304) 28703 ns/iter (± 5499) 0.80
base_tr_resolver_and_hygiene 127098 ns/iter (± 24481) 158637 ns/iter (± 28308) 0.80
codegen_es2015 52953 ns/iter (± 270) 54195 ns/iter (± 13636) 0.98
codegen_es2016 52595 ns/iter (± 355) 54724 ns/iter (± 7432) 0.96
codegen_es2017 52539 ns/iter (± 357) 56818 ns/iter (± 12442) 0.92
codegen_es2018 52605 ns/iter (± 365) 55151 ns/iter (± 7823) 0.95
codegen_es2019 52689 ns/iter (± 296) 56256 ns/iter (± 8793) 0.94
codegen_es2020 53009 ns/iter (± 325) 60150 ns/iter (± 10992) 0.88
codegen_es3 52778 ns/iter (± 2158) 57552 ns/iter (± 8938) 0.92
codegen_es5 53064 ns/iter (± 491) 54072 ns/iter (± 11182) 0.98
full_es2015 180917865 ns/iter (± 6461087) 183018082 ns/iter (± 21758076) 0.99
full_es2016 146462012 ns/iter (± 4981696) 144549215 ns/iter (± 12482237) 1.01
full_es2017 152456774 ns/iter (± 6526220) 150006073 ns/iter (± 21338366) 1.02
full_es2018 152017287 ns/iter (± 6457730) 149482604 ns/iter (± 20924274) 1.02
full_es2019 149436951 ns/iter (± 7227753) 145224749 ns/iter (± 11315376) 1.03
full_es2020 149656936 ns/iter (± 6836111) 149227626 ns/iter (± 21518910) 1.00
full_es3 207199749 ns/iter (± 14659026) 226531250 ns/iter (± 31075580) 0.91
full_es5 193925052 ns/iter (± 9649002) 190253138 ns/iter (± 18045581) 1.02
parser 687452 ns/iter (± 21513) 723487 ns/iter (± 214964) 0.95
ser_ast_node 152 ns/iter (± 5) 137 ns/iter (± 22) 1.11
ser_serde 150 ns/iter (± 2) 146 ns/iter (± 32) 1.03
emit_colors 16564264 ns/iter (± 21458740) 4555285 ns/iter (± 5894678) 3.64
emit_large 116016735 ns/iter (± 175888971) 65549155 ns/iter (± 88694077) 1.77
base_clone 2411345 ns/iter (± 38043) 2402710 ns/iter (± 478011) 1.00
fold_span 3910485 ns/iter (± 43405) 3961874 ns/iter (± 427560) 0.99
fold_span_panic 4094006 ns/iter (± 115009) 4126697 ns/iter (± 551332) 0.99
visit_mut_span 2902208 ns/iter (± 52619) 3061031 ns/iter (± 641860) 0.95
visit_mut_span_panic 2955559 ns/iter (± 42258) 2953359 ns/iter (± 452313) 1.00
ast_clone 17497 ns/iter (± 110) 21056 ns/iter (± 4898) 0.83
ast_clone_to_stable 51776 ns/iter (± 653) 67175 ns/iter (± 14003) 0.77
ast_clone_to_stable_then_to_unstable 94544 ns/iter (± 403) 116691 ns/iter (± 29552) 0.81
json_deserialize 1902402 ns/iter (± 7968) 2130988 ns/iter (± 393557) 0.89
json_serialize 92003 ns/iter (± 728) 87941 ns/iter (± 15446) 1.05
boxing_boxed 128 ns/iter (± 0) 118 ns/iter (± 34) 1.08
boxing_boxed_clone 67 ns/iter (± 0) 63 ns/iter (± 32) 1.06
boxing_unboxed 110 ns/iter (± 0) 104 ns/iter (± 17) 1.06
boxing_unboxed_clone 62 ns/iter (± 0) 61 ns/iter (± 17) 1.02
time_10 316 ns/iter (± 1) 303 ns/iter (± 81) 1.04
time_15 668 ns/iter (± 4) 610 ns/iter (± 144) 1.10
time_20 1390 ns/iter (± 12) 1108 ns/iter (± 223) 1.25
time_40 6588 ns/iter (± 43) 4413 ns/iter (± 934) 1.49
time_5 99 ns/iter (± 0) 99 ns/iter (± 17) 1
time_60 14792 ns/iter (± 31) 9458 ns/iter (± 1571) 1.56

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

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 1555ceb Previous: 4e214ce Ratio
emit_colors 16564264 ns/iter (± 21458740) 4555285 ns/iter (± 5894678) 3.64

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

CC: @kdy1

Please sign in to comment.