Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fix(rome_js_analyze): noPrecisionLoss correctly handle 1 digit ints
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Dec 21, 2022
1 parent 8d5b2ea commit d38a5b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/rome_js_analyze/src/analyzers/nursery/no_precision_loss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,18 @@ impl NormalizedNumber<'_> {
}

fn to_scientific(&self) -> String {
format!(
"{}.{}{}e{}",
&self.digits[..1],
&self.digits[1..],
self.digits_rest,
self.exponent - 1
)
let fraction = &self.digits[1..];
if fraction.is_empty() && self.digits_rest.is_empty() {
format!("{}e{}", &self.digits[..1], self.exponent - 1)
} else {
format!(
"{}.{}{}e{}",
&self.digits[..1],
fraction,
self.digits_rest,
self.exponent - 1
)
}
}

fn precision(&self) -> usize {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var x = 1
var x = 12345
var x = 123.456
var x = -123.456
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 92
expression: valid.js
---
# Input
```js
var x = 1
var x = 12345
var x = 123.456
var x = -123.456
Expand Down

0 comments on commit d38a5b6

Please sign in to comment.