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): Make sequential inliner respect resolution order #6509
Merged
Merged
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d9aff2a
Add tests
kdy1 61356c5
config.json
kdy1 15e22a8
Update test refs without inliner
kdy1 80f1e93
config.json
kdy1 c30c1eb
Reduce
kdy1 5d67098
Reduce
kdy1 9da8114
Reduce
kdy1 6a4671c
config.json
kdy1 cce7d46
Reduce
kdy1 d789f5c
Reduce
kdy1 448b379
Reduce
kdy1 867f33f
Reduce
kdy1 b8c38c9
Reduce
kdy1 767dc36
Reduce
kdy1 aaff633
Reduce
kdy1 0db66f0
Reduce
kdy1 5488594
Move
kdy1 b28f16f
REduce
kdy1 f82fc2a
Fix?
kdy1 50f954b
Pinpoint
kdy1 8ca20ea
cleanup
kdy1 9d84795
Fix
kdy1 13ba767
Update test refs
kdy1 d4f60a6
Comment
kdy1 b1485c9
Optimize
kdy1 8e256ee
Pinpoint
kdy1 c69e7f1
cmt
kdy1 652068e
Update test refs
kdy1 f82d3dd
Use intersection
kdy1 4474ac9
Update test refs
kdy1 c593df3
Merge branch 'main' into min-joyride
swc-bot ef5d112
Merge branch 'main' into min-joyride
swc-bot File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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
7 changes: 7 additions & 0 deletions
7
crates/swc_ecma_minifier/tests/fixture/issues/6509/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,7 @@ | ||
{ | ||
"toplevel": true, | ||
"defaults": false, | ||
"inline": true, | ||
"sequences": true, | ||
"conditionals": true | ||
} |
113 changes: 113 additions & 0 deletions
113
crates/swc_ecma_minifier/tests/fixture/issues/6509/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,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 | ||
}, | ||
}; | ||
|
63 changes: 63 additions & 0 deletions
63
crates/swc_ecma_minifier/tests/fixture/issues/6509/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,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 | ||
} | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this true? Wouldn't
(1, obj)[obj = {}, 'key']
hit the same problem?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.
Oh, I was wrong. Nice catch, and thank you!