Skip to content

Commit

Permalink
fix(es/minifier): Preserve op of the op-assignments in seq inliner (#…
Browse files Browse the repository at this point in the history
…6428)

**Description:**


**Related issue:**

 - Closes #6407.
  • Loading branch information
kdy1 committed Nov 15, 2022
1 parent 3c42789 commit 5fd7ab8
Show file tree
Hide file tree
Showing 24 changed files with 275 additions and 26 deletions.
69 changes: 69 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6407/input/.swcrc
@@ -0,0 +1,69 @@
{
"minify": false,
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"transform": {
"legacyDecorator": true,
"react": {
"runtime": "automatic"
}
},
"target": "es2022",
"loose": false,
"externalHelpers": true,
"minify": {
"compress": {
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"directives": true,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": false,
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"if_return": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"properties": true,
"reduce_funcs": false,
"reduce_vars": false,
"side_effects": true,
"switches": true,
"typeofs": true,
"unsafe": false,
"unsafe_arrows": false,
"unsafe_comps": false,
"unsafe_Function": false,
"unsafe_math": false,
"unsafe_symbols": false,
"unsafe_methods": false,
"unsafe_proto": false,
"unsafe_regexp": false,
"unsafe_undefined": false,
"unused": true,
"const_to_let": true,
"pristine_globals": true
},
"mangle": false
}
},
"module": {
"type": "es6"
}
}
18 changes: 18 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6407/input/index.js
@@ -0,0 +1,18 @@
export default class Demo {
static encode(value) {
const ranges = [];
let range = [];
let retrString = A.encode(value);
let bitField = '';
value.forEach((curValue, i) => {
bitField += B.encode(curValue);
range.push(i);
ranges.push(range);
});
retrString += '.';
retrString += C.encode(ranges);
return retrString;
}
}

console.log(Deno.encode())
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6407/output/index.js
@@ -0,0 +1,9 @@
export default class Demo {
static encode(value) {
let ranges = [], range = [], retrString = A.encode(value), bitField = '';
return value.forEach((curValue, i)=>{
bitField += B.encode(curValue), range.push(i), ranges.push(range);
}), retrString += '.' + C.encode(ranges);
}
}
console.log(Deno.encode());
2 changes: 1 addition & 1 deletion crates/swc/tests/tsc-references/symbolType12.2.minified.js
@@ -1,3 +1,3 @@
//// [symbolType12.ts]
var s = Symbol.for("assign"), str = "";
s *= 0, s /= s, s /= 0, s %= s, s %= 0, str += s = s + 0 + "", s -= s, s -= 0, s <<= s, s <<= 0, s >>= s, s >>= 0, s >>>= s, s >>>= 0, s &= s, s &= 0, s ^= s, s ^= 0, s |= s, s |= 0, str += s || str;
s *= 0 * s, s /= s, s /= 0, s %= s, s %= 0, s += s + 0 + "", str += s, s -= s, s -= 0, s <<= s, s <<= 0, s >>= s, s >>= 0, s >>>= s, s >>>= 0, s &= s, s &= 0, s ^= s, s ^= 0, s |= s, s |= 0, str += s || str;
Expand Up @@ -2305,7 +2305,7 @@ where
);
self.changed = true;

b.op = op!("=");
b.op = a_op;

let to = take_a!(true, true);

Expand Down
4 changes: 2 additions & 2 deletions crates/swc_ecma_minifier/tests/benches-full/echarts.js
Expand Up @@ -5298,7 +5298,7 @@
var width = data[i++], height = data[i++];
if (x1 = x0 + width, y1 = y0 + height, isStroke) {
if (containStroke(x0, y0, x1, y0, lineWidth, x, y) || containStroke(x1, y0, x1, y1, lineWidth, x, y) || containStroke(x1, y1, x0, y1, lineWidth, x, y) || containStroke(x0, y1, x0, y0, lineWidth, x, y)) return !0;
} else w = windingLine(x1, y0, x1, y1, x, y) + windingLine(x0, y1, x0, y0, x, y);
} else w += windingLine(x1, y0, x1, y1, x, y) + windingLine(x0, y1, x0, y0, x, y);
break;
case CMD$1.Z:
if (isStroke) {
Expand Down Expand Up @@ -34777,7 +34777,7 @@
var blockMetaList = result1.meta, buttonContainer = document.createElement('div');
buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
var buttonStyle = "float:right;margin-right:20px;border:none;cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px", closeButton = document.createElement('div'), refreshButton = document.createElement('div');
buttonStyle = ';background-color:' + model.get('buttonColor') + ';color:' + model.get('buttonTextColor');
buttonStyle += ';background-color:' + model.get('buttonColor') + ';color:' + model.get('buttonTextColor');
var self1 = this;
function close() {
container.removeChild(root), self1._dom = null;
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/tests/benches-full/moment.js
Expand Up @@ -799,7 +799,7 @@
getParsingFlags(config).invalidFormat = !0, config._d = new Date(NaN);
return;
}
for(i = 0; i < config._f.length; i++)currentScore = 0, validFormatFound = !1, tempConfig = copyConfig({}, config), null != config._useUTC && (tempConfig._useUTC = config._useUTC), tempConfig._f = config._f[i], configFromStringAndFormat(tempConfig), isValid(tempConfig) && (validFormatFound = !0), currentScore = getParsingFlags(tempConfig).charsLeftOver + 10 * getParsingFlags(tempConfig).unusedTokens.length, getParsingFlags(tempConfig).score = currentScore, bestFormatIsValid ? currentScore < scoreToBeat && (scoreToBeat = currentScore, bestMoment = tempConfig) : (null == scoreToBeat || currentScore < scoreToBeat || validFormatFound) && (scoreToBeat = currentScore, bestMoment = tempConfig, validFormatFound && (bestFormatIsValid = !0));
for(i = 0; i < config._f.length; i++)currentScore = 0, validFormatFound = !1, tempConfig = copyConfig({}, config), null != config._useUTC && (tempConfig._useUTC = config._useUTC), tempConfig._f = config._f[i], configFromStringAndFormat(tempConfig), isValid(tempConfig) && (validFormatFound = !0), currentScore += getParsingFlags(tempConfig).charsLeftOver + 10 * getParsingFlags(tempConfig).unusedTokens.length, getParsingFlags(tempConfig).score = currentScore, bestFormatIsValid ? currentScore < scoreToBeat && (scoreToBeat = currentScore, bestMoment = tempConfig) : (null == scoreToBeat || currentScore < scoreToBeat || validFormatFound) && (scoreToBeat = currentScore, bestMoment = tempConfig, validFormatFound && (bestFormatIsValid = !0));
extend(config, bestMoment || tempConfig);
}(config) : format ? configFromStringAndFormat(config) : isUndefined(input = (config1 = config)._i) ? config1._d = new Date(hooks.now()) : isDate(input) ? config1._d = new Date(input.valueOf()) : 'string' == typeof input ? function(config) {
var matched = aspNetJsonRegex.exec(config._i);
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/tests/benches-full/terser.js
Expand Up @@ -1913,7 +1913,7 @@
for(var code = "return function AST_" + type + "(props){ if (props) { ", i = props.length; --i >= 0;)code += "this." + props[i] + " = props." + props[i] + ";";
const proto = base && Object.create(base.prototype);
(proto && proto.initialize || methods && methods.initialize) && (code += "this.initialize();");
var ctor = Function(code = "}this.flags = 0;}")();
var ctor = Function(code += "}this.flags = 0;}")();
if (proto && (ctor.prototype = proto, ctor.BASE = base), base && base.SUBCLASSES.push(ctor), ctor.prototype.CTOR = ctor, ctor.prototype.constructor = ctor, ctor.PROPS = props || null, ctor.SELF_PROPS = self_props, ctor.SUBCLASSES = [], type && (ctor.prototype.TYPE = ctor.TYPE = type), methods) for(i in methods)HOP(methods, i) && ("$" === i[0] ? ctor[i.substr(1)] = methods[i] : ctor.prototype[i] = methods[i]);
return ctor.DEFMETHOD = function(name, method) {
this.prototype[name] = method;
Expand Down
46 changes: 46 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/6407/1/config.json
@@ -0,0 +1,46 @@
{
"arguments": false,
"arrows": true,
"booleans": true,
"booleans_as_integers": false,
"collapse_vars": true,
"comparisons": true,
"computed_props": true,
"conditionals": true,
"dead_code": true,
"directives": true,
"drop_console": false,
"drop_debugger": true,
"evaluate": true,
"expression": false,
"hoist_funs": false,
"hoist_props": true,
"hoist_vars": false,
"if_return": true,
"join_vars": true,
"keep_classnames": false,
"keep_fargs": true,
"keep_fnames": false,
"keep_infinity": false,
"loops": true,
"negate_iife": true,
"properties": true,
"reduce_funcs": false,
"reduce_vars": false,
"side_effects": true,
"switches": true,
"typeofs": true,
"unsafe": false,
"unsafe_arrows": false,
"unsafe_comps": false,
"unsafe_Function": false,
"unsafe_math": false,
"unsafe_symbols": false,
"unsafe_methods": false,
"unsafe_proto": false,
"unsafe_regexp": false,
"unsafe_undefined": false,
"unused": true,
"const_to_let": true,
"pristine_globals": true
}
18 changes: 18 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/6407/1/input.js
@@ -0,0 +1,18 @@
export default class Demo {
static encode(value) {
const ranges = [];
let range = [];
let retrString = A.encode(value);
let bitField = '';
value.forEach((curValue, i) => {
bitField += B.encode(curValue);
range.push(i);
ranges.push(range);
});
retrString += '.';
retrString += C.encode(ranges);
return retrString;
}
}

console.log(Deno.encode())
12 changes: 12 additions & 0 deletions crates/swc_ecma_minifier/tests/fixture/issues/6407/1/output.js
@@ -0,0 +1,12 @@
export default class Demo {
static encode(value) {
const ranges = [];
let range = [], retrString = A.encode(value), bitField = '';
return value.forEach((curValue, i)=>{
bitField += B.encode(curValue);
range.push(i);
ranges.push(range);
}), retrString += '.' + C.encode(ranges);
}
}
console.log(Deno.encode());
Expand Up @@ -1287,7 +1287,7 @@
d = !0;
}
d || (b1 = "", xa(c, function(c, d) {
b1 = d + ":" + c + "\r\n";
b1 += d + ":" + c + "\r\n";
}), c = b1, "string" == typeof a ? null != c && encodeURIComponent(String(c)) : R(a, b, c));
}
function Hd(a, b, c) {
Expand Down
Expand Up @@ -838,7 +838,7 @@
const e = t;
if (null === e.A) {
let t1 = e.path.canonicalString();
null !== e.collectionGroup && (t1 += "|cg:" + e.collectionGroup), t1 = "|f:" + e.filters.map((t)=>t.field.canonicalString() + t.op.toString() + xt(t.value)).join(",") + "|ob:" + e.orderBy.map((t)=>t.field.canonicalString() + t.dir).join(","), At(e.limit) || (t1 = "|l:" + e.limit), e.startAt && (t1 = "|lb:" + ce(e.startAt)), e.endAt && (t1 = "|ub:" + ce(e.endAt)), e.A = t1;
null !== e.collectionGroup && (t1 += "|cg:" + e.collectionGroup), t1 += "|f:" + e.filters.map((t)=>t.field.canonicalString() + t.op.toString() + xt(t.value)).join(",") + "|ob:" + e.orderBy.map((t)=>t.field.canonicalString() + t.dir).join(","), At(e.limit) || (t1 += "|l:" + e.limit), e.startAt && (t1 += "|lb:" + ce(e.startAt)), e.endAt && (t1 += "|ub:" + ce(e.endAt)), e.A = t1;
}
return e.A;
}
Expand Down
Expand Up @@ -799,7 +799,7 @@
getParsingFlags(config).invalidFormat = !0, config._d = new Date(NaN);
return;
}
for(i = 0; i < config._f.length; i++)currentScore = 0, validFormatFound = !1, tempConfig = copyConfig({}, config), null != config._useUTC && (tempConfig._useUTC = config._useUTC), tempConfig._f = config._f[i], configFromStringAndFormat(tempConfig), isValid(tempConfig) && (validFormatFound = !0), currentScore = getParsingFlags(tempConfig).charsLeftOver + 10 * getParsingFlags(tempConfig).unusedTokens.length, getParsingFlags(tempConfig).score = currentScore, bestFormatIsValid ? currentScore < scoreToBeat && (scoreToBeat = currentScore, bestMoment = tempConfig) : (null == scoreToBeat || currentScore < scoreToBeat || validFormatFound) && (scoreToBeat = currentScore, bestMoment = tempConfig, validFormatFound && (bestFormatIsValid = !0));
for(i = 0; i < config._f.length; i++)currentScore = 0, validFormatFound = !1, tempConfig = copyConfig({}, config), null != config._useUTC && (tempConfig._useUTC = config._useUTC), tempConfig._f = config._f[i], configFromStringAndFormat(tempConfig), isValid(tempConfig) && (validFormatFound = !0), currentScore += getParsingFlags(tempConfig).charsLeftOver + 10 * getParsingFlags(tempConfig).unusedTokens.length, getParsingFlags(tempConfig).score = currentScore, bestFormatIsValid ? currentScore < scoreToBeat && (scoreToBeat = currentScore, bestMoment = tempConfig) : (null == scoreToBeat || currentScore < scoreToBeat || validFormatFound) && (scoreToBeat = currentScore, bestMoment = tempConfig, validFormatFound && (bestFormatIsValid = !0));
extend(config, bestMoment || tempConfig);
}(config) : format ? configFromStringAndFormat(config) : isUndefined(input = (config1 = config)._i) ? config1._d = new Date(hooks.now()) : isDate(input) ? config1._d = new Date(input.valueOf()) : "string" == typeof input ? function(config) {
var matched = aspNetJsonRegex.exec(config._i);
Expand Down
Expand Up @@ -9364,7 +9364,7 @@
pts: buffer[0].pts,
dts: buffer[0].dts
}; i < tagSize;)tag.data.set(buffer[0].data.subarray(0, tagSize - i), i), i += buffer[0].data.byteLength, bufferSize -= buffer[0].data.byteLength, buffer.shift();
frameStart = 10, 0x40 & tag.data[5] && (frameStart = 4 + parseSyncSafeInteger$1(tag.data.subarray(10, 14)), tagSize -= parseSyncSafeInteger$1(tag.data.subarray(16, 20)));
frameStart = 10, 0x40 & tag.data[5] && (frameStart += 4 + parseSyncSafeInteger$1(tag.data.subarray(10, 14)), tagSize -= parseSyncSafeInteger$1(tag.data.subarray(16, 20)));
do {
if ((frameSize = parseSyncSafeInteger$1(tag.data.subarray(frameStart + 4, frameStart + 8))) < 1) {
this.trigger("log", {
Expand All @@ -9380,7 +9380,7 @@
var d = frame.data, size = (0x01 & d[3]) << 30 | d[4] << 22 | d[5] << 14 | d[6] << 6 | d[7] >>> 2;
size *= 4, size += 0x03 & d[7], frame.timeStamp = size, void 0 === tag.pts && void 0 === tag.dts && (tag.pts = frame.timeStamp, tag.dts = frame.timeStamp), this.trigger("timestamp", frame);
}
tag.frames.push(frame), frameStart = 10 + frameSize;
tag.frames.push(frame), frameStart += 10 + frameSize;
}while (frameStart < tagSize)
this.trigger("data", tag);
}
Expand Down Expand Up @@ -9920,7 +9920,7 @@
},
parseAacTimestamp: function(packet) {
var frameStart, frameSize, frame;
frameStart = 10, 0x40 & packet[5] && (frameStart = 4 + parseSyncSafeInteger(packet.subarray(10, 14)));
frameStart = 10, 0x40 & packet[5] && (frameStart += 4 + parseSyncSafeInteger(packet.subarray(10, 14)));
do {
if ((frameSize = parseSyncSafeInteger(packet.subarray(frameStart + 4, frameStart + 8))) < 1) break;
if ("PRIV" === String.fromCharCode(packet[frameStart], packet[frameStart + 1], packet[frameStart + 2], packet[frameStart + 3])) {
Expand All @@ -9933,7 +9933,7 @@
break;
}
}
frameStart = 10 + frameSize;
frameStart += 10 + frameSize;
}while (frameStart < packet.byteLength)
return null;
}
Expand Down Expand Up @@ -10244,7 +10244,7 @@
return ("00" + value.toString(16)).slice(-2);
}
}, parseType_1 = function(buffer) {
return String.fromCharCode(buffer[0]) + String.fromCharCode(buffer[1]) + String.fromCharCode(buffer[2]) + String.fromCharCode(buffer[3]);
return "" + (String.fromCharCode(buffer[0]) + String.fromCharCode(buffer[1]) + String.fromCharCode(buffer[2]) + String.fromCharCode(buffer[3]));
}, toUnsigned$2 = bin.toUnsigned, findBox_1 = function findBox(data, path) {
var i, size, type, end, subresults, results = [];
if (!path.length) return null;
Expand Down
Expand Up @@ -15868,7 +15868,7 @@
i += "".concat(t[0], " and ").concat(t[1], " arguments");
break;
default:
i = t.slice(0, o - 1).join(", ") + ", and ".concat(t[o - 1], " arguments");
i += t.slice(0, o - 1).join(", ") + ", and ".concat(t[o - 1], " arguments");
}
return "".concat(i, " must be specified");
}, TypeError), e.exports.codes = l;
Expand Down
Expand Up @@ -19185,7 +19185,7 @@
}, Toolbar.prototype.itemWidthCal = function(items) {
var style, _this = this, width = 0;
return [].slice.call((0, ej2_base.td)('.' + CLS_ITEM, items)).forEach(function(el) {
(0, ej2_base.pn)(el) && (style = window.getComputedStyle(el), width = (_this.isVertical ? el.offsetHeight : el.offsetWidth) + parseFloat(_this.isVertical ? style.marginTop : style.marginRight) + parseFloat(_this.isVertical ? style.marginBottom : style.marginLeft));
(0, ej2_base.pn)(el) && (style = window.getComputedStyle(el), width += (_this.isVertical ? el.offsetHeight : el.offsetWidth) + parseFloat(_this.isVertical ? style.marginTop : style.marginRight) + parseFloat(_this.isVertical ? style.marginBottom : style.marginLeft));
}), width;
}, Toolbar.prototype.getScrollCntEle = function(innerItem) {
var trgClass = this.isVertical ? '.e-vscroll-content' : '.e-hscroll-content';
Expand Down Expand Up @@ -23519,7 +23519,7 @@
});
}, ToolbarRenderer.prototype.renderColorPickerDropDown = function(args, item, colorPicker, defaultColor) {
var range, _this = this, proxy = this, css = classes.i7 + ' ' + classes.Fs + (this.parent.inlineMode ? ' ' + classes.ZV : '');
css = ' ' + ('backgroundcolor' === item ? classes.Z8 : classes.UQ) + ' ' + this.parent.cssClass;
css += ' ' + ('backgroundcolor' === item ? classes.Z8 : classes.UQ) + ' ' + this.parent.cssClass;
var content = proxy.parent.createElement('span', {
className: classes.uN
}), inlineEle = proxy.parent.createElement('span', {
Expand Down

1 comment on commit 5fd7ab8

@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: 5fd7ab8 Previous: 1dd8b3d Ratio
es/full/bugs-1 384386 ns/iter (± 27258) 359764 ns/iter (± 35638) 1.07
es/full/minify/libraries/antd 2157855976 ns/iter (± 154647760) 1859260645 ns/iter (± 50064656) 1.16
es/full/minify/libraries/d3 507326098 ns/iter (± 43450517) 407449725 ns/iter (± 22362328) 1.25
es/full/minify/libraries/echarts 1824283509 ns/iter (± 87224373) 1612858764 ns/iter (± 52492529) 1.13
es/full/minify/libraries/jquery 125674262 ns/iter (± 10270302) 100909663 ns/iter (± 11908356) 1.25
es/full/minify/libraries/lodash 161841571 ns/iter (± 23767299) 134324510 ns/iter (± 10291658) 1.20
es/full/minify/libraries/moment 68607780 ns/iter (± 9180227) 67175152 ns/iter (± 8010933) 1.02
es/full/minify/libraries/react 25933890 ns/iter (± 4050584) 21767308 ns/iter (± 633949) 1.19
es/full/minify/libraries/terser 350526660 ns/iter (± 27602752) 318945153 ns/iter (± 12126350) 1.10
es/full/minify/libraries/three 623627713 ns/iter (± 11338445) 575525366 ns/iter (± 33154379) 1.08
es/full/minify/libraries/typescript 3761569636 ns/iter (± 115227394) 3525404089 ns/iter (± 93756360) 1.07
es/full/minify/libraries/victory 911504195 ns/iter (± 73599321) 854009311 ns/iter (± 18508124) 1.07
es/full/minify/libraries/vue 185860561 ns/iter (± 21242771) 186769157 ns/iter (± 10795873) 1.00
es/full/codegen/es3 46380 ns/iter (± 14989) 35987 ns/iter (± 2947) 1.29
es/full/codegen/es5 40437 ns/iter (± 8242) 35271 ns/iter (± 2919) 1.15
es/full/codegen/es2015 39676 ns/iter (± 8266) 35398 ns/iter (± 2191) 1.12
es/full/codegen/es2016 37263 ns/iter (± 6019) 35354 ns/iter (± 3173) 1.05
es/full/codegen/es2017 40107 ns/iter (± 7901) 35284 ns/iter (± 2622) 1.14
es/full/codegen/es2018 38133 ns/iter (± 7170) 35578 ns/iter (± 4212) 1.07
es/full/codegen/es2019 40487 ns/iter (± 6505) 35800 ns/iter (± 3202) 1.13
es/full/codegen/es2020 42072 ns/iter (± 6483) 35466 ns/iter (± 3811) 1.19
es/full/all/es3 265106839 ns/iter (± 38190047) 217580563 ns/iter (± 21596484) 1.22
es/full/all/es5 244142811 ns/iter (± 32437808) 185495295 ns/iter (± 15440090) 1.32
es/full/all/es2015 192458130 ns/iter (± 34969575) 162503849 ns/iter (± 17551828) 1.18
es/full/all/es2016 198876122 ns/iter (± 26085312) 155546701 ns/iter (± 21213081) 1.28
es/full/all/es2017 195382082 ns/iter (± 25498989) 165784208 ns/iter (± 18397331) 1.18
es/full/all/es2018 188338284 ns/iter (± 37307217) 160782944 ns/iter (± 18813240) 1.17
es/full/all/es2019 188593759 ns/iter (± 26596396) 149664700 ns/iter (± 11898224) 1.26
es/full/all/es2020 173921773 ns/iter (± 27236630) 147589823 ns/iter (± 12281102) 1.18
es/full/parser 862147 ns/iter (± 109307) 752944 ns/iter (± 74353) 1.15
es/full/base/fixer 31531 ns/iter (± 4793) 27952 ns/iter (± 3623) 1.13
es/full/base/resolver_and_hygiene 110707 ns/iter (± 15719) 95506 ns/iter (± 8627) 1.16
serialization of ast node 248 ns/iter (± 51) 215 ns/iter (± 3) 1.15
serialization of serde 248 ns/iter (± 43) 228 ns/iter (± 24) 1.09

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

Please sign in to comment.