mirror of
https://github.com/antebudimir/eslint-plugin-vanilla-extract.git
synced 2026-01-01 01:13:32 +00:00
feat 🥁: initialize project with complete codebase
This commit is contained in:
commit
d569dea1fb
35 changed files with 4413 additions and 0 deletions
57
src/css-rules/shared-utils/property-separator.ts
Normal file
57
src/css-rules/shared-utils/property-separator.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { TSESTree } from '@typescript-eslint/utils';
|
||||
|
||||
/**
|
||||
* Extracts the name of a property from a TSESTree.Property node.
|
||||
* @param property The property node to extract the name from.
|
||||
* @returns The name of the property as a string, or an empty string if the name cannot be determined.
|
||||
*
|
||||
* This function handles two types of property keys:
|
||||
* - Identifier: Returns the name directly.
|
||||
* - Literal (string): Returns the string value.
|
||||
* For any other type of key, it returns an empty string.
|
||||
*/
|
||||
export const getPropertyName = (property: TSESTree.Property): string => {
|
||||
if (property.key.type === 'Identifier') {
|
||||
return property.key.name;
|
||||
} else if (property.key.type === 'Literal' && typeof property.key.value === 'string') {
|
||||
return property.key.value;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
/**
|
||||
* Separates object properties into regular and special categories.
|
||||
* @param properties An array of object literal elements to be categorized.
|
||||
* @returns An object containing two arrays: regularProperties and specialProperties.
|
||||
*
|
||||
* This function categorizes properties as follows:
|
||||
* - Regular properties: Standard CSS properties.
|
||||
* - Special properties: Properties that start with ':' (pseudo-selectors),
|
||||
* '@' (at-rules), or are named 'selectors'.
|
||||
*
|
||||
* Non-Property type elements in the input array are ignored.
|
||||
*/
|
||||
export const separateProperties = (
|
||||
properties: TSESTree.ObjectLiteralElement[],
|
||||
): {
|
||||
regularProperties: TSESTree.Property[];
|
||||
specialProperties: TSESTree.Property[];
|
||||
} => {
|
||||
const regularProperties: TSESTree.Property[] = [];
|
||||
const specialProperties: TSESTree.Property[] = [];
|
||||
|
||||
// Separate regular CSS properties from special ones (pseudo selectors, etc.)
|
||||
properties.forEach((property) => {
|
||||
if (property.type === 'Property') {
|
||||
const propName = getPropertyName(property);
|
||||
|
||||
if (propName.startsWith(':') || propName.startsWith('@') || propName === 'selectors') {
|
||||
specialProperties.push(property);
|
||||
} else {
|
||||
regularProperties.push(property);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return { regularProperties, specialProperties };
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue