summaryrefslogtreecommitdiff
path: root/cli/tests/testdata/compiler_api_test.ts
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2021-11-09 12:26:39 +1100
committerGitHub <noreply@github.com>2021-11-09 12:26:39 +1100
commitf5eb177f50a0bf37bc6bd9d87b447c73a53b6ea5 (patch)
tree1990dadf311de59b45c677e234219a161f3ebf9d /cli/tests/testdata/compiler_api_test.ts
parent45425c114610516287c8e5831c9b6f023dfc8180 (diff)
feat(cli): support React 17 JSX transforms (#12631)
Closes #8440
Diffstat (limited to 'cli/tests/testdata/compiler_api_test.ts')
-rw-r--r--cli/tests/testdata/compiler_api_test.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/cli/tests/testdata/compiler_api_test.ts b/cli/tests/testdata/compiler_api_test.ts
index 9870908d1..42d6f54eb 100644
--- a/cli/tests/testdata/compiler_api_test.ts
+++ b/cli/tests/testdata/compiler_api_test.ts
@@ -557,3 +557,81 @@ Deno.test({
assertEquals(sourceMap.sourcesContent.length, 1);
},
});
+
+Deno.test({
+ name: "Deno.emit() - JSX import source pragma",
+ async fn() {
+ const { files } = await Deno.emit(
+ "file:///a.tsx",
+ {
+ sources: {
+ "file:///a.tsx": `/** @jsxImportSource https://example.com/jsx */
+
+ export function App() {
+ return (
+ <div><></></div>
+ );
+ }`,
+ "https://example.com/jsx/jsx-runtime": `export function jsx(
+ _type,
+ _props,
+ _key,
+ _source,
+ _self,
+ ) {}
+ export const jsxs = jsx;
+ export const jsxDEV = jsx;
+ export const Fragment = Symbol("Fragment");
+ console.log("imported", import.meta.url);
+ `,
+ },
+ },
+ );
+ assert(files["file:///a.tsx.js"]);
+ assert(
+ files["file:///a.tsx.js"].startsWith(
+ `import { Fragment as _Fragment, jsx as _jsx } from "https://example.com/jsx/jsx-runtime";\n`,
+ ),
+ );
+ },
+});
+
+Deno.test({
+ name: "Deno.emit() - JSX import source no pragma",
+ async fn() {
+ const { files } = await Deno.emit(
+ "file:///a.tsx",
+ {
+ compilerOptions: {
+ jsx: "react-jsx",
+ jsxImportSource: "https://example.com/jsx",
+ },
+ sources: {
+ "file:///a.tsx": `export function App() {
+ return (
+ <div><></></div>
+ );
+ }`,
+ "https://example.com/jsx/jsx-runtime": `export function jsx(
+ _type,
+ _props,
+ _key,
+ _source,
+ _self,
+ ) {}
+ export const jsxs = jsx;
+ export const jsxDEV = jsx;
+ export const Fragment = Symbol("Fragment");
+ console.log("imported", import.meta.url);
+ `,
+ },
+ },
+ );
+ assert(files["file:///a.tsx.js"]);
+ assert(
+ files["file:///a.tsx.js"].startsWith(
+ `import { Fragment as _Fragment, jsx as _jsx } from "https://example.com/jsx/jsx-runtime";\n`,
+ ),
+ );
+ },
+});