mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(napi/transform): make isolated_declaration options optional (#5880)
closes #5871
This commit is contained in:
parent
52c99031ae
commit
6c04fa1e46
2 changed files with 8 additions and 6 deletions
4
napi/transform/index.d.ts
vendored
4
napi/transform/index.d.ts
vendored
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue