Skip to content

Commit cf0ad92

Browse files
Add jsdoc typings for autocompletion
1 parent 359a58e commit cf0ad92

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/index.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ function renderToString(vnode, context, opts) {
8989
return res;
9090
}
9191

92+
/**
93+
* @param {VNode} vnode
94+
* @param {Record<string, unknown>} context
95+
* @returns {string}
96+
*/
9297
function renderFunctionComponent(vnode, context) {
98+
// eslint-disable-next-line lines-around-comment
99+
/** @type {string} */
93100
let rendered,
94101
c = createComponent(vnode, context),
95102
cctx = getContext(vnode.type, context);
@@ -115,11 +122,16 @@ function renderFunctionComponent(vnode, context) {
115122
return rendered;
116123
}
117124

125+
/**
126+
* @param {VNode} vnode
127+
* @param {Record<string, unknown>} context
128+
* @returns {VNode}
129+
*/
118130
function renderClassComponent(vnode, context) {
119131
let nodeName = vnode.type,
120132
cctx = getContext(nodeName, context);
121133

122-
// c = new nodeName(props, context);
134+
/** @type {import("preact").Component} */
123135
let c = new nodeName(vnode.props, cctx);
124136
vnode[COMPONENT] = c;
125137
c[VNODE] = vnode;
@@ -153,6 +165,11 @@ function renderClassComponent(vnode, context) {
153165
return c.render(c.props, c.state, c.context);
154166
}
155167

168+
/**
169+
* @param {string} name
170+
* @param {boolean} isSvgMode
171+
* @returns {string}
172+
*/
156173
function normalizePropName(name, isSvgMode) {
157174
if (name === 'className') {
158175
return 'class';
@@ -171,6 +188,11 @@ function normalizePropName(name, isSvgMode) {
171188
return name;
172189
}
173190

191+
/**
192+
* @param {string} name
193+
* @param {string | Record<string, unknown>} v
194+
* @returns {string}
195+
*/
174196
function normalizePropValue(name, v) {
175197
if (name === 'style' && v != null && typeof v === 'object') {
176198
return styleObjToCss(v);
@@ -186,7 +208,15 @@ function normalizePropValue(name, v) {
186208
const isArray = Array.isArray;
187209
const assign = Object.assign;
188210

189-
/** The default export is an alias of `render()`. */
211+
/**
212+
* The default export is an alias of `render()`.
213+
* @param {any} vnode
214+
* @param {Record<string, unknown>} context
215+
* @param {boolean} isSvgMode
216+
* @param {any} selectValue
217+
* @param {VNode | null} parent
218+
* @returns {string}
219+
*/
190220
function _renderToString(vnode, context, isSvgMode, selectValue, parent) {
191221
// Ignore non-rendered VNodes/values
192222
if (vnode == null || vnode === true || vnode === false || vnode === '') {

0 commit comments

Comments
 (0)