Skip to content

Commit

Permalink
fix: input code
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Jul 9, 2024
1 parent d1c7666 commit 7e3e579
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const enum RSCError {
*
* Validate a file is a valid Server file or Client File
*
* @param code: string - the code to validate
*
* @param file_path: string - the path to the file
*
* @param is_server_layer: boolean - if the file is in the server layer, enable this in server side rendering
*/
export function validate(filePath: string, isServerLayer: boolean): Promise<ValidateResult>
export function validate(code: string, filePath: string, isServerLayer: boolean): ValidateResult

export interface ValidateResult {
isClientEntry: boolean
Expand Down
13 changes: 5 additions & 8 deletions src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use oxc_ast::visit::walk;
use oxc_parser::Parser;
use oxc_span::SourceType;
use oxc_syntax::scope::ScopeFlags;
use tokio::fs;

#[napi(object)]
pub struct ValidateResult {
Expand All @@ -33,22 +32,20 @@ pub struct ModuleImports {
///
/// Validate a file is a valid Server file or Client File
///
/// @param code: string - the code to validate
///
/// @param file_path: string - the path to the file
///
/// @param is_server_layer: boolean - if the file is in the server layer, enable this in server side rendering
#[napi]
pub async fn validate(
pub fn validate(
code: String,
file_path: String,
is_server_layer: bool,
) -> napi::Result<ValidateResult> {
let path = Path::new(&file_path);
let source_text = String::from_utf8(
fs::read(path)
.await
.map_err(|e| Error::new(Status::Unknown, format!("Failed to read file: {}", e)))?
).unwrap();
let source_type = SourceType::from_path(path).unwrap();
validate_string(&source_text, source_type, is_server_layer)
validate_string(&code, source_type, is_server_layer)
}

pub fn validate_string(
Expand Down

0 comments on commit 7e3e579

Please sign in to comment.