@@ -81,48 +81,51 @@ test.suite('swc', (test) => {
8181 } ) ;
8282 } ) ;
8383
84- test . suite ( 'transforms various forms of jsx' , ( test ) => {
85- const macro = test . macro (
86- ( compilerOptions : object , expectedOutput : string ) => [
87- ( ) => `${ JSON . stringify ( compilerOptions ) } ` ,
88- async ( t ) => {
89- const code = t . context . tsNodeUnderTest
90- . create ( {
91- swc : true ,
92- skipProject : true ,
93- compilerOptions : {
94- module : 'esnext' ,
95- ...compilerOptions ,
96- } ,
97- } )
98- . compile ( input , 'input.tsx' ) ;
99- expect ( code . replace ( / \/ \/ # s o u r c e M a p p i n g U R L .* / , '' ) . trim ( ) ) . toBe (
100- expectedOutput
101- ) ;
102- } ,
103- ]
104- ) ;
84+ const compileMacro = test . macro (
85+ ( compilerOptions : object , input : string , expectedOutput : string ) => [
86+ ( title ?: string ) => title ?? `${ JSON . stringify ( compilerOptions ) } ` ,
87+ async ( t ) => {
88+ const code = t . context . tsNodeUnderTest
89+ . create ( {
90+ swc : true ,
91+ skipProject : true ,
92+ compilerOptions : {
93+ module : 'esnext' ,
94+ ...compilerOptions ,
95+ } ,
96+ } )
97+ . compile ( input , 'input.tsx' ) ;
98+ expect ( code . replace ( / \/ \/ # s o u r c e M a p p i n g U R L .* / , '' ) . trim ( ) ) . toBe (
99+ expectedOutput
100+ ) ;
101+ } ,
102+ ]
103+ ) ;
105104
105+ test . suite ( 'transforms various forms of jsx' , ( test ) => {
106106 const input = outdent `
107107 const div = <div></div>;
108108 ` ;
109109
110110 test (
111- macro ,
111+ compileMacro ,
112112 { jsx : 'react' } ,
113+ input ,
113114 `const div = /*#__PURE__*/ React.createElement("div", null);`
114115 ) ;
115116 test (
116- macro ,
117+ compileMacro ,
117118 { jsx : 'react-jsx' } ,
119+ input ,
118120 outdent `
119121 import { jsx as _jsx } from "react/jsx-runtime";
120122 const div = /*#__PURE__*/ _jsx("div", {});
121123 `
122124 ) ;
123125 test (
124- macro ,
126+ compileMacro ,
125127 { jsx : 'react-jsxdev' } ,
128+ input ,
126129 outdent `
127130 import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
128131 const div = /*#__PURE__*/ _jsxDEV("div", {}, void 0, false, {
@@ -133,4 +136,22 @@ test.suite('swc', (test) => {
133136 `
134137 ) ;
135138 } ) ;
139+
140+ test . suite ( 'preserves import assertions for json imports' , ( test ) => {
141+ test (
142+ 'basic json import' ,
143+ compileMacro ,
144+ { module : 'esnext' } ,
145+ outdent `
146+ import document from './document.json' assert {type: 'json'};
147+ document;
148+ ` ,
149+ outdent `
150+ import document from './document.json' assert {
151+ type: 'json'
152+ };
153+ document;
154+ `
155+ ) ;
156+ } ) ;
136157} ) ;
0 commit comments