Skip to content

Commit db91521

Browse files
committed
wip
1 parent 0e99e35 commit db91521

File tree

6 files changed

+54
-22
lines changed

6 files changed

+54
-22
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
"scripts": {
1010
"build": "rollup -c",
1111
"prebuild": "rm -rf dist/",
12+
"build:esm": "tsc --module esnext --outDir lib/esm",
13+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
1214
"lint": "eslint --ext ts --ext tsx src/",
1315
"lint:fix": "yarn run lint -- --fix",
1416
"prettier:fix": "prettier --write \"**/*.{ts,tsx,js,json}\"",
1517
"test": "jest",
1618
"test:watch": "jest --watch",
1719
"release": "./release.sh",
18-
"smoke": "node tests/smoke/run",
19-
"ts:progress": "tsc > tserrors.txt"
20+
"smoke": "node tests/smoke/run"
2021
},
2122
"author": {
2223
"name": "Algolia, Inc.",
@@ -30,6 +31,7 @@
3031
"@babel/preset-env": "7.15.6",
3132
"@babel/preset-react": "7.14.5",
3233
"@babel/preset-typescript": "^7.15.0",
34+
"@rollup/plugin-typescript": "^8.2.5",
3335
"@types/enzyme": "^3.10.9",
3436
"@types/enzyme-adapter-react-16": "^1.0.6",
3537
"@types/jest": "^27.0.2",
@@ -83,8 +85,6 @@
8385
"react-is": "17.0.2"
8486
},
8587
"jest": {
86-
"setupFilesAfterEnv": [
87-
"<rootDir>tests/setupTests.ts"
88-
]
88+
"setupFilesAfterEnv": ["<rootDir>tests/setupTests.ts"]
8989
}
9090
}

rollup.config.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ import babel from 'rollup-plugin-babel';
22
import resolve from 'rollup-plugin-node-resolve';
33
import builtins from 'rollup-plugin-node-builtins';
44
import globals from 'rollup-plugin-node-globals';
5+
import typescript from '@rollup/plugin-typescript';
56
import pkg from './package.json';
67

78
const extractExternals = () => [
89
...Object.keys(pkg.dependencies || {}),
910
...Object.keys(pkg.peerDependencies || {}),
1011
];
1112

12-
export default {
13-
input: 'src/index.js',
13+
/**
14+
* @type {import('rollup').RollupOptions}
15+
*/
16+
const config = {
17+
input: 'src/index.ts',
1418
output: [
1519
{
1620
file: pkg.main,
@@ -25,19 +29,22 @@ export default {
2529
],
2630
external: extractExternals(),
2731
plugins: [
28-
babel({
29-
babelrc: false,
30-
exclude: 'node_modules/**',
31-
presets: [
32-
'@babel/preset-env',
33-
'@babel/preset-react',
34-
'@babel/preset-typescript',
35-
],
36-
}),
32+
typescript(),
33+
// babel({
34+
// babelrc: false,
35+
// exclude: 'node_modules/**',
36+
// presets: [
37+
// '@babel/preset-env',
38+
// '@babel/preset-react',
39+
// '@babel/preset-typescript',
40+
// ],
41+
// }),
3742
resolve({
3843
mainFields: ['module', 'main', 'jsnext', 'browser'],
3944
}),
4045
globals(),
4146
builtins(),
4247
],
4348
};
49+
50+
export default config;

src/index.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
* @jest-environment jsdom
33
*/
44

5+
/* eslint-disable react/prefer-stateless-function */
6+
/* eslint-disable react/jsx-curly-brace-presence */
7+
/* eslint-disable max-classes-per-file */
58
/* eslint-disable react/no-string-refs */
9+
/* eslint-disable prefer-arrow-callback */
10+
/* eslint-disable react/destructuring-assignment */
611

712
import React, { Fragment, Component } from 'react';
813
import { createRenderer } from 'react-test-renderer/shallow';
@@ -842,6 +847,7 @@ describe('reactElementToJSXString(ReactElement)', () => {
842847
it('reactElementToJSXString(<TestComponent />, { useBooleanShorthandSyntax: false })', () => {
843848
expect(
844849
reactElementToJSXString(
850+
// eslint-disable-next-line react/jsx-boolean-value
845851
<TestComponent testTrue={true} testFalse={false} />,
846852
{
847853
useBooleanShorthandSyntax: false,

src/parser/parseReactElement.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { ReactElement, ReactNode } from 'react';
2-
import React, { Fragment } from 'react';
1+
import React, { Fragment, ReactElement, ReactNode } from 'react';
32
import {
43
ForwardRef,
54
isContextConsumer,
@@ -106,7 +105,7 @@ const onlyMeaningfulChildren = (children: ReactNode): boolean =>
106105
children !== '';
107106

108107
const filterProps = (
109-
originalProps: Record<string, any>,
108+
originalProps: Record<string, unknown>,
110109
cb: (propsValue: any, propsName: string) => boolean
111110
): Record<string, any> => {
112111
const filteredProps: Record<string, any> = {};
@@ -139,6 +138,7 @@ const parseReactElement = (
139138
}
140139

141140
const displayName = displayNameFn(element);
141+
// @ts-expect-error: flow to TS
142142
const props = filterProps(element.props, noChildren);
143143

144144
// @ts-expect-error: flow to TS
@@ -156,9 +156,11 @@ const parseReactElement = (
156156

157157
// @ts-expect-error: flow to TS
158158
const defaultProps = filterProps(element.type.defaultProps || {}, noChildren);
159+
// @ts-expect-error: flow to TS
159160
const children = React.Children.toArray(element.props.children)
160161
.filter(onlyMeaningfulChildren)
161-
.map((child: ReactElement<any>) => parseReactElement(child, options));
162+
// @ts-expect-error: flow to TS
163+
.map((child: ReactNode) => parseReactElement(child, options));
162164

163165
if (supportFragment && element.type === Fragment) {
164166
return createReactFragmentTreeNode(key, children);

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// "composite": true, /* Enable project compilation */
2323
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
2424
// "removeComments": true, /* Do not emit comments to output. */
25-
"noEmit": true /* Do not emit outputs. */,
25+
// "noEmit": true, /* Do not emit outputs. */
2626
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
2727
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
2828
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
@@ -46,7 +46,7 @@
4646
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
4747

4848
/* Module Resolution Options */
49-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
49+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
5050
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
5151
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
5252
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,14 @@
16761676
"@nodelib/fs.scandir" "2.1.5"
16771677
fastq "^1.6.0"
16781678

1679+
"@rollup/plugin-typescript@^8.2.5":
1680+
version "8.2.5"
1681+
resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-8.2.5.tgz#e0319761b2b5105615e5a0c371ae05bc2984b7de"
1682+
integrity sha512-QL/LvDol/PAGB2O0S7/+q2HpSUNodpw7z6nGn9BfoVCPOZ0r4EALrojFU29Bkoi2Hr2jgTocTejJ5GGWZfOxbQ==
1683+
dependencies:
1684+
"@rollup/pluginutils" "^3.1.0"
1685+
resolve "^1.17.0"
1686+
16791687
"@rollup/pluginutils@^3.0.9":
16801688
version "3.0.10"
16811689
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.0.10.tgz#a659b9025920378494cd8f8c59fbf9b3a50d5f12"
@@ -1685,6 +1693,15 @@
16851693
estree-walker "^1.0.1"
16861694
picomatch "^2.2.2"
16871695

1696+
"@rollup/pluginutils@^3.1.0":
1697+
version "3.1.0"
1698+
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
1699+
integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==
1700+
dependencies:
1701+
"@types/estree" "0.0.39"
1702+
estree-walker "^1.0.1"
1703+
picomatch "^2.2.2"
1704+
16881705
"@sindresorhus/is@^0.14.0":
16891706
version "0.14.0"
16901707
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"

0 commit comments

Comments
 (0)