-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add an execution test for
paren_remover
(vercel/turborepo#8371)
### Description I copied the test from swc-project/swc#8442. This input file fails if the `paren_remover` is not applied. ### Testing Instructions Closes PACK-3110
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
crates/turbopack-tests/tests/execution/turbopack/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,34 @@ | ||
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; | ||
} | ||
|
||
it("should work", () => { | ||
expect(toFixed(1.2345, 2, Math.round, 1)).toBe("1.23"); | ||
}); |