Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/minifier): Use unsafe option for arrow => method #6521

Merged
merged 15 commits into from Nov 29, 2022
@@ -1,7 +1,7 @@
//// [computedPropertyNamesContextualType6_ES6.ts]
foo({
p: "",
0 () {},
0: ()=>{},
hibye: !0,
1: 0,
[NaN]: [
Expand Down
@@ -1,6 +1,6 @@
//// [computedPropertyNamesContextualType7_ES6.ts]
foo({
0 () {},
0: ()=>{},
hibye: !0,
1: 0,
[NaN]: [
Expand Down
Expand Up @@ -8,14 +8,14 @@ export class cl1 {
}
}
export const obj = {
async m () {
m: async ()=>{
await import('./test');
}
};
export class cl2 {
constructor(){
this.p = {
async m () {
m: async ()=>{
await import('./test');
}
};
Expand Down
9 changes: 9 additions & 0 deletions crates/swc_ecma_minifier/src/compress/pure/arrows.rs
Expand Up @@ -121,6 +121,15 @@ impl Pure<'_> {
}

if let Prop::KeyValue(kv) = p {
// See https://github.com/swc-project/swc/pull/6521
//
// ({foo(){}}).foo.toString()
//
// returns `foo(){}`
if !self.options.unsafe_methods {
return;
}

//
if contains_this_expr(&kv.value) {
return;
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/tests/benches-full/d3.js
Expand Up @@ -390,7 +390,7 @@
}, axis;
}
var noop = {
value () {}
value: ()=>{}
};
function dispatch() {
for(var t, i = 0, n = arguments.length, _ = {}; i < n; ++i){
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/tests/benches-full/terser.js
Expand Up @@ -1963,7 +1963,7 @@
walk: function(visitor) {
return this._walk(visitor);
},
_children_backwards () {}
_children_backwards: ()=>{}
}, null), AST_Statement = DEFNODE("Statement", null, {
$documentation: "Base class of all statements"
}), AST_Debugger = DEFNODE("Debugger", null, {
Expand Down
Expand Up @@ -3207,7 +3207,7 @@
const c = s.createWebChannel(o, r);
let a = !1, u = !1;
const h = new Gr({
vi (t) {
vi: (t)=>{
u ? $("Connection", "Not sending because WebChannel is closed:", t) : (a || ($("Connection", "Opening WebChannel transport."), c.open(), a = !0), $("Connection", "WebChannel sending:", t), c.send(t));
},
Vi: ()=>c.close()
Expand Down Expand Up @@ -4947,7 +4947,7 @@
const s = new Q();
return t.asyncQueue.enqueueAndForget(async ()=>(function(t, e, n, s, i) {
const r = new Lc({
next (n) {
next: (n)=>{
e.enqueueAndForget(()=>Uo(t, o)), n.fromCache && "server" === s.source ? i.reject(new j(K.UNAVAILABLE, 'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')) : i.resolve(n);
},
error: (t)=>i.reject(t)
Expand Down
@@ -0,0 +1,6 @@
{
"defaults": true,
"toplevel": true,
"arrows": true,
"ecma": 2022
}
@@ -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__;
/******/
}
]);
@@ -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();
}
]);