Skip to content

Commit

Permalink
Cow
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Mar 8, 2023
1 parent 734b3c6 commit 586c223
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/swc_ecma_parser/src/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//!
//! See https://tc39.github.io/ecma262/#sec-literals-numeric-literals
use std::fmt::Write;
use std::{borrow::Cow, fmt::Write};

use either::Either;
use num_bigint::BigInt as BigIntValue;
Expand Down Expand Up @@ -153,11 +153,14 @@ impl<'a> Lexer<'a> {
raw_val.push_str(raw.0.as_ref().unwrap());
}

raw_val
// Remove number separator from number
.replace('_', "")
.parse()
.expect("failed to parse float using rust's impl")
// Remove number separator from number
if raw_val.contains('_') {
Cow::Owned(raw_val.replace('_', ""))
} else {
Cow::Borrowed(&raw_val)
}
.parse()
.expect("failed to parse float using rust's impl")
};
}

Expand Down

0 comments on commit 586c223

Please sign in to comment.