Skip to content

Commit 7eda9c2

Browse files
committed
fix
1 parent 25db656 commit 7eda9c2

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

src/test/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export const tsSupportsStableNodeNextNode16 =
9999
// TS 4.5 is first version to understand .cts, .mts, .cjs, and .mjs extensions
100100
export const tsSupportsMtsCtsExtensions = semver.gte(ts.version, '4.5.0');
101101
export const tsSupportsImportAssertions = semver.gte(ts.version, '4.5.0');
102+
// TS 4.1 added jsx=react-jsx and react-jsxdev: https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#react-17-jsx-factories
103+
export const tsSupportsReact17JsxFactories = semver.gte(ts.version, '4.1.0');
102104
//#endregion
103105

104106
export const xfs = new NodeFS(fs);

src/test/transpilers.spec.ts

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
// Should consolidate them here.
44

55
import { context } from './testlib';
6-
import { ctxTsNode, testsDirRequire } from './helpers';
6+
import {
7+
ctxTsNode,
8+
testsDirRequire,
9+
tsSupportsImportAssertions,
10+
tsSupportsReact17JsxFactories,
11+
} from './helpers';
712
import { createSwcOptions } from '../transpilers/swc';
813
import * as expect from 'expect';
914
import { outdent } from 'outdent';
@@ -76,8 +81,11 @@ test.suite('swc', (test) => {
7681
);
7782

7883
test(macro, 'react', undefined, undefined);
79-
test(macro, 'react-jsx', 'automatic', undefined);
80-
test(macro, 'react-jsxdev', 'automatic', true);
84+
test.suite('react 17 jsx factories', (test) => {
85+
test.runIf(tsSupportsReact17JsxFactories);
86+
test(macro, 'react-jsx', 'automatic', undefined);
87+
test(macro, 'react-jsxdev', 'automatic', true);
88+
});
8189
});
8290
});
8391

@@ -113,31 +121,35 @@ test.suite('swc', (test) => {
113121
input,
114122
`const div = /*#__PURE__*/ React.createElement("div", null);`
115123
);
116-
test(
117-
compileMacro,
118-
{ jsx: 'react-jsx' },
119-
input,
120-
outdent`
121-
import { jsx as _jsx } from "react/jsx-runtime";
122-
const div = /*#__PURE__*/ _jsx("div", {});
123-
`
124-
);
125-
test(
126-
compileMacro,
127-
{ jsx: 'react-jsxdev' },
128-
input,
129-
outdent`
130-
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
131-
const div = /*#__PURE__*/ _jsxDEV("div", {}, void 0, false, {
132-
fileName: "input.tsx",
133-
lineNumber: 1,
134-
columnNumber: 13
135-
}, this);
136-
`
137-
);
124+
test.suite('react 17 jsx factories', (test) => {
125+
test.runIf(tsSupportsReact17JsxFactories);
126+
test(
127+
compileMacro,
128+
{ jsx: 'react-jsx' },
129+
input,
130+
outdent`
131+
import { jsx as _jsx } from "react/jsx-runtime";
132+
const div = /*#__PURE__*/ _jsx("div", {});
133+
`
134+
);
135+
test(
136+
compileMacro,
137+
{ jsx: 'react-jsxdev' },
138+
input,
139+
outdent`
140+
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
141+
const div = /*#__PURE__*/ _jsxDEV("div", {}, void 0, false, {
142+
fileName: "input.tsx",
143+
lineNumber: 1,
144+
columnNumber: 13
145+
}, this);
146+
`
147+
);
148+
});
138149
});
139150

140151
test.suite('preserves import assertions for json imports', (test) => {
152+
test.runIf(tsSupportsImportAssertions);
141153
test(
142154
'basic json import',
143155
compileMacro,

0 commit comments

Comments
 (0)