diff --git a/crates/oxc_isolated_declarations/src/lib.rs b/crates/oxc_isolated_declarations/src/lib.rs index a5cb746f7be1a..1efa2c86c58ac 100644 --- a/crates/oxc_isolated_declarations/src/lib.rs +++ b/crates/oxc_isolated_declarations/src/lib.rs @@ -425,8 +425,18 @@ impl<'a> IsolatedDeclarations<'a> { ) -> FxHashMap<&'a str, FxHashSet> { let mut assignable_properties_for_namespace = FxHashMap::<&str, FxHashSet>::default(); for stmt in stmts { - let Statement::ExportNamedDeclaration(decl) = stmt else { continue }; - let Some(Declaration::TSModuleDeclaration(decl)) = &decl.declaration else { continue }; + let decl = match stmt { + Statement::ExportNamedDeclaration(decl) => { + if let Some(Declaration::TSModuleDeclaration(decl)) = &decl.declaration { + decl + } else { + continue; + } + } + Statement::TSModuleDeclaration(decl) => decl, + _ => continue, + }; + if decl.kind != TSModuleDeclarationKind::Namespace { continue; } diff --git a/crates/oxc_isolated_declarations/tests/fixtures/expando-function.ts b/crates/oxc_isolated_declarations/tests/fixtures/expando-function.ts index 6856fbe2c75ab..c36a527cd1b1d 100644 --- a/crates/oxc_isolated_declarations/tests/fixtures/expando-function.ts +++ b/crates/oxc_isolated_declarations/tests/fixtures/expando-function.ts @@ -16,14 +16,19 @@ export namespace foo { export let baz = 100; } -// namespace must be exported -namespace foo { - export let bar = 42; -} - foo.bar = 42; foo.baz = 100; // unexported const zoo = (): void => {} -zoo.toString = () => {} \ No newline at end of file +zoo.toString = () => {} + +function qux(): void {} + +namespace qux { + export let woo = 42; +} + +qux.woo = 42; + +export default qux; \ No newline at end of file diff --git a/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap b/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap index fe3405c670e92..7bd2565b320e0 100644 --- a/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap +++ b/crates/oxc_isolated_declarations/tests/snapshots/expando-function.snap @@ -12,6 +12,11 @@ export declare namespace NS { export declare namespace foo { export let baz: number; } +declare function qux(): void; +declare namespace qux { + export let woo: number; +} +export default qux; ==================== Errors ==================== @@ -49,9 +54,9 @@ export declare namespace foo { x TS9023: Assigning properties to functions without declaring them is not | supported with --isolatedDeclarations. Add an explicit declaration for the | properties assigned to this function. - ,-[24:1] - 23 | - 24 | foo.bar = 42; + ,-[19:1] + 18 | + 19 | foo.bar = 42; : ^^^^^^^ - 25 | foo.baz = 100; + 20 | foo.baz = 100; `----