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

JSX transforms in classic mode should still respect @jsxImportSource pragma #1933

Closed
kitsonk opened this issue Jul 19, 2021 · 2 comments · Fixed by #2004
Closed

JSX transforms in classic mode should still respect @jsxImportSource pragma #1933

kitsonk opened this issue Jul 19, 2021 · 2 comments · Fixed by #2004
Labels
Milestone

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Jul 19, 2021

Describe the bug

Even when transforming JSX, the @jsxImportSource pragma should cause the code to be transformed as the new "transforms".

Input code

/* @jsxImportSource react */
const p = () => (
  <div>Hello World</div>
);

Config

// pass options
swc_ecmascript::transforms::react::Options {
  runtime: react::Runtime::Classic,
  pragma: "React.createElement".to_string(),
  pragma_frag: "React.Fragment".to_string(),
  import_source: "react".to_string(),
  use_builtins: true,
  use_spread: true,
  development: false,
  ..Default::default()
}

Expected behavior

Output like Babel (tsc outputs something similar)

import { jsx as _jsx } from "react/jsx-runtime";

/* @jsxImportSource react */
const p = () => /*#__PURE__*/_jsx("div", {
  children: "Hello World"
});

Note that the mode react runtime is Classic and not Automatic.

Actual output

/* @jsxImportSource react */ const p = ()=>/*#__PURE__*/ React.createElement("div", null, "Hello World")
;

Version

swc_bundler: 0.46.0
swc_common: 0.11.0
swc_ecmascript: 0.46.0

Additional context

Trying to incorporate the new JSX transforms into Deno.

@kitsonk kitsonk added the C-bug label Jul 19, 2021
@kdy1 kdy1 modified the milestones: v1.2.66, v1.2.67 Jul 19, 2021
@kdy1 kdy1 modified the milestones: v1.2.67, v1.2.68, v1.2.72, v1.2.73, v1.2.74 Jul 31, 2021
@kdy1 kdy1 mentioned this issue Aug 4, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 4, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Aug 4, 2021
@kdy1 kdy1 closed this as completed in #2004 Aug 4, 2021
kdy1 added a commit that referenced this issue Aug 4, 2021
swc_ecma_codegen:
 - Fix codegen of regexp where `minify` = `true`. (#2000)

swc_ecma_transforms_react:
 - Respect `@jsxImportSource` in `classic` mode. (#1933)

swc:
 - Upgrade `base64`.
@kitsonk
Copy link
Contributor Author

kitsonk commented Aug 4, 2021

Awesome! thanks 👍

@swc-bot
Copy link
Collaborator

swc-bot commented Oct 23, 2022

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 Oct 23, 2022
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.

3 participants