From be2293a1b5c3fe00de30b1aa3353459d9045500e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Deng=20=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 3 Dec 2024 11:57:44 +0800 Subject: [PATCH] fix(napi/transform): respect `options.sourcemap` for id (#7590) Don't pass `source_map_path` if `options.sourcemap` is undefined or false; then, `IsolatedDeclarationsResult.map` should be undefined. Downstream issue https://github.com/unplugin/unplugin-isolated-decl/issues/42 --------- Co-authored-by: Boshen --- napi/transform/src/isolated_declaration.rs | 9 +++++---- napi/transform/test/transform.test.ts | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/napi/transform/src/isolated_declaration.rs b/napi/transform/src/isolated_declaration.rs index 88a0df50840ac..f8aa5938288ee 100644 --- a/napi/transform/src/isolated_declaration.rs +++ b/napi/transform/src/isolated_declaration.rs @@ -39,11 +39,12 @@ pub fn isolated_declaration( ) .build(&ret.program); + let source_map_path = match options.sourcemap { + Some(true) => Some(source_path.to_path_buf()), + _ => None, + }; let codegen_ret = CodeGenerator::new() - .with_options(CodegenOptions { - source_map_path: Some(source_path.to_path_buf()), - ..CodegenOptions::default() - }) + .with_options(CodegenOptions { source_map_path, ..CodegenOptions::default() }) .build(&transformed_ret.program); let errors = ret.errors.into_iter().chain(transformed_ret.errors).collect(); diff --git a/napi/transform/test/transform.test.ts b/napi/transform/test/transform.test.ts index ae93af02b607e..9c2f4e4cc8c67 100644 --- a/napi/transform/test/transform.test.ts +++ b/napi/transform/test/transform.test.ts @@ -25,10 +25,15 @@ describe('simple', () => { assert.equal(ret.code, 'export class A {}\n'); }); - it('uses the `declaration option`', () => { + it('uses the `declaration` option', () => { const ret = transform('test.ts', code, { typescript: { declaration: {} } }); assert.equal(ret.declaration, 'export declare class A {}\n'); }); + + it('uses the `sourcemap` option', () => { + const ret = transform('test.ts', code, { typescript: { declaration: {} }, sourcemap: true }); + assert(ret.declarationMap); + }); }); describe('transform', () => {