-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Apply
paren-remover
while minifying (#8348)
### Description This is required to fix https://vercel.slack.com/archives/C04KC8A53T7/p1717599802994489 ### Testing Instructions Closes SWC-171
- Loading branch information
Showing
7 changed files
with
83 additions
and
0 deletions.
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
30 changes: 30 additions & 0 deletions
30
crates/turbopack-tests/tests/snapshot/minification/paren-remover/input/index.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,30 @@ | ||
function toFixed(value, maxDecimals, roundingFunction, optionals) { | ||
var splitValue = value.toString().split('.'), | ||
minDecimals = maxDecimals - (optionals || 0), | ||
|
||
optionalsRegExp, | ||
power, | ||
output; | ||
var boundedPrecisions; | ||
// var unused = 'xxxx'; | ||
|
||
// Use the smallest precision value possible to avoid errors from floating point representation | ||
if (splitValue.length === 2) { | ||
boundedPrecisions = Math.min(Math.max(splitValue[1].length, minDecimals), maxDecimals); | ||
} else { | ||
boundedPrecisions = minDecimals; | ||
} | ||
|
||
power = Math.pow(10, boundedPrecisions); | ||
|
||
// Multiply up by precision, round accurately, then divide and use native toFixed(): | ||
output = (roundingFunction(value + 'e+' + boundedPrecisions) / power).toFixed(boundedPrecisions); | ||
|
||
if (optionals > maxDecimals - boundedPrecisions) { | ||
optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecisions)) + '}$'); | ||
output = output.replace(optionalsRegExp, ''); | ||
} | ||
|
||
return output; | ||
} | ||
toFixed(1.2345, 2, Math.round, 1); |
3 changes: 3 additions & 0 deletions
3
crates/turbopack-tests/tests/snapshot/minification/paren-remover/options.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,3 @@ | ||
{ | ||
"minifyType": "Minify" | ||
} |
29 changes: 29 additions & 0 deletions
29
...put/79fb1_turbopack-tests_tests_snapshot_minification_paren-remover_input_index_80e2cf.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...79fb1_turbopack-tests_tests_snapshot_minification_paren-remover_input_index_80e2cf.js.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...put/79fb1_turbopack-tests_tests_snapshot_minification_paren-remover_input_index_eab450.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...79fb1_turbopack-tests_tests_snapshot_minification_paren-remover_input_index_eab450.js.map
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.