Skip to content

Commit 1126dbd

Browse files
committed
wip
1 parent fc34061 commit 1126dbd

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
"scripts": {
1111
"build": "rollup -c",
1212
"prebuild": "rm -rf dist/",
13+
"build:esm": "tsc --module esnext --outDir lib/esm",
14+
"build:cjs": "tsc --module commonjs --outDir lib/cjs",
1315
"lint": "eslint --ext ts --ext tsx src/",
1416
"lint:fix": "yarn run lint -- --fix",
1517
"prettier:fix": "prettier --write \"**/*.{ts,tsx,js,json}\"",
1618
"test": "jest",
1719
"test:watch": "jest --watch",
1820
"release": "./release.sh",
19-
"smoke": "node tests/smoke/run",
20-
"ts:progress": "tsc > tserrors.txt"
21+
"smoke": "node tests/smoke/run"
2122
},
2223
"author": {
2324
"name": "Algolia, Inc.",
@@ -31,6 +32,7 @@
3132
"@babel/preset-env": "7.15.6",
3233
"@babel/preset-react": "7.14.5",
3334
"@babel/preset-typescript": "^7.15.0",
35+
"@rollup/plugin-typescript": "^8.2.5",
3436
"@types/enzyme": "^3.10.9",
3537
"@types/enzyme-adapter-react-16": "^1.0.6",
3638
"@types/jest": "^27.0.2",

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,8 +2,13 @@
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 */
69
/* eslint-disable react/prop-types */
10+
/* eslint-disable prefer-arrow-callback */
11+
/* eslint-disable react/destructuring-assignment */
712

813
import React, { Fragment, Component } from 'react';
914
import { render, screen } from '@testing-library/react';
@@ -802,6 +807,7 @@ describe('reactElementToJSXString(ReactElement)', () => {
802807
it('reactElementToJSXString(<TestComponent />, { useBooleanShorthandSyntax: false })', () => {
803808
expect(
804809
reactElementToJSXString(
810+
// eslint-disable-next-line react/jsx-boolean-value
805811
<TestComponent testTrue={true} testFalse={false} />,
806812
{
807813
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,
@@ -104,7 +103,7 @@ const onlyMeaningfulChildren = (children: ReactNode): boolean =>
104103
children !== '';
105104

106105
const filterProps = (
107-
originalProps: Record<string, any>,
106+
originalProps: Record<string, unknown>,
108107
cb: (propsValue: any, propsName: string) => boolean
109108
): Record<string, any> => {
110109
const filteredProps: Record<string, any> = {};
@@ -137,6 +136,7 @@ const parseReactElement = (
137136
}
138137

139138
const displayName = displayNameFn(element);
139+
// @ts-expect-error: flow to TS
140140
const props = filterProps(element.props, noChildren);
141141

142142
const key = element.key;
@@ -148,9 +148,11 @@ const parseReactElement = (
148148

149149
// @ts-expect-error: flow to TS
150150
const defaultProps = filterProps(element.type.defaultProps || {}, noChildren);
151+
// @ts-expect-error: flow to TS
151152
const children = React.Children.toArray(element.props.children)
152153
.filter(onlyMeaningfulChildren)
153-
.map((child: ReactElement<any>) => parseReactElement(child, options));
154+
// @ts-expect-error: flow to TS
155+
.map((child: ReactNode) => parseReactElement(child, options));
154156

155157
if (supportFragment && element.type === Fragment) {
156158
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. */

0 commit comments

Comments
 (0)