Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cspotcode committed Jun 27, 2022
1 parent 25db656 commit 7eda9c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export const tsSupportsStableNodeNextNode16 =
// TS 4.5 is first version to understand .cts, .mts, .cjs, and .mjs extensions
export const tsSupportsMtsCtsExtensions = semver.gte(ts.version, '4.5.0');
export const tsSupportsImportAssertions = semver.gte(ts.version, '4.5.0');
// TS 4.1 added jsx=react-jsx and react-jsxdev: https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#react-17-jsx-factories
export const tsSupportsReact17JsxFactories = semver.gte(ts.version, '4.1.0');
//#endregion

export const xfs = new NodeFS(fs);
Expand Down
62 changes: 37 additions & 25 deletions src/test/transpilers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// Should consolidate them here.

import { context } from './testlib';
import { ctxTsNode, testsDirRequire } from './helpers';
import {
ctxTsNode,
testsDirRequire,
tsSupportsImportAssertions,
tsSupportsReact17JsxFactories,
} from './helpers';
import { createSwcOptions } from '../transpilers/swc';
import * as expect from 'expect';
import { outdent } from 'outdent';
Expand Down Expand Up @@ -76,8 +81,11 @@ test.suite('swc', (test) => {
);

test(macro, 'react', undefined, undefined);
test(macro, 'react-jsx', 'automatic', undefined);
test(macro, 'react-jsxdev', 'automatic', true);
test.suite('react 17 jsx factories', (test) => {
test.runIf(tsSupportsReact17JsxFactories);
test(macro, 'react-jsx', 'automatic', undefined);
test(macro, 'react-jsxdev', 'automatic', true);
});
});
});

Expand Down Expand Up @@ -113,31 +121,35 @@ test.suite('swc', (test) => {
input,
`const div = /*#__PURE__*/ React.createElement("div", null);`
);
test(
compileMacro,
{ jsx: 'react-jsx' },
input,
outdent`
import { jsx as _jsx } from "react/jsx-runtime";
const div = /*#__PURE__*/ _jsx("div", {});
`
);
test(
compileMacro,
{ jsx: 'react-jsxdev' },
input,
outdent`
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
const div = /*#__PURE__*/ _jsxDEV("div", {}, void 0, false, {
fileName: "input.tsx",
lineNumber: 1,
columnNumber: 13
}, this);
`
);
test.suite('react 17 jsx factories', (test) => {
test.runIf(tsSupportsReact17JsxFactories);
test(
compileMacro,
{ jsx: 'react-jsx' },
input,
outdent`
import { jsx as _jsx } from "react/jsx-runtime";
const div = /*#__PURE__*/ _jsx("div", {});
`
);
test(
compileMacro,
{ jsx: 'react-jsxdev' },
input,
outdent`
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
const div = /*#__PURE__*/ _jsxDEV("div", {}, void 0, false, {
fileName: "input.tsx",
lineNumber: 1,
columnNumber: 13
}, this);
`
);
});
});

test.suite('preserves import assertions for json imports', (test) => {
test.runIf(tsSupportsImportAssertions);
test(
'basic json import',
compileMacro,
Expand Down

0 comments on commit 7eda9c2

Please sign in to comment.