swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.18k stars 1.23k forks source link

Custom statement for importing `importSource` for jsx #2663

Open aelbore opened 3 years ago

aelbore commented 3 years ago

Describe the bug

react is not the only library/framework that uses jsx, for example atomicojs (https://atomico.gitbook.io/doc/) i want to import source other that react.

Input code

const App = () => {
    return (
        <h1>Hello World</h1>
    )
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": true
    },
    "transform": {
      "react": {
        "pragma": "_jsx",
        "runtime": "automatic",
        "importSource": "import {h as _jsx} from 'atomico'"
      }
    },
    "target": "es2019",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}

Playground link

No response

Expected behavior

import {h as _jsx} from 'atomico'
const App = ()=>{
    return _jsx("h1", {
        children: "Hello World"
    });
};

Version

1.2.106

Additional context

No response

kdy1 commented 3 years ago

You can already use import sources other than react.

aelbore commented 3 years ago

@kdy1 is this applicable to my case? or is there something i missed in the config? i tried importSource but it always add jsx-runtime