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

Typescript namespace local component #8594

Closed
ValeryLosik opened this issue Feb 2, 2024 · 1 comment · Fixed by #8596
Closed

Typescript namespace local component #8594

ValeryLosik opened this issue Feb 2, 2024 · 1 comment · Fixed by #8596
Assignees
Labels
Milestone

Comments

@ValeryLosik
Copy link

ValeryLosik commented Feb 2, 2024

Describe the bug

SWC incorrectly transpiles local usage of react component within namespace

Input code

import * as React from 'react';

export namespace FooNs {
  export const Shared = () => 'I\'m shared component';
  export const Main = () => <Shared/>;
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2015",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.107&code=H4sIAAAAAAAAA8vMLcgvKlHQUkgsVghKTUwuUUgrys9VUC8CsdWtebl4uVIrwEryEnNTiwsSk1MV3PLz%2FYoVqnm5FBSgcsn5ecUlCsEZiUWpKQq2ChqaCrZ2CuqeMeq5CsUQweR8oEV5qXlgM9H0%2BSZm5sF12UBM0bcDqqsFAMZ0SDGeAAAA&config=H4sIAAAAAAAAA1WPTQ7CIBCF9z0FmbULNdGFd%2FAQBKcNhr8w00TS9O4FSlF3zPfe480sgxDwJgUPseRnHoKMhLHPmVByLD%2BZAKeApKIODKdDZSoSxxkrWXcBWMYJuYSQrufLrQXAeE%2BY8SgNYWNWOz2m30rlbYhI9G8sVukm0%2FN749BawfrXXMV2Sll33%2BAOX9NR1j8GTc8jWe9YN%2BKXZ60WAQAA

Expected behavior

SWC should output code like this.

import * as React from 'react';
export var FooNs;
(function(FooNs) {
    FooNs.Shared = ()=>'I\'m shared component';
    FooNs.Main = ()=>React.createElement(FooNs.Shared, null); // <===== Fix
})(FooNs || (FooNs = {}));

Actual behavior

Transpiled code produces an error "Shared is not defined"

import * as React from 'react';
export var FooNs;
(function(FooNs) {
    FooNs.Shared = ()=>'I\'m shared component';
    FooNs.Main = ()=>React.createElement(Shared, null);
})(FooNs || (FooNs = {}));

Version

1.3.107

Additional context

Interesting, that swc produces correct code, if we don't export 'Shared' component from namespace
Input

import * as React from 'react';

export namespace FooNs {
  const Shared = () => 'I\'m shared component';
  export const Main = () => <Shared/>;
}

Output

import * as React from 'react';
export var FooNs;
(function(FooNs) {
    const Shared = ()=>'I\'m shared component';
    FooNs.Main = ()=>React.createElement(Shared, null);
})(FooNs || (FooNs = {}));
@swc-bot
Copy link
Collaborator

swc-bot commented Mar 6, 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 Mar 6, 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