Skip to content

Commit eed72ca

Browse files
committed
refactor(many): fix docs parsing for arrow functions
The new parsing algorithm was wrong for cases like const f = () => {}. This patch fixes it
1 parent c1032a0 commit eed72ca

File tree

16 files changed

+90
-81
lines changed

16 files changed

+90
-81
lines changed

packages/__docs__/buildScripts/build-docs.mts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,39 +63,32 @@ const pathsToProcess = [
6363
'CHANGELOG.md',
6464
'**/packages/**/*.md', // package READMEs
6565
'**/docs/**/*.md', // general docs
66-
'**/src/*.{js,ts,tsx}', // util src files
67-
'**/src/*/*.{js,ts,tsx}', // component src files
68-
'**/src/*/*/*.{js,ts,tsx}', // child component src files
66+
'**/src/*.{ts,tsx}', // util src files
67+
'**/src/*/*.{ts,tsx}', // component src files
68+
'**/src/*/*/*.{ts,tsx}', // child component src files
6969
'CODE_OF_CONDUCT.md',
7070
'LICENSE.md'
7171
]
7272

7373
const pathsToIgnore = [
7474
'**/macro.{js,ts}',
75-
'**/*-loader.{js,ts}',
7675
'**/svg/**',
7776
'packages/*/README.md', // main package READMEs
7877
'**/packages/**/CHANGELOG.md',
7978
'**/config/**',
8079
'**/templates/**',
8180
'**/node_modules/**',
8281
'**/__docs__/**',
83-
'**/__svg__/**',
82+
'**/__build__/**',
8483
'**/__fixtures__/**',
8584
'**/__testfixtures__/**',
8685
'**/__tests__/**',
87-
'**/__new-tests__/**',
88-
'**/locales/**',
89-
'**/styles.{js,ts}',
90-
'**/theme.{js,ts}',
91-
'**/props.ts',
92-
'**/locator.{js,ts}',
93-
'**/*Locator.{js,ts}',
94-
86+
'**/styles.{tsx,ts}',
87+
'**/theme.{tsx,ts}',
9588
'**/types/**',
9689

9790
// ignore index files that just re-export
98-
'**/src/index.{js,ts}',
91+
'**/src/index.ts',
9992

10093
// packages to ignore:
10194
'**/canvas-theme/**',
@@ -106,7 +99,7 @@ const pathsToIgnore = [
10699
'**/ui-code-editor/src/CodeMirrorWrapper/**',
107100

108101
// deprecated packages and modules:
109-
'**/InputModeListener.{js,ts}',
102+
'**/InputModeListener.ts',
110103
// regression testing app:
111104
'**/regression-test/**',
112105
]

packages/__docs__/buildScripts/utils/getJSDoc.mts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function extractFunctionData(node: FunctionDeclaration | FunctionExpression | Ar
105105
description: description,
106106
...(parameters.length > 0 && {params: parameters}),
107107
...((genericParameters && genericParameters.length > 0) && {genericParameters: genericParameters}),
108-
...((returnsDesc || returnsType) && {
108+
...((returnsDesc || (returnsType && returnsType !== 'void')) && {
109109
returns: {
110110
description: returnsDesc,
111111
type: returnsType
@@ -131,7 +131,14 @@ function parseNode(node: ts.Node, typeChecker: TypeChecker): JsDocResult | undef
131131
}
132132

133133
let result: JsDocResult | undefined = undefined
134-
if (ts.isVariableStatement(node)) { // e.g. const x = function(){}, y = 5
134+
if (ts.isVariableDeclaration(node)) { // e.g. x=1
135+
if (node.initializer) {
136+
if (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) {
137+
result = extractFunctionData(node.initializer, typeChecker)
138+
}
139+
}
140+
}
141+
else if (ts.isVariableStatement(node)) { // e.g. const x = function(){}, y = 5
135142
for (const d of node.declarationList.declarations) {
136143
if (d.initializer) {
137144
if (ts.isArrowFunction(d.initializer) || ts.isFunctionExpression(d.initializer)) {
@@ -140,12 +147,11 @@ function parseNode(node: ts.Node, typeChecker: TypeChecker): JsDocResult | undef
140147
}
141148
}
142149
}
143-
// e.g. function focusable(el: Element)
144-
if (ts.isFunctionDeclaration(node)) {
150+
else if (ts.isFunctionDeclaration(node)) { // e.g. function focusable(el: Element)
145151
result = extractFunctionData(node, typeChecker)
146152
}
147153
// if it's not a function, then try to parse types from the JSDoc comment
148-
else if (!result) {
154+
if (!result) {
149155
let description = ''
150156
const params: JsDocResult['params'] = []
151157
const docs = ts.getJSDocCommentsAndTags(node)

packages/debounce/src/debounce.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@
2323
*/
2424

2525
interface DebounceOptions {
26+
/**
27+
* Specify invoking on the leading edge of the timeout
28+
*/
2629
leading?: boolean
30+
/**
31+
* The maximum time `func` is allowed to be delayed before it's invoked
32+
*/
2733
maxWait?: number
34+
/**
35+
* Specify invoking on the trailing edge of the timeout
36+
*/
2837
trailing?: boolean
2938
}
3039

@@ -54,16 +63,10 @@ export type Debounced<F extends (...args: any) => any> = F & {
5463
*
5564
* @module debounce
5665
*
57-
* @param {Function} func The function to debounce.
58-
* @param {number} [wait=0] The number of milliseconds to delay.
59-
* @param {Object} [options={}] The options object.
60-
* @param {boolean} [options.leading=false]
61-
* Specify invoking on the leading edge of the timeout.
62-
* @param {number} [options.maxWait]
63-
* The maximum time `func` is allowed to be delayed before it's invoked.
64-
* @param {boolean} [options.trailing=true]
65-
* Specify invoking on the trailing edge of the timeout.
66-
* @returns {Function} Returns the new debounced function.
66+
* @param func The function to debounce.
67+
* @param wait The number of milliseconds to delay.
68+
* @param options options object.
69+
* @returns Returns the new debounced function.
6770
*/
6871
function debounce<F extends (...args: any) => any>(
6972
func: F,

packages/emotion/src/getComponentThemeOverride.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ type ComponentName = keyof ComponentOverride | undefined
3939
* This is a utility function which calculates the correct component theme
4040
* based on every possible override there is.
4141
42-
* @param {object} theme - Theme object
43-
* @param {*} displayName - Name of the component
44-
* @param {*} componentId - componentId of the component
45-
* @param {*} props - The component's props object
46-
* @param {*} componentTheme - The component's default theme
47-
* @returns {object} The calculated theme override object
42+
* @param theme - Theme object
43+
* @param displayName - Name of the component
44+
* @param componentId - componentId of the component
45+
* @param props - The component's props object
46+
* @param componentTheme - The component's default theme
47+
* @returns The calculated theme override object
4848
*/
4949
const getComponentThemeOverride = (
5050
theme: ThemeOrOverride,

packages/ui-color-utils/src/alpha.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import Color from 'tinycolor2'
3030
* ---
3131
* Adjust the alpha transparency of a color
3232
* @module alpha
33-
* @param {String} color
34-
* @param {Number} percent
35-
* @returns {String} color as rgb string
33+
* @param color
34+
* @param percent
35+
* @returns color as rgb string
3636
*/
3737
function alpha(color: string, percent: number): string {
3838
return Color(color)

packages/ui-color-utils/src/contrast.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import Color from 'tinycolor2'
3030
* ---
3131
* check the contrast ratio of 2 colors. Optionally number of decimal places can be added
3232
* @module contrast
33-
* @param {String} color1
34-
* @param {String} color2
35-
* @param {Number} decimalPlaces
36-
* @returns {Number} color contrast ratio
33+
* @param color1
34+
* @param color2
35+
* @param decimalPlaces
36+
* @returns color contrast ratio
3737
*/
3838
const contrast = (
3939
color1: string,

packages/ui-color-utils/src/conversions.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ import type { ColorInputWithoutInstance } from 'tinycolor2'
2727

2828
/**
2929
* Converts any valid `TinyColor` colors to hex string
30-
* @param {ColorInputWithoutInstance} rgb a color string
31-
* @returns {String} a hex string like `#FF0000`
30+
* @param rgb a color string
31+
* @returns a hex string like `#FF0000`
3232
*/
3333
const colorToHex = (rgb: ColorInputWithoutInstance): string => {
3434
return Color(rgb).toHexString().toUpperCase()
3535
}
3636

3737
/**
3838
* Transforms any `TinyColor` to 8 length HEX (alpha included)
39-
* @param {ColorInputWithoutInstance} color representation from `TinyColor`
40-
* @returns {String} An 8 length hex string like `#FF0000FF`
39+
* @param color representation from `TinyColor`
40+
* @returns An 8 length hex string like `#FF0000FF`
4141
*/
4242
const colorToHex8 = (color: ColorInputWithoutInstance): string => {
4343
return Color(color).toHex8String().toUpperCase()
@@ -46,8 +46,8 @@ const colorToHex8 = (color: ColorInputWithoutInstance): string => {
4646
/**
4747
* Transforms any `TinyColor` to RGBA object ( {r:number, g:number, b:number, a:number} )
4848
* also exported as `hexToRgb` for backward compatiblity reasons
49-
* @param {ColorInputWithoutInstance} color representation from `TinyColor`
50-
* @returns {Color.ColorFormats.RGBA} A `TinyColor` RGBA type
49+
* @param color representation from `TinyColor`
50+
* @returns A `TinyColor` RGBA type
5151
*/
5252
const colorToRGB = (
5353
color: ColorInputWithoutInstance
@@ -57,8 +57,8 @@ const colorToRGB = (
5757

5858
/**
5959
* Transforms any `TinyColor` to HSVA object ( {h:number, s:number, v:number, a:number} )
60-
* @param {ColorInputWithoutInstance} color representation from `TinyColor`
61-
* @returns {Color.ColorFormats.HSVA} A `TinyColor` HSVA type
60+
* @param color representation from `TinyColor`
61+
* @returns A `TinyColor` HSVA type
6262
*/
6363
const colorToHsva = (
6464
color: ColorInputWithoutInstance
@@ -68,8 +68,8 @@ const colorToHsva = (
6868

6969
/**
7070
* Transforms any `TinyColor` to HSLA object ( {h:number, s:number, l:number, a:number} )
71-
* @param {ColorInputWithoutInstance} color representation from `TinyColor`
72-
* @returns {Color.ColorFormats.HSLA} A `TinyColor` HSLA type
71+
* @param color representation from `TinyColor`
72+
* @returns A `TinyColor` HSLA type
7373
*/
7474
const colorToHsla = (
7575
color: ColorInputWithoutInstance

packages/ui-color-utils/src/validateContrast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interface ValidatedContrasts {
4949
*
5050
* @module validateContrast
5151
* @param contrast
52-
* @param validationLevel
52+
* @param validationLevel WCAG 2.2 validation level
5353
* @returns validation object
5454
*/
5555
const validateContrast = (

packages/ui-dom-utils/src/handleMouseOverOut.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ import { contains } from './contains'
3636
* from one child element to another.
3737
*
3838
* @module handleMouseOverOut
39-
* @param handler {function} Callback function for handling the event
40-
* @param event {Event} The DOM Event that was fired
39+
* @param handler Callback function for handling the event
40+
* @param event The DOM Event that was fired
4141
*/
4242
function handleMouseOverOut(
4343
handler: (event: React.MouseEvent) => void,

packages/ui-react-utils/src/ensureSingleChild.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import { safeCloneElement } from './safeCloneElement'
3535
* wrap in a span and return the child. Return null if child has
3636
* no length.
3737
* @module ensureSingleChild
38-
* @param {ReactNode} child
39-
* @param {Object} props - props for child
40-
* @returns {ReactElement|null} cloned instance for a single child, or children wrapped in a span
38+
* @param child
39+
* @param props props for child
40+
* @returns cloned instance for a single child, or children wrapped in a span
4141
*/
4242
function ensureSingleChild(child: ReactNode, props = {}) {
4343
const childCount = Children.count(child)

0 commit comments

Comments
 (0)