"'
+ '"
"',
)
expect(
// @ts-expect-error
- jsxToString(
)
- ).toMatchInlineSnapshot('"
"')
+ jsxToString(
),
+ ).toMatchInlineSnapshot('"
"')
expect(
// @ts-expect-error
- jsxToString(
)
+ jsxToString(
),
).toMatchInlineSnapshot(
- '"
"'
+ '"
"',
)
})
test('style', () => {
expect(
- jsxToString(
)
- ).toMatchInlineSnapshot(
- '"
"'
- )
+ jsxToString(
),
+ ).toMatchInlineSnapshot('"
"')
// @ts-expect-error
expect(jsxToString(
)).toMatchInlineSnapshot(
- '"
"'
+ '"
"',
)
})
test('boolean', () => {
expect(
- jsxToString(
)
- ).toMatchInlineSnapshot('"
"')
+ jsxToString(
),
+ ).toMatchInlineSnapshot('"
"')
expect(
- jsxToString(
)
- ).toMatchInlineSnapshot('"
"')
+ jsxToString(
),
+ ).toMatchInlineSnapshot('"
"')
expect(
- jsxToString(
)
- ).toMatchInlineSnapshot('"
"')
+ jsxToString(
),
+ ).toMatchInlineSnapshot('"
"')
expect(
// @ts-expect-error
- jsxToString(
)
- ).toMatchInlineSnapshot(
- '"
"'
- )
+ jsxToString(
),
+ ).toMatchInlineSnapshot('"
"')
})
test('event', () => {
expect(
- jsxToString(
)
+ jsxToString(
),
).toMatchInlineSnapshot(
- '"
"'
+ '"
"',
)
expect(
jsxToString(
@@ -100,18 +95,18 @@ describe('jsxToString', () => {
onClick={function () {
console.warn('clicked')
}}
- >
- )
+ >,
+ ),
).toMatchInlineSnapshot(`
- "
"
+ }">"
`)
expect(
// @ts-expect-error
- jsxToString(
)
- ).toMatchInlineSnapshot('"
"')
+ jsxToString(
),
+ ).toMatchInlineSnapshot('"
"')
})
})
@@ -125,10 +120,10 @@ describe('jsxToString', () => {
123
<>foo>
-
- )
+
,
+ ),
).toMatchInlineSnapshot(
- '"
"'
+ '"
"',
)
})
@@ -145,16 +140,16 @@ describe('jsxToString', () => {
qux
abc
- >
- )
+ >,
+ ),
).toMatchInlineSnapshot(
- '"
foo
bar
baz
qux abc"'
+ '"
foo
bar
baz
qux abc"',
)
})
test('comments', () => {
expect(jsxToString(<>{/*hello*/}>)).toMatchInlineSnapshot(
- '""'
+ '""',
)
})
@@ -162,7 +157,7 @@ describe('jsxToString', () => {
describe('Literal', () => {
test('Primitive Literal', () => {
expect(jsxToString(<>{122}>)).toMatchInlineSnapshot('"122"')
- expect(jsxToString(<>{'false"'}>)).toMatchInlineSnapshot('"false\\""')
+ expect(jsxToString(<>{'false"'}>)).toMatchInlineSnapshot('"false""')
expect(jsxToString(<>{false}>)).toMatchInlineSnapshot('"false"')
expect(jsxToString(<>{null}>)).toMatchInlineSnapshot('"null"')
})
@@ -171,7 +166,7 @@ describe('jsxToString', () => {
expect(jsxToString(<>{`basic`}>)).toMatchInlineSnapshot('"basic"')
expect(jsxToString(<>{`1${1}${2}b`}>)).toMatchInlineSnapshot('"112b"')
expect(jsxToString(<>{`1${1 + 2 + 3}b`}>)).toMatchInlineSnapshot(
- '"16b"'
+ '"16b"',
)
expect(
jsxToString(
@@ -179,29 +174,35 @@ describe('jsxToString', () => {
<>{`a${true}${false}b${null}${true + 1 + 2 + false}${
// @ts-expect-error
null + 1
- }${[]}${{}}`}>
- )
+ }${[]}${{}}`}>,
+ ),
).toBe(
// @ts-expect-error
- `a${true}${false}b${null}${true + 1 + 2 + false}${null + 1}${[]}${{}}`
+ `a${true}${false}b${null}${true + 1 + 2 + false}${
+ // @ts-expect-error
+ null + 1
+ }${[]}${{}}`,
)
})
test('BigIntLiteral', () => {
expect(jsxToString(<>{1n}>)).toMatchInlineSnapshot('"1"')
expect(
- jsxToString(<>{100012301203123123123123n}>)
+ jsxToString(<>{100012301203123123123123n}>),
).toMatchInlineSnapshot('"100012301203123123123123"')
})
test('Object/Array Literal', () => {
+ // @ts-ignore
expect(jsxToString(<>{{}}>)).toMatchInlineSnapshot('"{}"')
+ // @ts-ignore
expect(jsxToString(<>{[{ foo: 'bar' }]}>)).toMatchInlineSnapshot(
- '"[{\\"foo\\":\\"bar\\"}]"'
+ '"[{"foo":"bar"}]"',
)
})
test('RegExpLiteral', () => {
+ // @ts-ignore
expect(jsxToString(<>{/a(.*)/g}>)).toMatchInlineSnapshot('"/a(.*)/g"')
})
})
@@ -209,36 +210,39 @@ describe('jsxToString', () => {
test('BinaryExpression', () => {
expect(jsxToString(<>{`a` + 1 + 'b'}>)).toMatchInlineSnapshot('"a1b"')
expect(
- jsxToString(<>{`a` + true + false + 'b'}>)
+ jsxToString(<>{`a` + true + false + 'b'}>),
).toMatchInlineSnapshot('"atruefalseb"')
// @ts-expect-error
expect(jsxToString(<>{1 + 2 + true}>)).toMatchInlineSnapshot('"4"')
expect(jsxToString(<>{1 - 2 + 3 / 5}>)).toMatchInlineSnapshot('"-0.4"')
expect(jsxToString(<>{2 ** 2}>)).toMatchInlineSnapshot('"4"')
expect(jsxToString(<>{false || 2}>)).toMatchInlineSnapshot('"2"')
+ // @ts-expect-error
expect(jsxToString(<>{null ?? 'foo'}>)).toMatchInlineSnapshot('"foo"')
expect(jsxToString(<>{1 && (false || 0.2)}>)).toMatchInlineSnapshot(
- '"0.2"'
+ '"0.2"',
)
expect(jsxToString(<>{false === false}>)).toMatchInlineSnapshot(
- '"true"'
+ '"true"',
)
})
test('UnaryExpression', () => {
expect(jsxToString(<>{!false}>)).toMatchInlineSnapshot('"true"')
expect(jsxToString(<>{typeof false}>)).toMatchInlineSnapshot(
- '"boolean"'
+ '"boolean"',
)
expect(jsxToString(<>{~100}>)).toMatchInlineSnapshot('"-101"')
expect(jsxToString(<>{+-100}>)).toMatchInlineSnapshot('"-100"')
expect(jsxToString(<>{'foo' in { foo: true }}>)).toMatchInlineSnapshot(
- '"true"'
+ '"true"',
)
})
test('ConditionalExpression', () => {
+ // @ts-expect-error
expect(jsxToString(<>{'1' ? 1 : 2}>)).toMatchInlineSnapshot('"1"')
+ // @ts-expect-error
expect(jsxToString(<>{void 1 ? 1 : 2}>)).toMatchInlineSnapshot('"2"')
})
@@ -259,35 +263,35 @@ describe('jsxToString', () => {
const s = 'str'
expect(() =>
- jsxToString(
)
+ jsxToString(
),
).toThrowErrorMatchingInlineSnapshot(
- '"Error: not supported Identifier: s"'
+ '[Error: Error: not supported Identifier: s]',
)
expect(() =>
- jsxToString(
)
+ jsxToString(
),
).toThrowErrorMatchingInlineSnapshot(
- '"Error: not supported Identifier: undefined"'
+ '[Error: Error: not supported Identifier: undefined]',
)
expect(() =>
- jsxToString(
{...[]}
)
+ jsxToString(
{...[]}
),
).toThrowErrorMatchingInlineSnapshot(
- '"Error: not supported JSXSpreadChild: {...[]}"'
+ '[Error: Error: not supported JSXSpreadChild: {...[]}]',
)
expect(() =>
- jsxToString(
)
+ jsxToString(
),
).toThrowErrorMatchingInlineSnapshot(
- '"Error: not supported Identifier: n"'
+ '[Error: Error: not supported Identifier: n]',
)
expect(() =>
- jsxToString(
)
+ jsxToString(
),
).toThrowErrorMatchingInlineSnapshot(
- '"Error: not supported UpdateExpression: n++"'
+ '[Error: Error: not supported UpdateExpression: n++]',
)
expect(() =>
// @ts-expect-error
- jsxToString(
)
+ jsxToString(
),
).toThrowErrorMatchingInlineSnapshot(
- '"Error: not supported Identifier: s"'
+ '[Error: Error: not supported Identifier: s]',
)
})
})
@@ -297,8 +301,8 @@ describe('jsxToString', () => {
jsxToString(
`///\\\\`${233}${'foo'}
-
- )
- ).toMatchInlineSnapshot('"
`///\\\\\\\\\\\\\\\\`$233$foo
"')
+
,
+ ),
+ ).toMatchInlineSnapshot('"
`///\\\\\\\\`$233$foo
"')
})
})
diff --git a/tsconfig.json b/tsconfig.json
index 06d6114..88d24db 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,18 +1,17 @@
{
"compilerOptions": {
- "target": "es2021",
+ "target": "es2022",
+ "jsx": "preserve",
+ "lib": ["es2022"],
"module": "esnext",
- "lib": ["es2021"],
- "strict": true,
- "esModuleInterop": true,
"moduleResolution": "node",
- "skipLibCheck": true,
- "noUnusedLocals": true,
"resolveJsonModule": true,
"types": ["node", "react"],
+ "strict": true,
"exactOptionalPropertyTypes": true,
- "jsx": "preserve"
+ "noUnusedLocals": true,
+ "esModuleInterop": true,
+ "skipLibCheck": true
},
- "include": ["src", "tests", "scripts"],
- "exclude": ["tests/fixtures"]
+ "include": ["src", "tests"]
}
diff --git a/tsup.config.ts b/tsup.config.ts
index 0197060..8ade12d 100644
--- a/tsup.config.ts
+++ b/tsup.config.ts
@@ -1,9 +1,11 @@
import { defineConfig } from 'tsup'
export default defineConfig({
- entry: ['./src'],
+ entry: ['./src/*.ts'],
format: ['cjs', 'esm'],
- target: 'node16.14',
+ target: 'node18',
+ splitting: true,
+ cjsInterop: true,
clean: true,
dts: true,
})