fix(isolated_declarations): namespaces that are default exported should be considered for expando functions (#4935)

This should be ok but currently has an error reported
```ts
function foo(): void {}

namespace foo {
  export let bar = 42;
}

foo.bar = 42;

export default foo;
```

Co-authored-by: MichaelMitchell-at <=>
Co-authored-by: Dunqing <dengqing0821@gmail.com>
Co-authored-by: Don Isaac <donald.isaac@gmail.com>
This commit is contained in:
michaelm 2024-08-18 23:24:05 -04:00 committed by GitHub
parent 7859f58b4e
commit 185eb206a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 12 deletions

View file

@ -425,8 +425,18 @@ impl<'a> IsolatedDeclarations<'a> {
) -> FxHashMap<&'a str, FxHashSet<Atom>> { ) -> FxHashMap<&'a str, FxHashSet<Atom>> {
let mut assignable_properties_for_namespace = FxHashMap::<&str, FxHashSet<Atom>>::default(); let mut assignable_properties_for_namespace = FxHashMap::<&str, FxHashSet<Atom>>::default();
for stmt in stmts { for stmt in stmts {
let Statement::ExportNamedDeclaration(decl) = stmt else { continue }; let decl = match stmt {
let Some(Declaration::TSModuleDeclaration(decl)) = &decl.declaration else { continue }; Statement::ExportNamedDeclaration(decl) => {
if let Some(Declaration::TSModuleDeclaration(decl)) = &decl.declaration {
decl
} else {
continue;
}
}
Statement::TSModuleDeclaration(decl) => decl,
_ => continue,
};
if decl.kind != TSModuleDeclarationKind::Namespace { if decl.kind != TSModuleDeclarationKind::Namespace {
continue; continue;
} }

View file

@ -16,14 +16,19 @@ export namespace foo {
export let baz = 100; export let baz = 100;
} }
// namespace must be exported
namespace foo {
export let bar = 42;
}
foo.bar = 42; foo.bar = 42;
foo.baz = 100; foo.baz = 100;
// unexported // unexported
const zoo = (): void => {} const zoo = (): void => {}
zoo.toString = () => {} zoo.toString = () => {}
function qux(): void {}
namespace qux {
export let woo = 42;
}
qux.woo = 42;
export default qux;

View file

@ -12,6 +12,11 @@ export declare namespace NS {
export declare namespace foo { export declare namespace foo {
export let baz: number; export let baz: number;
} }
declare function qux(): void;
declare namespace qux {
export let woo: number;
}
export default qux;
==================== Errors ==================== ==================== Errors ====================
@ -49,9 +54,9 @@ export declare namespace foo {
x TS9023: Assigning properties to functions without declaring them is not x TS9023: Assigning properties to functions without declaring them is not
| supported with --isolatedDeclarations. Add an explicit declaration for the | supported with --isolatedDeclarations. Add an explicit declaration for the
| properties assigned to this function. | properties assigned to this function.
,-[24:1] ,-[19:1]
23 | 18 |
24 | foo.bar = 42; 19 | foo.bar = 42;
: ^^^^^^^ : ^^^^^^^
25 | foo.baz = 100; 20 | foo.baz = 100;
`---- `----