refactor(rslint_parser): Use `f64` and `i64` to parse numbers, remove lexical
MODIFY
Cargo.lock
Cargo.lock
@@ -50,12 +50,6 @@ version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
-[[package]]
-name = "arrayvec"
-version = "0.5.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
-
[[package]]
name = "ascii_table"
version = "3.0.2"
@@ -751,29 +745,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
-[[package]]
-name = "lexical"
-version = "5.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f404a90a744e32e8be729034fc33b90cf2a56418fbf594d69aa3c0214ad414e5"
-dependencies = [
- "cfg-if",
- "lexical-core",
-]
-
-[[package]]
-name = "lexical-core"
-version = "0.7.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
-dependencies = [
- "arrayvec",
- "bitflags",
- "cfg-if",
- "ryu",
- "static_assertions",
-]
-
[[package]]
name = "libc"
version = "0.2.112"
@@ -1344,7 +1315,6 @@ dependencies = [
"drop_bomb",
"expect-test",
"indexmap",
- "lexical",
"num-bigint",
"rome_rowan",
"rslint_errors",
@@ -1596,12 +1566,6 @@ dependencies = [
"lock_api",
]
-[[package]]
-name = "static_assertions"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
-
[[package]]
name = "strsim"
version = "0.10.0"

MODIFY
crates/rslint_parser/Cargo.toml
crates/rslint_parser/Cargo.toml
@@ -13,7 +13,6 @@ rslint_syntax = { path = "../rslint_syntax", version = "0.1" }
rslint_lexer = { path = "../rslint_lexer", version = "0.2", features = ["highlight"] }
rome_rowan = { path = "../rome_rowan", version = "0.0.0" }
num-bigint = "0.4.3"
-lexical = { version = "5.2.0", features = ["radix"] }
drop_bomb = "0.1.5"
bitflags = "1.3.2"
indexmap = "1.8.0"

MODIFY
crates/rslint_parser/src/numbers.rs
crates/rslint_parser/src/numbers.rs
//! JS Number parsing.
-use lexical::parse_radix;
+use std::str::FromStr;
pub use num_bigint::BigInt;
@@ -15,16 +15,18 @@ fn split_into_radix_and_number(num: &str) -> (u32, String) {
/// Parse a js number as a string into a number.
pub fn parse_js_number(num: &str) -> Option<f64> {
- let (radix, raw) = split_into_radix_and_number(num);
+ let (mut radix, raw) = split_into_radix_and_number(num);
- if radix == 10 && raw.starts_with('0') {
// account for legacy octal literals
- if let Ok(parsed) = parse_radix::<f64, _>(raw.as_bytes(), 8) {
- return Some(parsed);
- }
+ if raw.starts_with('0') && !raw.contains(&['8', '9']) {
+ radix = 8
}
- parse_radix::<f64, _>(raw.as_bytes(), radix as u8).ok()
+ if radix == 10 {
+ f64::from_str(&raw).ok()
+ } else {
+ i64::from_str_radix(&raw, radix).map(|num| num as f64).ok()
+ }
}
/// Parse a big int number as a string into a number.

refactor(rslint_parser): Use `f64` and `i64` to parse numbers, remove lexical (#1957)