Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS] Exporting Namespace Aliases Breaks export = Syntax #9632

Closed
manuth opened this issue Oct 11, 2024 · 2 comments · Fixed by #9635
Closed

[TS] Exporting Namespace Aliases Breaks export = Syntax #9632

manuth opened this issue Oct 11, 2024 · 2 comments · Fixed by #9635
Assignees
Labels
Milestone

Comments

@manuth
Copy link

manuth commented Oct 11, 2024

Describe the bug

Exporting namespace aliases (using the export import = ...-syntax) breaks the use of the export = syntax.

Input code

meta.ts

export const version = "1.0.0";

nameof.ts

import * as meta from "./meta.js";

function nameof(obj: unknown) { }

namespace nameof {
    export import version = meta.version;
}

export = nameof;

Config

{
    "jsc": {
        "parser": {
            "syntax": "typescript",
            "isModule": false
        }
    },
    "module": "commonjs"
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.35&code=H4sIAAAAAAAAA8tLzE0tLkhMTlXITS1JVKjmUgCC1IqC%2FKISheT8vOIShbLUouLM%2FDwFWwUlQz0DPQMla65aLq48uD4QKz8NVWdmLphCaAUZrgflgvVDFUJkrLkA%2BHamM4cAAAA%3D&config=H4sIAAAAAAAAA1WPSw7DMAhE9z6FxbrbbnqHHsJySeTIPwGRakW5e%2B3UTpsdzAw82JTWsLCFh95qWZtsiJHOvipcoph3VUBKRrbkssBtuMLNmoxnPKT964AYmlHaFPK9x8GnxDjiXQsuuqn8A20KmZD5GmxRE2ePV5zqSAjptR5mf6Qd2%2FB1W0hxYfglB%2FHcDo6fY1xoRbV%2FALu7P%2BkZAQAA

SWC Info output


    Operating System:
        Platform: linux
        Arch: x64
        Machine Type: x86_64
        Version: #1 SMP PREEMPT_DYNAMIC Fri, 04 Oct 2024 21:51:11 +0000
        CPU: (32 cores)
            Models: AMD Ryzen Threadripper 2950X 16-Core Processor

    Binaries:
        Node: 22.9.0
        npm: 10.8.3
        Yarn: 1.22.22
        pnpm: N/A

    Relevant Packages:
        @swc/core: 1.7.35
        @swc/helpers: N/A
        @swc/types: 0.1.13
        typescript: 5.6.3

    SWC Config:
        output: N/A
        .swcrc path: N/A

    Next.js info:
        output: N/A

Expected behavior

Output should equal to the one in TypeScript Playground:
https://www.typescriptlang.org/play/?module=1#code/HYQwtgpgzgDiDGEAEkAuIkG8BQS9IgA8YB7AJ1SXhOCkoDcIyoBLGpAXiQCIBGAOgAMQ7gG5sAX2zZQkWAmSyIJAGZZc+IqQpIWYbQyat2XNCH6NmbYOKnYt5SlyWrxQA

"use strict";
var meta;
(function (meta) {
    meta.version = "1.0.0";
})(meta || (meta = {}));
var nameof;
(function (nameof) {
    nameof.version = meta.version;
})(nameof || (nameof = {}));
module.exports = nameof;

Actual behavior

Following error is displayed:

  × An export assignment cannot be used in a module with other exported elements.
   ╭─[./packages/nameof/src/index.cts:9:1]
 6 │     export import version = meta.version;
 7 │ }
 8 │ 
 9 │ export = nameof;
   · ────────────────
   ╰────

Version

1.7.35

Additional context

A workaround which seems to work currently is using export const =, export var = or export let = instead of export import =.

Namespace aliases are documented here:
https://www.typescriptlang.org/docs/handbook/namespaces.html#aliases

@manuth
Copy link
Author

manuth commented Oct 12, 2024

Wow - that was fast!
Thank you guys so much 😄

@kdy1 kdy1 modified the milestones: Planned, v1.7.36 Oct 12, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Nov 15, 2024

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

4 participants