chore(cli): Upgrade jsonc_parser to 0.17 (#9977)

Use new parse_to_serde_value as it's faster and less code here.
This commit is contained in:
David Sherret 2021-04-04 07:27:13 -04:00 committed by GitHub
parent 1312a57984
commit eed4e29337
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 45 deletions

View file

@ -44,15 +44,15 @@ base64 = "0.13.0"
byteorder = "1.4.2"
clap = "2.33.3"
dissimilar = "1.0.2"
dprint-plugin-json = "0.9.0"
dprint-plugin-markdown = "0.6.0"
dprint-plugin-json = "0.10.1"
dprint-plugin-markdown = "0.6.2"
dprint-plugin-typescript = "0.41.0"
encoding_rs = "0.8.28"
env_logger = "0.8.2"
filetime = "0.2.14"
http = "0.2.3"
indexmap = { version = "1.6.1", features = ["serde"] }
jsonc-parser = "0.15.1"
jsonc-parser = { version = "0.17.0", features = ["serde"] }
lazy_static = "1.4.0"
libc = "0.2.86"
log = { version = "0.4.14", features = ["serde"] }

View file

@ -8,13 +8,11 @@ use deno_core::serde::Serializer;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use jsonc_parser::JsonValue;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fmt;
use std::path::Path;
use std::path::PathBuf;
use std::str::FromStr;
/// The transpile options that are significant out of a user provided tsconfig
/// file, that we want to deserialize out of the final config for a transpile.
@ -148,31 +146,6 @@ pub fn json_merge(a: &mut Value, b: &Value) {
}
}
/// Convert a jsonc libraries `JsonValue` to a serde `Value`.
fn jsonc_to_serde(j: JsonValue) -> Value {
match j {
JsonValue::Array(arr) => {
let vec = arr.into_iter().map(jsonc_to_serde).collect();
Value::Array(vec)
}
JsonValue::Boolean(bool) => Value::Bool(bool),
JsonValue::Null => Value::Null,
JsonValue::Number(num) => {
let number =
serde_json::Number::from_str(&num).expect("could not parse number");
Value::Number(number)
}
JsonValue::Object(obj) => {
let mut map = serde_json::map::Map::new();
for (key, json_value) in obj.into_iter() {
map.insert(key, jsonc_to_serde(json_value));
}
Value::Object(map)
}
JsonValue::String(str) => Value::String(str),
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct TsConfigJson {
@ -220,8 +193,8 @@ pub fn parse_config(
path: &Path,
) -> Result<(Value, Option<IgnoredCompilerOptions>), AnyError> {
assert!(!config_text.is_empty());
let jsonc = jsonc_parser::parse_to_value(config_text)?.unwrap();
let config: TsConfigJson = serde_json::from_value(jsonc_to_serde(jsonc))?;
let jsonc = jsonc_parser::parse_to_serde_value(config_text)?.unwrap();
let config: TsConfigJson = serde_json::from_value(jsonc)?;
if let Some(compiler_options) = config.compiler_options {
parse_compiler_options(&compiler_options, Some(path.to_owned()), false)