-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/minifier): Use unsafe option for arrow => method (#6521)
**Related issue:** - Closes #6504. - vercel/next.js#43208.
- Loading branch information
Showing
15 changed files
with
244 additions
and
96 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/tsc-references/computedPropertyNamesContextualType6_ES6.2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
//// [computedPropertyNamesContextualType6_ES6.ts] | ||
foo({ | ||
p: "", | ||
0 () {}, | ||
0: ()=>{}, | ||
hibye: !0, | ||
1: 0, | ||
[NaN]: [ | ||
|
2 changes: 1 addition & 1 deletion
2
crates/swc/tests/tsc-references/computedPropertyNamesContextualType7_ES6.2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//// [computedPropertyNamesContextualType7_ES6.ts] | ||
foo({ | ||
0 () {}, | ||
0: ()=>{}, | ||
hibye: !0, | ||
1: 0, | ||
[NaN]: [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
crates/swc_ecma_minifier/tests/fixture/next/43208/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"defaults": true, | ||
"toplevel": true, | ||
"arrows": true, | ||
"ecma": 2022 | ||
} |
77 changes: 77 additions & 0 deletions
77
...cma_minifier/tests/fixture/next/43208/static/chunks/pages/index-e1d69965f0f167c9/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([[405], { | ||
|
||
/***/ 4186: | ||
/***/ (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { | ||
|
||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "default": function () { return /* binding */ Home; } | ||
/* harmony export */ | ||
}); | ||
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5893); | ||
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7294); | ||
/* harmony import */ var _styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7160); | ||
/* harmony import */ var _styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4__); | ||
/* harmony import */ var _gmod_binary_parser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9996); | ||
/* harmony import */ var binary_parser__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9567); | ||
/* provided dependency */ var Buffer = __webpack_require__(1876)["Buffer"]; | ||
|
||
|
||
|
||
|
||
|
||
function Home() { | ||
(0, react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => { | ||
const ipHeader1 = new _gmod_binary_parser__WEBPACK_IMPORTED_MODULE_2__/* .Parser */._().uint8("compressionMethod", { | ||
formatter: (b) => { | ||
const method = [ | ||
"raw" | ||
][b]; | ||
if (!method) { | ||
// never gets here | ||
console.log("in @gmod/binary-parser"); | ||
} | ||
return method; | ||
} | ||
}); | ||
const ipHeader2 = new binary_parser__WEBPACK_IMPORTED_MODULE_3__/* .Parser */._().uint8("compressionMethod", { | ||
formatter: (b) => { | ||
const method = [ | ||
"raw" | ||
][b]; | ||
if (!method) { | ||
console.log("in binary-parser"); | ||
} | ||
return method; | ||
} | ||
}); | ||
console.log({ | ||
ipHeader1, | ||
ipHeader2 | ||
}); | ||
// wouldn't actually parse correctly, just shows minification crash | ||
const buf = Buffer.from("450002c5939900002c06ef98adc24f6c850186d1", "hex"); | ||
console.log(ipHeader2.parse(buf)); | ||
console.log(ipHeader1.parse(buf)); | ||
}, []); | ||
return /*#__PURE__*/ (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", { | ||
className: (_styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4___default().container), | ||
children: "hello" | ||
}); | ||
} | ||
|
||
|
||
/***/ | ||
}), | ||
|
||
|
||
}, | ||
/******/ function (__webpack_require__) { // webpackRuntimeModules | ||
/******/ var __webpack_exec__ = function (moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); } | ||
/******/ __webpack_require__.O(0, [390, 774, 888, 179], function () { return __webpack_exec__(8312); }); | ||
/******/ var __webpack_exports__ = __webpack_require__.O(); | ||
/******/ _N_E = __webpack_exports__; | ||
/******/ | ||
} | ||
]); |
54 changes: 54 additions & 0 deletions
54
...ma_minifier/tests/fixture/next/43208/static/chunks/pages/index-e1d69965f0f167c9/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(self.webpackChunk_N_E = self.webpackChunk_N_E || []).push([ | ||
[ | ||
405 | ||
], | ||
{ | ||
4186: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, { | ||
default: function() { | ||
return Home; | ||
} | ||
}); | ||
var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5893), react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7294), _styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7160), _styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4___default = __webpack_require__.n(_styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4__), _gmod_binary_parser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9996), binary_parser__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9567), Buffer = __webpack_require__(1876).Buffer; | ||
function Home() { | ||
return (0, react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(()=>{ | ||
const ipHeader1 = new _gmod_binary_parser__WEBPACK_IMPORTED_MODULE_2__._().uint8("compressionMethod", { | ||
formatter: (b)=>{ | ||
const method = [ | ||
"raw" | ||
][b]; | ||
return method || console.log("in @gmod/binary-parser"), method; | ||
} | ||
}), ipHeader2 = new binary_parser__WEBPACK_IMPORTED_MODULE_3__._().uint8("compressionMethod", { | ||
formatter: (b)=>{ | ||
const method = [ | ||
"raw" | ||
][b]; | ||
return method || console.log("in binary-parser"), method; | ||
} | ||
}); | ||
console.log({ | ||
ipHeader1, | ||
ipHeader2 | ||
}); | ||
const buf = Buffer.from("450002c5939900002c06ef98adc24f6c850186d1", "hex"); | ||
console.log(ipHeader2.parse(buf)), console.log(ipHeader1.parse(buf)); | ||
}, []), (0, react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div", { | ||
className: _styles_Home_module_css__WEBPACK_IMPORTED_MODULE_4___default().container, | ||
children: "hello" | ||
}); | ||
} | ||
} | ||
}, | ||
function(__webpack_require__) { | ||
__webpack_require__.O(0, [ | ||
390, | ||
774, | ||
888, | ||
179 | ||
], function() { | ||
return __webpack_require__(__webpack_require__.s = 8312); | ||
}), _N_E = __webpack_require__.O(); | ||
} | ||
]); |
Oops, something went wrong.
9752b43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/bugs-1
357364
ns/iter (± 35796
)341625
ns/iter (± 25478
)1.05
es/full/minify/libraries/antd
2131237530
ns/iter (± 72038343
)1966387121
ns/iter (± 78100252
)1.08
es/full/minify/libraries/d3
480329648
ns/iter (± 15777311
)425075683
ns/iter (± 10580068
)1.13
es/full/minify/libraries/echarts
1816439044
ns/iter (± 78383203
)1713521769
ns/iter (± 41812674
)1.06
es/full/minify/libraries/jquery
124948647
ns/iter (± 6799524
)111480275
ns/iter (± 4014781
)1.12
es/full/minify/libraries/lodash
145997877
ns/iter (± 32065108
)128800553
ns/iter (± 3316350
)1.13
es/full/minify/libraries/moment
73168104
ns/iter (± 2262237
)64739075
ns/iter (± 1349941
)1.13
es/full/minify/libraries/react
23579280
ns/iter (± 518914
)21808633
ns/iter (± 731131
)1.08
es/full/minify/libraries/terser
416086071
ns/iter (± 41672935
)331808118
ns/iter (± 10949519
)1.25
es/full/minify/libraries/three
658232817
ns/iter (± 29911362
)600709409
ns/iter (± 8130627
)1.10
es/full/minify/libraries/typescript
3920999765
ns/iter (± 85016022
)3687546872
ns/iter (± 61290690
)1.06
es/full/minify/libraries/victory
942921236
ns/iter (± 18143935
)897428408
ns/iter (± 19344686
)1.05
es/full/minify/libraries/vue
183013789
ns/iter (± 9555227
)163375698
ns/iter (± 11900145
)1.12
es/full/codegen/es3
33808
ns/iter (± 1248
)34336
ns/iter (± 4348
)0.98
es/full/codegen/es5
33630
ns/iter (± 1120
)34350
ns/iter (± 497
)0.98
es/full/codegen/es2015
34238
ns/iter (± 3398
)34403
ns/iter (± 969
)1.00
es/full/codegen/es2016
33937
ns/iter (± 2419
)34328
ns/iter (± 672
)0.99
es/full/codegen/es2017
34069
ns/iter (± 894
)34364
ns/iter (± 3109
)0.99
es/full/codegen/es2018
34065
ns/iter (± 663
)34309
ns/iter (± 1607
)0.99
es/full/codegen/es2019
34470
ns/iter (± 2486
)34695
ns/iter (± 1505
)0.99
es/full/codegen/es2020
34315
ns/iter (± 2747
)34282
ns/iter (± 409
)1.00
es/full/all/es3
219182420
ns/iter (± 20462811
)190879705
ns/iter (± 7592810
)1.15
es/full/all/es5
177529055
ns/iter (± 8672744
)176483638
ns/iter (± 6194266
)1.01
es/full/all/es2015
141581974
ns/iter (± 6687565
)140163774
ns/iter (± 3081952
)1.01
es/full/all/es2016
141052236
ns/iter (± 6868129
)139584940
ns/iter (± 2700492
)1.01
es/full/all/es2017
140774098
ns/iter (± 7470869
)138687736
ns/iter (± 2575811
)1.02
es/full/all/es2018
139076792
ns/iter (± 6972836
)136956861
ns/iter (± 3000282
)1.02
es/full/all/es2019
146613024
ns/iter (± 5657803
)136426344
ns/iter (± 5033853
)1.07
es/full/all/es2020
138453334
ns/iter (± 7151806
)131369065
ns/iter (± 3631371
)1.05
es/full/parser
724678
ns/iter (± 34459
)693589
ns/iter (± 20979
)1.04
es/full/base/fixer
26866
ns/iter (± 443
)25421
ns/iter (± 1346
)1.06
es/full/base/resolver_and_hygiene
94089
ns/iter (± 4151
)88031
ns/iter (± 2547
)1.07
serialization of ast node
219
ns/iter (± 8
)211
ns/iter (± 4
)1.04
serialization of serde
234
ns/iter (± 10
)216
ns/iter (± 12
)1.08
This comment was automatically generated by workflow using github-action-benchmark.