diff --git a/crates/swc/tests/tsc-references/enumBasics.2.minified.js b/crates/swc/tests/tsc-references/enumBasics.2.minified.js index 58f0f083a7dc..0039ea8d7165 100644 --- a/crates/swc/tests/tsc-references/enumBasics.2.minified.js +++ b/crates/swc/tests/tsc-references/enumBasics.2.minified.js @@ -1,8 +1,9 @@ //// [enumBasics.ts] -var E1, E2, E3, E4, E5, E6, E7, E8, E9; !function(E1) { E1[E1.A = 0] = "A", E1[E1.B = 1] = "B", E1[E1.C = 2] = "C"; -}(E1 || (E1 = {})), E1.A, E1[E1.A], function(E2) { +}(E1 || (E1 = {})), E1.A; +var E1, E2, E3, E4, E5, E6, E7, E8, E9, e = E1; +E1[e.A], function(E2) { E2[E2.A = 1] = "A", E2[E2.B = 2] = "B", E2[E2.C = 3] = "C"; }(E2 || (E2 = {})), function(E3) { E3[E3.X = 3] = "X", E3[E3.Y = 7] = "Y", E3[E3.Z = NaN] = "Z"; diff --git a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs index b45d9a9b4a6d..1ce418dd1164 100644 --- a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs +++ b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs @@ -1597,6 +1597,21 @@ where return Ok(false); } + // We can't merge into `[]` in some cases because `obj` is **resolved** before + // evaluating `[]`. + // + // See https://github.com/swc-project/swc/pull/6509 + + let obj_ids = idents_used_by_ignoring_nested(obj); + let a_ids = match a { + Mergable::Var(a) => idents_used_by_ignoring_nested(&a.init), + Mergable::Expr(a) => idents_used_by_ignoring_nested(&**a), + Mergable::FnDecl(a) => idents_used_by_ignoring_nested(&**a), + }; + if obj_ids.intersection(&a_ids).next().is_some() { + return Ok(false); + } + trace_op!("seq: Try prop of member (computed)"); return self.merge_sequential_expr(a, &mut c.expr); } diff --git a/crates/swc_ecma_minifier/tests/benches-full/echarts.js b/crates/swc_ecma_minifier/tests/benches-full/echarts.js index 62d2d74e6e01..81e6404e3db0 100644 --- a/crates/swc_ecma_minifier/tests/benches-full/echarts.js +++ b/crates/swc_ecma_minifier/tests/benches-full/echarts.js @@ -15339,7 +15339,7 @@ } if (isArray(template)) { var levelId = null == tick.level ? 0 : tick.level >= 0 ? tick.level : template.length + tick.level; - template = template[levelId = Math.min(levelId, template.length - 1)]; + levelId = Math.min(levelId, template.length - 1), template = template[levelId]; } } return format(new Date(tick.value), template, isUTC, lang); @@ -23629,7 +23629,7 @@ function getSpecifiedVisual(value) { var thisOption = this.option, pieceList = thisOption.pieceList; if (thisOption.hasSpecialVisual) { - var piece = pieceList[VisualMapping.findPieceIndex(value, pieceList)]; + var pieceIndex = VisualMapping.findPieceIndex(value, pieceList), piece = pieceList[pieceIndex]; if (piece && piece.visual) return piece.visual[this.type]; } } @@ -27805,7 +27805,7 @@ var result, axisList; each((result = [], axisList = [], ecModel.eachSeriesByType('boxplot', function(seriesModel) { var baseAxis = seriesModel.getBaseAxis(), idx = indexOf(axisList, baseAxis); - idx < 0 && (axisList[idx = axisList.length] = baseAxis, result[idx] = { + idx < 0 && (idx = axisList.length, axisList[idx] = baseAxis, result[idx] = { axis: baseAxis, seriesModels: [] }), result[idx].seriesModels.push(seriesModel); diff --git a/crates/swc_ecma_minifier/tests/benches-full/jquery.js b/crates/swc_ecma_minifier/tests/benches-full/jquery.js index 1586659030c6..a5dc1ff06c5e 100644 --- a/crates/swc_ecma_minifier/tests/benches-full/jquery.js +++ b/crates/swc_ecma_minifier/tests/benches-full/jquery.js @@ -487,7 +487,7 @@ "", argument ], Expr.setFilters.hasOwnProperty(pseudo.toLowerCase()) ? markFunction(function(seed, matches) { - for(var idx, matched = fn(seed, argument), i = matched.length; i--;)seed[idx = indexOf(seed, matched[i])] = !(matches[idx] = matched[i]); + for(var idx, matched = fn(seed, argument), i = matched.length; i--;)idx = indexOf(seed, matched[i]), seed[idx] = !(matches[idx] = matched[i]); }) : function(elem) { return fn(elem, 0, args); }) : fn; diff --git a/crates/swc_ecma_minifier/tests/benches-full/three.js b/crates/swc_ecma_minifier/tests/benches-full/three.js index 30d3362666ca..0e1fab351277 100644 --- a/crates/swc_ecma_minifier/tests/benches-full/three.js +++ b/crates/swc_ecma_minifier/tests/benches-full/three.js @@ -5561,7 +5561,10 @@ return void 0 === program && (program = new WebGLProgram(renderer, cacheKey, parameters, bindingStates), programs.push(program)), program; }, releaseProgram: function(program) { - 0 == --program.usedTimes && (programs[programs.indexOf(program)] = programs[programs.length - 1], programs.pop(), program.destroy()); + if (0 == --program.usedTimes) { + var i = programs.indexOf(program); + programs[i] = programs[programs.length - 1], programs.pop(), program.destroy(); + } }, programs: programs }; @@ -10006,7 +10009,7 @@ iPrev = i1, tPrev = 2 * t0 - t1; break; case 2402: - tPrev = t0 + pp[iPrev = pp.length - 2] - pp[iPrev + 1]; + iPrev = pp.length - 2, tPrev = t0 + pp[iPrev] - pp[iPrev + 1]; break; default: iPrev = i1, tPrev = t1; diff --git a/crates/swc_ecma_minifier/tests/benches-full/vue.js b/crates/swc_ecma_minifier/tests/benches-full/vue.js index 9a78b840d071..9b33adb24a91 100644 --- a/crates/swc_ecma_minifier/tests/benches-full/vue.js +++ b/crates/swc_ecma_minifier/tests/benches-full/vue.js @@ -761,7 +761,7 @@ createTextVNode(children) ] : Array.isArray(children) ? function normalizeArrayChildren(children, nestedIndex) { var i, c, lastIndex, last, res = []; - for(i = 0; i < children.length; i++)!isUndef(c = children[i]) && 'boolean' != typeof c && (last = res[lastIndex = res.length - 1], Array.isArray(c) ? c.length > 0 && (isTextNode((c = normalizeArrayChildren(c, (nestedIndex || '') + "_" + i))[0]) && isTextNode(last) && (res[lastIndex] = createTextVNode(last.text + c[0].text), c.shift()), res.push.apply(res, c)) : isPrimitive(c) ? isTextNode(last) ? res[lastIndex] = createTextVNode(last.text + c) : '' !== c && res.push(createTextVNode(c)) : isTextNode(c) && isTextNode(last) ? res[lastIndex] = createTextVNode(last.text + c.text) : (isTrue(children._isVList) && isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex) && (c.key = "__vlist" + nestedIndex + "_" + i + "__"), res.push(c))); + for(i = 0; i < children.length; i++)!isUndef(c = children[i]) && 'boolean' != typeof c && (lastIndex = res.length - 1, last = res[lastIndex], Array.isArray(c) ? c.length > 0 && (isTextNode((c = normalizeArrayChildren(c, (nestedIndex || '') + "_" + i))[0]) && isTextNode(last) && (res[lastIndex] = createTextVNode(last.text + c[0].text), c.shift()), res.push.apply(res, c)) : isPrimitive(c) ? isTextNode(last) ? res[lastIndex] = createTextVNode(last.text + c) : '' !== c && res.push(createTextVNode(c)) : isTextNode(c) && isTextNode(last) ? res[lastIndex] = createTextVNode(last.text + c.text) : (isTrue(children._isVList) && isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex) && (c.key = "__vlist" + nestedIndex + "_" + i + "__"), res.push(c))); return res; }(children) : void 0; } diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6509/config.json b/crates/swc_ecma_minifier/tests/fixture/issues/6509/config.json new file mode 100644 index 000000000000..872836f33f9e --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6509/config.json @@ -0,0 +1,7 @@ +{ + "toplevel": true, + "defaults": false, + "inline": true, + "sequences": true, + "conditionals": true +} diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6509/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/6509/input.js new file mode 100644 index 000000000000..4a2b9c5be108 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6509/input.js @@ -0,0 +1,113 @@ + + +function parseOffset(offset, popperOffsets, referenceOffsets, basePlacement) { + var offsets = [0, 0]; + + // Use height if placement is left or right and index is 0 otherwise use width + // in this way the first offset will use an axis and the second one + // will use the other one + var useHeight = ['right', 'left'].indexOf(basePlacement) !== -1; + + // Split the offset string to obtain a list of values and operands + // The regex addresses values with the plus or minus sign in front (+10, -20, etc) + var fragments = offset.split(/(\+|\-)/).map(function (frag) { + return frag.trim(); + }); + + // Detect if the offset string contains a pair of values or a single one + // they could be separated by comma or space + var divider = fragments.indexOf(find(fragments, function (frag) { + return frag.search(/,|\s/) !== -1; + })); + + if (fragments[divider] && fragments[divider].indexOf(',') === -1) { + console.warn('Offsets separated by white space(s) are deprecated, use a comma (,) instead.'); + } + + // If divider is found, we divide the list of values and operands to divide + // them by ofset X and Y. + var splitRegex = /\s*,\s*|\s+/; + var ops = divider !== -1 ? [fragments.slice(0, divider).concat([fragments[divider].split(splitRegex)[0]]), [fragments[divider].split(splitRegex)[1]].concat(fragments.slice(divider + 1))] : [fragments]; + + // Convert the values with units to absolute pixels to allow our computations + ops = ops.map(function (op, index) { + // Most of the units rely on the orientation of the popper + var measurement = (index === 1 ? !useHeight : useHeight) ? 'height' : 'width'; + var mergeWithPrevious = false; + return op + // This aggregates any `+` or `-` sign that aren't considered operators + // e.g.: 10 + +5 => [10, +, +5] + .reduce(function (a, b) { + if (a[a.length - 1] === '' && ['+', '-'].indexOf(b) !== -1) { + a[a.length - 1] = b; + mergeWithPrevious = true; + return a; + } else if (mergeWithPrevious) { + a[a.length - 1] += b; + mergeWithPrevious = false; + return a; + } else { + return a.concat(b); + } + }, []) + // Here we convert the string values into number values (in px) + .map(function (str) { + return toValue(str, measurement, popperOffsets, referenceOffsets); + }); + }); + + // Loop trough the offsets arrays and execute the operations + ops.forEach(function (op, index) { + op.forEach(function (frag, index2) { + if (isNumeric(frag)) { + offsets[index] += frag * (op[index2 - 1] === '-' ? -1 : 1); + } + }); + }); + return offsets; +} + +function offset(data, _ref) { + var offset = _ref.offset; + var placement = data.placement, + _data$offsets = data.offsets, + popper = _data$offsets.popper, + reference = _data$offsets.reference; + + var basePlacement = placement.split('-')[0]; + + var offsets = void 0; + if (isNumeric(+offset)) { + offsets = [+offset, 0]; + } else { + offsets = parseOffset(offset, popper, reference, basePlacement); + } + + if (basePlacement === 'left') { + popper.top += offsets[0]; + popper.left -= offsets[1]; + } else if (basePlacement === 'right') { + popper.top += offsets[0]; + popper.left += offsets[1]; + } else if (basePlacement === 'top') { + popper.left += offsets[0]; + popper.top -= offsets[1]; + } else if (basePlacement === 'bottom') { + popper.left += offsets[0]; + popper.top += offsets[1]; + } + + data.popper = popper; + return data; +} + + +export var modifiers = { + offset: { + order: 200, + enabled: true, + fn: offset, + offset: 0 + }, +}; + diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/6509/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/6509/output.js new file mode 100644 index 000000000000..167b5a1c3658 --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/issues/6509/output.js @@ -0,0 +1,63 @@ +export var modifiers = { + offset: { + order: 200, + enabled: true, + fn: function(data, _ref) { + var offset = _ref.offset; + var placement = data.placement, _data$offsets = data.offsets, popper = _data$offsets.popper, reference = _data$offsets.reference; + var basePlacement = placement.split('-')[0]; + var offsets = void 0; + if (isNumeric(+offset)) offsets = [ + +offset, + 0 + ]; + else { + var offsets1; + var useHeight; + var fragments; + var divider; + var splitRegex; + var ops; + offsets1 = [ + 0, + 0 + ], useHeight = -1 !== [ + 'right', + 'left' + ].indexOf(basePlacement), divider = (fragments = offset.split(/(\+|\-)/).map(function(frag) { + return frag.trim(); + })).indexOf(find(fragments, function(frag) { + return -1 !== frag.search(/,|\s/); + })), fragments[divider] && -1 === fragments[divider].indexOf(',') && console.warn('Offsets separated by white space(s) are deprecated, use a comma (,) instead.'), splitRegex = /\s*,\s*|\s+/, (ops = (-1 !== divider ? [ + fragments.slice(0, divider).concat([ + fragments[divider].split(splitRegex)[0] + ]), + [ + fragments[divider].split(splitRegex)[1] + ].concat(fragments.slice(divider + 1)) + ] : [ + fragments + ]).map(function(op, index) { + var measurement = (1 === index ? !useHeight : useHeight) ? 'height' : 'width'; + var mergeWithPrevious = false; + return op.reduce(function(a, b) { + if ('' === a[a.length - 1] && -1 !== [ + '+', + '-' + ].indexOf(b)) return a[a.length - 1] = b, mergeWithPrevious = true, a; + if (mergeWithPrevious) return a[a.length - 1] += b, mergeWithPrevious = false, a; + return a.concat(b); + }, []).map(function(str) { + return toValue(str, measurement, popper, reference); + }); + })).forEach(function(op, index) { + op.forEach(function(frag, index2) { + isNumeric(frag) && (offsets1[index] += frag * ('-' === op[index2 - 1] ? -1 : 1)); + }); + }), offsets = offsets1; + } + return 'left' === basePlacement ? (popper.top += offsets[0], popper.left -= offsets[1]) : 'right' === basePlacement ? (popper.top += offsets[0], popper.left += offsets[1]) : 'top' === basePlacement ? (popper.left += offsets[0], popper.top -= offsets[1]) : 'bottom' === basePlacement && (popper.left += offsets[0], popper.top += offsets[1]), data.popper = popper, data; + }, + offset: 0 + } +}; diff --git a/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/output.js b/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/output.js index 0c18857535d3..4ae2c114c074 100644 --- a/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/d6e1aeb5-38a8d7ae57119c23/output.js @@ -10418,7 +10418,7 @@ var tkhd, index, id, mdhd; return (tkhd = findBox_1(trak, [ "tkhd" - ])[0]) && (id = toUnsigned(tkhd[index = 0 === tkhd[0] ? 12 : 20] << 24 | tkhd[index + 1] << 16 | tkhd[index + 2] << 8 | tkhd[index + 3]), mdhd = findBox_1(trak, [ + ])[0]) && (index = 0 === tkhd[0] ? 12 : 20, id = toUnsigned(tkhd[index] << 24 | tkhd[index + 1] << 16 | tkhd[index + 2] << 8 | tkhd[index + 3]), mdhd = findBox_1(trak, [ "mdia", "mdhd" ])[0]) ? (index = 0 === mdhd[0] ? 12 : 20, result[id] = toUnsigned(mdhd[index] << 24 | mdhd[index + 1] << 16 | mdhd[index + 2] << 8 | mdhd[index + 3]), result) : null; @@ -13053,7 +13053,7 @@ var syncPoint = null, lastDistance = null, partsAndSegments = getPartsAndSegments(playlist); currentTime = currentTime || 0; for(var i = 0; i < partsAndSegments.length; i++){ - var partAndSegment = partsAndSegments[playlist.endList || 0 === currentTime ? i : partsAndSegments.length - (i + 1)], segment = partAndSegment.segment, datetimeMapping = syncController.timelineToDatetimeMappings[segment.timeline]; + var index = playlist.endList || 0 === currentTime ? i : partsAndSegments.length - (i + 1), partAndSegment = partsAndSegments[index], segment = partAndSegment.segment, datetimeMapping = syncController.timelineToDatetimeMappings[segment.timeline]; if (datetimeMapping && segment.dateTimeObject) { var start = segment.dateTimeObject.getTime() / 1000 + datetimeMapping; if (segment.parts && "number" == typeof partAndSegment.partIndex) for(var z = 0; z < partAndSegment.partIndex; z++)start += segment.parts[z].duration; @@ -13075,7 +13075,7 @@ var syncPoint = null, lastDistance = null; currentTime = currentTime || 0; for(var partsAndSegments = getPartsAndSegments(playlist), i = 0; i < partsAndSegments.length; i++){ - var partAndSegment = partsAndSegments[playlist.endList || 0 === currentTime ? i : partsAndSegments.length - (i + 1)], segment = partAndSegment.segment, start = partAndSegment.part && partAndSegment.part.start || segment && segment.start; + var index = playlist.endList || 0 === currentTime ? i : partsAndSegments.length - (i + 1), partAndSegment = partsAndSegments[index], segment = partAndSegment.segment, start = partAndSegment.part && partAndSegment.part.start || segment && segment.start; if (segment.timeline === currentTimeline && void 0 !== start) { var distance = Math.abs(currentTime - start); if (null !== lastDistance && lastDistance < distance) break; diff --git a/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/output.js b/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/output.js index 94da6ebfdd01..7d2b9fa1f56a 100644 --- a/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/next/33265/static/chunks/pages/index-cb36c1bf7f830e3c/output.js @@ -3175,7 +3175,11 @@ var formatted = addSidxSegmentsToPlaylist$1(formatAudioPlaylist(playlist, isAudioOnly), sidxMapping); return a[label].playlists.push(formatted), void 0 === mainPlaylist && "main" === role && ((mainPlaylist = playlist).default = !0), a; }, {}); - return mainPlaylist || (formattedPlaylists[Object.keys(formattedPlaylists)[0]].default = !0), formattedPlaylists; + if (!mainPlaylist) { + var firstLabel = Object.keys(formattedPlaylists)[0]; + formattedPlaylists[firstLabel].default = !0; + } + return formattedPlaylists; }, formatVideoPlaylist = function(_ref3) { var _attributes2, attributes = _ref3.attributes, segments = _ref3.segments, sidx = _ref3.sidx, playlist = { attributes: ((_attributes2 = { diff --git a/crates/swc_ecma_minifier/tests/fixture/next/chakra/output.js b/crates/swc_ecma_minifier/tests/fixture/next/chakra/output.js index 0bb4dafc83f0..42741c4284b5 100644 --- a/crates/swc_ecma_minifier/tests/fixture/next/chakra/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/next/chakra/output.js @@ -1675,7 +1675,7 @@ var index = 0; if (0 === str.length) return list[0]; for(var i = 0; i < str.length; i += 1)index = str.charCodeAt(i) + ((index << 5) - index), index &= index; - return list[index = (index % list.length + list.length) % list.length]; + return index = (index % list.length + list.length) % list.length, list[index]; }(opts.string, opts.colors) : opts.string && !opts.colors ? function(str) { var hash = 0; if (0 === str.length) return hash.toString(); diff --git a/crates/swc_ecma_minifier/tests/fixture/next/feedback-3/579-dcac359116b2707c/output.js b/crates/swc_ecma_minifier/tests/fixture/next/feedback-3/579-dcac359116b2707c/output.js index eac7aa43b216..b87cd145a4eb 100644 --- a/crates/swc_ecma_minifier/tests/fixture/next/feedback-3/579-dcac359116b2707c/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/next/feedback-3/579-dcac359116b2707c/output.js @@ -1073,16 +1073,17 @@ }; }(e); "function" == typeof u.filter ? n = (0, u.filter)("", n) : c(u.filter) && (r = u.filter); - var y = []; + var y, l = []; if ("object" != typeof n || null === n) return ""; - var l = p[e && e.arrayFormat in p ? e.arrayFormat : e && "indices" in e ? e.indices ? "indices" : "repeat" : "indices"]; + y = e && e.arrayFormat in p ? e.arrayFormat : e && "indices" in e ? e.indices ? "indices" : "repeat" : "indices"; + var b = p[y]; r || (r = Object.keys(n)), u.sort && r.sort(u.sort); - for(var b = o(), g = 0; g < r.length; ++g){ - var h = r[g]; - u.skipNulls && null === n[h] || f(y, d(n[h], h, l, u.strictNullHandling, u.skipNulls, u.encode ? u.encoder : null, u.filter, u.sort, u.allowDots, u.serializeDate, u.format, u.formatter, u.encodeValuesOnly, u.charset, b)); + for(var g = o(), h = 0; h < r.length; ++h){ + var m = r[h]; + u.skipNulls && null === n[m] || f(l, d(n[m], m, b, u.strictNullHandling, u.skipNulls, u.encode ? u.encoder : null, u.filter, u.sort, u.allowDots, u.serializeDate, u.format, u.formatter, u.encodeValuesOnly, u.charset, g)); } - var m = y.join(u.delimiter), v = !0 === u.addQueryPrefix ? "?" : ""; - return u.charsetSentinel && ("iso-8859-1" === u.charset ? v += "utf8=%26%2310003%3B&" : v += "utf8=%E2%9C%93&"), m.length > 0 ? v + m : ""; + var v = l.join(u.delimiter), S = !0 === u.addQueryPrefix ? "?" : ""; + return u.charsetSentinel && ("iso-8859-1" === u.charset ? S += "utf8=%26%2310003%3B&" : S += "utf8=%E2%9C%93&"), v.length > 0 ? S + v : ""; }; }, 769 (t, e, r) { diff --git a/crates/swc_ecma_minifier/tests/fixture/next/react-ace/chunks/8a28b14e.d8fbda268ed281a1/output.js b/crates/swc_ecma_minifier/tests/fixture/next/react-ace/chunks/8a28b14e.d8fbda268ed281a1/output.js index a774c401756f..be79e59df396 100644 --- a/crates/swc_ecma_minifier/tests/fixture/next/react-ace/chunks/8a28b14e.d8fbda268ed281a1/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/next/react-ace/chunks/8a28b14e.d8fbda268ed281a1/output.js @@ -241,7 +241,7 @@ ], function(require, exports, module) { "use strict"; var oop = require("./oop"), Keys = function() { - var i, ret = { + var name, i, ret = { MODIFIER_KEYS: { 16: "Shift", 17: "Ctrl", @@ -364,8 +364,8 @@ 106: "*" } }; - for(i in ret.FUNCTION_KEYS)ret[ret.FUNCTION_KEYS[i].toLowerCase()] = parseInt(i, 10); - for(i in ret.PRINTABLE_KEYS)ret[ret.PRINTABLE_KEYS[i].toLowerCase()] = parseInt(i, 10); + for(i in ret.FUNCTION_KEYS)name = ret.FUNCTION_KEYS[i].toLowerCase(), ret[name] = parseInt(i, 10); + for(i in ret.PRINTABLE_KEYS)name = ret.PRINTABLE_KEYS[i].toLowerCase(), ret[name] = parseInt(i, 10); return oop.mixin(ret, ret.MODIFIER_KEYS), oop.mixin(ret, ret.PRINTABLE_KEYS), oop.mixin(ret, ret.FUNCTION_KEYS), ret.enter = ret.return, ret.escape = ret.esc, ret.del = ret.delete, ret[173] = "-", function() { for(var mods = [ "cmd", diff --git a/crates/swc_ecma_minifier/tests/fixture/next/syncfusion/933-e9f9a6bf671b96fc/output.js b/crates/swc_ecma_minifier/tests/fixture/next/syncfusion/933-e9f9a6bf671b96fc/output.js index 02dc5948250f..69b1b629eda7 100644 --- a/crates/swc_ecma_minifier/tests/fixture/next/syncfusion/933-e9f9a6bf671b96fc/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/next/syncfusion/933-e9f9a6bf671b96fc/output.js @@ -23041,10 +23041,10 @@ e.preventDefault(), selectedEle = prevSelectedEle ? tiles[this.tilePosition(tiles, prevSelectedEle, this.enableRtl ? 1 : -1)] : tiles[this.enableRtl ? 0 : tiles.length - 1], this.keySelectionChanges(selectedEle); break; case 38: - e.preventDefault(), selectedEle = tiles[idx = prevSelectedEle ? this.tilePosition(tiles, prevSelectedEle, -this.columns) : 0] ? tiles[idx] : tiles[idx - this.columns], this.keySelectionChanges(selectedEle); + e.preventDefault(), idx = prevSelectedEle ? this.tilePosition(tiles, prevSelectedEle, -this.columns) : 0, selectedEle = tiles[idx] ? tiles[idx] : tiles[idx - this.columns], this.keySelectionChanges(selectedEle); break; case 40: - e.preventDefault(), tiles[idx = prevSelectedEle ? this.tilePosition(tiles, prevSelectedEle, this.columns) : tiles.length - 1] || (idx %= tiles.length, idx += tiles[tiles.length - 1].parentElement.childElementCount), selectedEle = tiles[idx], this.keySelectionChanges(selectedEle); + e.preventDefault(), idx = prevSelectedEle ? this.tilePosition(tiles, prevSelectedEle, this.columns) : tiles.length - 1, tiles[idx] || (idx %= tiles.length, idx += tiles[tiles.length - 1].parentElement.childElementCount), selectedEle = tiles[idx], this.keySelectionChanges(selectedEle); break; case 13: if (e.preventDefault(), prevSelectedEle) { diff --git a/crates/swc_ecma_minifier/tests/fixture/next/target-es2015/static/chunks/main-04b5934c26266542/output.js b/crates/swc_ecma_minifier/tests/fixture/next/target-es2015/static/chunks/main-04b5934c26266542/output.js index be0f632c7ab0..4fcaa44494ac 100644 --- a/crates/swc_ecma_minifier/tests/fixture/next/target-es2015/static/chunks/main-04b5934c26266542/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/next/target-es2015/static/chunks/main-04b5934c26266542/output.js @@ -3149,7 +3149,7 @@ }); }) || H(n); }); - var T = V[Math.min(V.length - 1, Math.floor(R() / 50))]; + var y, T = (y = Math.min(V.length - 1, Math.floor(R() / 50)), V[y]); T && T.latency !== w.value && (w.value = T.latency, w.entries = T.entries, C()); }, P = s("event", a, { durationThreshold: y.durationThreshold || 40 diff --git a/crates/swc_ecma_minifier/tests/fixture/projects/underscore/22/output.js b/crates/swc_ecma_minifier/tests/fixture/projects/underscore/22/output.js index 0d4f68fab976..e1814aaf5d36 100644 --- a/crates/swc_ecma_minifier/tests/fixture/projects/underscore/22/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/projects/underscore/22/output.js @@ -2,7 +2,7 @@ _.indexOf = function(array, item, isSorted) { if (null == array) return -1; var i = 0, length = array.length; if (isSorted) { - if ("number" != typeof isSorted) return array[i = _.sortedIndex(array, item)] === item ? i : -1; + if ("number" != typeof isSorted) return i = _.sortedIndex(array, item), array[i] === item ? i : -1; i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; } if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted); diff --git a/crates/swc_ecma_minifier/tests/fixture/projects/underscore/6/output.js b/crates/swc_ecma_minifier/tests/fixture/projects/underscore/6/output.js index 0d4f68fab976..e1814aaf5d36 100644 --- a/crates/swc_ecma_minifier/tests/fixture/projects/underscore/6/output.js +++ b/crates/swc_ecma_minifier/tests/fixture/projects/underscore/6/output.js @@ -2,7 +2,7 @@ _.indexOf = function(array, item, isSorted) { if (null == array) return -1; var i = 0, length = array.length; if (isSorted) { - if ("number" != typeof isSorted) return array[i = _.sortedIndex(array, item)] === item ? i : -1; + if ("number" != typeof isSorted) return i = _.sortedIndex(array, item), array[i] === item ? i : -1; i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; } if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted); diff --git a/crates/swc_ecma_minifier/tests/projects/output/angular-1.2.5.js b/crates/swc_ecma_minifier/tests/projects/output/angular-1.2.5.js index cb11a14451f6..2adeafaa70d3 100644 --- a/crates/swc_ecma_minifier/tests/projects/output/angular-1.2.5.js +++ b/crates/swc_ecma_minifier/tests/projects/output/angular-1.2.5.js @@ -722,7 +722,7 @@ arg.replace(FN_ARG, function(all, underscore, name) { $inject.push(name); }); - }), fn.$inject = $inject) : isArray(fn) ? (assertArgFn(fn[last = fn.length - 1], "fn"), $inject = fn.slice(0, last)) : assertArgFn(fn, "fn", !0), $inject; + }), fn.$inject = $inject) : isArray(fn) ? (last = fn.length - 1, assertArgFn(fn[last], "fn"), $inject = fn.slice(0, last)) : assertArgFn(fn, "fn", !0), $inject; } function createInjector(modulesToLoad) { var INSTANTIATING = {}, providerSuffix = "Provider", path = [], loadedModules = new HashMap(), providerCache = { @@ -3990,7 +3990,7 @@ for(key in trackByIdFn = trackByIdExpFn || trackByIdObjFn, collectionKeys = [], collection)collection.hasOwnProperty(key) && "$" != key.charAt(0) && collectionKeys.push(key); collectionKeys.sort(); } - for(index = 0, arrayLength = collectionKeys.length, length = nextBlockOrder.length = collectionKeys.length; index < length; index++)if (value = collection[key = collection === collectionKeys ? index : collectionKeys[index]], assertNotHasOwnProperty(trackById = trackByIdFn(key, value, index), "`track by` id"), lastBlockMap.hasOwnProperty(trackById)) block = lastBlockMap[trackById], delete lastBlockMap[trackById], nextBlockMap[trackById] = block, nextBlockOrder[index] = block; + for(index = 0, arrayLength = collectionKeys.length, length = nextBlockOrder.length = collectionKeys.length; index < length; index++)if (key = collection === collectionKeys ? index : collectionKeys[index], value = collection[key], assertNotHasOwnProperty(trackById = trackByIdFn(key, value, index), "`track by` id"), lastBlockMap.hasOwnProperty(trackById)) block = lastBlockMap[trackById], delete lastBlockMap[trackById], nextBlockMap[trackById] = block, nextBlockOrder[index] = block; else if (nextBlockMap.hasOwnProperty(trackById)) throw forEach(nextBlockOrder, function(block) { block && block.scope && (lastBlockMap[block.id] = block); }), ngRepeatMinErr("dupes", "Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}", expression, trackById); @@ -4001,7 +4001,7 @@ element[NG_REMOVED] = !0; }), block.scope.$destroy()); for(index = 0, length = collectionKeys.length; index < length; index++){ - if (value = collection[key = collection === collectionKeys ? index : collectionKeys[index]], block = nextBlockOrder[index], nextBlockOrder[index - 1] && (previousNode = getBlockEnd(nextBlockOrder[index - 1])), block.scope) { + if (key = collection === collectionKeys ? index : collectionKeys[index], value = collection[key], block = nextBlockOrder[index], nextBlockOrder[index - 1] && (previousNode = getBlockEnd(nextBlockOrder[index - 1])), block.scope) { childScope = block.scope, nextNode = previousNode; do nextNode = nextNode.nextSibling; while (nextNode && nextNode[NG_REMOVED]) diff --git a/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js b/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js index 7864568630d6..ee62767a6711 100644 --- a/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js +++ b/crates/swc_ecma_minifier/tests/projects/output/jquery-1.9.1.js @@ -631,7 +631,7 @@ return jQuery.isFunction(value) ? this.each(function(i) { jQuery(this).toggleClass(value.call(this, i, this.className, stateVal), stateVal); }) : this.each(function() { - if ("string" === type) for(var className, i = 0, self = jQuery(this), state = stateVal, classNames = value.match(core_rnotwhite) || []; className = classNames[i++];)self[(state = isBool ? state : !self.hasClass(className)) ? "addClass" : "removeClass"](className); + if ("string" === type) for(var className, i = 0, self = jQuery(this), state = stateVal, classNames = value.match(core_rnotwhite) || []; className = classNames[i++];)state = isBool ? state : !self.hasClass(className), self[state ? "addClass" : "removeClass"](className); else (type === core_strundefined || "boolean" === type) && (this.className && jQuery._data(this, "__className__", this.className), this.className = this.className || !1 === value ? "" : jQuery._data(this, "__className__") || ""); }); }, @@ -1443,7 +1443,7 @@ "", argument ], Expr.setFilters.hasOwnProperty(pseudo.toLowerCase()) ? markFunction(function(seed, matches) { - for(var idx, matched = fn(seed, argument), i = matched.length; i--;)seed[idx = indexOf.call(seed, matched[i])] = !(matches[idx] = matched[i]); + for(var idx, matched = fn(seed, argument), i = matched.length; i--;)idx = indexOf.call(seed, matched[i]), seed[idx] = !(matches[idx] = matched[i]); }) : function(elem) { return fn(elem, 0, args); }) : fn; diff --git a/crates/swc_ecma_minifier/tests/projects/output/underscore-1.5.2.js b/crates/swc_ecma_minifier/tests/projects/output/underscore-1.5.2.js index 7e3412ab8ae8..d6c0e10b0751 100644 --- a/crates/swc_ecma_minifier/tests/projects/output/underscore-1.5.2.js +++ b/crates/swc_ecma_minifier/tests/projects/output/underscore-1.5.2.js @@ -218,7 +218,7 @@ if (null == array) return -1; var i = 0, length = array.length; if (isSorted) { - if ("number" != typeof isSorted) return array[i = _.sortedIndex(array, item)] === item ? i : -1; + if ("number" != typeof isSorted) return i = _.sortedIndex(array, item), array[i] === item ? i : -1; i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted; } if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);