Skip to content

Commit 8700e57

Browse files
authored
chore: bump Babel & react-docgen (#4454)
1 parent 5646905 commit 8700e57

22 files changed

+1517
-1166
lines changed

.babel-preset.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ const browsers = [
1616
]
1717

1818
const plugins = [
19-
['@babel/plugin-proposal-class-properties', { loose: true }],
20-
['@babel/plugin-proposal-optional-chaining', { loose: true }],
2119
'@babel/plugin-proposal-export-default-from',
22-
'@babel/plugin-proposal-export-namespace-from',
2320
'@babel/plugin-syntax-dynamic-import',
2421
[
2522
'@babel/plugin-transform-runtime',

.circleci/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ general:
55
ignore:
66
- gh-pages
77

8+
orbs:
9+
browser-tools: circleci/[email protected]
10+
811
docker_defaults: &docker_defaults
912
docker:
10-
- image: circleci/node:16-browsers
13+
- image: cimg/node:16.16-browsers
1114
working_directory: ~/project/semantic-ui-react
1215

1316
environment:
@@ -32,6 +35,7 @@ jobs:
3235
key: v6-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
3336
paths:
3437
- ~/.cache/yarn
38+
- browser-tools/install-chrome
3539
- persist_to_workspace:
3640
root: ~/
3741
paths:

gulp/plugins/gulp-component-menu.js renamed to gulp/plugins/gulp-component-menu.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Vinyl from 'vinyl'
22
import gutil from 'gulp-util'
33
import through from 'through2'
44

5-
import getComponentInfo from './util/getComponentInfo'
5+
import getComponentInfo from './util/getComponentInfo.mjs'
66

77
const pluginName = 'gulp-component-menu'
88

gulp/plugins/gulp-example-menu.js renamed to gulp/plugins/gulp-example-menu.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import _ from 'lodash'
44
import path from 'path'
55
import through from 'through2'
66

7-
import { parseDocSection } from './util'
7+
import parseDocSection from './util/parseDocSection.mjs'
88

99
const SECTION_ORDER = {
1010
Types: 1,

gulp/plugins/gulp-react-docgen.js renamed to gulp/plugins/gulp-react-docgen.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Vinyl from 'vinyl'
22
import gutil from 'gulp-util'
33
import through from 'through2'
44

5-
import { getComponentInfo } from './util'
5+
import getComponentInfo from './util/getComponentInfo.mjs'
66

77
const pluginName = 'gulp-react-docgen'
88

gulp/plugins/util/getComponentInfo.js renamed to gulp/plugins/util/getComponentInfo.mjs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import _ from 'lodash'
22
import path from 'path'
3-
import { defaultHandlers, parse, resolver } from 'react-docgen'
3+
import { builtinResolvers, defaultHandlers, parse } from 'react-docgen'
44
import fs from 'fs'
55

6-
import config from '../../../config'
7-
import parseDefaultValue from './parseDefaultValue'
8-
import parseDocblock from './parseDocblock'
9-
import parserCustomHandler from './parserCustomHandler'
10-
import parseType from './parseType'
6+
import parseDefaultValue from './parseDefaultValue.mjs'
7+
import parseDocblock from './parseDocblock.mjs'
8+
import parserCustomHandler from './parserCustomHandler.mjs'
9+
import parseType from './parseType.mjs'
10+
11+
const config = (await import('../../../config.js')).default
1112

1213
const getComponentInfo = (filepath) => {
1314
const absPath = path.resolve(process.cwd(), filepath)
@@ -24,10 +25,11 @@ const getComponentInfo = (filepath) => {
2425
const componentType = path.basename(path.dirname(dir)).replace(/s$/, '')
2526

2627
// start with react-docgen info
27-
const components = parse(contents, resolver.findAllComponentDefinitions, [
28-
...defaultHandlers,
29-
parserCustomHandler,
30-
])
28+
const resolver = new builtinResolvers.FindAllDefinitionsResolver()
29+
const components = parse(contents, {
30+
resolver,
31+
handlers: [...defaultHandlers, parserCustomHandler],
32+
})
3133

3234
if (!components.length) {
3335
throw new Error(`Could not find a component definition in "${filepath}".`)

gulp/plugins/util/index.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.

gulp/plugins/util/parseDocSection.js renamed to gulp/plugins/util/parseDocSection.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash'
2-
import traverse from '@babel/traverse'
2+
import { traverse } from '@babel/core'
33

4-
import parseBuffer from './parseBuffer'
4+
import parseBuffer from './parseBuffer.mjs'
55

66
const getJSXAttributes = (jsxPath) =>
77
_.map(_.get(jsxPath, 'node.attributes'), (attr) => ({

gulp/plugins/util/parseType.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

gulp/plugins/util/parseType.mjs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
await import('@babel/register')
2+
3+
import _ from 'lodash'
4+
5+
const { names } = (await import('../../../src/elements/Flag/Flag.js')).default
6+
const { positions } = (await import('../../../src/modules/Popup/lib/positions.js')).default
7+
const SUI = (await import('../../../src/lib/SUI.js')).default
8+
9+
const evalValue = (value) => eval(value) // eslint-disable-line no-eval
10+
11+
const isTransformable = (value) =>
12+
typeof value === 'string' &&
13+
(value.includes('SUI') || value.includes('names') || value.includes('positions'))
14+
15+
const uniqValues = (values) => {
16+
return values.filter((val, i, arr) => arr.indexOf(`${val}`) === arr.lastIndexOf(`${val}`))
17+
}
18+
19+
const transformEnumValues = (values) => {
20+
return values.flatMap(({ value }) => {
21+
if (value === 'names') {
22+
return evalValue(value)
23+
}
24+
25+
if (value.startsWith('...SUI')) {
26+
return evalValue(value.substring(3))
27+
}
28+
29+
return value.replace(/'/g, '')
30+
})
31+
}
32+
33+
const parseEnum = (propDef) => {
34+
const { value } = propDef.type
35+
36+
if (value) {
37+
if (isTransformable(value)) {
38+
return { ...propDef.type, value: uniqValues(evalValue(value)) }
39+
}
40+
41+
return { ...propDef.type, value: uniqValues(transformEnumValues(value)) }
42+
}
43+
44+
return {
45+
...propDef.type,
46+
value: undefined,
47+
}
48+
}
49+
50+
const parseUnion = (propDef) => {
51+
const { value } = propDef.type
52+
const values = value.filter((v) => v.name === 'enum').flatMap((type) => parseEnum({ type }).value)
53+
54+
return {
55+
...propDef.type,
56+
name: value.map((v) => v.name).join('|'),
57+
value: values,
58+
}
59+
}
60+
61+
const parsers = {
62+
enum: parseEnum,
63+
union: parseUnion,
64+
}
65+
66+
export default function parseType(propName, propDef) {
67+
if (propDef.type === undefined) {
68+
throw new Error(
69+
[
70+
`The prop "${propName}" does not contain propType definition. This happens if the property is in the `,
71+
'defaultProps, but it is not in the propTypes',
72+
].join(' '),
73+
)
74+
}
75+
76+
const parser = parsers[propDef.type.name]
77+
78+
return parser ? parser(propDef) : propDef.type
79+
}

gulp/plugins/util/parserCustomHandler.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)