Skip to content

Commit 6677d0c

Browse files
committed
chore: bulk update all jsdoc and jsdoctypes
1 parent 9eb3af5 commit 6677d0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+553
-499
lines changed

lib/parser.js

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,28 @@ const config = {
8686
/**
8787
* Convert SVG (XML) string to SVG-as-JS object.
8888
*
89-
* @type {(data: string, from?: string) => XastRoot}
89+
* @param {string} data
90+
* @param {string=} from
91+
* @returns {XastRoot}
9092
*/
9193
export const parseSvg = (data, from) => {
9294
const sax = SAX.parser(config.strict, config);
93-
/**
94-
* @type {XastRoot}
95-
*/
95+
/** @type {XastRoot} */
9696
const root = { type: 'root', children: [] };
97-
/**
98-
* @type {XastParent}
99-
*/
97+
/** @type {XastParent} */
10098
let current = root;
101-
/**
102-
* @type {XastParent[]}
103-
*/
99+
/** @type {XastParent[]} */
104100
const stack = [root];
105101

106102
/**
107-
* @type {(node: XastChild) => void}
103+
* @param {XastChild} node
108104
*/
109105
const pushToContent = (node) => {
110106
current.children.push(node);
111107
};
112108

113109
sax.ondoctype = (doctype) => {
114-
/**
115-
* @type {XastDoctype}
116-
*/
110+
/** @type {XastDoctype} */
117111
const node = {
118112
type: 'doctype',
119113
// TODO parse doctype for name, public and system to match xast
@@ -135,9 +129,7 @@ export const parseSvg = (data, from) => {
135129
};
136130

137131
sax.onprocessinginstruction = (data) => {
138-
/**
139-
* @type {XastInstruction}
140-
*/
132+
/** @type {XastInstruction} */
141133
const node = {
142134
type: 'instruction',
143135
name: data.name,
@@ -147,9 +139,7 @@ export const parseSvg = (data, from) => {
147139
};
148140

149141
sax.oncomment = (comment) => {
150-
/**
151-
* @type {XastComment}
152-
*/
142+
/** @type {XastComment} */
153143
const node = {
154144
type: 'comment',
155145
value: comment.trim(),
@@ -158,9 +148,7 @@ export const parseSvg = (data, from) => {
158148
};
159149

160150
sax.oncdata = (cdata) => {
161-
/**
162-
* @type {XastCdata}
163-
*/
151+
/** @type {XastCdata} */
164152
const node = {
165153
type: 'cdata',
166154
value: cdata,
@@ -169,9 +157,7 @@ export const parseSvg = (data, from) => {
169157
};
170158

171159
sax.onopentag = (data) => {
172-
/**
173-
* @type {XastElement}
174-
*/
160+
/** @type {XastElement} */
175161
let element = {
176162
type: 'element',
177163
name: data.name,
@@ -190,18 +176,14 @@ export const parseSvg = (data, from) => {
190176
if (current.type === 'element') {
191177
// prevent trimming of meaningful whitespace inside textual tags
192178
if (textElems.has(current.name)) {
193-
/**
194-
* @type {XastText}
195-
*/
179+
/** @type {XastText} */
196180
const node = {
197181
type: 'text',
198182
value: text,
199183
};
200184
pushToContent(node);
201185
} else if (/\S/.test(text)) {
202-
/**
203-
* @type {XastText}
204-
*/
186+
/** @type {XastText} */
205187
const node = {
206188
type: 'text',
207189
value: text.trim(),

lib/path.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { removeLeadingZero, toFixed } from './svgo/tools.js';
44
* @typedef {import('./types.js').PathDataItem} PathDataItem
55
* @typedef {import('./types.js').PathDataCommand} PathDataCommand
66
* @typedef {'none' | 'sign' | 'whole' | 'decimal_point' | 'decimal' | 'e' | 'exponent_sign' | 'exponent'} ReadNumberState
7+
*
8+
* @typedef StringifyPathDataOptions
9+
* @property {PathDataItem[]} pathData
10+
* @property {number=} precision
11+
* @property {boolean=} disableSpaceAfterFlags
712
*/
813

914
// Based on https://www.w3.org/TR/SVG11/paths.html#PathDataBNF
@@ -32,7 +37,8 @@ const argsCountPerCommand = {
3237
};
3338

3439
/**
35-
* @type {(c: string) => c is PathDataCommand}
40+
* @param {string} c
41+
* @returns {c is PathDataCommand}
3642
*/
3743
const isCommand = (c) => {
3844
return c in argsCountPerCommand;
@@ -59,7 +65,9 @@ const isDigit = (c) => {
5965
};
6066

6167
/**
62-
* @type {(string: string, cursor: number) => [number, ?number]}
68+
* @param {string} string
69+
* @param {number} cursor
70+
* @returns {[number, ?number]}
6371
*/
6472
const readNumber = (string, cursor) => {
6573
let i = cursor;
@@ -130,13 +138,9 @@ const readNumber = (string, cursor) => {
130138
* @returns {PathDataItem[]}
131139
*/
132140
export const parsePathData = (string) => {
133-
/**
134-
* @type {PathDataItem[]}
135-
*/
141+
/** @type {PathDataItem[]} */
136142
const pathData = [];
137-
/**
138-
* @type {?PathDataCommand}
139-
*/
143+
/** @type {?PathDataCommand} */
140144
let command = null;
141145
let args = /** @type {number[]} */ ([]);
142146
let argsCount = 0;
@@ -232,10 +236,9 @@ export const parsePathData = (string) => {
232236
};
233237

234238
/**
235-
* @type {(number: number, precision?: number) => {
236-
* roundedStr: string,
237-
* rounded: number
238-
* }}
239+
* @param {number} number
240+
* @param {number=} precision
241+
* @returns {{ roundedStr: string, rounded: number }}
239242
*/
240243
const roundAndStringify = (number, precision) => {
241244
if (precision != null) {
@@ -252,12 +255,11 @@ const roundAndStringify = (number, precision) => {
252255
* Elliptical arc large-arc and sweep flags are rendered with spaces
253256
* because many non-browser environments are not able to parse such paths
254257
*
255-
* @type {(
256-
* command: string,
257-
* args: number[],
258-
* precision?: number,
259-
* disableSpaceAfterFlags?: boolean
260-
* ) => string}
258+
* @param {string} command
259+
* @param {number[]} args
260+
* @param {number=} precision
261+
* @param {boolean=} disableSpaceAfterFlags
262+
* @returns {string}
261263
*/
262264
const stringifyArgs = (command, args, precision, disableSpaceAfterFlags) => {
263265
let result = '';
@@ -288,14 +290,6 @@ const stringifyArgs = (command, args, precision, disableSpaceAfterFlags) => {
288290
return result;
289291
};
290292

291-
/**
292-
* @typedef {{
293-
* pathData: PathDataItem[];
294-
* precision?: number;
295-
* disableSpaceAfterFlags?: boolean;
296-
* }} StringifyPathDataOptions
297-
*/
298-
299293
/**
300294
* @param {StringifyPathDataOptions} options
301295
* @returns {string}

lib/path.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ describe('stringify path data', () => {
154154
).toBe('M.1 1e-7 2 2');
155155
});
156156
it('should configure precision', () => {
157-
/**
158-
* @type {PathDataItem[]}
159-
*/
157+
/** @type {PathDataItem[]} */
160158
const pathData = [
161159
{ command: 'M', args: [0, -1.9876] },
162160
{ command: 'L', args: [0.3, 3.14159265] },
@@ -177,9 +175,7 @@ describe('stringify path data', () => {
177175
).toBe('M0-2 0 3 0-3 100 200');
178176
});
179177
it('allows to avoid spaces after arc flags', () => {
180-
/**
181-
* @type {PathDataItem[]}
182-
*/
178+
/** @type {PathDataItem[]} */
183179
const pathData = [
184180
{ command: 'M', args: [0, 0] },
185181
{ command: 'A', args: [50, 50, 10, 1, 0, 0.2, 20] },

lib/stringifier.js

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ import { textElems } from '../plugins/_collections.js';
1010
* @typedef {import('./types.js').XastCdata} XastCdata
1111
* @typedef {import('./types.js').XastComment} XastComment
1212
* @typedef {import('./types.js').StringifyOptions} StringifyOptions
13-
* @typedef {{
14-
* indent: string,
15-
* textContext: ?XastElement,
16-
* indentLevel: number,
17-
* }} State
1813
* @typedef {Required<StringifyOptions>} Options
14+
*
15+
* @typedef State
16+
* @property {string} indent
17+
* @property {?XastElement} textContext
18+
* @property {number} indentLevel
1919
*/
2020

2121
/**
22-
* @type {(char: string) => string}
22+
* @param {string} char
23+
* @returns {string}
2324
*/
2425
const encodeEntity = (char) => {
2526
return entities[char];
@@ -65,9 +66,11 @@ const entities = {
6566
};
6667

6768
/**
68-
* convert XAST to SVG string
69+
* Converts XAST to SVG string.
6970
*
70-
* @type {(data: XastRoot, userOptions?: StringifyOptions) => string}
71+
* @param {XastRoot} data
72+
* @param {StringifyOptions=} userOptions
73+
* @returns {string}
7174
*/
7275
export const stringifySvg = (data, userOptions = {}) => {
7376
/** @type {Options} */
@@ -104,7 +107,10 @@ export const stringifySvg = (data, userOptions = {}) => {
104107
};
105108

106109
/**
107-
* @type {(node: XastParent, config: Options, state: State) => string}
110+
* @param {XastParent} data
111+
* @param {Options} config
112+
* @param {State} state
113+
* @returns {string}
108114
*/
109115
const stringifyNode = (data, config, state) => {
110116
let svg = '';
@@ -134,9 +140,11 @@ const stringifyNode = (data, config, state) => {
134140
};
135141

136142
/**
137-
* create indent string in accordance with the current node level.
143+
* Create indent string in accordance with the current node level.
138144
*
139-
* @type {(config: Options, state: State) => string}
145+
* @param {Options} config
146+
* @param {State} state
147+
* @returns {string}
140148
*/
141149
const createIndent = (config, state) => {
142150
let indent = '';
@@ -147,14 +155,18 @@ const createIndent = (config, state) => {
147155
};
148156

149157
/**
150-
* @type {(node: XastDoctype, config: Options) => string}
158+
* @param {XastDoctype} node
159+
* @param {Options} config
160+
* @returns {string}
151161
*/
152162
const stringifyDoctype = (node, config) => {
153163
return config.doctypeStart + node.data.doctype + config.doctypeEnd;
154164
};
155165

156166
/**
157-
* @type {(node: XastInstruction, config: Options) => string}
167+
* @param {XastInstruction} node
168+
* @param {Options} config
169+
* @returns {string}
158170
*/
159171
const stringifyInstruction = (node, config) => {
160172
return (
@@ -163,14 +175,19 @@ const stringifyInstruction = (node, config) => {
163175
};
164176

165177
/**
166-
* @type {(node: XastComment, config: Options) => string}
178+
* @param {XastComment} node
179+
* @param {Options} config
180+
* @returns {string}
167181
*/
168182
const stringifyComment = (node, config) => {
169183
return config.commentStart + node.value + config.commentEnd;
170184
};
171185

172186
/**
173-
* @type {(node: XastCdata, config: Options, state: State) => string}
187+
* @param {XastCdata} node
188+
* @param {Options} config
189+
* @param {State} state
190+
* @returns {string}
174191
*/
175192
const stringifyCdata = (node, config, state) => {
176193
return (
@@ -182,7 +199,10 @@ const stringifyCdata = (node, config, state) => {
182199
};
183200

184201
/**
185-
* @type {(node: XastElement, config: Options, state: State) => string}
202+
* @param {XastElement} node
203+
* @param {Options} config
204+
* @param {State} state
205+
* @returns {string}
186206
*/
187207
const stringifyElement = (node, config, state) => {
188208
// empty element and short tag
@@ -251,7 +271,9 @@ const stringifyElement = (node, config, state) => {
251271
};
252272

253273
/**
254-
* @type {(node: XastElement, config: Options) => string}
274+
* @param {XastElement} node
275+
* @param {Options} config
276+
* @returns {string}
255277
*/
256278
const stringifyAttributes = (node, config) => {
257279
let attrs = '';
@@ -270,7 +292,10 @@ const stringifyAttributes = (node, config) => {
270292
};
271293

272294
/**
273-
* @type {(node: XastText, config: Options, state: State) => string}
295+
* @param {XastText} node
296+
* @param {Options} config
297+
* @param {State} state
298+
* @returns {string}
274299
*/
275300
const stringifyText = (node, config, state) => {
276301
return (

0 commit comments

Comments
 (0)