mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-09 13:38:03 -05:00
Prefer str
This commit is contained in:
@@ -39,12 +39,7 @@ fn main() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let resolved_path = resolve_entry_path(
|
||||
&file_path
|
||||
.to_str()
|
||||
.expect("Failed to convert to str")
|
||||
.to_string(),
|
||||
);
|
||||
let resolved_path = resolve_entry_path(file_path.to_str().expect("Failed to convert to str"));
|
||||
|
||||
let compile_result = compile(resolved_path, |path| {
|
||||
fs::read_to_string(path).map_err(|err| err.to_string())
|
||||
@@ -137,7 +132,7 @@ fn get_files_recursively(dir_path: &PathBuf) -> Result<Vec<PathBuf>, std::io::Er
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
pub fn resolve_entry_path(entry_path: &String) -> ResolvedPath {
|
||||
pub fn resolve_entry_path(entry_path: &str) -> ResolvedPath {
|
||||
// Like cwd (current working dir), but it's cwd/file.
|
||||
// This is a bit of a hack so we can use resolve_path to get the absolute path of the entry point.
|
||||
let cwd_file = ResolvedPath {
|
||||
|
||||
@@ -34,12 +34,7 @@ pub fn main() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let resolved_path = resolve_entry_path(
|
||||
&file_path
|
||||
.to_str()
|
||||
.expect("Failed to convert to str")
|
||||
.to_string(),
|
||||
);
|
||||
let resolved_path = resolve_entry_path(file_path.to_str().expect("Failed to convert to str"));
|
||||
|
||||
let compile_result = compile(resolved_path, |path| {
|
||||
fs::read_to_string(path).map_err(|err| err.to_string())
|
||||
@@ -85,7 +80,7 @@ fn get_files_recursively(dir_path: impl AsRef<Path>) -> Result<Vec<PathBuf>, std
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
fn resolve_entry_path(entry_path: &String) -> ResolvedPath {
|
||||
fn resolve_entry_path(entry_path: &str) -> ResolvedPath {
|
||||
// Like cwd (current working dir), but it's cwd/file.
|
||||
// This is a bit of a hack so we can use resolve_path to get the absolute path of the entry point.
|
||||
let cwd_file = ResolvedPath {
|
||||
|
||||
@@ -17,7 +17,7 @@ impl std::fmt::Display for ResolvedPath {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_path(importer_path: &ResolvedPath, path: &String) -> ResolvedPath {
|
||||
pub fn resolve_path(importer_path: &ResolvedPath, path: &str) -> ResolvedPath {
|
||||
let importer_path_buf = PathBuf::from(&importer_path.path);
|
||||
let parent = importer_path_buf.parent().unwrap_or_else(|| Path::new("/"));
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use valuescript_compiler::{resolve_path, ResolvedPath};
|
||||
|
||||
pub fn resolve_entry_path(entry_path: &String) -> ResolvedPath {
|
||||
pub fn resolve_entry_path(entry_path: &str) -> ResolvedPath {
|
||||
// Like cwd (current working dir), but it's cwd/file.
|
||||
// This is a bit of a hack so we can use resolve_path to get the absolute path of the entry point.
|
||||
let cwd_file = ResolvedPath {
|
||||
|
||||
@@ -54,12 +54,8 @@ mod tests {
|
||||
failed_paths.insert(rel_file_path.clone());
|
||||
}
|
||||
|
||||
let resolved_path = resolve_entry_path(
|
||||
&file_path
|
||||
.to_str()
|
||||
.expect("Failed to convert to str")
|
||||
.to_string(),
|
||||
);
|
||||
let resolved_path =
|
||||
resolve_entry_path(file_path.to_str().expect("Failed to convert to str"));
|
||||
|
||||
let compile_result = compile(resolved_path, |path| {
|
||||
fs::read_to_string(path).map_err(|err| err.to_string())
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
handle_diagnostics_cli::handle_diagnostics_cli, resolve_entry_path::resolve_entry_path,
|
||||
};
|
||||
|
||||
pub fn to_bytecode(format: RunFormat, file_path: &String) -> Bytecode {
|
||||
pub fn to_bytecode(format: RunFormat, file_path: &str) -> Bytecode {
|
||||
Bytecode::new(match format {
|
||||
RunFormat::TypeScript => {
|
||||
let resolved_entry_path = resolve_entry_path(file_path);
|
||||
@@ -47,7 +47,7 @@ pub enum RunFormat {
|
||||
Bytecode,
|
||||
}
|
||||
|
||||
pub fn format_from_path(file_path: &String) -> RunFormat {
|
||||
pub fn format_from_path(file_path: &str) -> RunFormat {
|
||||
let ext = Path::new(&file_path)
|
||||
.extension()
|
||||
.and_then(OsStr::to_str)
|
||||
|
||||
Reference in New Issue
Block a user