Struct tsconfig::TsConfig

source ·
pub struct TsConfig {
    pub exclude: Option<Vec<String>>,
    pub extends: Option<String>,
    pub files: Option<Vec<String>>,
    pub include: Option<Vec<String>>,
    pub references: Option<References>,
    pub type_acquisition: Option<TypeAcquisition>,
    pub compiler_options: Option<CompilerOptions>,
}
Expand description

The main struct representing a parsed .tsconfig file.

Fields§

§exclude: Option<Vec<String>>§extends: Option<String>§files: Option<Vec<String>>§include: Option<Vec<String>>§references: Option<References>§type_acquisition: Option<TypeAcquisition>§compiler_options: Option<CompilerOptions>

Implementations§

source§

impl TsConfig

source

pub fn parse_file<P: AsRef<Path>>(path: &P) -> Result<TsConfig>

Parses a .tsconfig file into a TsConfig.

The extends field will be respected, allowing for one .tsconfig file to inherit properties from another. Comments and trailing commas are both allowed, although they are not valid JSON.

§Example

Assuming the following .tsconfig files:

tsconfig.base.json:

{
    "useDefineForClassFields": false,
    "traceResolution": true,
    "jsx": "preserve",
}

tsconfig.inherits.json:

{
    "extends": "./tsconfig.base.json",
    "compilerOptions": {
        "traceResolution": false,
        "declaration": true,
        "jsx": "react-jsxdev",
    }
}
use std::path::Path;
use tsconfig::TsConfig;
let path = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap())
    .join("test/tsconfig.inherits.json");
let config = TsConfig::parse_file(&path).unwrap();

assert_eq!(
    config
        .compiler_options
        .clone()
        .unwrap()
        .use_define_for_class_fields,
    Some(false)
);

assert_eq!(
    config.compiler_options.clone().unwrap().declaration,
    Some(true)
);

assert_eq!(
    config.compiler_options.unwrap().trace_resolution,
    Some(false)
);
source

pub fn parse_str(json: &str) -> Result<TsConfig>

Parse a JSON string into a single TsConfig.

The ‘extends’ field will be ignored. Comments and trailing commas are both allowed, although they are not valid JSON.

§Example
use tsconfig::{TsConfig, Jsx};
let json = r#"{"compilerOptions": {"jsx": /*here's a comment*/ "react-jsx"},}"#;

let config = TsConfig::parse_str(json).unwrap();
assert_eq!(config.compiler_options.unwrap().jsx, Some(Jsx::ReactJsx));     

Trait Implementations§

source§

impl Clone for TsConfig

source§

fn clone(&self) -> TsConfig

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TsConfig

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for TsConfig

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,