Skip to content

Commit

Permalink
feat(typescript): Port deno isolatedDeclarations updates (#9712)
Browse files Browse the repository at this point in the history
  • Loading branch information
CPunisher authored Nov 6, 2024
1 parent b49317a commit 6194044
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 135 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-bears-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
swc_typescript: major
---

feat(typescript): port deno `isolatedDeclarations` updates
12 changes: 6 additions & 6 deletions crates/swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,22 +971,21 @@ impl Compiler {
Default::default()
};

let dts_code = if emit_dts && program.is_module() {
let dts_code = if emit_dts {
let (leading, trailing) = comments.borrow_all();

let leading = std::rc::Rc::new(RefCell::new(leading.clone()));
let trailing = std::rc::Rc::new(RefCell::new(trailing.clone()));

let comments = SingleThreadedComments::from_leading_and_trailing(leading, trailing);
let mut checker = FastDts::new(fm.name.clone());
let mut module = program.clone();
let mut program = program.clone();

if let Some((base, resolver)) = config.resolver {
module.mutate(import_rewriter(base, resolver));
program.mutate(import_rewriter(base, resolver));
}

let mut module = module.expect_module();
let issues = checker.transform(&mut module);
let issues = checker.transform(&mut program);

for issue in issues {
let range = issue.range();
Expand All @@ -995,7 +994,8 @@ impl Compiler {
.struct_span_err(range.span, &issue.to_string())
.emit();
}
let dts_code = to_code_with_comments(Some(&comments), &module);

let dts_code = to_code_with_comments(Some(&comments), &program);
Some(dts_code)
} else {
None
Expand Down
Loading

0 comments on commit 6194044

Please sign in to comment.