Skip to content

Commit

Permalink
fix(isolated_declarations): Always emit module declarations that perf…
Browse files Browse the repository at this point in the history
…orm augmentation
  • Loading branch information
MichaelMitchell-at committed Aug 15, 2024
1 parent 9c700ed commit f0ebcb1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/oxc_isolated_declarations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ impl<'a> IsolatedDeclarations<'a> {
new_ast_stmts.push(Statement::ImportDeclaration(decl));
}
}
Statement::TSModuleDeclaration(decl) => {
if decl.kind.is_global() || decl.id.is_string_literal() {
new_ast_stmts.push(Statement::TSModuleDeclaration(decl));
}
}
_ => {}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'foo';
declare module 'foo' {
interface Foo {}
const foo = 42;
}

declare global {
interface Bar {}
const bar = 42 ;
}

// should not be emitted
module baz {
interface Baz {}
const baz = 42;
}

declare module x {
interface Qux {}
const qux = 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: crates/oxc_isolated_declarations/tests/mod.rs
input_file: crates/oxc_isolated_declarations/tests/fixtures/module-declaration.ts
---
==================== .D.TS ====================

import "foo";
declare module "foo" {
interface Foo {}
const foo = 42;
}
declare global {
interface Bar {}
const bar = 42;
}

0 comments on commit f0ebcb1

Please sign in to comment.