1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = getJSXOptions;
|
7 |
|
8 | var _path = _interopRequireDefault(require("path"));
|
9 |
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 |
|
12 | const JSX_EXTENSIONS = {
|
13 | '.jsx': true,
|
14 | '.tsx': true
|
15 | };
|
16 | const JSX_PRAGMA = {
|
17 | react: {
|
18 | pragma: 'React.createElement',
|
19 | pragmaFrag: 'React.Fragment'
|
20 | },
|
21 | preact: {
|
22 | pragma: 'h',
|
23 | pragmaFrag: 'Fragment'
|
24 | },
|
25 | nervjs: {
|
26 | pragma: 'Nerv.createElement',
|
27 | pragmaFrag: undefined
|
28 | },
|
29 | hyperapp: {
|
30 | pragma: 'h',
|
31 | pragmaFrag: undefined
|
32 | }
|
33 | };
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | async function getJSXOptions(config) {
|
40 | if (!config.isSource) {
|
41 | return null;
|
42 | }
|
43 |
|
44 |
|
45 | const pkg = await config.getPackage();
|
46 | const reactLib = Object.keys(JSX_PRAGMA).find(libName => pkg && (pkg.dependencies && pkg.dependencies[libName] || pkg.devDependencies && pkg.devDependencies[libName]));
|
47 | const pragma = reactLib ? JSX_PRAGMA[reactLib].pragma : undefined;
|
48 | const pragmaFrag = reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined;
|
49 |
|
50 | if (pragma || JSX_EXTENSIONS[_path.default.extname(config.searchPath)]) {
|
51 | return {
|
52 | plugins: [['@babel/plugin-transform-react-jsx', {
|
53 | pragma,
|
54 | pragmaFrag
|
55 | }]]
|
56 | };
|
57 | }
|
58 | } |
\ | No newline at end of file |