Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions napi/parser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,9 @@ export interface ParserOptions {
}
export interface ParseResult {
program: string
comments: Array<Comment>
comments: string
errors: Array<string>
}
export interface Comment {
type: string
value: 'Line' | 'Block'
start: number
end: number
}
/**
* Parse without returning anything.
* This is for benchmark purposes such as measuring napi communication overhead.
Expand Down
1 change: 1 addition & 0 deletions napi/parser/parse.bench.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ for (const {filename, code} of files) {
const res = parseSync(code, {sourceFilename: filename});
assert(res.errors.length === 0);
JSON.parse(res.program);
JSON.parse(res.comments);
});
}
12 changes: 6 additions & 6 deletions napi/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ pub struct ParserOptions {
#[napi(object)]
pub struct ParseResult {
pub program: String,
pub comments: Vec<Comment>,
pub comments: String,
pub errors: Vec<String>,
}

#[napi(object)]
pub struct Comment {
#[derive(Serialize)]
pub struct Comment<'a> {
pub r#type: &'static str,
#[napi(ts_type = "'Line' | 'Block'")]
pub value: String,
pub value: &'a str,
pub start: u32,
pub end: u32,
}
Expand Down Expand Up @@ -121,11 +120,12 @@ pub fn parse_sync(source_text: String, options: Option<ParserOptions>) -> ParseR
CommentKind::SingleLine => "Line",
CommentKind::MultiLine => "Block",
},
value: span.source_text(&source_text).to_string(),
value: span.source_text(&source_text),
start: span.start,
end: span.end,
})
.collect::<Vec<Comment>>();
let comments = serde_json::to_string(&comments).unwrap();

ParseResult { program, comments, errors }
}
Expand Down