Skip to content

Commit

Permalink
chore: update TypeScript and improve types (#1404)
Browse files Browse the repository at this point in the history
* chore: update TypeScript and improve types
  • Loading branch information
ludofischer committed May 29, 2022
1 parent 0d62a4c commit 4dc2fc5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"postcss-simple-vars": "^6.0.1",
"postcss-value-parser": "^4.2.0",
"prettier": "^2.6.2",
"typescript": "^4.6.4",
"typescript": "^4.7.2",
"uvu": "^0.5.3"
},
"browserslist": {
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-convert-values/src/lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function dropLeadingZero(number) {
/**
* @param {number} number
* @param {string} originalUnit
* @param {Map<string, number>} conversions
* @param {lengthConv | timeConv | angleConv} conversions
* @return {string}
*/
function transform(number, originalUnit, conversions) {
Expand Down
7 changes: 2 additions & 5 deletions packages/postcss-discard-comments/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ function pluginCreator(opts = {}) {
return;
}

if (node.raws.between) {
node.raws.between = replaceComments(
/** @type {string} */ (node.raws.between),
list.space
);
if (typeof node.raws.between === 'string') {
node.raws.between = replaceComments(node.raws.between, list.space);
}

if (node.type === 'decl') {
Expand Down
38 changes: 22 additions & 16 deletions packages/postcss-merge-rules/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function indexOfDeclaration(array, decl) {
*/
function intersect(a, b, not) {
return a.filter((c) => {
const index = ~indexOfDeclaration(b, c);
const index = indexOfDeclaration(b, c) !== -1;
return not ? !index : index;
});
}
Expand Down Expand Up @@ -74,21 +74,32 @@ function canMerge(ruleA, ruleB, browsers, compatibilityCache) {
/** @type {any} */ (ruleA),
/** @type {any} */ (ruleB)
);
const { name } = /** @type {any} */ (ruleA).parent;
if (parent && name && name.includes('keyframes')) {
if (
parent &&
ruleA.parent &&
ruleA.parent.type === 'atrule' &&
/** @type {import('postcss').AtRule} */ (ruleA.parent).name.includes(
'keyframes'
)
) {
return false;
}
return parent && (selectors.every(noVendor) || sameVendor(a, b));
}

/**
* @param {import('postcss').ChildNode} node
* @return {node is import('postcss').Declaration}
*/
function isDeclaration(node) {
return node.type === 'decl';
}
/**
* @param {import('postcss').Rule} rule
* @return {import('postcss').Declaration[]}
*/
function getDecls(rule) {
return /** @type {import('postcss').Declaration[]} */ (
rule.nodes.filter((node) => node.type === 'decl')
);
return rule.nodes.filter(isDeclaration);
}

/** @type {(...rules: import('postcss').Rule[]) => string} */
Expand Down Expand Up @@ -290,7 +301,7 @@ function partialMerge(first, second) {
*/
function moveDecl(callback) {
return (decl) => {
if (~indexOfDeclaration(intersection, decl)) {
if (indexOfDeclaration(intersection, decl) !== -1) {
callback.call(this, decl);
}
};
Expand Down Expand Up @@ -359,17 +370,12 @@ function selectorMerger(browsers, compatibilityCache) {
// e.g. a { color: blue } a { font-weight: bold }
if (cache.selector === rule.selector) {
const cached = getDecls(cache);
rule.walk((decl) => {
if (
~indexOfDeclaration(
cached,
/** @type {import('postcss').Declaration} */ (decl)
)
) {
decl.remove();
rule.walk((node) => {
if (node.type === 'decl' && indexOfDeclaration(cached, node) !== -1) {
node.remove();
return;
}
/** @type {import('postcss').Rule} */ (cache).append(decl);
/** @type {import('postcss').Rule} */ (cache).append(node);
});
rule.remove();
return;
Expand Down
11 changes: 4 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4dc2fc5

Please sign in to comment.