mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Add TS support (#1370)
Added Typescript support via JSDoc comments for some files. The code has really outdated type signatures, so in order to fully type the codebase the changes need to be incremental. To check the types run: npx tsc
This commit is contained in:
@ -8,7 +8,7 @@ var csstree = require('css-tree'),
|
||||
/**
|
||||
* Flatten a CSS AST to a selectors list.
|
||||
*
|
||||
* @param {Object} cssAst css-tree AST to flatten
|
||||
* @param {import('css-tree').CssNode} cssAst css-tree AST to flatten
|
||||
* @return {Array} selectors
|
||||
*/
|
||||
function flattenToSelectors(cssAst) {
|
||||
@ -29,7 +29,7 @@ function flattenToSelectors(cssAst) {
|
||||
item: selectorItem,
|
||||
atrule: atrule,
|
||||
rule: rule,
|
||||
pseudos: [],
|
||||
pseudos: /** @type {{item: any; list: any[]}[]} */ ([]),
|
||||
};
|
||||
|
||||
selectorNode.children.each(function (
|
||||
@ -108,7 +108,7 @@ function filterByPseudos(selectors, usePseudos) {
|
||||
* Remove pseudo-elements and/or -classes from the selectors for proper matching.
|
||||
*
|
||||
* @param {Array} selectors to clean
|
||||
* @return {Array} Selectors without pseudo-elements and/or -classes
|
||||
* @return {void}
|
||||
*/
|
||||
function cleanPseudos(selectors) {
|
||||
selectors.forEach(function (selector) {
|
||||
@ -124,7 +124,7 @@ function cleanPseudos(selectors) {
|
||||
*
|
||||
* @param {Array} aSpecificity Specificity of selector A
|
||||
* @param {Array} bSpecificity Specificity of selector B
|
||||
* @return {Number} Score of selector specificity A compared to selector specificity B
|
||||
* @return {number} Score of selector specificity A compared to selector specificity B
|
||||
*/
|
||||
function compareSpecificity(aSpecificity, bSpecificity) {
|
||||
for (var i = 0; i < 4; i += 1) {
|
||||
@ -143,7 +143,7 @@ function compareSpecificity(aSpecificity, bSpecificity) {
|
||||
*
|
||||
* @param {Object} aSimpleSelectorNode Simple selector A
|
||||
* @param {Object} bSimpleSelectorNode Simple selector B
|
||||
* @return {Number} Score of selector A compared to selector B
|
||||
* @return {number} Score of selector A compared to selector B
|
||||
*/
|
||||
function compareSimpleSelectorNode(aSimpleSelectorNode, bSimpleSelectorNode) {
|
||||
var aSpecificity = specificity(aSimpleSelectorNode),
|
||||
@ -168,7 +168,7 @@ function sortSelectors(selectors) {
|
||||
/**
|
||||
* Convert a css-tree AST style declaration to CSSStyleDeclaration property.
|
||||
*
|
||||
* @param {Object} declaration css-tree style declaration
|
||||
* @param {import('css-tree').CssNode} declaration css-tree style declaration
|
||||
* @return {Object} CSSStyleDeclaration property
|
||||
*/
|
||||
function csstreeToStyleDeclaration(declaration) {
|
||||
@ -185,8 +185,8 @@ function csstreeToStyleDeclaration(declaration) {
|
||||
/**
|
||||
* Gets the CSS string of a style element
|
||||
*
|
||||
* @param {Object} element style element
|
||||
* @return {String|Array} CSS string or empty array if no styles are set
|
||||
* @param {Object} elem style element
|
||||
* @return {string|Array} CSS string or empty array if no styles are set
|
||||
*/
|
||||
function getCssStr(elem) {
|
||||
return elem.content[0].text || elem.content[0].cdata || [];
|
||||
@ -195,8 +195,8 @@ function getCssStr(elem) {
|
||||
/**
|
||||
* Sets the CSS string of a style element
|
||||
*
|
||||
* @param {Object} element style element
|
||||
* @param {String} CSS string to be set
|
||||
* @param {Object} elem style element
|
||||
* @param {string} css string to be set
|
||||
* @return {Object} reference to field with CSS
|
||||
*/
|
||||
function setCssStr(elem, css) {
|
||||
|
Reference in New Issue
Block a user