Skip to content

Commit

Permalink
fix(napi/transform): respect options.sourcemap for id (#7590)
Browse files Browse the repository at this point in the history
Don't pass `source_map_path` if `options.sourcemap` is undefined or
false; then, `IsolatedDeclarationsResult.map` should be undefined.

Downstream issue
unplugin/unplugin-isolated-decl#42

---------

Co-authored-by: Boshen <[email protected]>
  • Loading branch information
sxzz and Boshen authored Dec 3, 2024
1 parent b553d6f commit be2293a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 5 additions & 4 deletions napi/transform/src/isolated_declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion napi/transform/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit be2293a

Please sign in to comment.