mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(napi/transform): make isolated_declaration options optional (#5880)
closes #5871
This commit is contained in:
1 parent
52c99031ae
commit
6c04fa1e46
2 files changed
+8
-6
No files matched your search
Vendored
+2
-2
@@ -18,10 +18,10 @@ export interface Es2015BindingOptions {
|
||||
}
|
||||
|
||||
/** TypeScript Isolated Declarations for Standalone DTS Emit */
|
||||
export declare function isolatedDeclaration(filename: string, sourceText: string, options: IsolatedDeclarationsOptions): IsolatedDeclarationsResult
|
||||
export declare function isolatedDeclaration(filename: string, sourceText: string, options?: IsolatedDeclarationsOptions | undefined | null): IsolatedDeclarationsResult
|
||||
|
||||
export interface IsolatedDeclarationsOptions {
|
||||
sourcemap: boolean
|
||||
sourcemap?: boolean
|
||||
}
|
||||
|
||||
export interface IsolatedDeclarationsResult {
|
||||
|
||||
@@ -13,9 +13,10 @@ pub struct IsolatedDeclarationsResult {
|
||||
pub errors: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[napi(object)]
|
||||
pub struct IsolatedDeclarationsOptions {
|
||||
pub sourcemap: bool,
|
||||
pub sourcemap: Option<bool>,
|
||||
}
|
||||
|
||||
/// TypeScript Isolated Declarations for Standalone DTS Emit
|
||||
@@ -24,22 +25,23 @@ pub struct IsolatedDeclarationsOptions {
|
||||
pub fn isolated_declaration(
|
||||
filename: String,
|
||||
source_text: String,
|
||||
options: IsolatedDeclarationsOptions,
|
||||
options: Option<IsolatedDeclarationsOptions>,
|
||||
) -> IsolatedDeclarationsResult {
|
||||
let source_type = SourceType::from_path(&filename).unwrap_or_default().with_typescript(true);
|
||||
let allocator = Allocator::default();
|
||||
let options = options.unwrap_or_default();
|
||||
let ctx = TransformContext::new(
|
||||
&allocator,
|
||||
&filename,
|
||||
&source_text,
|
||||
source_type,
|
||||
Some(TransformOptions { sourcemap: Some(options.sourcemap), ..Default::default() }),
|
||||
Some(TransformOptions { sourcemap: options.sourcemap, ..Default::default() }),
|
||||
);
|
||||
let transformed_ret = build_declarations(&ctx);
|
||||
|
||||
IsolatedDeclarationsResult {
|
||||
code: transformed_ret.source_text,
|
||||
map: options.sourcemap.then(|| transformed_ret.source_map.map(Into::into)).flatten(),
|
||||
map: options.sourcemap.and_then(|_| transformed_ret.source_map.map(Into::into)),
|
||||
errors: ctx.take_and_render_reports(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user