Skip to content

Commit 52e37e6

Browse files
danieldelcoreNoviny
authored andcommitted
feat: option to hide errors (#91)
1 parent 2e473dd commit 52e37e6

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

.changeset/long-vans-lay/changes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "releases": [{ "name": "kind2string", "type": "patch" }], "dependents": [] }

.changeset/long-vans-lay/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Introduces flag "EXTRACT_REACT_TYPES_HIDE_ERRORS" to suppress errors

packages/kind2string/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as K from 'extract-react-types'
1414
import { resolveToLast, resolveFromGeneric, reduceToObj } from './utils';
1515

1616
const unaryWhiteList = ['-', '+', '!'];
17+
const hideErrors = !!process.env.EXTRACT_REACT_TYPES_HIDE_ERRORS;
1718

1819
function mapConvertAndJoin(array, joiner = ', ') {
1920
if (!Array.isArray(array)) return '';
@@ -185,7 +186,7 @@ const converters = {
185186
const object = resolveToLast(type.object);
186187
const property = convert(type.property);
187188

188-
if (!object) {
189+
if (!object && !hideErrors) {
189190
console.error('Object property does not exist on this member expression');
190191
return '';
191192
}

packages/kind2string/src/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const hideErrors = !!process.env.EXTRACT_REACT_TYPES_HIDE_ERRORS;
2+
13
export function resolveToLast(type /*: MemberExpression | Obj | Id*/) {
24
switch (type.kind) {
35
case 'id':
@@ -7,8 +9,10 @@ export function resolveToLast(type /*: MemberExpression | Obj | Id*/) {
79
case 'memberExpression':
810
return resolveToLast(type.object);
911
default:
10-
/* eslint-disable-next-line no-console */
11-
console.error(`Unexpected initial type of member expression`, JSON.stringify(type));
12+
if (hideErrors) {
13+
/* eslint-disable-next-line no-console */
14+
console.error(`Unexpected initial type of member expression`, JSON.stringify(type));
15+
}
1216
break;
1317
}
1418
}

0 commit comments

Comments
 (0)