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): Preserve op of the op-assignments in seq inliner #6428

Merged
merged 7 commits into from Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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());
@@ -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
@@ -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