1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-03 17:08:35 -05:00

chore: update jsonc_parser to 0.20 (#15316)

This commit is contained in:
David Sherret 2022-07-26 21:24:56 -04:00 committed by cjihrig
parent 7733597166
commit a6c2387d8e
No known key found for this signature in database
GPG key ID: 7434390BDBE9B9C5
4 changed files with 27 additions and 24 deletions

8
Cargo.lock generated
View file

@ -1371,9 +1371,9 @@ dependencies = [
[[package]]
name = "dprint-plugin-json"
version = "0.15.3"
version = "0.15.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1e5fe967adc699073aa92ce4c931de1932ee58f4b755c3b32fed15580636558"
checksum = "db127f7ccb9b497b5b32e5e8eca4b19a7f191e38a3505195f029d5fbb728e51a"
dependencies = [
"anyhow",
"dprint-core",
@ -2342,9 +2342,9 @@ dependencies = [
[[package]]
name = "jsonc-parser"
version = "0.19.0"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34bbb0cd324c4ed32861be1d00c58635b94d03a2d2c70f6aec5f1a419c532783"
checksum = "ccff81ff106af12c93c06935c50ee0723325095e8cbb8c0b41ed276b9469c4cb"
dependencies = [
"serde_json",
]

View file

@ -63,7 +63,7 @@ clap_complete = "=3.1.2"
clap_complete_fig = "=3.1.5"
data-url = "=0.1.1"
dissimilar = "=1.0.3"
dprint-plugin-json = "=0.15.3"
dprint-plugin-json = "=0.15.4"
dprint-plugin-markdown = "=0.13.3"
dprint-plugin-typescript = "=0.71.1"
encoding_rs = "=0.8.31"
@ -73,7 +73,7 @@ fancy-regex = "=0.9.0"
http = "=0.2.6"
import_map = "=0.12.1"
indexmap = "1.8.1"
jsonc-parser = { version = "=0.19.0", features = ["serde"] }
jsonc-parser = { version = "=0.20.0", features = ["serde"] }
libc = "=0.2.126"
log = { version = "=0.4.17", features = ["serde"] }
mitata = '=0.0.7'

View file

@ -557,23 +557,24 @@ impl ConfigFile {
text: &str,
specifier: &ModuleSpecifier,
) -> Result<Self, AnyError> {
let jsonc = match jsonc_parser::parse_to_serde_value(text) {
Ok(None) => json!({}),
Ok(Some(value)) if value.is_object() => value,
Ok(Some(_)) => {
return Err(anyhow!(
"config file JSON {:?} should be an object",
specifier,
))
}
Err(e) => {
return Err(anyhow!(
"Unable to parse config file JSON {:?} because of {}",
specifier,
e.to_string()
))
}
};
let jsonc =
match jsonc_parser::parse_to_serde_value(text, &Default::default()) {
Ok(None) => json!({}),
Ok(Some(value)) if value.is_object() => value,
Ok(Some(_)) => {
return Err(anyhow!(
"config file JSON {:?} should be an object",
specifier,
))
}
Err(e) => {
return Err(anyhow!(
"Unable to parse config file JSON {:?} because of {}",
specifier,
e.to_string()
))
}
};
let json: ConfigFileJson = serde_json::from_value(jsonc)?;
Ok(Self {

View file

@ -203,7 +203,9 @@ fn update_config_text(
) -> Option<String> {
use jsonc_parser::ast::ObjectProp;
use jsonc_parser::ast::Value;
let ast = jsonc_parser::parse_to_ast(text, &Default::default()).ok()?;
let ast =
jsonc_parser::parse_to_ast(text, &Default::default(), &Default::default())
.ok()?;
let obj = match ast.value {
Some(Value::Object(obj)) => obj,
_ => return None, // shouldn't happen, so ignore