Skip to content

Namespace with declared members should not be type only #5197

@nayeemrmn

Description

@nayeemrmn

Describe the bug

A namespace with only declared values is treated as type-only and elided at transpilation, it should be transpiled to an empty namespace.

Input code

export namespace foo {
  export declare const bar: number;
}

Config

No response

Playground link

https://play.swc.rs/?version=1.2.212&code=H4sIAAAAAAAAA0utKMgvKlHIS8xNLS5ITE5VSMvPV6jmUlBIhUikpCbnJBalKiTn5xWXKCQlFlkp5JXmJqUWWXPVAgDtD19xPAAAAA%3D%3D&config=H4sIAAAAAAAAA0WOSwrDMAxE76J1Fm0XhfoOPYRwleDgH5ICNcZ3r21SshtmRk9TYRcLpkJGFuKhpETFLxjQkkksu6ywgEq3lA9qXSNvpL1B8rjdXz31KQmBWdELLRBcdGsZLJtCZhK5Ioyb%2FzdbZ4X0OYZR57vJfEK7GOedk%2FdZnBt%2BJYyKhrcAAAA%3D

Expected behavior

TSC output:

export var foo;
(function (foo) {
})(foo || (foo = {}));

https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBAOwIYFtgGcxIMbDgMwgjgG8AoOOUSWOAE2GwBsko9sIF14AjVgLkQBXFD2BQA3GQC+ZIA

Actual behavior

Produces empty module.

Version

swc_ecma_parser 0.111.0, swc_ecma_transforms_typescript 0.137.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions