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 <boshenc@gmail.com>
This commit is contained in:
Kevin Deng 三咲智子 2024-12-03 11:57:44 +08:00 committed by GitHub
parent b553d6ff9c
commit be2293a1b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 5 deletions

View file

@ -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();

View file

@ -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<T> {}\n');
});
it('uses the `sourcemap` option', () => {
const ret = transform('test.ts', code, { typescript: { declaration: {} }, sourcemap: true });
assert(ret.declarationMap);
});
});
describe('transform', () => {